/*
* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* Michael G. Sloan <mgsloan@gmail.com>
*
* This code is in public domain
*/
namespace Geom {
/** Creates a Affine given an axis and origin point.
* The axis is represented as two vectors, which represent skew, rotation, and scaling in two dimensions.
* from_basis(Point(1, 0), Point(0, 1), Point(0, 0)) would return the identity matrix.
\param x_basis the vector for the x-axis.
\param y_basis the vector for the y-axis.
\param offset the translation applied by the matrix.
\return The new Affine.
*/
//NOTE: Inkscape's version is broken, so when including this version, you'll have to search for code with this func
}
}
}
/// Gets the translation imparted by the Affine.
}
for(int i = 0; i < 2; i++)
}
for(int i = 0; i < 2; i++)
}
/// Sets the translation imparted by the Affine.
for(int i = 0; i < 2; i++)
}
/** Calculates the amount of x-scaling imparted by the Affine. This is the scaling applied to
* the original x-axis region. It is \emph{not} the overall x-scaling of the transformation.
* Equivalent to L2(m.xAxis()). */
}
/** Calculates the amount of y-scaling imparted by the Affine. This is the scaling applied before
* the other transformations. It is \emph{not} the overall y-scaling of the transformation.
* Equivalent to L2(m.yAxis()). */
}
for (unsigned i = 0; i < 2; ++i) {
}
}
}
for (unsigned i = 2; i < 4; ++i) {
}
}
}
/** Sets this matrix to be the Identity Affine. */
}
/** @brief Check whether this matrix is an identity matrix.
* @param eps Numerical tolerance
* @return True iff the matrix is of the form
* \f$\left[\begin{array}{ccc}
1 & 0 & 0 \\
0 & 1 & 0 \\
0 & 0 & 1 \end{array}\right]\f$ */
}
/** @brief Check whether this matrix represents a pure translation.
* Will return true for the identity matrix, which represents a zero translation.
* @param eps Numerical tolerance
* @return True iff the matrix is of the form
* \f$\left[\begin{array}{ccc}
1 & 0 & 0 \\
0 & 1 & 0 \\
a & b & 1 \end{array}\right]\f$ */
}
/** @brief Check whether this matrix represents a pure nonzero translation.
* @param eps Numerical tolerance
* @return True iff the matrix is of the form
* \f$\left[\begin{array}{ccc}
1 & 0 & 0 \\
0 & 1 & 0 \\
a & b & 1 \end{array}\right]\f$ and \f$a, b \neq 0\f$ */
}
/** @brief Check whether this matrix represents pure scaling.
* @param eps Numerical tolerance
* @return True iff the matrix is of the form
* \f$\left[\begin{array}{ccc}
a & 0 & 0 \\
0 & b & 0 \\
0 & 0 & 1 \end{array}\right]\f$. */
if (isSingular(eps)) return false;
}
/** @brief Check whether this matrix represents pure, nonzero scaling.
* @param eps Numerical tolerance
* @return True iff the matrix is of the form
* \f$\left[\begin{array}{ccc}
a & 0 & 0 \\
0 & b & 0 \\
0 & 0 & 1 \end{array}\right]\f$ and \f$a, b \neq 1\f$. */
if (isSingular(eps)) return false;
return (!are_near(_c[0], 1.0, eps) || !are_near(_c[3], 1.0, eps)) && //NOTE: these are the diags, and the next line opposite diags
}
/** @brief Check whether this matrix represents pure uniform scaling.
* @param eps Numerical tolerance
* @return True iff the matrix is of the form
* \f$\left[\begin{array}{ccc}
a_1 & 0 & 0 \\
0 & a_2 & 0 \\
0 & 0 & 1 \end{array}\right]\f$ where \f$|a_1| = |a_2|\f$. */
if (isSingular(eps)) return false;
}
/** @brief Check whether this matrix represents pure, nonzero uniform scaling.
* @param eps Numerical tolerance
* @return True iff the matrix is of the form
* \f$\left[\begin{array}{ccc}
a_1 & 0 & 0 \\
0 & a_2 & 0 \\
0 & 0 & 1 \end{array}\right]\f$ where \f$|a_1| = |a_2|\f$
* and \f$a_1, a_2 \neq 1\f$. */
if (isSingular(eps)) return false;
// we need to test both c0 and c3 to handle the case of flips,
// which should be treated as nonzero uniform scales
}
/** @brief Check whether this matrix represents a pure rotation.
* @param eps Numerical tolerance
* @return True iff the matrix is of the form
* \f$\left[\begin{array}{ccc}
a & b & 0 \\
-b & a & 0 \\
0 & 0 & 1 \end{array}\right]\f$ and \f$a^2 + b^2 = 1\f$. */
}
/** @brief Check whether this matrix represents a pure, nonzero rotation.
* @param eps Numerical tolerance
* @return True iff the matrix is of the form
* \f$\left[\begin{array}{ccc}
a & b & 0 \\
-b & a & 0 \\
0 & 0 & 1 \end{array}\right]\f$, \f$a^2 + b^2 = 1\f$ and \f$a \neq 1\f$. */
}
/** @brief Check whether this matrix represents a non-zero rotation about any point.
* @param eps Numerical tolerance
* @return True iff the matrix is of the form
* \f$\left[\begin{array}{ccc}
a & b & 0 \\
-b & a & 0 \\
c & d & 1 \end{array}\right]\f$, \f$a^2 + b^2 = 1\f$ and \f$a \neq 1\f$. */
}
/** @brief For a (possibly non-pure) non-zero-rotation matrix, calculate the rotation center.
* @pre The matrix must be a non-zero-rotation matrix to prevent division by zero, see isNonzeroNonpureRotation().
* @return The rotation center x, the solution to the equation
* \f$A x = x\f$. */
return Point(x,y);
};
/** @brief Check whether this matrix represents pure horizontal shearing.
* @param eps Numerical tolerance
* @return True iff the matrix is of the form
* \f$\left[\begin{array}{ccc}
1 & 0 & 0 \\
k & 1 & 0 \\
0 & 0 & 1 \end{array}\right]\f$. */
}
/** @brief Check whether this matrix represents pure, nonzero horizontal shearing.
* @param eps Numerical tolerance
* @return True iff the matrix is of the form
* \f$\left[\begin{array}{ccc}
1 & 0 & 0 \\
k & 1 & 0 \\
0 & 0 & 1 \end{array}\right]\f$ and \f$k \neq 0\f$. */
}
/** @brief Check whether this matrix represents pure vertical shearing.
* @param eps Numerical tolerance
* @return True iff the matrix is of the form
* \f$\left[\begin{array}{ccc}
1 & k & 0 \\
0 & 1 & 0 \\
0 & 0 & 1 \end{array}\right]\f$. */
}
/** @brief Check whether this matrix represents pure, nonzero vertical shearing.
* @param eps Numerical tolerance
* @return True iff the matrix is of the form
* \f$\left[\begin{array}{ccc}
1 & k & 0 \\
0 & 1 & 0 \\
0 & 0 & 1 \end{array}\right]\f$ and \f$k \neq 0\f$. */
}
/** @brief Check whether this matrix represents zooming.
* Zooming is any combination of translation and uniform non-flipping scaling.
* It preserves angles, ratios of distances between arbitrary points
* and unit vectors of line segments.
* @param eps Numerical tolerance
* @return True iff the matrix is invertible and of the form
* \f$\left[\begin{array}{ccc}
a & 0 & 0 \\
0 & a & 0 \\
b & c & 1 \end{array}\right]\f$. */
if (isSingular(eps)) return false;
}
/** @brief Check whether the transformation preserves areas of polygons.
* This means that the transformation can be any combination of translation, rotation,
* shearing and squeezing (non-uniform scaling such that the absolute value of the product
* of Y-scale and X-scale is 1).
* @param eps Numerical tolerance
* @return True iff \f$|\det A| = 1\f$. */
{
}
/** @brief Check whether the transformation preserves angles between lines.
* This means that the transformation can be any combination of translation, uniform scaling,
* rotation and flipping.
* @param eps Numerical tolerance
* @return True iff the matrix is of the form
* \f$\left[\begin{array}{ccc}
a & b & 0 \\
-b & a & 0 \\
c & d & 1 \end{array}\right]\f$ or
\f$\left[\begin{array}{ccc}
-a & b & 0 \\
b & a & 0 \\
c & d & 1 \end{array}\right]\f$. */
{
if (isSingular(eps)) return false;
}
/** @brief Check whether the transformation preserves distances between points.
* This means that the transformation can be any combination of translation,
* rotation and flipping.
* @param eps Numerical tolerance
* @return True iff the matrix is of the form
* \f$\left[\begin{array}{ccc}
a & b & 0 \\
-b & a & 0 \\
c & d & 1 \end{array}\right]\f$ or
\f$\left[\begin{array}{ccc}
-a & b & 0 \\
b & a & 0 \\
c & d & 1 \end{array}\right]\f$ and \f$a^2 + b^2 = 1\f$. */
{
}
/** @brief Check whether this transformation flips objects.
* A transformation flips objects if it has a negative scaling component. */
return det() < 0;
}
/** @brief Check whether this matrix is singular.
* Singular matrices have no inverse, which means that applying them to a set of points
* results in a loss of information.
* @param eps Numerical tolerance
* @return True iff the determinant is near zero. */
}
/** @brief Compute the inverse matrix.
* Inverse is a matrix (denoted \f$A^{-1}\f$) such that \f$AA^{-1} = A^{-1}A = I\f$.
* Singular matrices have no inverse (for example a matrix that has two of its columns equal).
* For such matrices, the identity matrix will be returned instead.
* @param eps Numerical tolerance
* @return Inverse of the matrix, or the identity matrix if the inverse is undefined.
* @post (m * m.inverse()).isIdentity() == true */
Affine d;
if(mx > 0) {
} else {
d.setIdentity();
}
} else {
d.setIdentity();
}
return d;
}
/** @brief Calculate the determinant.
* @return \f$\det A\f$. */
// TODO this can overflow
}
/** @brief Calculate the square of the descriminant.
* This is simply the absolute value of the determinant.
* @return \f$|\det A|\f$. */
}
/** @brief Calculate the descriminant.
* If the matrix doesn't contain a shearing or non-uniform scaling component, this value says
* how will the length of any line segment change after applying this transformation
* to arbitrary objects on a plane. The new length will be
* @code line_seg.length() * m.descrim()) @endcode
* @return \f$\sqrt{|\det A|}\f$. */
}
/** @brief Combine this transformation with another one.
* After this operation, the matrix will correspond to the transformation
* obtained by first applying the original version of this matrix, and then
* applying @a m. */
for(int a = 0; a < 5; a += 2) {
for(int b = 0; b < 2; b++) {
}
}
for(int a = 0; a < 6; ++a) {
}
return *this;
}
//TODO: What's this!?!
/** Given a matrix m such that unit_circle = m*x, this returns the
* quadratic form x*A*x = 1.
* @relates Affine */
0, 0);
return ret; // allow NRVO
}
double const B = -m[0] - m[3];
double const C = m[0]*m[3] - m[1]*m[2];
for (unsigned i = 0; i < v.size(); ++i) {
values[i] = v[i];
}
for (unsigned i = v.size(); i < 2; ++i) {
values[i] = 0;
}
}
double const B = -m[0][0] - m[1][1];
double const C = m[0][0]*m[1][1] - m[1][0]*m[0][1];
for (unsigned i = 0; i < v.size(); ++i) {
values[i] = v[i];
}
for (unsigned i = v.size(); i < 2; ++i) {
values[i] = 0;
}
}
/** @brief Nearness predicate for affine transforms.
* @returns True if all entries of matrices are within eps of each other.
* @relates Affine */
{
}
} //namespace Geom
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :