affine.cpp revision 40742313779ee5e43be93a9191f1c86412cf183b
/*
* 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())
*/
double Affine::expansionX() const {
}
/** 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())
*/
double Affine::expansionY() const {
}
double exp_x = expansionX();
}
}
double exp_y = expansionY();
}
}
/** Sets this matrix to be the Identity Affine. */
void Affine::setIdentity() {
}
/** @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$. */
}
/** @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$. */
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 & 0 & 0 \\
0 & a & 0 \\
0 & 0 & 1 \end{array}\right]\f$. */
}
/** @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 & 0 & 0 \\
0 & a & 0 \\
0 & 0 & 1 \end{array}\right]\f$ and \f$a \neq 1\f$. */
}
/** @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 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 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 of the form
* \f$\left[\begin{array}{ccc}
a & 0 & 0 \\
0 & a & 0 \\
b & c & 1 \end{array}\right]\f$. */
}
/** @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
* and 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 \\
c & d & 1 \end{array}\right]\f$. */
{
}
/** @brief Check whether the transformation preserves distances between points.
* This means that the transformation can be any combination of translation and 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 \\
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. */
// TODO shouldn't this be 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}) 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!?!
0, 0);
return ret; // allow NRVO
}
double const B = -m[0] - m[3];
double const C = m[0]*m[3] - m[1]*m[2];
double const center = -B/2.0;
for (int i = 0; i < 2; i++) {
}
}
if(q2 == 0) {
if(q1 == 0) { // zero or infinite roots
n = 0;
} else {
n = 1;
}
} else {
if (desc < 0)
n = 0;
else if (desc == 0) {
n = 1;
} else {
n = 2;
}
}
}
double const B = -m[0][0] - m[1][1];
double const C = m[0][0]*m[1][1] - m[1][0]*m[0][1];
//double const desc = B*B-4*C;
//double t = -0.5*(B+sgn(B)*desc);
int n;
for (int i = 0; i < n; i++)
for (int i = n; i < 2; i++)
}
} //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 :