libgnomecanvasmm
affinetrans.h
Go to the documentation of this file.
1 #ifndef _LIBGNOMECANVASMM_AFFINETRANS_H
2 #define _LIBGNOMECANVASMM_AFFINETRANS_H
3 
4 // -*- C++ -*-
5 /* $Id: affinetrans.h 2019 2009-01-27 08:29:42Z murrayc $ */
6 
7 /* affinetrans.h
8  *
9  * Copyright (C) 1999 The gnomemm Development Team
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public
22  * License along with this library; if not, write to the Free
23  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  */
25 
26 #include <glibmm/containers.h>
27 #include <libgnomecanvasmm/point.h>
28 
29 namespace Gnome
30 {
31 
32 namespace Art
33 {
34 
35 //: Used by CanvasItem.
37 {
38 public:
39  //: Initialize the affine as unit matrix, with a scaling factor
40  AffineTrans(double scale = 1.0);
41 
42  //: aff[6]
43  explicit AffineTrans(const double aff[6]);
44 
45  AffineTrans(const AffineTrans& src);
46  AffineTrans& operator=(const AffineTrans& src);
47  ~AffineTrans();
48 
49  double& operator[](unsigned int idx);
50  const double& operator[](unsigned int idx) const;
51 
52  double* gobj();
53  const double* gobj() const;
54 
55  //: Apply the affine to a given point
56  //: e.g. Point dst = affine.apply(Point(x,y));
57  //: is the same as:
58  //: dst.x = x * affine[0] + y * affine[2] + affine[4];
59  //: dst.y = x * affine[1] + y * affine[3] + affine[5];
60  Point apply_to(const Point& p) const;
61 
62  //: Apply the affine to a given point
63  Point operator*(const Point& p) const;
64 
65  //: Compose two affines
66  AffineTrans operator*(const AffineTrans& aff2);
67 
68  //: Apply other affine to the affine
69  AffineTrans const & operator*=(AffineTrans& other);
70 
71  bool operator==(const AffineTrans& other) const;
72  bool operator!=(const AffineTrans& other) const;
73 
74  //: Give the inverse of the affine
75  void invert();
76 
77  //: Flip horizontally and/or vertically the affine
78  void flip(bool horiz, bool vert);
79 
80  //: Determine whether the affine is rectilinear (rotates 0, 90, 180 or 270 degrees)
81  bool rectilinear() const;
82 
83  //: Find the affine's "expansion factor", i.e. the scale amount
84  double expansion() const;
85 
86  //: Set up the identity matrix
87  static AffineTrans identity();
88 
89  //: Set up a scaling matrix
90  static AffineTrans scaling(double s);
91 
92  //: Set up a scaling matrix
93  static AffineTrans scaling(double sx, double sy);
94 
95  //: Set up a rotation matrix; theta is given in degrees
96  static AffineTrans rotation(double theta);
97 
98  //: Set up a shearing matrix; theta given in degrees
99  static AffineTrans shearing(double theta);
100 
101  //: Set up a translation matrix
102  static AffineTrans translation(double dx, double dy);
103 
104  //: Set up a translation matrix
105  static AffineTrans translation(const Point& p);
106 
107  Glib::ustring to_string() const;
108 
109 protected:
110  double trans_[6];
111 };
112 
113 } //namespace Art
114 
115 } /* namespace Gnome */
116 
117 std::ostream& operator<<(std::ostream& out, const Gnome::Art::AffineTrans& aff);
118 
119 #endif // _GNOMEMM_AFFINETRANS_H
static AffineTrans shearing(double theta)
double trans_[6]
Definition: affinetrans.h:110
Definition: affinetrans.h:29
Definition: affinetrans.h:36
Point apply_to(const Point &p) const
static AffineTrans rotation(double theta)
bool rectilinear() const
static AffineTrans scaling(double s)
Point operator*(const Point &p) const
Wrapper for ArtPoint struct.
Definition: point.h:39
AffineTrans const & operator*=(AffineTrans &other)
Glib::ustring to_string() const
bool operator!=(const AffineTrans &other) const
static AffineTrans identity()
std::ostream & operator<<(std::ostream &out, const Gnome::Art::AffineTrans &aff)
double expansion() const
bool operator==(const AffineTrans &other) const
double & operator[](unsigned int idx)
AffineTrans & operator=(const AffineTrans &src)
static AffineTrans translation(double dx, double dy)
void flip(bool horiz, bool vert)
AffineTrans(double scale=1.0)