TwiceAsNice  2019-02-18
Public Member Functions | Related Functions | List of all members
Nice::WMatrix Class Reference

The Nice::WMatrix class specifies 2D transformations of a coordinate system. More...

#include <WMatrix.h>

Inheritance diagram for Nice::WMatrix:
Inheritance graph
Collaboration diagram for Nice::WMatrix:
Collaboration graph

Public Member Functions

 WMatrix ()
 
 WMatrix (double _m11, double _m12, double _m21, double _m22, double _dx, double _dy)
 
 WMatrix (const WMatrix &matrix)
 
 WMatrix (const Nice::WMatrixVar &matrix)
 
void setWMatrixVar (double _m11, double _m12, double _m21, double _m22, double _dx, double _dy)
 
double m11 () const
 
double m12 () const
 
double m21 () const
 
double m22 () const
 
double dx () const
 
double dy () const
 
void map (int x, int y, int *tx, int *ty) const
 
void map (double x, double y, double *tx, double *ty) const
 
Nice::Rect map (const Nice::Rect &) const
 
Point map (const Point &p) const
 
Line map (const Line &l) const
 
Polygon map (const Polygon &a) const
 
void reset ()
 
bool isIdentity () const
 
WMatrixtranslate (double dx, double dy)
 
WMatrixscale (double sx, double sy)
 
WMatrixshear (double sh, double sv)
 
WMatrixrotate (double a)
 
bool isInvertible () const
 
double det () const
 
WMatrix inverted (bool *invertible=0) const
 
bool operator== (const WMatrix &) const
 
bool operator!= (const WMatrix &) const
 
WMatrixoperator*= (const WMatrix &)
 
WMatrix operator* (const WMatrix &o) const
 
WMatrixoperator= (const WMatrix &)
 
 WMatrix ()
 
 WMatrix (double _m11, double _m12, double _m21, double _m22, double _dx, double _dy)
 
 WMatrix (const WMatrix &matrix)
 
 WMatrix (const Nice::WMatrixVar &matrix)
 
void setWMatrixVar (double _m11, double _m12, double _m21, double _m22, double _dx, double _dy)
 
double m11 () const
 
double m12 () const
 
double m21 () const
 
double m22 () const
 
double dx () const
 
double dy () const
 
void map (int x, int y, int *tx, int *ty) const
 
void map (double x, double y, double *tx, double *ty) const
 
Nice::Rect map (const Nice::Rect &) const
 
Point map (const Point &p) const
 
Line map (const Line &l) const
 
Polygon map (const Polygon &a) const
 
void reset ()
 
bool isIdentity () const
 
WMatrixtranslate (double dx, double dy)
 
WMatrixscale (double sx, double sy)
 
WMatrixshear (double sh, double sv)
 
WMatrixrotate (double a)
 
bool isInvertible () const
 
double det () const
 
WMatrix inverted (bool *invertible=0) const
 
bool operator== (const WMatrix &) const
 
bool operator!= (const WMatrix &) const
 
WMatrixoperator*= (const WMatrix &)
 
WMatrix operator* (const WMatrix &o) const
 
WMatrixoperator= (const WMatrix &)
 
- Public Member Functions inherited from Nice::WMatrixVar
bool operator== (const WMatrixVar &__rhs) const
 
bool operator< (const WMatrixVar &__rhs) const
 
bool operator!= (const WMatrixVar &__rhs) const
 
bool operator<= (const WMatrixVar &__rhs) const
 
bool operator> (const WMatrixVar &__rhs) const
 
bool operator>= (const WMatrixVar &__rhs) const
 
bool operator== (const WMatrixVar &__rhs) const
 
bool operator< (const WMatrixVar &__rhs) const
 
bool operator!= (const WMatrixVar &__rhs) const
 
bool operator<= (const WMatrixVar &__rhs) const
 
bool operator> (const WMatrixVar &__rhs) const
 
