5 //this module should contain some classes for geometrical transformations
6 //usable with selections, etc... once it's done, that is. :)
13 CxPoint2::CxPoint2(float const x_, float const y_)
19 CxPoint2::CxPoint2(CxPoint2 const &p)
25 float CxPoint2::Distance(CxPoint2 const p2)
27 return (float)sqrt((x-p2.x)*(x-p2.x)+(y-p2.y)*(y-p2.y));
30 float CxPoint2::Distance(float const x_, float const y_)
32 return (float)sqrt((x-x_)*(x-x_)+(y-y_)*(y-y_));
39 CxRect2::CxRect2(float const x1_, float const y1_, float const x2_, float const y2_)
47 CxRect2::CxRect2(CxRect2 const &p)
53 float CxRect2::Surface() const
55 * Returns the surface of rectangle.
58 return (topRight.x-botLeft.x)*(topRight.y-botLeft.y);
61 CxRect2 CxRect2::CrossSection(CxRect2 const &r2) const
63 * Returns crossection with another rectangle.
67 cs.botLeft.x=__max(botLeft.x, r2.botLeft.x);
68 cs.botLeft.y=__max(botLeft.y, r2.botLeft.y);
69 cs.topRight.x=__min(topRight.x, r2.topRight.x);
70 cs.topRight.y=__min(topRight.y, r2.topRight.y);
71 if (cs.botLeft.x<=cs.topRight.x && cs.botLeft.y<=cs.topRight.y) {
74 return CxRect2(0,0,0,0);
78 CxPoint2 CxRect2::Center() const
80 * Returns the center point of rectangle.
83 return CxPoint2((topRight.x+botLeft.x)/2.0f, (topRight.y+botLeft.y)/2.0f);
86 float CxRect2::Width() const
87 //returns rectangle width
89 return topRight.x-botLeft.x;
92 float CxRect2::Height() const
93 //returns rectangle height
95 return topRight.y-botLeft.y;