matrix.cpp revision a7db6de6cc11de8b084ef3b9061a4b40a9c08a2b
#define __Geom_MATRIX_C__
/** \file
* Various matrix routines. Currently includes some Geom::Rotate etc. routines too.
*/
/*
* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* Michael G. Sloan <mgsloan@gmail.com>
*
* This code is in public domain
*/
namespace Geom {
/** Creates a Matrix 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 Matrix.
*/
//NOTE: Inkscape's version is broken, so when including this version, you'll have to search for code with this func
//TODO: move to Matrix::from_basis
}
}
}
/** Gets the translation imparted by the Matrix.
*/
}
for(int i = 0; i < 2; i++)
}
for(int i = 0; i < 2; i++)
}
/** Sets the translation imparted by the Matrix.
*/
for(int i = 0; i < 2; i++)
}
/** Calculates the amount of x-scaling imparted by the Matrix. 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 Matrix::expansionX() const {
}
/** Calculates the amount of y-scaling imparted by the Matrix. 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 Matrix::expansionY() const {
}
double exp_x = expansionX();
}
}
double exp_y = expansionY();
}
}
/** Sets this matrix to be the Identity Matrix. */
void Matrix::setIdentity() {
}
//TODO: use eps
}
/** Answers the question "Does this matrix perform a translation, and \em{only} a translation?"
\param eps an epsilon value defaulting to EPSILON
*/
}
/** Answers the question "Does this matrix perform a scale, and \em{only} a Scale?"
\param eps an epsilon value defaulting to EPSILON
*/
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
}
/** Answers the question "Does this matrix perform a uniform scale, and \em{only} a uniform scale?"
\param eps an epsilon value defaulting to EPSILON
*/
}
/** Answers the question "Does this matrix perform a rotation, and \em{only} a rotation?"
\param eps an epsilon value defaulting to EPSILON
*/
}
}
}
}
}
/** Attempts to calculate the inverse of a matrix.
* This is a Matrix such that m * m.inverse() is very near (hopefully < epsilon difference) the identity Matrix.
* \textbf{The Identity Matrix is returned if the matrix has no inverse.}
\return The inverse of the Matrix if defined, otherwise the Identity Matrix.
*/
Matrix d;
} else {
d.setIdentity();
}
return d;
}
/** Calculates the determinant of a Matrix. */
}
/** Calculates the scalar of the descriminant of the Matrix.
* This is simply the absolute value of the determinant.
*/
}
/** Calculates the descriminant of the Matrix. */
}
for(int a = 0; a < 5; a += 2) {
for(int b = 0; b < 2; b++) {
}
}
return ret;
}
//TODO: What's this!?!
0, 0);
}
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++) {
}
}
} //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:encoding=utf-8:textwidth=99 :