/usr/include/synfig-1.0/synfig/transformation.h is in libsynfig-dev 1.0.2-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | /* === S Y N F I G ========================================================= */
/*! \file transformation.h
** \brief Affine Transformation
**
** $Id$
**
** \legal
** ......... ... 2013 Ivan Mahonin
**
** This package is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License as
** published by the Free Software Foundation; either version 2 of
** the License, or (at your option) any later version.
**
** This package is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** General Public License for more details.
** \endlegal
*/
/* ========================================================================= */
/* === S T A R T =========================================================== */
#ifndef __SYNFIG_TRANSFORMATION_H
#define __SYNFIG_TRANSFORMATION_H
/* === H E A D E R S ======================================================= */
#include "vector.h"
#include "matrix.h"
#include "rect.h"
/* === M A C R O S ========================================================= */
/* === T Y P E D E F S ===================================================== */
/* === C L A S S E S & S T R U C T S ======================================= */
namespace synfig {
/*! \class Transformation
** \todo writeme
*/
class Transformation
{
public:
Vector offset;
Angle angle;
Angle skew_angle;
Vector scale;
Transformation():
offset(0.0, 0.0),
angle(Angle::rad(0.0)),
skew_angle(Angle::rad(0.0)),
scale(1.0, 1.0)
{ }
Transformation(
const Vector &offset,
const Angle &angle = Angle::rad(0.0),
const Angle &skew_angle = Angle::rad(0.0),
const Vector &scale = Vector(1.0, 1.0)
):
offset(offset),
angle(angle),
skew_angle(skew_angle),
scale(scale)
{ }
bool is_valid()const
{
return offset.is_valid()
&& !isnan(Angle::rad(angle).get())
&& !isnan(Angle::rad(skew_angle).get())
&& scale.is_valid();
}
bool
operator==(const Transformation &rhs)const
{
return offset==rhs.offset
&& angle==rhs.angle
&& skew_angle==rhs.skew_angle
&& scale==rhs.scale;
}
bool
operator!=(const Transformation &rhs)const
{
return offset!=rhs.offset
|| angle!=rhs.angle
|| skew_angle!=rhs.skew_angle
|| scale!=rhs.scale;
}
bool is_equal_to(const Transformation& rhs)const
{
static const Angle::rad epsilon_angle(0.0000000000001);
Angle::rad a = angle - rhs.angle;
Angle::rad sa = skew_angle - rhs.skew_angle;
return offset.is_equal_to(rhs.offset)
&& a < epsilon_angle && a > -epsilon_angle
&& sa < epsilon_angle && sa > -epsilon_angle
&& scale.is_equal_to(rhs.scale);
}
bool is_identity()const
{
return is_equal_to(Transformation());
}
Matrix get_matrix() const
{
if (is_identity()) return Matrix();
Vector axis_x(scale[0], angle);
Vector axis_y(scale[1], angle + skew_angle + Angle::deg(90.0));
return Matrix(axis_x, axis_y, offset);
}
void set_matrix(const Matrix &matrix)
{
if (matrix.is_identity()) *this = Transformation();
Vector axis_x(matrix.get_axis_x());
Vector axis_y(matrix.get_axis_y());
angle = axis_x.angle();
skew_angle = axis_y.angle() - angle - Angle::deg(90.0);
scale[0] = axis_x.mag();
scale[1] = axis_y.mag();
offset = matrix.get_offset();
}
explicit Transformation(const Matrix &matrix)
{ set_matrix(matrix); }
Matrix get_inverted_matrix() const
{ return get_matrix().invert(); }
Transformation get_back_transformation() const
{ return Transformation(get_inverted_matrix()); }
static Rect transform_bounds(const Matrix &matrix, const Rect &bounds)
{
if (isnan(bounds.minx) || isinf(bounds.minx)
|| isnan(bounds.maxx) || isinf(bounds.maxx)
|| isnan(bounds.miny) || isinf(bounds.miny)
|| isnan(bounds.maxy) || isinf(bounds.maxy))
return Rect::infinite();
Rect transformed_bounds(
matrix.get_transformed(
Vector(bounds.minx, bounds.miny) ));
transformed_bounds.expand(
matrix.get_transformed(
Vector(bounds.minx, bounds.maxy) ));
transformed_bounds.expand(
matrix.get_transformed(
Vector(bounds.maxx, bounds.miny) ));
transformed_bounds.expand(
matrix.get_transformed(
Vector(bounds.maxx, bounds.maxy) ));
return transformed_bounds;
}
Vector transform(const Vector &v, bool translate = true) const
{ return get_matrix().get_transformed(v, translate); }
Transformation transform(const Transformation &transformation) const
{ return Transformation( transformation.get_matrix()*get_matrix() ); }
Matrix transform(const Matrix &matrix) const
{ return matrix*get_matrix(); }
Rect transform_bounds(const Rect &bounds) const
{ return transform_bounds(get_matrix(), bounds); }
Vector back_transform(const Vector &v, bool translate = true) const
{ return get_inverted_matrix().get_transformed(v, translate); }
Transformation back_transform(const Transformation &transformation) const
{ return Transformation( transformation.get_matrix()*get_inverted_matrix() ); }
Matrix back_transform(const Matrix &matrix) const
{ return matrix*get_inverted_matrix(); }
Rect back_transform_bounds(const Rect &bounds) const
{ return transform_bounds(get_inverted_matrix(), bounds); }
static const Transformation identity() { return Transformation(); }
};
}; // END of namespace synfig
/* === E N D =============================================================== */
#endif
|