Beatmup
Beatmup::CustomMatrix2< numeric > Class Template Reference

2D affine transformation. More...

#include <geometry.h>

Public Member Functions

 CustomMatrix2 ()
 
 CustomMatrix2 (numeric lambda1, numeric lambda2)
 
 CustomMatrix2 (numeric _11, numeric _12, numeric _21, numeric _22)
 
numeric getA11 () const
 
numeric getA12 () const
 
numeric getA21 () const
 
numeric getA22 () const
 
CustomPoint< numeric > operator() (numeric x, numeric y) const
 Computes the corresponding transformed point of the point (x,y) More...
 
CustomPoint< numeric > operator() (int x, int y) const
 Integer overloading of (x,y) operator to avoid warnings. More...
 
CustomPoint< numeric > operator() (const CustomPoint< numeric > &point) const
 Computes transformed point of a given one. More...
 
CustomMatrix2 operator* (const CustomMatrix2 &matrix) const
 Multiplies two matrices. More...
 
CustomPoint< numeric > operator* (const CustomPoint< numeric > &point) const
 Multiplies matrix by a vector. More...
 
CustomMatrix2 operator* (const numeric factor) const
 Multiplies matrix by a scalar. More...
 
void scale (numeric factor)
 
void scale (numeric x, numeric y)
 
void prescale (numeric x, numeric y)
 
void rotateRadians (float angle)
 
void rotateDegrees (float angle)
 
void skewRadians (float x, float y)
 
void skewDegrees (float x, float y)
 
numeric det () const
 Transformation determinant. More...
 
bool isInvertible () const
 
CustomMatrix2 getInverse () const
 Computes inverse transformation. More...
 
CustomPoint< numeric > getInverse (numeric x, numeric y) const
 Computes inverse of a given point. More...
 
CustomPoint< numeric > getInverse (const CustomPoint< numeric > &point) const
 Computes inverse of a given point. More...
 
CustomMatrix2 getTransposed () const
 
void rescaleUnits (numeric xIn, numeric yIn, numeric xOut, numeric yOut)
 Scales transformation input and output units If input/output axes change their scales, the transformation may be rescaled to keep the correspondence between the same points as before but in newly scaled coordinates. More...
 
template<typename num >
bool isPointInsideBox (num x, num y, CustomRectangle< num > box) const
 Checks whether a given input point is inside a rectangular area when transformed. More...
 
bool isPointInsideAxes (numeric x, numeric y, numeric w, numeric h) const
 Checks whether a given input point is inside the unit square when transformed. More...
 
bool isPointInsideAxes (numeric x, numeric y) const
 
numeric getScalingX ()
 Computes X axis scaling factor. More...
 
numeric getScalingY ()
 Computes Y axis scaling factor. More...
 
float getOrientationDegrees ()
 Returns first axis orientation in degrees. More...
 
void getElements (float &a11, float &a12, float &a21, float &a22) const
 Retrieves matrix element values. More...
 
void setElements (float a11, float a12, float a21, float a22)
 Sets matrix element values. More...
 

Static Public Attributes

static const CustomMatrix2 IDENTITY
 

Private Attributes

numeric a11
 
numeric a12
 
numeric a21
 
numeric a22
 transformation matrix coefficients More...
 

Detailed Description

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

2D affine transformation.

Defines operators to transform 2D points and a set of useful utilities to work with affine mappings

Definition at line 329 of file geometry.h.

Constructor & Destructor Documentation

◆ CustomMatrix2() [1/3]

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

Definition at line 333 of file geometry.h.

333  : a11(1), a12(0), a21(0), a22(1)
334  {}
numeric a22
transformation matrix coefficients
Definition: geometry.h:331

◆ CustomMatrix2() [2/3]

template<typename numeric >
Beatmup::CustomMatrix2< numeric >::CustomMatrix2 ( numeric  lambda1,
numeric  lambda2 
)
inline

Definition at line 336 of file geometry.h.

336  : a11(lambda1), a12(0), a21(0), a22(lambda2)
337  {}

◆ CustomMatrix2() [3/3]

