Beatmup
geometry.cpp
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 #include "geometry.h"
20 #include <limits>
21 
22 using namespace Beatmup;
23 
25 
26 
28 
29 AffineMapping::AffineMapping(const Matrix2& aMatrix, const Point& aPosition) :
30  matrix(aMatrix), position(aPosition)
31 {}
32 
34  matrix(rectangle.width(), rectangle.height()), position(rectangle.getX1(), rectangle.getY1())
35 {}
36 
37 
40 }
41 
43  matrix.setElements(1.0f, 0.0f, 0.0f, 1.0f);
45 }
46 
49  position = -(matrix * position);
50 }
51 
53  AffineMapping inverse;
54  inverse.matrix = matrix.getInverse();
55  inverse.position = - ( inverse.matrix * position );
56  return inverse;
57 }
58 
59 Point AffineMapping::getInverse(const Point& point) const {
60  return matrix.getInverse(point.x - position.x, point.y - position.y);
61 }
62 
63 Point AffineMapping::getInverse(float x, float y) const {
64  return matrix.getInverse(x - position.x, y - position.y);
65 }
66 
68  position = newPos - matrix(0.5f, 0.5f);
69 }
70 
71 void AffineMapping::translate(const Point& shift) {
72  position = position + shift;
73 }
74 
75 void AffineMapping::scale(float factor, const Point& fixedPoint) {
76  const Point pos0 = matrix(fixedPoint);
78  position = position + pos0 - matrix * fixedPoint;
79 }
80 
81 void AffineMapping::rotateDegrees(float angle, const Point& fixedPoint) {
82  const Point pos0 = matrix(fixedPoint);
83  matrix.rotateDegrees(angle);
84  position = position + pos0 - matrix * fixedPoint;
85 }
86 
87 bool AffineMapping::isPointInside(const Point& point) const {
88  return isPointInside(point.x, point.y);
89 }
90 
91 bool AffineMapping::isPointInside(float x, float y) const {
93 }
94 
95 bool AffineMapping::isPointInside(float x, float y, float width, float height) const {
97 }
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
static const AffineMapping IDENTITY
Definition: geometry.h:717
void setElements(float a11, float a12, float a21, float a22)
Sets matrix element values.
Definition: geometry.h:582
CustomMatrix2 getInverse() const
Computes inverse transformation.
Definition: geometry.h:464
void rotateDegrees(float angle)
Definition: geometry.h:429
static const CustomMatrix2 IDENTITY
Definition: geometry.h:588
void scale(numeric factor)
Definition: geometry.h:399
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
static const CustomPoint ZERO
Definition: geometry.h:122
jobject jlong jint jint y
jlong jint width
jlong jint jint height
jobject jlong jint x
Beatmup::AffineMapping & mapping
layer getMapping().setCenterPosition(Beatmup jlong jfloat factor