Changeset 866
 Timestamp:
 04/07/19 03:16:14 (4 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

cpp/common/2d.h
r856 r866 88 88 template <typename Q> const XYRect& operator=(const Q& other) { p = other.p; size = other.size; return *this; } 89 89 90 T right() const { return p.x+size.x;}91 T bottom() const { return p.y+size.y;}92 T top() const { return p.y;}93 T left() const { return p.x;}94 XY<T> center() const { return p+size/2;}95 const XY<T>& topLeft() const { return p;}96 XY<T> bottomRight() const { return p+size;}97 XY<T> topRight() const { return XY<T>(p.x+size.x,p.y);}98 XY<T> bottomLeft() const { return XY<T>(p.x,p.y+size.y);}99 90 T right() const { return p.x + size.x; } 91 T bottom() const { return p.y + size.y; } 92 T top() const { return p.y; } 93 T left() const { return p.x; } 94 XY<T> center() const { return p + size / 2; } 95 const XY<T>& topLeft() const { return p; } 96 XY<T> bottomRight() const { return p + size; } 97 XY<T> topRight() const { return XY<T>(p.x + size.x, p.y); } 98 XY<T> bottomLeft() const { return XY<T>(p.x, p.y + size.y); } 99 100 100 T area() const { return size.x*size.y; } 101 101 … … 120 120 bool contains(const XYRect& r) const 121 121 { 122 return contains(r.p) && contains(r.p +r.size);123 } 124 122 return contains(r.p) && contains(r.p + r.size); 123 } 124 125 125 void add(const XY<T>& n) 126 126 { … … 184 184 T distanceTo(const XYRect<T>& r) const 185 185 { 186 bool r_above = (r.bottom() <= top());187 bool r_below = (r.top() >= bottom());188 bool r_left = (r.right() <= left());189 bool r_right = (r.left() >= right());190 191 if (r_above)192 { 193 if (r_left) return r.bottomRight().distanceTo(topLeft());194 else if (r_right) return r.bottomLeft().distanceTo(topRight());195 else return top()r.bottom();196 } 197 else if (r_below)198 { 199 if (r_left) return r.topRight().distanceTo(bottomLeft());200 else if (r_right) return r.topLeft().distanceTo(bottomRight());201 else return r.top()bottom();202 } 203 else if (r_left)204 { 205 return left()r.right();206 } 207 else if (r_right)208 { 209 return r.left()right();210 } 211 else212 return 0; //intersection186 bool r_above = (r.bottom() <= top()); 187 bool r_below = (r.top() >= bottom()); 188 bool r_left = (r.right() <= left()); 189 bool r_right = (r.left() >= right()); 190 191 if (r_above) 192 { 193 if (r_left) return r.bottomRight().distanceTo(topLeft()); 194 else if (r_right) return r.bottomLeft().distanceTo(topRight()); 195 else return top()  r.bottom(); 196 } 197 else if (r_below) 198 { 199 if (r_left) return r.topRight().distanceTo(bottomLeft()); 200 else if (r_right) return r.topLeft().distanceTo(bottomRight()); 201 else return r.top()  bottom(); 202 } 203 else if (r_left) 204 { 205 return left()  r.right(); 206 } 207 else if (r_right) 208 { 209 return r.left()  right(); 210 } 211 else 212 return 0; //intersection 213 213 } 214 214 … … 220 220 typedef XYRect<int> IntRect; 221 221 222 typedef XY<float> FloatXY; 223 typedef XYRect<float> FloatRect; 224 222 225 #endif
Note: See TracChangeset
for help on using the changeset viewer.