template<typename numeric >
Beatmup::CustomMatrix2< numeric >::CustomMatrix2 ( numeric  _11,
numeric  _12,
numeric  _21,
numeric  _22 
)
inline

Definition at line 339 of file geometry.h.

339  : a11(_11), a12(_12), a21(_21), a22(_22)
340  {}

Member Function Documentation

◆ getA11()

template<typename numeric >
numeric Beatmup::CustomMatrix2< numeric >::getA11 ( ) const
inline

Definition at line 342 of file geometry.h.

342 { return a11; }

◆ getA12()

template<typename numeric >
numeric Beatmup::CustomMatrix2< numeric >::getA12 ( ) const
inline

Definition at line 343 of file geometry.h.

343 { return a12; }

◆ getA21()

template<typename numeric >
numeric Beatmup::CustomMatrix2< numeric >::getA21 ( ) const
inline

Definition at line 344 of file geometry.h.

344 { return a21; }

◆ getA22()

template<typename numeric >
numeric Beatmup::CustomMatrix2< numeric >::getA22 ( ) const
inline

Definition at line 345 of file geometry.h.

345 { return a22; }

◆ operator()() [1/3]

template<typename numeric >
CustomPoint<numeric> Beatmup::CustomMatrix2< numeric >::operator() ( numeric  x,
numeric  y 
) const
inline

Computes the corresponding transformed point of the point (x,y)

Definition at line 350 of file geometry.h.

350  {
351  return CustomPoint<numeric>(a11 * x + a12 * y, a21 * x + a22 * y);
352  }
2D point class
Definition: geometry.h:38
jobject jlong jint jint y
jobject jlong jint x

◆ operator()() [2/3]

template<typename numeric >
CustomPoint<numeric> Beatmup::CustomMatrix2< numeric >::operator() ( int  x,
int  y 
) const
inline

Integer overloading of (x,y) operator to avoid warnings.

Definition at line 357 of file geometry.h.

357  {
358  return this->operator()((float)x, (float)y);
359  }
CustomPoint< numeric > operator()(numeric x, numeric y) const
Computes the corresponding transformed point of the point (x,y)
Definition: geometry.h:350

◆ operator()() [3/3]

template<typename numeric >
CustomPoint<numeric> Beatmup::CustomMatrix2< numeric >::operator() ( const CustomPoint< numeric > &  point) const
inline

Computes transformed point of a given one.

Definition at line 364 of file geometry.h.

364  {
365  return CustomPoint<numeric>(a11 * point.x + a12 * point.y, a21 * point.x + a22 * point.y);
366  }

◆ operator*() [1/3]

template<typename numeric >
CustomMatrix2 Beatmup::CustomMatrix2< numeric >::operator* ( const CustomMatrix2< numeric > &  matrix) const
inline

Multiplies two matrices.

Definition at line 371 of file geometry.h.

371  {
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  }
2D affine transformation.
Definition: geometry.h:329
Beatmup::IntPoint result

◆ operator*() [2/3]

template<typename numeric >
CustomPoint<numeric> Beatmup::CustomMatrix2< numeric >::operator* ( const CustomPoint< numeric > &  point) const
inline

Multiplies matrix by a vector.

Definition at line 383 of file geometry.h.

383  {
384  return this->operator()(point);
385  }

◆ operator*() [3/3]

template<typename numeric >
CustomMatrix2 Beatmup::CustomMatrix2< numeric >::operator* ( const numeric  factor) const
inline

Multiplies matrix by a scalar.

Definition at line 390 of file geometry.h.

