Beatmup
Beatmup::CustomRectangle< numeric > Class Template Reference

2D rectangle class All the utilities assume that the rectangle is normalized, e.g. More...

#include <geometry.h>

Public Member Functions

 CustomRectangle ()
 
 CustomRectangle (const CustomPoint< numeric > &a, const CustomPoint< numeric > &b)
 
 CustomRectangle (numeric x1, numeric y1, numeric x2, numeric y2)
 
bool operator== (const CustomRectangle< numeric > &other) const
 
bool operator!= (const CustomRectangle< numeric > &other) const
 
bool empty () const
 
CustomRectangle operator* (numeric _) const
 
CustomRectangle operator/ (numeric _) const
 
CustomRectangle operator* (const CustomPoint< numeric > &_) const
 
CustomRectangle operator/ (const CustomPoint< numeric > &_) const
 
numeric getX1 () const
 
numeric getY1 () const
 
numeric getX2 () const
 
numeric getY2 () const
 
numeric width () const
 
numeric height () const
 
numeric getArea () const
 Computes the rectangle area. More...
 
void normalize ()
 Flips corners coordinates guaranteeing that it has a non negative area, i.e. More...
 
void translate (numeric x, numeric y)
 Translates the box. More...
 
void translate (const CustomPoint< numeric > pt)
 
void scale (numeric x, numeric y)
 Scales the box. More...
 
void limit (const CustomRectangle &frame)
 Truncates a rectangle to a limiting frame. More...
 
CustomRectangle translated (numeric x, numeric y) const
 Returns a translated box. More...
 
CustomRectangle translated (CustomPoint< numeric > by) const
 
bool isInside (const CustomPoint< numeric > &point) const
 Test if a point is inside the rectangle (or on its the border) More...
 
bool isInsideHalfOpened (const CustomPoint< numeric > &point) const
 Test if a point is inside the rectangle including left and top borders, but excluding right and bottom. More...
 
short int horizontalPositioningTest (numeric x) const
 Rectangle positioning test with respect to a given vertical line. More...
 
short int verticalPositioningTest (numeric y) const
 Rectangle positioning test with respect to a given horizontal line. More...
 
void grow (numeric r)
 
CustomRectangle< numeric > split (const int part, const int totalParts)
 
 operator CustomRectangle< float > () const
 Typecast to float-valued coordinates. More...
 
void getMapping (const CustomRectangle &target, CustomPoint< float > &scale, CustomPoint< float > &offset) const
 Finds a linear mapping of the rectangle onto another rectangle. More...
 

Public Attributes

CustomPoint< numeric > a
 
CustomPoint< numeric > b
 

Static Public Attributes

static const CustomRectangle UNIT_SQUARE = CustomRectangle<T>(0, 0, 1, 1)
 

Detailed Description

template<typename numeric>
class Beatmup::CustomRectangle< numeric >

2D rectangle class All the utilities assume that the rectangle is normalized, e.g.

its area is not negative

Definition at line 129 of file geometry.h.

Constructor & Destructor Documentation

◆ CustomRectangle() [1/3]

template<typename numeric >
Beatmup::CustomRectangle< numeric >::CustomRectangle ( )
inline

Definition at line 132 of file geometry.h.

132  : a(0, 0), b(0, 0)
133  {}
CustomPoint< numeric > b
Definition: geometry.h:131
CustomPoint< numeric > a
Definition: geometry.h:131

◆ CustomRectangle() [2/3]

template<typename numeric >
Beatmup::CustomRectangle< numeric >::CustomRectangle ( const CustomPoint< numeric > &  a,
const CustomPoint< numeric > &  b 
)
inline

Definition at line 135 of file geometry.h.

135  : a(a), b(b)
136  {}

◆ CustomRectangle() [3/3]

template<typename numeric >
Beatmup::CustomRectangle< numeric >::CustomRectangle ( numeric  x1,
numeric  y1,
numeric  x2,
numeric  y2 
)
inline

Definition at line 138 of file geometry.h.

139  {}
2D point class
Definition: geometry.h:38
JNIEnv jlong jint jint jint jint y2
JNIEnv jlong jint x1
JNIEnv jlong jint jint jint x2
JNIEnv jlong jint jint jint y1

Member Function Documentation

◆ operator==()

template<typename numeric >
bool Beatmup::CustomRectangle< numeric >::operator== ( const CustomRectangle< numeric > &  other) const
inline

Definition at line 141 of file geometry.h.

141  {
142  return a == other.a && b == other.b;
143  }

◆ operator!=()

template<typename numeric >
bool Beatmup::CustomRectangle< numeric >::operator!= ( const CustomRectangle< numeric > &  other) const
inline

Definition at line 145 of file geometry.h.

145  {
146  return a != other.a || b != other.b;
147  }

◆ empty()

template<typename numeric >
bool Beatmup::CustomRectangle< numeric >::empty ( ) const
inline

Definition at line 149 of file geometry.h.

