TwiceAsNice
2019-02-18
|
The Nice::WMatrix class specifies 2D transformations of a coordinate system. More...
#include <WMatrix.h>
Related Functions | |
(Note that these are not member functions.) | |
Nice::Point | operator* (const Nice::Point &point, const Nice::WMatrix &matrix) |
std::ostream & | operator<< (std::ostream &stream, const Nice::WMatrix &matrix) |
std::istream & | operator>> (std::istream &stream, Nice::WMatrix &matrix) |
Additional Inherited Members | |
![]() | |
::Ice::Double | m11 |
::Ice::Double | m12 |
::Ice::Double | m21 |
::Ice::Double | m22 |
::Ice::Double | dx |
::Ice::Double | dy |
The Nice::WMatrix class specifies 2D transformations of a coordinate system.
A matrix specifies how to translate, scale, shear or rotate the coordinate system, and is typically used when rendering graphics.
A Nice::WMatrix object can be built using the setWMatrixVar(), scale(), rotate(), translate() and shear() functions. Alternatively, it can be built by applying {Nice::WMatrix::Basic WMatrixVar Operations}{basic matrix operations}. The matrix can also be defined when constructed, and it can be reset to the identity matrix (the default) using the reset() function.
The Nice::WMatrix class supports mapping of graphic primitives: A given point, line, polygon, region, or painter path can be mapped to the coordinate system defined by this matrix using the map() function. In case of a rectangle, its coordinates can be transformed using the mapRect() function. A rectangle can also be transformed into a polygon (mapped to the coordinate system defined by this matrix), using the mapToPolygon() function.
Nice::WMatrix provides the isIdentity() function which returns true if the matrix is the identity matrix, and the isInvertible() function which returns true if the matrix is non-singular (i.e. AB = BA = I). The inverted() function returns an inverted copy of this matrix if it is invertible (otherwise it returns the identity matrix). In addition, Nice::WMatrix provides the det() function returning the matrix's determinant.
Finally, the Nice::WMatrix class supports matrix multiplication, and objects of the class can be streamed as well as compared.
Nice::WMatrix::WMatrix | ( | ) |
Constructs an identity matrix.
All elements are set to zero except Nice::WMatrixVar::m11
and Nice::WMatrixVar::m22
(specifying the scale), which are set to 1.
Nice::WMatrix::WMatrix | ( | double | _m11, |
double | _m12, | ||
double | _m21, | ||
double | _m22, | ||
double | _dx, | ||
double | _dy | ||
) |
Constructs a matrix with the elements, Nice::WMatrixVar::m11, Nice::WMatrixVar::m12, Nice::WMatrixVar::m21, Nice::WMatrixVar::m22, Nice::WMatrixVar::dx and Nice::WMatrixVar::dy.
Constructs a matrix that is a copy of the given matrix.
Nice::WMatrix::WMatrix | ( | const Nice::WMatrixVar & | _matrix | ) |
Constructs a matrix that is a copy of the given matrix.
Nice::WMatrix::WMatrix | ( | ) |
Nice::WMatrix::WMatrix | ( | double | _m11, |
double | _m12, | ||
double | _m21, | ||
double | _m22, | ||
double | _dx, | ||
double | _dy | ||
) |
Nice::WMatrix::WMatrix | ( | const Nice::WMatrixVar & | matrix | ) |
|
inline |
Returns the matrix's determinant.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Nice::WMatrix Nice::WMatrix::inverted | ( | bool * | invertible = 0 | ) | const |
Returns an inverted copy of this matrix.
If the matrix is singular (not invertible), the returned matrix is the identity matrix. If invertible is valid (i.e. not 0), its value is set to true if the matrix is invertible, otherwise it is set to false.
|
inline |
|
inline |
Returns true if the matrix is the identity matrix, otherwise returns false.
|
inline |
Returns true if the matrix is invertible, otherwise returns false.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
void Nice::WMatrix::map | ( | int | x, |
int | y, | ||
int * | tx, | ||
int * | ty | ||
) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Maps the given coordinates x and y into the coordinate system defined by this matrix. The resulting values are put in *tx and *ty, respectively. Note that the transformed coordinates are rounded to the nearest integer.
void Nice::WMatrix::map | ( | int | x, |
int | y, | ||
int * | tx, | ||
int * | ty | ||
) | const |
void Nice::WMatrix::map | ( | double | x, |
double | y, | ||
double * | tx, | ||
double * | ty | ||
) | const |
Maps the given coordinates x and y into the coordinate system defined by this matrix. The resulting values are put in *tx and *ty, respectively.
The coordinates are transformed using the following formulas:
The point (x, y) is the original point, and (x', y') is the transformed point.
void Nice::WMatrix::map | ( | double | x, |
double | y, | ||
double * | tx, | ||
double * | ty | ||
) | const |
Nice::Rect Nice::WMatrix::map | ( | const Nice::Rect & | ) | const |
Nice::Rect Nice::WMatrix::map | ( | const Nice::Rect & | rect | ) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Creates and returns a Nice::Rect object that is a copy of the given rectangle, mapped into the coordinate system defined by this matrix. Note that the transformed coordinates are rounded to the nearest integer.
Creates and returns a Nice::Rect object that is a copy of the given rectangle, mapped into the coordinate system defined by this matrix.
Use the mapRect() function instead.
Nice::Point Nice::WMatrix::map | ( | const Point & | p | ) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Creates and returns a Nice::Point object that is a copy of the given point, mapped into the coordinate system defined by this matrix. Note that the transformed coordinates are rounded to the nearest integer.
Nice::Line Nice::WMatrix::map | ( | const Line & | l | ) | const |
Nice::Polygon Nice::WMatrix::map | ( | const Polygon & | a | ) | const |
Returns true if this matrix is not equal to the given matrix, otherwise returns false.
Nice::WMatrix Nice::WMatrix::operator* | ( | const WMatrix & | o | ) | const |
Returns the result of multiplying this matrix by the given matrix.
Note that matrix multiplication is not commutative, i.e. a*b != b*a.
Nice::WMatrix & Nice::WMatrix::operator*= | ( | const WMatrix & | matrix | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns the result of multiplying this matrix by the given matrix.
Nice::WMatrix & Nice::WMatrix::operator= | ( | const WMatrix & | matrix | ) |
Assigns the given matrix's values to this matrix.
Returns true if this matrix is equal to the given matrix, otherwise returns false.
void Nice::WMatrix::reset | ( | ) |
void Nice::WMatrix::reset | ( | ) |
Nice::WMatrix & Nice::WMatrix::rotate | ( | double | degrees | ) |
Rotates the coordinate system the given degrees counterclockwise.
Note that if you apply a Nice::WMatrix to a point defined in widget coordinates, the direction of the rotation will be clockwise because the y-axis points downwards.
Returns a reference to the matrix.
WMatrix& Nice::WMatrix::rotate | ( | double | a | ) |
Nice::WMatrix & Nice::WMatrix::scale | ( | double | sx, |
double | sy | ||
) |
Scales the coordinate system by sx horizontally and sy vertically, and returns a reference to the matrix.
WMatrix& Nice::WMatrix::scale | ( | double | sx, |
double | sy | ||
) |
void Nice::WMatrix::setWMatrixVar | ( | double | _m11, |
double | _m12, | ||
double | _m21, | ||
double | _m22, | ||
double | _dx, | ||
double | _dy | ||
) |
void Nice::WMatrix::setWMatrixVar | ( | double | _m11, |
double | _m12, | ||
double | _m21, | ||
double | _m22, | ||
double | _dx, | ||
double | _dy | ||
) |
Sets the matrix elements to the specified values, Nice::WMatrixVar::m11, Nice::WMatrixVar::m12, Nice::WMatrixVar::m21, Nice::WMatrixVar::m22, Nice::WMatrixVar::dx and Nice::WMatrixVar::dy.
Note that this function replaces the previous values. Nice::WMatrix provide the translate(), rotate(), scale() and shear() convenience functions to manipulate the various matrix elements based on the currently defined coordinate system.
Nice::WMatrix & Nice::WMatrix::shear | ( | double | sh, |
double | sv | ||
) |
Shears the coordinate system by sh horizontally and sv vertically, and returns a reference to the matrix.
WMatrix& Nice::WMatrix::shear | ( | double | sh, |
double | sv | ||
) |
WMatrix& Nice::WMatrix::translate | ( | double | dx, |
double | dy | ||
) |
Nice::WMatrix & Nice::WMatrix::translate | ( | double | _dx, |
double | _dy | ||
) |
Moves the coordinate system Nice::WMatrixVar::dx along the x axis and Nice::WMatrixVar::dy along the y axis, and returns a reference to the matrix.
|
related |
This is the same as {matrix}.map({point}).
|
related |
Writes the given matrix to the given stream and returns a reference to the stream.
|
related |
Reads the given matrix from the given stream and returns a reference to the stream.