390  {
392  result.a11 = a11*factor;
393  result.a12 = a12*factor;
394  result.a21 = a21*factor;
395  result.a22 = a22*factor;
396  return result;
397  }
layer getMapping().setCenterPosition(Beatmup jlong jfloat factor

◆ scale() [1/2]

template<typename numeric >
void Beatmup::CustomMatrix2< numeric >::scale ( numeric  factor)
inline

Definition at line 399 of file geometry.h.

399  {
400  scale(factor, factor);
401  }
void scale(numeric factor)
Definition: geometry.h:399

◆ scale() [2/2]

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

Definition at line 403 of file geometry.h.

403  {
404  a11 *= x;
405  a12 *= y;
406  a21 *= x;
407  a22 *= y;
408  }

◆ prescale()

template<typename numeric >
void Beatmup::CustomMatrix2< numeric >::prescale ( numeric  x,
numeric  y 
)
inline

Definition at line 410 of file geometry.h.

410  {
411  a11 *= x;
412  a12 *= x;
413  a21 *= y;
414  a22 *= y;
415  }

◆ rotateRadians()

template<typename numeric >
void Beatmup::CustomMatrix2< numeric >::rotateRadians ( float  angle)
inline

Definition at line 417 of file geometry.h.

417  {
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  }
JNIEnv jlong jfloat jfloat s

◆ rotateDegrees()

template<typename numeric >
void Beatmup::CustomMatrix2< numeric >::rotateDegrees ( float  angle)
inline

Definition at line 429 of file geometry.h.

429  {
430  rotateRadians(angle * pi / 180.0f);
431  }
void rotateRadians(float angle)
Definition: geometry.h:417
const float pi
Definition: basic_types.h:29

◆ skewRadians()

template<typename numeric >
void Beatmup::CustomMatrix2< numeric >::skewRadians ( float  x,
float  y 
)
inline

Definition at line 433 of file geometry.h.

433  {
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  }

◆ skewDegrees()

template<typename numeric >
void Beatmup::CustomMatrix2< numeric >::skewDegrees ( float  x,
float  y 
)
inline

Definition at line 445 of file geometry.h.

445  {
446  skewRadians(x * pi / 180.0f, y * pi / 180.0f);
447  }
void skewRadians(float x, float y)
Definition: geometry.h:433

◆ det()

template<typename numeric >
numeric Beatmup::CustomMatrix2< numeric >::det ( ) const
inline

Transformation determinant.

Definition at line 452 of file geometry.h.

452  {
453  return a11*a22 - a12*a21;
454  }

◆ isInvertible()

template<typename numeric >
bool Beatmup::CustomMatrix2< numeric >::isInvertible ( ) const
inline

Definition at line 456 of file geometry.h.

456  {
457  return det() != 0;
458  }
numeric det() const
Transformation determinant.
Definition: geometry.h:452

◆ getInverse() [1/3]

template<typename numeric >
CustomMatrix2 Beatmup::CustomMatrix2< numeric >::getInverse ( ) const
inline

Computes inverse transformation.

Returns
the inverse

Definition at line 464 of file geometry.h.

464  {
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  }

◆ getInverse() [2/3]

template<typename numeric >
CustomPoint<numeric> Beatmup::CustomMatrix2< numeric >::getInverse ( numeric  x,
numeric  y 
) const
inline

Computes inverse of a given point.

Returns
the inverse

Definition at line 478 of file geometry.h.

478  {
479  numeric D = det();
480  return CustomPoint<numeric>(
481  ( x * a22 - y * a12) / D,
482  (-x * a21 + y * a11) / D
483  );
484  }

◆ getInverse() [3/3]

template<typename numeric >
CustomPoint<numeric> Beatmup::CustomMatrix2< numeric >::getInverse ( const CustomPoint< numeric > &  point) const
inline

Computes inverse of a given point.

Returns
the inverse

Definition at line 490 of file geometry.h.

490  {
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  }

◆ getTransposed()

template<typename numeric >
CustomMatrix2 Beatmup::CustomMatrix2< numeric >::getTransposed ( ) const
inline
Returns
transposed matrix

Definition at line 501 of file geometry.h.

501  {
502  CustomMatrix2 t;
503  t.a11 = a11;
504  t.a12 = a21;
505  t.a21 = a12;
506  t.a22 = a22;
507  return t;
508  }

◆ rescaleUnits()

template<typename numeric >
void Beatmup::CustomMatrix2< numeric >::rescaleUnits ( numeric  xIn,
numeric  yIn,
numeric  xOut,
numeric  yOut 
)
inline

Scales transformation input and output units If input/output axes change their scales, the transformation may be rescaled to keep the correspondence between the same points as before but in newly scaled coordinates.

Definition at line 515 of file geometry.h.

515  {
516  a11 = a11 * xOut / xIn;
517  a12 = a12 * xOut / yIn;
518  a21 = a21 * yOut / xIn;
519  a22 = a22 * yOut / yIn;
520  }

◆ isPointInsideBox()

template<typename numeric >
template<typename num >
bool Beatmup::CustomMatrix2< numeric >::isPointInsideBox ( num  x,
num  y,
CustomRectangle< num >  box 
) const
inline

Checks whether a given input point is inside a rectangular area when transformed.

Definition at line 525 of file geometry.h.

525  {
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  }
CustomPoint< numeric > b
Definition: geometry.h:131
CustomPoint< numeric > a
Definition: geometry.h:131
Beatmup::IntPoint p((int) x,(int) y)

◆ isPointInsideAxes() [1/2]

template<typename numeric >
bool Beatmup::CustomMatrix2< numeric >::isPointInsideAxes ( numeric  x,
numeric  y,
numeric  w,
numeric  h 
) const
inline

Checks whether a given input point is inside the unit square when transformed.

Definition at line 536 of file geometry.h.

536  {
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  }
jlong h
jlong jstring jint jint jint jint w

◆ isPointInsideAxes() [2/2]

template<typename numeric >
bool Beatmup::CustomMatrix2< numeric >::isPointInsideAxes ( numeric  x,
numeric  y 
) const
inline

Definition at line 544 of file geometry.h.

544  {
545  return isPointInsideAxes(x, y, 1, 1);
546  }
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

◆ getScalingX()

template<typename numeric >
numeric Beatmup::CustomMatrix2< numeric >::getScalingX ( )
inline

Computes X axis scaling factor.

Definition at line 551 of file geometry.h.

551  {
552  return sqrt(sqr(a11) + sqr(a21));
553  }
#define sqr(X)
Definition: geometry.h:24

◆ getScalingY()

template<typename numeric >
numeric Beatmup::CustomMatrix2< numeric >::getScalingY ( )
inline

Computes Y axis scaling factor.

Definition at line 558 of file geometry.h.

558  {
559  return sqrt(sqr(a12) + sqr(a22));
560  }

◆ getOrientationDegrees()

template<typename numeric >
float Beatmup::CustomMatrix2< numeric >::getOrientationDegrees ( )
inline

Returns first axis orientation in degrees.

Definition at line 565 of file geometry.h.

565  {
566  return atan2(a11, a12) *180/pi;
567  }

◆ getElements()

template<typename numeric >
void Beatmup::CustomMatrix2< numeric >::getElements ( float &  a11,
float &  a12,
float &  a21,
float &  a22 
) const
inline

Retrieves matrix element values.

Definition at line 572 of file geometry.h.

572  {
573  a11 = this->a11;
574  a12 = this->a12;
575  a21 = this->a21;
576  a22 = this->a22;
577  }

◆ setElements()

template<typename numeric >
void Beatmup::CustomMatrix2< numeric >::setElements ( float  a11,
float  a12,
float  a21,
float  a22 
)
inline

Sets matrix element values.

Definition at line 582 of file geometry.h.

582  {
583  this->a11 = a11;
584  this->a12 = a12;
585  this->a21 = a21;
586  this->a22 = a22;
587  }

Member Data Documentation

◆ a11

template<typename numeric >
numeric Beatmup::CustomMatrix2< numeric >::a11
private

Definition at line 331 of file geometry.h.

◆ a12

template<typename numeric >
numeric Beatmup::CustomMatrix2< numeric >::a12
private

Definition at line 331 of file geometry.h.

◆ a21

template<typename numeric >
numeric Beatmup::CustomMatrix2< numeric >::a21
private

Definition at line 331 of file geometry.h.

◆ a22

template<typename numeric >
numeric Beatmup::CustomMatrix2< numeric >::a22
private

transformation matrix coefficients

Definition at line 331 of file geometry.h.

◆ IDENTITY

template<typename T >
const CustomMatrix2< T > Beatmup::CustomMatrix2< T >::IDENTITY
static

Definition at line 588 of file geometry.h.


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