Beatmup
geometry.h
Go to the documentation of this file.
1 /*
2  Beatmup image and signal processing library
3  Copyright (C) 2019, lnstadrum
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #pragma once
20 #include "basic_types.h"
21 #include <cmath>
22 
23 #define between(A,X,B) (((A) <= (X) && (X) <= (B)) || ((A) >= (X) && (X) >= (B)))
24 #define sqr(X) ((X)*(X))
25 
26 namespace Beatmup {
27 
28  template<typename T> inline void order(T& a, T& b) {
29  if (a > b) {
30  T _;
31  _ = a; a = b; b = _;
32  }
33  }
34 
35  /**
36  2D point class
37  */
38  template<typename numeric> class CustomPoint {
39  public:
40  numeric x, y;
41 
42  inline numeric getX() const {
43  return x;
44  }
45 
46  inline numeric getY() const {
47  return y;
48  }
49 
50  inline bool operator==(const CustomPoint<numeric>& _) const {
51  return x == _.x && y == _.y;
52  }
53 
54  inline bool operator!=(const CustomPoint<numeric>& _) const {
55  return x != _.x || y != _.y;
56  }
57 
59  return CustomPoint<numeric>(x + _.x, y + _.y);
60  }
61 
63  return CustomPoint<numeric>(x - _.x, y - _.y);
64  }
65 
67  return CustomPoint<numeric>(x * _.x, y * _.y);
68  }
69 
71  return CustomPoint<numeric>(x / _.x, y / _.y);
72  }
73 
74  inline CustomPoint<numeric> operator+(numeric _) const {
75  return CustomPoint<numeric>(x + _, y + _);
76  }
77 
78  inline CustomPoint<numeric> operator-(numeric _) const {
79  return CustomPoint<numeric>(x - _, y - _);
80  }
81 
82  inline CustomPoint<numeric> operator*(numeric _) const {
83  return CustomPoint<numeric>(x * _, y * _);
84  }
85 
86  inline CustomPoint<numeric> operator/(numeric _) const {
87  return CustomPoint<numeric>(x / _, y / _);
88  }
89 
90  inline void translate(numeric x, numeric y) {
91  this->x += x;
92  this->y += y;
93  }
94 
95  inline CustomPoint<numeric>() { x = y = 0; }
96  inline CustomPoint<numeric>(numeric x, numeric y) : x(x), y(y) {}
97 
98  inline numeric hypot2() const {
99  return x*x + y*y;
100  }
101 
102  inline bool isInsideAxesSpan(numeric scaleX, numeric scaleY) const {
103  return 0 <= x && x <= scaleX && 0 <= y && y <= scaleY;
104  }
105 
106  /**
107  Typecast to float-valued coordinates
108  */
109  inline operator CustomPoint<float>() const {
110  CustomPoint<float> p((float)x, (float)y);
111  return p;
112  }
113 
114  /**
115  Typecast to integer valued coordinates
116  */
117  inline operator CustomPoint<int>() const {
118  CustomPoint<int> p((int)(x), (int)(y));
119  return p;
120  }
121 
122  static const CustomPoint ZERO; // zero point of type numeric
123  };
124 
125  /**
126  2D rectangle class
127  All the utilities assume that the rectangle is normalized, e.g. its area is not negative
128  */
129  template<typename numeric> class CustomRectangle {
130  public:
132  CustomRectangle() : a(0, 0), b(0, 0)
133  {}
134 
136  {}
137 
138  CustomRectangle(numeric x1, numeric y1, numeric x2, numeric y2) : a(CustomPoint<numeric>(x1, y1)), b(CustomPoint<numeric>(x2, y2))
139  {}
140 
141  inline bool operator==(const CustomRectangle<numeric>& other) const {
142  return a == other.a && b == other.b;
143  }
144 
145  inline bool operator!=(const CustomRectangle<numeric>& other) const {
146  return a != other.a || b != other.b;
147  }
148 
149  inline bool empty() const {
150  return b.x <= a.x || b.y <= a.y;
151  }
152 
153  inline CustomRectangle operator*(numeric _) const {
154  return CustomRectangle(a * _, b * _);
155  }
156 
157  inline CustomRectangle operator/(numeric _) const {
158  return CustomRectangle(a / _, b / _);
159  }
160 
162  return CustomRectangle(a * _, b * _);
163  }
164 
166  return CustomRectangle(a / _, b / _);
167  }
168 
169  inline numeric getX1() const { return a.x; }
170  inline numeric getY1() const { return a.y; }
171  inline numeric getX2() const { return b.x; }
172  inline numeric getY2() const { return b.y; }
173 
174  inline numeric width() const {
175  return b.x - a.x;
176  }
177 
178  inline numeric height() const {
179  return b.y - a.y;
180  }
181 
182  /**
183  Computes the rectangle area
184  */
185  inline numeric getArea() const {
186  return (b.x - a.x) * (b.y - a.y);
187  }
188 
189  /**
190  Flips corners coordinates guaranteeing that it has a non negative area, i.e. a <= b (componentwise)
191  */
192  inline void normalize() {
193  order<numeric>(a.x, b.x);
194  order<numeric>(a.y, b.y);
195  }
196 
197  /**
198  Translates the box
199  */
200  inline void translate(numeric x, numeric y) {
201  a.translate(x, y);
202  b.translate(x, y);
203  }
204 
205  inline void translate(const CustomPoint<numeric> pt) {
206  a.translate(pt.x, pt.y);
207  b.translate(pt.x, pt.y);
208  }
209 
210  /**
211  Scales the box
212  */
213  inline void scale(numeric x, numeric y) {
214  a.x *= x; a.y *= y;
215  b.x *= x; b.y *= y;
216  }
217 
218  /**
219  Truncates a rectangle to a limiting frame
220  */
221  inline void limit(const CustomRectangle& frame) {
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  }
231 
232  /**
233  Returns a translated box
234  */
235  inline CustomRectangle translated(numeric x, numeric y) const {
236  return CustomRectangle(
237  CustomPoint<numeric>(a.x + x, a.y + y),
238  CustomPoint<numeric>(b.x + x, b.y + y)
239  );
240  }
241 
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  }
248 
249  /**
250  Test if a point is inside the rectangle (or on its the border)
251  */
252  bool isInside(const CustomPoint<numeric>& point) const {
253  return (a.x <= point.x) && (point.x <= b.x) && (a.y <= point.y) && (point.y <= b.y);
254  }
255 
256  /**
257  Test if a point is inside the rectangle including left and top borders, but excluding right and bottom
258  */
259  bool isInsideHalfOpened(const CustomPoint<numeric>& point) const {
260  return (a.x <= point.x) && (point.x < b.x) && (a.y <= point.y) && (point.y < b.y);
261  }
262 
263  /**
264  Rectangle positioning test with respect to a given vertical line
265  \returns -1 if the line passes on the left side of the rectangle, 1 if it is on the right side, 0 otherwise
266  */
267  short int horizontalPositioningTest(numeric x) const {
268  if (x < a.x)
269  return -1;
270  if (x > b.x)
271  return 1;
272  return 0;
273  }
274 
275  /**
276  Rectangle positioning test with respect to a given horizontal line
277  \returns -1 if the line passes above the rectangle, 1 if it passes below, 0 otherwise
278  */
279  short int verticalPositioningTest(numeric y) const {
280  if (y < a.y)
281  return -1;
282  if (y > b.y)
283  return 1;
284  return 0;
285  }
286 
287  void grow(numeric r) {
288  a.x -= r;
289  a.y -= r;
290  b.x += r;
291  b.y += r;
292  }
293 
294  inline CustomRectangle<numeric> split(const int part, const int totalParts) {
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  }
300 
301  /**
302  Typecast to float-valued coordinates
303  */
304  inline operator CustomRectangle<float>() const {
306  return r;
307  }
308 
309  /**
310  \brief Finds a linear mapping of the rectangle onto another rectangle.
311  target = scale * this + offset
312  \param[in] target The target domain rectangle
313  \param[out] scale The scaling factor to apply to the current rectangle
314  \param[out] offset The offset to apply to the current rectangle
315  */
316  inline void getMapping(const CustomRectangle& target, CustomPoint<float>& scale, CustomPoint<float>& offset) const {
317  scale.x = (float)target.width() / width();
318  scale.y = (float)target.height() / height();
319  offset = target.a - scale * a;
320  }
321 
323  };
324 
325  /**
326  2D affine transformation.
327  Defines operators to transform 2D points and a set of useful utilities to work with affine mappings
328  */
329  template<typename numeric> class CustomMatrix2 {
330  private:
331  numeric a11, a12, a21, a22; //!< transformation matrix coefficients
332  public:
333  CustomMatrix2() : a11(1), a12(0), a21(0), a22(1)
334  {}
335 
336  CustomMatrix2(numeric lambda1, numeric lambda2) : a11(lambda1), a12(0), a21(0), a22(lambda2)
337  {}
338 
339  CustomMatrix2(numeric _11, numeric _12, numeric _21, numeric _22): a11(_11), a12(_12), a21(_21), a22(_22)
340  {}
341 
342  inline numeric getA11() const { return a11; }
343  inline numeric getA12() const { return a12; }
344  inline numeric getA21() const { return a21; }
345  inline numeric getA22() const { return a22; }
346 
347  /**
348  Computes the corresponding transformed point of the point (x,y)
349  */
350  inline CustomPoint<numeric> operator()(numeric x, numeric y) const {
351  return CustomPoint<numeric>(a11 * x + a12 * y, a21 * x + a22 * y);
352  }
353 
354  /**
355  Integer overloading of (x,y) operator to avoid warnings
356  */
357  inline CustomPoint<numeric> operator()(int x, int y) const {
358  return this->operator()((float)x, (float)y);
359  }
360 
361  /**
362  Computes transformed point of a given one
363  */
365  return CustomPoint<numeric>(a11 * point.x + a12 * point.y, a21 * point.x + a22 * point.y);
366  }
367 
368  /**
369  Multiplies two matrices
370  */
371  inline CustomMatrix2 operator*(const CustomMatrix2& matrix) const {
373  result.a11 = a11 * matrix.a11 + a12 * matrix.a21;
374  result.a12 = a11 * matrix.a12 + a12 * matrix.a22;
375  result.a21 = a21 * matrix.a11 + a22 * matrix.a21;
376  result.a22 = a21 * matrix.a12 + a22 * matrix.a22;
377  return result;
378  }
379 
380  /**
381  Multiplies matrix by a vector
382  */
384  return this->operator()(point);
385  }
386 
387  /**
388  Multiplies matrix by a scalar
389  */
390  inline CustomMatrix2 operator*(const numeric factor) const {
392  result.a11 = a11*factor;
393  result.a12 = a12*factor;
394  result.a21 = a21*factor;
395  result.a22 = a22*factor;
396  return result;
397  }
398 
399  void scale(numeric factor) {
400  scale(factor, factor);
401  }
402 
403  void scale(numeric x, numeric y) {
404  a11 *= x;
405  a12 *= y;
406  a21 *= x;
407  a22 *= y;
408  }
409 
410  void prescale(numeric x, numeric y) {
411  a11 *= x;
412  a12 *= x;
413  a21 *= y;
414  a22 *= y;
415  }
416 
417  void rotateRadians(float angle) {
418  float
419  c = cos(angle),
420  s = sin(angle),
421  _11 = c * a11 + s * a12,
422  _21 = c * a21 + s * a22;
423  a12 = -s * a11 + c * a12;
424  a22 = -s * a21 + c * a22;
425  a11 = _11;
426  a21 = _21;
427  }
428 
429  inline void rotateDegrees(float angle) {
430  rotateRadians(angle * pi / 180.0f);
431  }
432 
433  inline void skewRadians(float x, float y) {
434  float
435  tx = tan(x), ty = tan(y),
436  _11 = a11 * (1 + tx*ty) + a12 * ty,
437  _21 = a21 * (1 + tx*ty) + a22 * ty,
438  _12 = a11 * tx + a12;
439  a22 = a21 * tx + a22;
440  a11 = _11;
441  a12 = _12;
442  a21 = _21;
443  }
444 
445  inline void skewDegrees(float x, float y) {
446  skewRadians(x * pi / 180.0f, y * pi / 180.0f);
447  }
448 
449  /**
450  Transformation determinant
451  */
452  numeric det() const {
453  return a11*a22 - a12*a21;
454  }
455 
456  bool isInvertible() const {
457  return det() != 0;
458  }
459 
460  /**
461  Computes inverse transformation
462  \returns the inverse
463  */
465  numeric D = det();
466  CustomMatrix2 i;
467  i.a11 = a22 / D;
468  i.a22 = a11 / D;
469  i.a12 = -a12 / D;
470  i.a21 = -a21 / D;
471  return i;
472  }
473 
474  /**
475  Computes inverse of a given point
476  \returns the inverse
477  */
478  CustomPoint<numeric> getInverse(numeric x, numeric y) const {
479  numeric D = det();
480  return CustomPoint<numeric>(
481  ( x * a22 - y * a12) / D,
482  (-x * a21 + y * a11) / D
483  );
484  }
485 
486  /**
487  Computes inverse of a given point
488  \returns the inverse
489  */
491  const numeric det = det();
492  return CustomPoint<numeric>(
493  (+point.x * a22 - point.y * a12) / det,
494  (-point.x * a21 + point.y * a11) / det
495  );
496  }
497 
498  /**
499  \returns transposed matrix
500  */
502  CustomMatrix2 t;
503  t.a11 = a11;
504  t.a12 = a21;
505  t.a21 = a12;
506  t.a22 = a22;
507  return t;
508  }
509 
510  /**
511  Scales transformation input and output units
512  If input/output axes change their scales, the transformation may be rescaled to keep
513  the correspondence between the same points as before but in newly scaled coordinates.
514  */
515  void rescaleUnits(numeric xIn, numeric yIn, numeric xOut, numeric yOut) {
516  a11 = a11 * xOut / xIn;
517  a12 = a12 * xOut / yIn;
518  a21 = a21 * yOut / xIn;
519  a22 = a22 * yOut / yIn;
520  }
521 
522  /**
523  Checks whether a given input point is inside a rectangular area when transformed
524  */
525  template<typename num> inline bool isPointInsideBox(num x, num y, CustomRectangle<num> box) const {
526  num p = a11*x + a12*y;
527  if (p < box.a.x || box.b.x < p)
528  return false;
529  p = a21*x + a22*y;
530  return (box.a.y <= p && p <= box.b.y);
531  }
532 
533  /**
534  Checks whether a given input point is inside the unit square when transformed
535  */
536  inline bool isPointInsideAxes(numeric x, numeric y, numeric w, numeric h) const {
537  numeric p = a11*x + a12*y;
538  if (p < 0 || w < p)
539  return false;
540  p = a21*x + a22*y;
541  return (0 <= p && p <= h);
542  }
543 
544  inline bool isPointInsideAxes(numeric x, numeric y) const {
545  return isPointInsideAxes(x, y, 1, 1);
546  }
547 
548  /**
549  Computes X axis scaling factor
550  */
551  inline numeric getScalingX() {
552  return sqrt(sqr(a11) + sqr(a21));
553  }
554 
555  /**
556  Computes Y axis scaling factor
557  */
558  inline numeric getScalingY() {
559  return sqrt(sqr(a12) + sqr(a22));
560  }
561 
562  /**
563  Returns first axis orientation in degrees
564  */
565  inline float getOrientationDegrees() {
566  return atan2(a11, a12) *180/pi;
567  }
568 
569  /**
570  Retrieves matrix element values
571  */
572  inline void getElements(float& a11, float& a12, float& a21, float& a22) const {
573  a11 = this->a11;
574  a12 = this->a12;
575  a21 = this->a21;
576  a22 = this->a22;
577  }
578 
579  /**
580  Sets matrix element values
581  */
582  inline void setElements(float a11, float a12, float a21, float a22) {
583  this->a11 = a11;
584  this->a12 = a12;
585  this->a21 = a21;
586  this->a22 = a22;
587  }
588  static const CustomMatrix2 IDENTITY;
589  };
590 
591  /**
592  Point with negative coordinates
593  */
594  template<typename numeric> inline CustomPoint<numeric> operator-(const CustomPoint<numeric>& point) {
595  return CustomPoint<numeric>(-point.x, -point.y);
596  }
597 
598  /**
599  Product of a scalar and a point
600  */
601  template<typename numeric> inline CustomPoint<numeric> operator*(numeric val, const CustomPoint<numeric>& point) {
602  return point * val;
603  }
604 
605  /**
606  Product of a scalar and a matrix
607  */
608  template<typename numeric> inline CustomMatrix2<numeric> operator*(numeric val, const CustomMatrix2<numeric>& matrix) {
609  return matrix * val;
610  }
611 
612  /**
613  Checks whether two rectangles are of the same size
614  */
615  template<typename numeric> inline bool operator&&(const CustomRectangle<numeric>& lhs, const CustomRectangle<numeric>& rhs) {
616  return lhs.width() == rhs.width() && lhs.height() == rhs.height();
617  }
618 
619  /**
620  Checks whether two rectangles are actually the same
621  */
622  template<typename numeric> inline bool operator==(const CustomRectangle<numeric>& lhs, const CustomRectangle<numeric>& rhs) {
623  return lhs.a == rhs.a && lhs.b == rhs.b;
624  }
625 
631 
632  template<typename T> const CustomPoint<T> CustomPoint<T>::ZERO = CustomPoint<T>(0, 0);
633  template<typename T> const CustomMatrix2<T> CustomMatrix2<T>::IDENTITY(1,1);
634  template<typename T> const CustomRectangle<T> CustomRectangle<T>::UNIT_SQUARE = CustomRectangle<T>(0, 0, 1, 1);
635 
636  /**
637  2x3 affine mapping containing a 2x2 matrix and a 2D point
638  */
640  public:
643 
644  AffineMapping();
645  AffineMapping(const Matrix2& aMatrix, const Point& aPosition);
646 
647  /**
648  Creates a mapping of unit square to a given rectangle.
649  \param[in] rectangle The rectangle
650  */
651  AffineMapping(const Rectangle& rectangle);
652 
653  inline Point getPosition() const {
654  return position;
655  }
656 
657  inline Matrix2 getMatrix() const {
658  return matrix;
659  }
660 
661  /**
662  Maps a point
663  */
664  inline Point operator()(const Point& point) const {
665  return matrix(point) + position;
666  }
667 
668  /**
669  Composition of two mappings
670  */
672  void setIdentity();
673 
674  /**
675  Inverts the mapping
676  */
677  void invert();
678 
679  /**
680  Returns inverse mapping
681  */
682  AffineMapping getInverse() const;
683 
684  /**
685  Computes inverse mapping of a point
686  */
687  Point getInverse(const Point& pos) const;
688  Point getInverse(float x, float y) const;
689 
690  /**
691  Adjusts the mapping origin so that the center of the axes box matches a given point
692  */
693  void setCenterPosition(const Point& newPos);
694 
695  /**
696  Translates the mapping
697  */
698  void translate(const Point& shift);
699 
700  /**
701  Scales the mapping around a given point in target domain
702  */
703  void scale(float factor, const Point& fixedPoint = Point::ZERO);
704 
705  /**
706  Rotates the mapping around a given point in target domain
707  */
708  void rotateDegrees(float angle, const Point& fixedPoint = Point::ZERO);
709 
710  /**
711  Tests whether a point from the output domain is inside the input axes span
712  */
713  bool isPointInside(const Point& point) const;
714  bool isPointInside(float x, float y) const;
715  bool isPointInside(float x, float y, float width, float height) const;
716 
717  static const AffineMapping IDENTITY;
718  };
719 }
720 
721 namespace std {
722  using namespace Beatmup;
723 
724  template<typename numeric> inline CustomPoint<numeric> min(const CustomPoint<numeric>& a, const CustomPoint<numeric>& b) {
725  return CustomPoint<numeric>(std::min(a.x, b.x), std::min(a.y, b.y));
726  }
727 
728  template<typename numeric> inline CustomPoint<numeric> max(const CustomPoint<numeric>& a, const CustomPoint<numeric>& b) {
729  return CustomPoint<numeric>(std::max(a.x, b.x), std::max(a.y, b.y));
730  }
731 }
2x3 affine mapping containing a 2x2 matrix and a 2D point
Definition: geometry.h:639
void translate(const Point &shift)
Translates the mapping.
Definition: geometry.cpp:71
void invert()
Inverts the mapping.
Definition: geometry.cpp:47
void setCenterPosition(const Point &newPos)
Adjusts the mapping origin so that the center of the axes box matches a given point.
Definition: geometry.cpp:67
void scale(float factor, const Point &fixedPoint=Point::ZERO)
Scales the mapping around a given point in target domain.
Definition: geometry.cpp:75
void rotateDegrees(float angle, const Point &fixedPoint=Point::ZERO)
Rotates the mapping around a given point in target domain.
Definition: geometry.cpp:81
AffineMapping getInverse() const
Returns inverse mapping.
Definition: geometry.cpp:52
bool isPointInside(const Point &point) const
Tests whether a point from the output domain is inside the input axes span.
Definition: geometry.cpp:87
AffineMapping operator*(const AffineMapping &mapping) const
Composition of two mappings.
Definition: geometry.cpp:38
Point getPosition() const
Definition: geometry.h:653
static const AffineMapping IDENTITY
Definition: geometry.h:717
Point operator()(const Point &point) const
Maps a point.
Definition: geometry.h:664
Matrix2 getMatrix() const
Definition: geometry.h:657
2D affine transformation.
Definition: geometry.h:329
void rotateRadians(float angle)
Definition: geometry.h:417
CustomMatrix2 operator*(const numeric factor) const
Multiplies matrix by a scalar.
Definition: geometry.h:390
numeric getA21() const
Definition: geometry.h:344
numeric a22
transformation matrix coefficients
Definition: geometry.h:331
void setElements(float a11, float a12, float a21, float a22)
Sets matrix element values.
Definition: geometry.h:582
void prescale(numeric x, numeric y)
Definition: geometry.h:410
CustomPoint< numeric > operator()(const CustomPoint< numeric > &point) const
Computes transformed point of a given one.
Definition: geometry.h:364
void getElements(float &a11, float &a12, float &a21, float &a22) const
Retrieves matrix element values.
Definition: geometry.h:572
void rescaleUnits(numeric xIn, numeric yIn, numeric xOut, numeric yOut)
Scales transformation input and output units If input/output axes change their scales,...
Definition: geometry.h:515
CustomMatrix2 getInverse() const
Computes inverse transformation.
Definition: geometry.h:464
CustomMatrix2 getTransposed() const
Definition: geometry.h:501
void rotateDegrees(float angle)
Definition: geometry.h:429
numeric getA11() const
Definition: geometry.h:342
void scale(numeric x, numeric y)
Definition: geometry.h:403
numeric getA12() const
Definition: geometry.h:343
static const CustomMatrix2 IDENTITY
Definition: geometry.h:588
void skewDegrees(float x, float y)
Definition: geometry.h:445
bool isPointInsideBox(num x, num y, CustomRectangle< num > box) const
Checks whether a given input point is inside a rectangular area when transformed.
Definition: geometry.h:525
CustomMatrix2(numeric _11, numeric _12, numeric _21, numeric _22)
Definition: geometry.h:339
CustomMatrix2 operator*(const CustomMatrix2 &matrix) const
Multiplies two matrices.
Definition: geometry.h:371
CustomPoint< numeric > operator()(numeric x, numeric y) const
Computes the corresponding transformed point of the point (x,y)
Definition: geometry.h:350
bool isInvertible() const
Definition: geometry.h:456
bool isPointInsideAxes(numeric x, numeric y) const
Definition: geometry.h:544
void scale(numeric factor)
Definition: geometry.h:399
CustomPoint< numeric > operator*(const CustomPoint< numeric > &point) const
Multiplies matrix by a vector.
Definition: geometry.h:383
numeric getA22() const
Definition: geometry.h:345
float getOrientationDegrees()
Returns first axis orientation in degrees.
Definition: geometry.h:565
bool isPointInsideAxes(numeric x, numeric y, numeric w, numeric h) const
Checks whether a given input point is inside the unit square when transformed.
Definition: geometry.h:536
numeric det() const
Transformation determinant.
Definition: geometry.h:452
CustomMatrix2(numeric lambda1, numeric lambda2)
Definition: geometry.h:336
numeric getScalingX()
Computes X axis scaling factor.
Definition: geometry.h:551
CustomPoint< numeric > getInverse(const CustomPoint< numeric > &point) const
Computes inverse of a given point.
Definition: geometry.h:490
CustomPoint< numeric > operator()(int x, int y) const
Integer overloading of (x,y) operator to avoid warnings.
Definition: geometry.h:357
CustomPoint< numeric > getInverse(numeric x, numeric y) const
Computes inverse of a given point.
Definition: geometry.h:478
numeric getScalingY()
Computes Y axis scaling factor.
Definition: geometry.h:558
void skewRadians(float x, float y)
Definition: geometry.h:433
2D point class
Definition: geometry.h:38
numeric hypot2() const
Definition: geometry.h:98
CustomPoint< numeric > operator-(numeric _) const
Definition: geometry.h:78
void translate(numeric x, numeric y)
Definition: geometry.h:90
static const CustomPoint ZERO
Definition: geometry.h:122
CustomPoint< numeric > operator*(const CustomPoint< numeric > &_) const
Definition: geometry.h:66
numeric getX() const
Definition: geometry.h:42
numeric getY() const
Definition: geometry.h:46
CustomPoint< numeric > operator-(const CustomPoint< numeric > &_) const
Definition: geometry.h:62
bool operator==(const CustomPoint< numeric > &_) const
Definition: geometry.h:50
CustomPoint< numeric > operator*(numeric _) const
Definition: geometry.h:82
CustomPoint< numeric > operator+(const CustomPoint< numeric > &_) const
Definition: geometry.h:58
CustomPoint< numeric > operator/(const CustomPoint< numeric > &_) const
Definition: geometry.h:70
bool operator!=(const CustomPoint< numeric > &_) const
Definition: geometry.h:54
bool isInsideAxesSpan(numeric scaleX, numeric scaleY) const
Definition: geometry.h:102
CustomPoint< numeric > operator+(numeric _) const
Definition: geometry.h:74
CustomPoint< numeric > operator/(numeric _) const
Definition: geometry.h:86
2D rectangle class All the utilities assume that the rectangle is normalized, e.g.
Definition: geometry.h:129
CustomRectangle translated(CustomPoint< numeric > by) const
Definition: geometry.h:242
void limit(const CustomRectangle &frame)
Truncates a rectangle to a limiting frame.
Definition: geometry.h:221
void getMapping(const CustomRectangle &target, CustomPoint< float > &scale, CustomPoint< float > &offset) const
Finds a linear mapping of the rectangle onto another rectangle.
Definition: geometry.h:316
numeric height() const
Definition: geometry.h:178
CustomPoint< numeric > b
Definition: geometry.h:131
short int horizontalPositioningTest(numeric x) const
Rectangle positioning test with respect to a given vertical line.
Definition: geometry.h:267
bool empty() const
Definition: geometry.h:149
numeric getX2() const
Definition: geometry.h:171
numeric getArea() const
Computes the rectangle area.
Definition: geometry.h:185
void translate(numeric x, numeric y)
Translates the box.
Definition: geometry.h:200
CustomRectangle translated(numeric x, numeric y) const
Returns a translated box.
Definition: geometry.h:235
CustomRectangle(const CustomPoint< numeric > &a, const CustomPoint< numeric > &b)
Definition: geometry.h:135
numeric width() const
Definition: geometry.h:174
void translate(const CustomPoint< numeric > pt)
Definition: geometry.h:205
bool operator!=(const CustomRectangle< numeric > &other) const
Definition: geometry.h:145
CustomRectangle operator*(const CustomPoint< numeric > &_) const
Definition: geometry.h:161
CustomPoint< numeric > a
Definition: geometry.h:131
CustomRectangle(numeric x1, numeric y1, numeric x2, numeric y2)
Definition: geometry.h:138
short int verticalPositioningTest(numeric y) const
Rectangle positioning test with respect to a given horizontal line.
Definition: geometry.h:279
numeric getY2() const
Definition: geometry.h:172
void scale(numeric x, numeric y)
Scales the box.
Definition: geometry.h:213
bool operator==(const CustomRectangle< numeric > &other) const
Definition: geometry.h:141
CustomRectangle< numeric > split(const int part, const int totalParts)
Definition: geometry.h:294
bool isInside(const CustomPoint< numeric > &point) const
Test if a point is inside the rectangle (or on its the border)
Definition: geometry.h:252
CustomRectangle operator/(numeric _) const
Definition: geometry.h:157
numeric getX1() const
Definition: geometry.h:169
CustomRectangle operator*(numeric _) const
Definition: geometry.h:153
CustomRectangle operator/(const CustomPoint< numeric > &_) const
Definition: geometry.h:165
static const CustomRectangle UNIT_SQUARE
Definition: geometry.h:322
void grow(numeric r)
Definition: geometry.h:287
numeric getY1() const
Definition: geometry.h:170
void normalize()
Flips corners coordinates guaranteeing that it has a non negative area, i.e.
Definition: geometry.h:192
bool isInsideHalfOpened(const CustomPoint< numeric > &point) const
Test if a point is inside the rectangle including left and top borders, but excluding right and botto...
Definition: geometry.h:259
#define sqr(X)
Definition: geometry.h:24
bool operator&&(const CustomRectangle< numeric > &lhs, const CustomRectangle< numeric > &rhs)
Checks whether two rectangles are of the same size.
Definition: geometry.h:615
bool operator==(const CustomRectangle< numeric > &lhs, const CustomRectangle< numeric > &rhs)
Checks whether two rectangles are actually the same.
Definition: geometry.h:622
CustomPoint< numeric > operator-(const CustomPoint< numeric > &point)
Point with negative coordinates.
Definition: geometry.h:594
const float pi
Definition: basic_types.h:29
void order(T &a, T &b)
Definition: geometry.h:28
CustomPoint< numeric > operator*(numeric val, const CustomPoint< numeric > &point)
Product of a scalar and a point.
Definition: geometry.h:601
Definition: geometry.h:721
CustomPoint< numeric > min(const CustomPoint< numeric > &a, const CustomPoint< numeric > &b)
Definition: geometry.h:724
CustomPoint< numeric > max(const CustomPoint< numeric > &a, const CustomPoint< numeric > &b)
Definition: geometry.h:728
JNIEnv jlong jint jint jint jint y2
JNIEnv jlong jint x1
JNIEnv jlong jint jint jint x2
JNIEnv jlong jint jint jint y1
jobject jlong jint jint jint jint jint b
jobject jlong jint jint y
jlong h
jlong jstring jint jint jint jint w
jobject jlong jint jint jint r
jobject jlong jint jint jint jint jint jint a
jlong jint width
Beatmup::IntPoint result
jlong jint jint height
jobject jlong jint x
return(jlong) new Beatmup jlong jstring jint val
Beatmup::IntPoint p((int) x,(int) y)
JNIEnv jlong jfloat jfloat s
Beatmup::AffineMapping & mapping
layer getMapping().setCenterPosition(Beatmup jlong jfloat factor