File: affinematrix2dbase.h

package info (click to toggle)
wxwidgets3.0 3.0.5.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 120,464 kB
  • sloc: cpp: 896,633; makefile: 52,303; ansic: 21,971; sh: 5,713; python: 2,940; xml: 1,534; perl: 264; javascript: 33
file content (127 lines) | stat: -rw-r--r-- 3,720 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/////////////////////////////////////////////////////////////////////////////
// Name:         wx/affinematrix2dbase.h
// Purpose:      Common interface for 2D transformation matrices.
// Author:       Catalin Raceanu
// Created:      2011-04-06
// Copyright:    (c) wxWidgets team
// Licence:      wxWindows licence
/////////////////////////////////////////////////////////////////////////////

#ifndef _WX_AFFINEMATRIX2DBASE_H_
#define _WX_AFFINEMATRIX2DBASE_H_

#include "wx/defs.h"

#if wxUSE_GEOMETRY

#include "wx/geometry.h"

struct wxMatrix2D
{
    wxMatrix2D(wxDouble v11 = 1,
               wxDouble v12 = 0,
               wxDouble v21 = 0,
               wxDouble v22 = 1)
    {
        m_11 = v11; m_12 = v12;
        m_21 = v21; m_22 = v22;
    }

    wxDouble m_11, m_12, m_21, m_22;
};

// A 2x3 matrix representing an affine 2D transformation.
//
// This is an abstract base class implemented by wxAffineMatrix2D only so far,
// but in the future we also plan to derive wxGraphicsMatrix from it (it should
// also be documented then as currently only wxAffineMatrix2D itself is).
class WXDLLIMPEXP_CORE wxAffineMatrix2DBase
{
public:
    wxAffineMatrix2DBase() {}
    virtual ~wxAffineMatrix2DBase() {}

    // sets the matrix to the respective values
    virtual void Set(const wxMatrix2D& mat2D, const wxPoint2DDouble& tr) = 0;

    // gets the component valuess of the matrix
    virtual void Get(wxMatrix2D* mat2D, wxPoint2DDouble* tr) const = 0;

    // concatenates the matrix
    virtual void Concat(const wxAffineMatrix2DBase& t) = 0;

    // makes this the inverse matrix
    virtual bool Invert() = 0;

    // return true if this is the identity matrix
    virtual bool IsIdentity() const = 0;

    // returns true if the elements of the transformation matrix are equal ?
    virtual bool IsEqual(const wxAffineMatrix2DBase& t) const = 0;
    bool operator==(const wxAffineMatrix2DBase& t) const { return IsEqual(t); }
    bool operator!=(const wxAffineMatrix2DBase& t) const { return !IsEqual(t); }


    //
    // transformations
    //

    // add the translation to this matrix
    virtual void Translate(wxDouble dx, wxDouble dy) = 0;

    // add the scale to this matrix
    virtual void Scale(wxDouble xScale, wxDouble yScale) = 0;

    // add the rotation to this matrix (counter clockwise, radians)
    virtual void Rotate(wxDouble ccRadians) = 0;

    // add mirroring to this matrix
    void Mirror(int direction = wxHORIZONTAL)
    {
        wxDouble x = (direction & wxHORIZONTAL) ? -1 : 1;
        wxDouble y = (direction & wxVERTICAL) ? -1 : 1;
        Scale(x, y);
    }


    // applies that matrix to the point
    wxPoint2DDouble TransformPoint(const wxPoint2DDouble& src) const
    {
        return DoTransformPoint(src);
    }

    void TransformPoint(wxDouble* x, wxDouble* y) const
    {
        wxCHECK_RET( x && y, "Can't be NULL" );

        const wxPoint2DDouble dst = DoTransformPoint(wxPoint2DDouble(*x, *y));
        *x = dst.m_x;
        *y = dst.m_y;
    }

    // applies the matrix except for translations
    wxPoint2DDouble TransformDistance(const wxPoint2DDouble& src) const
    {
        return DoTransformDistance(src);
    }

    void TransformDistance(wxDouble* dx, wxDouble* dy) const
    {
        wxCHECK_RET( dx && dy, "Can't be NULL" );

        const wxPoint2DDouble
            dst = DoTransformDistance(wxPoint2DDouble(*dx, *dy));
        *dx = dst.m_x;
        *dy = dst.m_y;
    }

protected:
    virtual
        wxPoint2DDouble DoTransformPoint(const wxPoint2DDouble& p) const = 0;
    virtual
        wxPoint2DDouble DoTransformDistance(const wxPoint2DDouble& p) const = 0;
};

#endif // wxUSE_GEOMETRY

#endif // _WX_AFFINEMATRIX2DBASE_H_