149  {
150  return b.x <= a.x || b.y <= a.y;
151  }

◆ operator*() [1/2]

template<typename numeric >
CustomRectangle Beatmup::CustomRectangle< numeric >::operator* ( numeric  _) const
inline

Definition at line 153 of file geometry.h.

153  {
154  return CustomRectangle(a * _, b * _);
155  }

◆ operator/() [1/2]

template<typename numeric >
CustomRectangle Beatmup::CustomRectangle< numeric >::operator/ ( numeric  _) const
inline

Definition at line 157 of file geometry.h.

157  {
158  return CustomRectangle(a / _, b / _);
159  }

◆ operator*() [2/2]

template<typename numeric >
CustomRectangle Beatmup::CustomRectangle< numeric >::operator* ( const CustomPoint< numeric > &  _) const
inline

Definition at line 161 of file geometry.h.

161  {
162  return CustomRectangle(a * _, b * _);
163  }

◆ operator/() [2/2]

template<typename numeric >
CustomRectangle Beatmup::CustomRectangle< numeric >::operator/ ( const CustomPoint< numeric > &  _) const
inline

Definition at line 165 of file geometry.h.

165  {
166  return CustomRectangle(a / _, b / _);
167  }

◆ getX1()

template<typename numeric >
numeric Beatmup::CustomRectangle< numeric >::getX1 ( ) const
inline

Definition at line 169 of file geometry.h.

169 { return a.x; }

◆ getY1()

template<typename numeric >
numeric Beatmup::CustomRectangle< numeric >::getY1 ( ) const
inline

Definition at line 170 of file geometry.h.

170 { return a.y; }

◆ getX2()

template<typename numeric >
numeric Beatmup::CustomRectangle< numeric >::getX2 ( ) const
inline

Definition at line 171 of file geometry.h.

171 { return b.x; }

◆ getY2()

template<typename numeric >
numeric Beatmup::CustomRectangle< numeric >::getY2 ( ) const
inline

Definition at line 172 of file geometry.h.

172 { return b.y; }

◆ width()

template<typename numeric >
numeric Beatmup::CustomRectangle< numeric >::width ( ) const
inline

Definition at line 174 of file geometry.h.

174  {
175  return b.x - a.x;
176  }

◆ height()

template<typename numeric >
numeric Beatmup::CustomRectangle< numeric >::height ( ) const
inline

Definition at line 178 of file geometry.h.

178  {
179  return b.y - a.y;
180  }

◆ getArea()

template<typename numeric >
numeric Beatmup::CustomRectangle< numeric >::getArea ( ) const
inline

Computes the rectangle area.

Definition at line 185 of file geometry.h.

185  {
186  return (b.x - a.x) * (b.y - a.y);
187  }

◆ normalize()

template<typename numeric >
void Beatmup::CustomRectangle< numeric >::normalize ( )
inline

Flips corners coordinates guaranteeing that it has a non negative area, i.e.

a <= b (componentwise)

Definition at line 192 of file geometry.h.

192  {
193  order<numeric>(a.x, b.x);
194  order<numeric>(a.y, b.y);
195  }

◆ translate() [1/2]

template<typename numeric >
void Beatmup::CustomRectangle< numeric >::translate ( numeric  x,
numeric  y 
)
inline

Translates the box.

Definition at line 200 of file geometry.h.

200  {
201  a.translate(x, y);
202  b.translate(x, y);
203  }
jobject jlong jint jint y
jobject jlong jint x

◆ translate() [2/2]

template<typename numeric >
void Beatmup::CustomRectangle< numeric >::translate ( const CustomPoint< numeric >  pt)
inline

Definition at line 205 of file geometry.h.

205  {
206  a.translate(pt.x, pt.y);
207  b.translate(pt.x, pt.y);
208  }

◆ scale()

template<typename numeric >
void Beatmup::CustomRectangle< numeric >::scale ( numeric  x,
numeric  y 
)
inline

Scales the box.

Definition at line 213 of file geometry.h.

213  {
214  a.x *= x; a.y *= y;
215  b.x *= x; b.y *= y;
216  }

◆ limit()

template<typename numeric >
void Beatmup::CustomRectangle< numeric >::limit ( const CustomRectangle< numeric > &  frame)
inline

Truncates a rectangle to a limiting frame.

Definition at line 221 of file geometry.h.

221  {
222  if (a.x < frame.a.x)
223  a.x = frame.a.x;
224  if (a.y < frame.a.y)
225  a.y = frame.a.y;
226  if (b.x > frame.b.x)
227  b.x = frame.b.x;
228  if (b.y > frame.b.y)
229  b.y = frame.b.y;
230  }

◆ translated() [1/2]

template<typename numeric >
CustomRectangle Beatmup::CustomRectangle< numeric >::translated ( numeric  x,
numeric  y 
) const
inline

Returns a translated box.

Definition at line 235 of file geometry.h.

235  {
236  return CustomRectangle(
237  CustomPoint<numeric>(a.x + x, a.y + y),
238  CustomPoint<numeric>(b.x + x, b.y + y)
239  );
240  }

