diff options
author | neoraider <devnull@localhost> | 2007-09-16 22:59:04 +0200 |
---|---|---|
committer | neoraider <devnull@localhost> | 2007-09-16 22:59:04 +0200 |
commit | 96e9d04527dc17a2a4f8c2f7034c1c356ed5186e (patch) | |
tree | 20bc1fe6fd680005c47c49396aca5b6e237e1c7d /Rectangle.h | |
parent | 5ea7f0464eb13581322215f0614eaae52393e02a (diff) | |
download | zoomedit-96e9d04527dc17a2a4f8c2f7034c1c356ed5186e.tar zoomedit-96e9d04527dc17a2a4f8c2f7034c1c356ed5186e.zip |
zoomedit: C++ized Line & Rectangle
Diffstat (limited to 'Rectangle.h')
-rw-r--r-- | Rectangle.h | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/Rectangle.h b/Rectangle.h new file mode 100644 index 0000000..8a61321 --- /dev/null +++ b/Rectangle.h @@ -0,0 +1,54 @@ +#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() {} + Rectangle(const Vertex& v1, const Vertex& v2) { + this->v1 = v1; this->v2 = v2; + } + Rectangle(double x, double y, double width, double height) { + v1.setLocation(x, y); + v2.setLocation(x+width, y+height); + } + + 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;} + + double getWidth() const {return v2.getX()-v1.getX();} + void setWidth(double width) {v2.setX(v1.getX()+width);} + + double getHeight() const {return v2.getY()-v1.getY();} + void setHeight(double height) {v2.setY(v1.getY()+height);} + + double area() const {return getWidth()*getHeight();} + + 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_*/ |