bool operator>= (const WMatrixVar &__rhs) const
 

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

- Public Attributes inherited from Nice::WMatrixVar
::Ice::Double m11
 
::Ice::Double m12
 
::Ice::Double m21
 
::Ice::Double m22
 
::Ice::Double dx
 
::Ice::Double dy
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ WMatrix() [1/8]

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.

See also
reset()

◆ WMatrix() [2/8]

Nice::WMatrix::WMatrix ( double  _m11,
double  _m12,
double  _m21,
double  _m22,
double  _dx,
double  _dy 
)

◆ WMatrix() [3/8]

Nice::WMatrix::WMatrix ( const WMatrix matrix)

Constructs a matrix that is a copy of the given matrix.

◆ WMatrix() [4/8]

Nice::WMatrix::WMatrix ( const Nice::WMatrixVar _matrix)

Constructs a matrix that is a copy of the given matrix.

◆ WMatrix() [5/8]

Nice::WMatrix::WMatrix ( )

◆ WMatrix() [6/8]

Nice::WMatrix::WMatrix ( double  _m11,
double  _m12,
double  _m21,
double  _m22,
double  _dx,
double  _dy 
)

◆ WMatrix() [7/8]

Nice::WMatrix::WMatrix ( const WMatrix matrix)

◆ WMatrix() [8/8]

Nice::WMatrix::WMatrix ( const Nice::WMatrixVar matrix)

Member Function Documentation

◆ det() [1/2]

double Nice::WMatrix::det ( ) const
inline

Returns the matrix's determinant.

◆ det() [2/2]

double Nice::WMatrix::det ( ) const
inline

◆ dx() [1/2]

double Nice::WMatrix::dx ( ) const
inline

◆ dx() [2/2]

double Nice::WMatrix::dx ( ) const
inline

◆ dy() [1/2]

double Nice::WMatrix::dy ( ) const
inline

◆ dy() [2/2]

double Nice::WMatrix::dy ( ) const
inline

◆ inverted() [1/2]

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.

See also
isInvertible()

◆ inverted() [2/2]

WMatrix Nice::WMatrix::inverted ( bool invertible = 0) const

◆ isIdentity() [1/2]

bool Nice::WMatrix::isIdentity ( ) const
inline

◆ isIdentity() [2/2]

bool Nice::WMatrix::isIdentity ( ) const
inline

Returns true if the matrix is the identity matrix, otherwise returns false.

See also
reset()

◆ isInvertible() [1/2]

bool Nice::WMatrix::isInvertible ( ) const
inline

Returns true if the matrix is invertible, otherwise returns false.

See also
inverted()

◆ isInvertible() [2/2]

bool Nice::WMatrix::isInvertible ( ) const
inline

◆ m11() [1/2]

double Nice::WMatrix::m11 ( ) const
inline

◆ m11() [2/2]

double Nice::WMatrix::m11 ( ) const
inline

◆ m12() [1/2]

double Nice::WMatrix::m12 ( ) const
inline

◆ m12() [2/2]

double Nice::WMatrix::m12 ( ) const
inline

◆ m21() [1/2]

double Nice::WMatrix::m21 ( ) const
inline

◆ m21() [2/2]

double Nice::WMatrix::m21 ( ) const
inline

◆ m22() [1/2]

double Nice::WMatrix::m22 ( ) const
inline

◆ m22() [2/2]

double Nice::WMatrix::m22 ( ) const
inline

◆ map() [1/12]

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.

◆ map() [2/12]

void Nice::WMatrix::map ( int  x,
int  y,
int *  tx,
int *  ty 
) const

◆ map() [3/12]

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:

x' = Nice::WMatrixVar::m11*x + Nice::WMatrixVar::m21*y + Nice::WMatrixVar::dx

The point (x, y) is the original point, and (x', y') is the transformed point.

See also
{Nice::WMatrix::Basic WMatrixVar Operations}{Basic WMatrixVar Operations}

