Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

affinetrans.h

Go to the documentation of this file.
00001 #ifndef _LIBGNOMECANVASMM_AFFINETRANS_H
00002 #define _LIBGNOMECANVASMM_AFFINETRANS_H
00003 
00004 // -*- C++ -*-
00005 /* $Id: affinetrans.h,v 1.6 2002/12/09 16:08:47 aholzmann Exp $ */
00006 
00007 /* affinetrans.h
00008  * 
00009  * Copyright (C) 1999 The gnomemm Development Team
00010  *
00011  * This library is free software; you can redistribute it and/or
00012  * modify it under the terms of the GNU Library General Public
00013  * License as published by the Free Software Foundation; either
00014  * version 2 of the License, or (at your option) any later version.
00015  *
00016  * This library is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019  * Library General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU Library General Public
00022  * License along with this library; if not, write to the Free
00023  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00024  */
00025 
00026 #include <glibmm/containers.h>
00027 #include <libgnomecanvasmm/point.h>
00028 
00029 namespace Gnome
00030 {
00031 
00032 namespace Art
00033 {
00034 
00035 //: Used by CanvasItem.
00036 class AffineTrans
00037 {
00038 public:
00039   //: Initialize the affine as unit matrix, with a scaling factor
00040   AffineTrans(double scale = 1.0);
00041 
00042   //: aff[6]
00043   explicit AffineTrans(const double aff[6]);
00044 
00045   AffineTrans(const AffineTrans& src);
00046   AffineTrans& operator=(const AffineTrans& src);
00047   ~AffineTrans();
00048    
00049   double& operator[](unsigned int idx);
00050   const double& operator[](unsigned int idx) const;
00051 
00052   double* gobj();
00053   const double* gobj() const;
00054 
00055   //: Apply the affine to a given point
00056   //: e.g. Point dst = affine.apply(Point(x,y));
00057   //: is the same as:
00058   //: dst.x = x * affine[0] + y * affine[2] + affine[4];
00059   //: dst.y = x * affine[1] + y * affine[3] + affine[5];
00060   Point apply_to(const Point& p) const;
00061   
00062   //: Apply the affine to a given point
00063   Point operator*(const Point& p) const;
00064         
00065   //: Compose two affines
00066   AffineTrans operator*(const AffineTrans& aff2);
00067         
00068   //: Apply other affine to the affine
00069   AffineTrans const & operator*=(AffineTrans& other);
00070   
00071   bool operator==(const AffineTrans& other) const;
00072   bool operator!=(const AffineTrans& other) const;
00073                         
00074   //: Give the inverse of the affine
00075   void invert();
00076   
00077   //: Flip horizontally and/or vertically the affine
00078   void flip(bool horiz, bool vert);
00079 
00080   //: Determine whether the affine is rectilinear (rotates 0, 90, 180 or 270 degrees)
00081   bool rectilinear() const;
00082 
00083   //: Find the affine's "expansion factor", i.e. the scale amount
00084   double expansion() const;
00085 
00086   //: Set up the identity matrix
00087   static AffineTrans identity();
00088 
00089   //: Set up a scaling matrix
00090   static AffineTrans scaling(double s);
00091 
00092   //: Set up a scaling matrix
00093   static AffineTrans scaling(double sx, double sy);
00094 
00095   //: Set up a rotation matrix; theta is given in degrees
00096   static AffineTrans rotation(double theta);
00097 
00098   //: Set up a shearing matrix; theta given in degrees
00099   static AffineTrans shearing(double theta);
00100 
00101   //: Set up a translation matrix
00102   static AffineTrans translation(double dx, double dy);
00103 
00104   //: Set up a translation matrix
00105   static AffineTrans translation(const Point& p);
00106 
00107   Glib::ustring to_string() const;
00108 
00109 protected:
00110   double trans_[6];
00111 };
00112 
00113 } //namespace Art
00114 
00115 } /* namespace Gnome */
00116 
00117 std::ostream& operator<<(std::ostream& out, const Gnome::Art::AffineTrans& aff);
00118 
00119 #endif // _GNOMEMM_AFFINETRANS_H

Generated on Fri Nov 12 14:55:52 2004 for libgnomecanvasmm by doxygen 1.3.5