roo_display
API Documentation for roo_display
Loading...
Searching...
No Matches
smooth_transformation.cpp
Go to the documentation of this file.
2
3namespace roo_display {
4
5namespace {
6
7template <typename TransformationType>
8Box TransformExtents(const TransformationType& transformation, Box extents) {
9 FpPoint tl =
10 transformation.apply({(float)extents.xMin(), (float)extents.yMin()});
11 FpPoint tr =
12 transformation.apply({(float)extents.xMax(), (float)extents.yMin()});
13 FpPoint bl =
14 transformation.apply({(float)extents.xMin(), (float)extents.yMax()});
15 FpPoint br =
16 transformation.apply({(float)extents.xMax(), (float)extents.yMax()});
17 float xMin = std::min(std::min(tl.x, tr.x), std::min(bl.x, br.x));
18 float yMin = std::min(std::min(tl.y, tr.y), std::min(bl.y, br.y));
19 float xMax = std::max(std::max(tl.x, tr.x), std::max(bl.x, br.x));
20 float yMax = std::max(std::max(tl.y, tr.y), std::max(bl.y, br.y));
21 return Box((int16_t)floorf(xMin), (int16_t)floorf(yMin), (int16_t)ceilf(xMax),
22 (int16_t)ceilf(yMax));
23}
24
25} // namespace
26
27Translation Translate(float dx, float dy) { return Translation(dx, dy); }
28
29Scaling Scale(float sx, float sy) { return Scaling(sx, sy); }
30
31AffineTransformation ScaleAbout(float sx, float sy, const FpPoint& center) {
32 return Translate(-center.x, -center.y)
33 .then(Scale(sx, sy))
35}
36
38
39Rotation RotateRight() { return RotateRight(M_PI * 0.5f); }
40
46
52
54
55Rotation RotateLeft() { return RotateLeft(M_PI * 0.5f); }
56
60
64
65AffineTransformation Shear(float sx, float sy) {
66 return AffineTransformation(1.0f + sx * sy, sx, sy, 1.0f, 0.0f, 0.0f);
67}
68
69AffineTransformation Shear(float sx, float sy, const FpPoint& base) {
70 return Translate(-base.x, -base.y)
71 .then(Shear(sx, sy))
72 .then(Translate(base.x, base.y));
73}
74
76 return AffineTransformation(1.0f, sx, 0.0f, 1.0f, 0.0f, 0.0f);
77}
78
80 return Translate(0.0f, -base_y)
81 .then(Shear(sx, 0.0f))
82 .then(Translate(0.0f, base_y));
83}
84
86 return AffineTransformation(1.0f, 0.0f, sy, 1.0f, 0.0f, 0.0f);
87}
88
90 return Translate(-base_x, 0.0f)
91 .then(Shear(0.0f, sy))
92 .then(Translate(base_x, 0.0f));
93}
94
96 return ProjectiveTransformation(1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, px, py,
97 1.0f);
98}
99
101 const FpPoint& base) {
102 return Translate(-base.x, -base.y)
104 .then(Translate(base.x, base.y));
105}
106
111
113
115
117
122
124 return Translation(dx_ + t.dx(), dy_ + t.dy());
125}
126
128 return AffineTransformation(t.sx(), 0, 0, t.sy(), t.sx() * dx_, t.sy() * dy_);
129}
130
132 return AffineTransformation(t.cos_theta(), -t.sin_theta(), t.sin_theta(),
133 t.cos_theta(),
134 t.cos_theta() * dx_ - t.sin_theta() * dy_,
135 t.sin_theta() * dx_ + t.cos_theta() * dy_);
136}
137
139 return AffineTransformation(t.a11(), t.a12(), t.a21(), t.a22(),
140 t.a11() * dx_ + t.a12() * dy_ + t.tx(),
141 t.a21() * dx_ + t.a22() * dy_ + t.ty());
142}
143
147
149 return AffineTransformation(sx_, 0, 0, sy_, t.dx(), t.dy());
150}
151
153 return Scaling(sx_ * t.sx(), sy_ * t.sy());
154}
155
157 return AffineTransformation(sx_ * t.cos_theta(), -sy_ * t.sin_theta(),
158 sx_ * t.sin_theta(), sy_ * t.cos_theta(), 0, 0);
159}
160
162 return AffineTransformation(sx_ * t.a11(), sy_ * t.a12(), sx_ * t.a21(),
163 sy_ * t.a22(), t.tx(), t.ty());
164}
165
169
171 return TransformExtents(*this, extents);
172}
173
175 return AffineTransformation(cos_theta_, -sin_theta_, sin_theta_, cos_theta_,
176 t.dx(), t.dy());
177}
178
180 return AffineTransformation(t.sx() * cos_theta_, -t.sx() * sin_theta_,
181 t.sy() * sin_theta_, t.sy() * cos_theta_, 0, 0);
182}
183
185 return Rotation(theta_ + t.theta());
186}
187
189 return AffineTransformation(t.a11() * cos_theta_ + t.a12() * sin_theta_,
190 -t.a11() * sin_theta_ + t.a12() * cos_theta_,
191 t.a21() * cos_theta_ + t.a22() * sin_theta_,
192 -t.a21() * sin_theta_ + t.a22() * cos_theta_,
193 t.tx(), t.ty());
194}
195
199
201 return TransformExtents(*this, extents);
202}
203
205 return AffineTransformation(a11_, a12_, a21_, a22_, tx_ + t.dx(),
206 ty_ + t.dy());
207}
208
210 return AffineTransformation(t.sx() * a11_, t.sx() * a12_, t.sy() * a21_,
211 t.sy() * a22_, t.sx() * tx_, t.sy() * ty_);
212}
213
215 return AffineTransformation(t.cos_theta() * a11_ - t.sin_theta() * a21_,
216 t.cos_theta() * a12_ - t.sin_theta() * a22_,
217 t.sin_theta() * a11_ + t.cos_theta() * a21_,
218 t.sin_theta() * a12_ + t.cos_theta() * a22_,
219 t.cos_theta() * tx_ - t.sin_theta() * ty_,
220 t.sin_theta() * tx_ + t.cos_theta() * ty_);
221}
222
225 t.a11() * a11_ + t.a12() * a21_, t.a11() * a12_ + t.a12() * a22_,
226 t.a21() * a11_ + t.a22() * a21_, t.a21() * a12_ + t.a22() * a22_,
227 t.a11() * tx_ + t.a12() * ty_ + t.tx(),
228 t.a21() * tx_ + t.a22() * ty_ + t.ty());
229}
230
235
239
243
247
252
256 t.m11() * m11_ + t.m12() * m21_ + t.m13() * m31_,
257 t.m11() * m12_ + t.m12() * m22_ + t.m13() * m32_,
258 t.m11() * m13_ + t.m12() * m23_ + t.m13() * m33_,
259 t.m21() * m11_ + t.m22() * m21_ + t.m23() * m31_,
260 t.m21() * m12_ + t.m22() * m22_ + t.m23() * m32_,
261 t.m21() * m13_ + t.m22() * m23_ + t.m23() * m33_,
262 t.m31() * m11_ + t.m32() * m21_ + t.m33() * m31_,
263 t.m31() * m12_ + t.m32() * m22_ + t.m33() * m32_,
264 t.m31() * m13_ + t.m32() * m23_ + t.m33() * m33_);
265}
266
268 float c11 = m22_ * m33_ - m23_ * m32_;
269 float c12 = -(m21_ * m33_ - m23_ * m31_);
270 float c13 = m21_ * m32_ - m22_ * m31_;
271 float c21 = -(m12_ * m33_ - m13_ * m32_);
272 float c22 = m11_ * m33_ - m13_ * m31_;
273 float c23 = -(m11_ * m32_ - m12_ * m31_);
274 float c31 = m12_ * m23_ - m13_ * m22_;
275 float c32 = -(m11_ * m23_ - m13_ * m21_);
276 float c33 = m11_ * m22_ - m12_ * m21_;
277
278 float det = m11_ * c11 + m12_ * c12 + m13_ * c13;
279 float inv_det = 1.0f / det;
282 c13 * inv_det, c23 * inv_det, c33 * inv_det);
283}
284
286 return TransformExtents(*this, extents);
287}
288
289} // namespace roo_display
General affine transformation.
AffineTransformation then(IdentityTransformation t) const
Axis-aligned integer rectangle.
Definition box.h:12
IdentityTransformation then(IdentityTransformation t) const
General projective transformation (2D homography).
ProjectiveTransformation inversion() const
ProjectiveTransformation then(IdentityTransformation t) const
Rotation by angle in radians (clockwise).
Rotation then(IdentityTransformation t) const
Box transformExtents(Box extents) const
Scaling then(IdentityTransformation t) const
Translation by (dx, dy).
Translation then(IdentityTransformation t) const
Defines 140 opaque HTML named colors.
AffineTransformation RotateRightAbout(float angle, const FpPoint &center)
Return a clockwise rotation about a point.
AffineTransformation RotateLeftAbout(float angle, const FpPoint &center)
Return a 90-degree counter-clockwise rotation about a point.
AffineTransformation ShearVertically(float sy)
Return a vertical shear rooted at the origin.
Scaling Scale(float sx, float sy)
Return a scaling about the origin.
AffineTransformation ShearHorizontallyAbout(float sx, float base_y)
Return a horizontal shear rooted at base_y.
Rotation RotateRight()
Return a 90-degree clockwise rotation about the origin.
AffineTransformation ShearVerticallyAbout(float sy, float base_x)
Return a vertical shear rooted at base_x.
ProjectiveTransformation PerspectiveAbout(float px, float py, const FpPoint &base)
Return a perspective transformation rooted at base.
AffineTransformation ShearHorizontally(float sx)
Return a horizontal shear rooted at the origin.
Translation Translate(float dx, float dy)
Return a translation by the specified vector.
AffineTransformation ScaleAbout(float sx, float sy, const FpPoint &center)
Return a scaling about a given center.
AffineTransformation Shear(float sx, float sy)
Return a shear rooted at the origin.
ProjectiveTransformation Perspective(float px, float py)
Return a perspective transformation rooted at the origin.
Rotation RotateLeft()
Return a 90-degree counter-clockwise rotation about the origin.
Floating-point point.
Definition point.h:12