◆ map() [4/12]

void Nice::WMatrix::map ( double  x,
double  y,
double *  tx,
double *  ty 
) const

◆ map() [5/12]

Nice::Rect Nice::WMatrix::map ( const Nice::Rect ) const

◆ map() [6/12]

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.

◆ map() [7/12]

Point Nice::WMatrix::map ( const Point p) const

◆ map() [8/12]

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.

◆ map() [9/12]

Line Nice::WMatrix::map ( const Line l) const

◆ map() [10/12]

Nice::Line Nice::WMatrix::map ( const Line l) const

◆ map() [11/12]

Polygon Nice::WMatrix::map ( const Polygon a) const

◆ map() [12/12]

Nice::Polygon Nice::WMatrix::map ( const Polygon a) const

◆ operator!=() [1/2]

bool Nice::WMatrix::operator!= ( const WMatrix matrix) const

Returns true if this matrix is not equal to the given matrix, otherwise returns false.

◆ operator!=() [2/2]

bool Nice::WMatrix::operator!= ( const WMatrix ) const

◆ operator*() [1/2]

WMatrix Nice::WMatrix::operator* ( const WMatrix o) const

◆ operator*() [2/2]

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.

◆ operator*=() [1/2]

WMatrix& Nice::WMatrix::operator*= ( const WMatrix )

◆ operator*=() [2/2]

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.

◆ operator=() [1/2]

Nice::WMatrix & Nice::WMatrix::operator= ( const WMatrix matrix)

Assigns the given matrix's values to this matrix.

◆ operator=() [2/2]

WMatrix& Nice::WMatrix::operator= ( const WMatrix )

◆ operator==() [1/2]

bool Nice::WMatrix::operator== ( const WMatrix matrix) const

Returns true if this matrix is equal to the given matrix, otherwise returns false.

◆ operator==() [2/2]

bool Nice::WMatrix::operator== ( const WMatrix ) const

◆ reset() [1/2]

void Nice::WMatrix::reset ( )

◆ reset() [2/2]

void Nice::WMatrix::reset ( )

◆ rotate() [1/2]

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.

See also
setWMatrixVar()

◆ rotate() [2/2]

WMatrix& Nice::WMatrix::rotate ( double  a)

◆ scale() [1/2]

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.

See also
setWMatrixVar()

◆ scale() [2/2]

WMatrix& Nice::WMatrix::scale ( double  sx,
double  sy 
)

◆ setWMatrixVar() [1/2]

void Nice::WMatrix::setWMatrixVar ( double  _m11,
double  _m12,
double  _m21,
double  _m22,
double  _dx,
double  _dy 
)

◆ setWMatrixVar() [2/2]

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.

See also
Nice::WMatrix()

◆ shear() [1/2]

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.

See also
setWMatrixVar()

◆ shear() [2/2]

WMatrix& Nice::WMatrix::shear ( double  sh,
double  sv 
)

◆ translate() [1/2]

WMatrix& Nice::WMatrix::translate ( double  dx,
double  dy 
)

◆ translate() [2/2]

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.

See also
setWMatrixVar()

Friends And Related Function Documentation

◆ operator*()

Nice::Point operator* ( const Nice::Point point,
const Nice::WMatrix matrix 
)
related

This is the same as {matrix}.map({point}).

See also
Nice::WMatrix::map()

◆ operator<<()

std::ostream & operator<< ( std::ostream &  stream,
const Nice::WMatrix matrix 
)
related

Writes the given matrix to the given stream and returns a reference to the stream.

See also
{Format of the QDataStream Operators}

◆ operator>>()

std::istream & operator>> ( std::istream &  stream,
Nice::WMatrix matrix 
)
related

Reads the given matrix from the given stream and returns a reference to the stream.

See also
{Format of the QDataStream Operators}

The documentation for this class was generated from the following files: