2007-09-16 20:59:04 +00:00
|
|
|
#ifndef RECTANGLE_H_
|
|
|
|
#define RECTANGLE_H_
|
|
|
|
|
|
|
|
#include "Vertex.h"
|
|
|
|
#include "Line.h"
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
|
|
|
|
#define EDGE_NONE 0
|
|
|
|
#define EDGE_LEFT (1<<0)
|
|
|
|
#define EDGE_RIGHT (1<<1)
|
|
|
|
#define EDGE_TOP (1<<2)
|
|
|
|
#define EDGE_BOTTOM (1<<3)
|
|
|
|
#define EDGE_ALL (EDGE_LEFT|EDGE_RIGHT|EDGE_TOP|EDGE_BOTTOM)
|
|
|
|
|
|
|
|
class Rectangle {
|
|
|
|
private:
|
|
|
|
Vertex v1, v2;
|
|
|
|
public:
|
|
|
|
Rectangle() {}
|
2007-09-21 21:47:05 +00:00
|
|
|
Rectangle(const Vertex& vertex1, const Vertex& vertex2) : v1(vertex1), v2(vertex2) {}
|
2007-09-26 19:28:04 +00:00
|
|
|
Rectangle(float x, float y, float width, float height)
|
2007-09-21 21:47:05 +00:00
|
|
|
: v1(x, y), v2(x+width, y+height) {}
|
2007-09-16 20:59:04 +00:00
|
|
|
|
|
|
|
Vertex &getVertex1() {return v1;}
|
|
|
|
const Vertex &getVertex1() const {return v1;}
|
|
|
|
void setVertex1(const Vertex &v) {v1 = v;}
|
|
|
|
|
|
|
|
Vertex &getVertex2() {return v2;}
|
|
|
|
const Vertex &getVertex2() const {return v2;}
|
|
|
|
void setVertex2(const Vertex &v) {v2 = v;}
|
|
|
|
|
2007-09-26 19:28:04 +00:00
|
|
|
float getWidth() const {return v2.getX()-v1.getX();}
|
|
|
|
void setWidth(float width) {v2.setX(v1.getX()+width);}
|
2007-09-16 20:59:04 +00:00
|
|
|
|
2007-09-26 19:28:04 +00:00
|
|
|
float getHeight() const {return v2.getY()-v1.getY();}
|
|
|
|
void setHeight(float height) {v2.setY(v1.getY()+height);}
|
2007-09-16 20:59:04 +00:00
|
|
|
|
2007-09-26 19:28:04 +00:00
|
|
|
float area() const {return getWidth()*getHeight();}
|
2007-09-16 20:59:04 +00:00
|
|
|
|
|
|
|
bool contains(const Vertex &v) const;
|
|
|
|
|
|
|
|
int edges(const Vertex &v) const;
|
|
|
|
|
|
|
|
int intersects(const Line &l, Vertex *v, int edge = EDGE_NONE) const;
|
|
|
|
int intersects(const Line &l, Vertex *v1, Vertex *v2, int edge = EDGE_NONE) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif /*RECTANGLE_H_*/
|