◆ translated() [2/2]

template<typename numeric >
CustomRectangle Beatmup::CustomRectangle< numeric >::translated ( CustomPoint< numeric >  by) const
inline

Definition at line 242 of file geometry.h.

242  {
243  return CustomRectangle(
244  CustomPoint<numeric>(a.x + by.x, a.y + by.y),
245  CustomPoint<numeric>(b.x + by.x, b.y + by.y)
246  );
247  }

◆ isInside()

template<typename numeric >
bool Beatmup::CustomRectangle< numeric >::isInside ( const CustomPoint< numeric > &  point) const
inline

Test if a point is inside the rectangle (or on its the border)

Definition at line 252 of file geometry.h.

252  {
253  return (a.x <= point.x) && (point.x <= b.x) && (a.y <= point.y) && (point.y <= b.y);
254  }

◆ isInsideHalfOpened()

template<typename numeric >
bool Beatmup::CustomRectangle< numeric >::isInsideHalfOpened ( const CustomPoint< numeric > &  point) const
inline

Test if a point is inside the rectangle including left and top borders, but excluding right and bottom.

Definition at line 259 of file geometry.h.

259  {
260  return (a.x <= point.x) && (point.x < b.x) && (a.y <= point.y) && (point.y < b.y);
261  }

◆ horizontalPositioningTest()

template<typename numeric >
short int Beatmup::CustomRectangle< numeric >::horizontalPositioningTest ( numeric  x) const
inline

Rectangle positioning test with respect to a given vertical line.

Returns
-1 if the line passes on the left side of the rectangle, 1 if it is on the right side, 0 otherwise

Definition at line 267 of file geometry.h.

267  {
268  if (x < a.x)
269  return -1;
270  if (x > b.x)
271  return 1;
272  return 0;
273  }

◆ verticalPositioningTest()

template<typename numeric >
short int Beatmup::CustomRectangle< numeric >::verticalPositioningTest ( numeric  y) const
inline

Rectangle positioning test with respect to a given horizontal line.

Returns
-1 if the line passes above the rectangle, 1 if it passes below, 0 otherwise

Definition at line 279 of file geometry.h.

279  {
280  if (y < a.y)
281  return -1;
282  if (y > b.y)
283  return 1;
284  return 0;
285  }

◆ grow()

template<typename numeric >
void Beatmup::CustomRectangle< numeric >::grow ( numeric  r)
inline

Definition at line 287 of file geometry.h.

287  {
288  a.x -= r;
289  a.y -= r;
290  b.x += r;
291  b.y += r;
292  }
jobject jlong jint jint jint r

◆ split()

template<typename numeric >
CustomRectangle<numeric> Beatmup::CustomRectangle< numeric >::split ( const int  part,
const int  totalParts 
)
inline

Definition at line 294 of file geometry.h.

294  {
296  a.x, a.y + (b.y - a.y) * part / totalParts,
297  b.x, a.y + (b.y - a.y) * (part + 1) / totalParts
298  );
299  }
2D rectangle class All the utilities assume that the rectangle is normalized, e.g.
Definition: geometry.h:129

◆ operator CustomRectangle< float >()

template<typename numeric >
Beatmup::CustomRectangle< numeric >::operator CustomRectangle< float > ( ) const
inline

Typecast to float-valued coordinates.

Definition at line 304 of file geometry.h.

304  {
306  return r;
307  }

◆ getMapping()

template<typename numeric >
void Beatmup::CustomRectangle< numeric >::getMapping ( const CustomRectangle< numeric > &  target,
CustomPoint< float > &  scale,
CustomPoint< float > &  offset 
) const
inline

Finds a linear mapping of the rectangle onto another rectangle.

target = scale * this + offset

Parameters
[in]targetThe target domain rectangle
[out]scaleThe scaling factor to apply to the current rectangle
[out]offsetThe offset to apply to the current rectangle

Definition at line 316 of file geometry.h.

316  {
317  scale.x = (float)target.width() / width();
318  scale.y = (float)target.height() / height();
319  offset = target.a - scale * a;
320  }
numeric height() const
Definition: geometry.h:178
numeric width() const
Definition: geometry.h:174
void scale(numeric x, numeric y)
Scales the box.
Definition: geometry.h:213

Member Data Documentation

◆ a

template<typename numeric >
CustomPoint<numeric> Beatmup::CustomRectangle< numeric >::a

Definition at line 131 of file geometry.h.

◆ b

template<typename numeric >
CustomPoint<numeric> Beatmup::CustomRectangle< numeric >::b

Definition at line 131 of file geometry.h.

◆ UNIT_SQUARE

template<typename T >
const CustomRectangle< T > Beatmup::CustomRectangle< T >::UNIT_SQUARE = CustomRectangle<T>(0, 0, 1, 1)
static

Definition at line 322 of file geometry.h.


The documentation for this class was generated from the following file: