19 #include <ubit/uobject.hpp> 30 UPoint(
float _x,
float _y) : x(_x), y(_y) {}
32 float getX()
const {
return x;}
33 float getY()
const {
return y;}
35 void set(
float _x,
float _y) {x = _x, y = _y;}
36 void set(
const UPoint& p) {*
this = p;}
60 UDimension(
float _w,
float _h) : width(_w), height(_h) {}
62 float getWidth()
const {
return width;}
63 float getHeight()
const {
return height;}
65 void set(
float _w,
float _h) {width = _w, height = _h;}
97 virtual int getShapeType()
const = 0;
99 virtual URect getBounds()
const = 0;
102 virtual bool contains(
const UPoint&)
const = 0;
105 virtual bool contains(
const URect&)
const = 0;
108 virtual bool intersects(
const URect&)
const = 0;
111 virtual void draw(
const UGraph&)
const = 0;
112 virtual void fill(
const UGraph&)
const = 0;
124 int getShapeType()
const {
return LINE;}
129 URect getBounds()
const;
130 UPoint getP1()
const {
return p1;}
131 UPoint getP2()
const {
return p2;}
133 virtual void setLine(
const UPoint& _p1,
const UPoint& _p2) {p1 = _p1; p2 = _p2;}
134 virtual void setLine(
const ULine& l) {*
this = l;}
139 bool intersects(
const URect&)
const;
142 bool intersectsLine(
const ULine&)
const;
155 int relativeCCW(
const UPoint&)
const;
158 virtual void draw(
const UGraph&)
const;
159 virtual void fill(
const UGraph&)
const {};
169 float x, y, width, height;
171 int getShapeType()
const {
return RECT;}
173 URect() : x(0), y(0), width(0), height(0) {}
174 URect(
float _x,
float _y,
float _w,
float _h) : x(_x), y(_y), width(_w), height(_h) {}
178 bool isEmpty()
const {
return width <= 0.0 || height <= 0.0;}
180 void setRect(
const URect& r) {*
this = r;}
181 void setRect(
float x,
float y,
float width,
float height);
183 void setFrame(
const URect& r) {*
this = r;}
185 bool contains(
const UPoint&)
const;
186 bool contains(
const URect&)
const;
188 bool intersects(
const URect&)
const;
191 bool intersectsLine(
const ULine&)
const;
194 bool doIntersection(
const URect&);
199 void doUnion(
const URect&);
204 enum {OUT_LEFT = 1, OUT_TOP = 2, OUT_RIGHT = 4, OUT_BOTTOM = 8};
206 int outcode(
const UPoint& p)
const;
209 virtual void draw(
const UGraph&)
const;
210 virtual void fill(
const UGraph&)
const;
220 float x, y, width, height;
222 int getShapeType()
const {
return ELLIPSE;}
226 UEllipse(
float x,
float y,
float weight,
float height);
228 URect getBounds()
const;
229 bool isEmpty()
const {
return width <= 0.0 || height <= 0.0;}
231 void setFrame(
const URect&);
232 void setFrame(
float x,
float y,
float width,
float height);
234 bool contains(
float x,
float y)
const;
235 bool contains(
const UPoint&)
const;
236 bool contains(
const URect&)
const;
237 bool intersects(
const URect&)
const;
239 virtual void draw(
const UGraph&)
const;
240 virtual void fill(
const UGraph&)
const;
250 virtual int getShapeType()
const {
return POLYGON;}
257 UPolygon(
const std::vector<UPoint>& points,
bool closed =
true);
269 UPolygon& addPoints(
const std::vector<UPoint>& points);
272 UPolygon& addPoints(
const float* _points,
int _npoints);
278 void translate(
float dx,
float dy);
284 bool contains(
const UPoint&)
const;
285 bool contains(
const URect&)
const;
286 bool intersects(
const URect&)
const;
288 void draw(
const UGraph&)
const;
289 void fill(
const UGraph&)
const;
292 int npoints, memsize;
296 int evaluateCrossings(
float x,
float y,
bool useYaxis,
float distance)
const;
298 void updateBounds(
float x,
float y);
2D Dimension.
Definition: ugeom.hpp:55
2D Point.
Definition: ugeom.hpp:25
2D Ellipse.
Definition: ugeom.hpp:216
URect getBounds() const
returns the bounding box of this shape.
Definition: ugeom.hpp:177
2D Line.
Definition: ugeom.hpp:118
bool contains(const UPoint &) const
tests if a given point is inside the boundary of this Shape.
Definition: ugeom.hpp:136
class for drawing on widgets.
Definition: ugraph.hpp:44
2D Rectangle.
Definition: ugeom.hpp:165
friend std::istream & operator>>(std::istream &, UPoint &)
reads the point from an input stream (eg: cin >> point).
URect getBounds() const
returns the bounding box of the polygon.
Definition: ugeom.hpp:275
bool contains(const URect &) const
tests if the interior of this Shape entirely contains the specified Rectangle
Definition: ugeom.hpp:137
Abstract Base class for geometrical shapes.
Definition: ugeom.hpp:85
friend std::ostream & operator<<(std::ostream &, const UPoint &)
prints the point on an output stream (eg: cout << point).
Definition: uhardfont.hpp:31
2D Polygon or Polyline.
Definition: ugeom.hpp:246
Base class of most Ubit objects (SEE DETAILS!).
Definition: uobject.hpp:113