Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

ixlib_polygon.hh

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------------
00002 //  Description      : Polygon handling
00003 // ----------------------------------------------------------------------------
00004 //  (c) Copyright 2000 by iXiONmedia, all rights reserved.
00005 // ----------------------------------------------------------------------------
00006 
00007 
00008 
00009 
00010 #ifndef IXLIB_POLYGON
00011 #define IXLIB_POLYGON
00012 
00013 
00014 
00015 
00016 #include <vector>
00017 #include <ixlib_geometry.hh>
00018 
00019 
00020 
00021 
00022 namespace ixion {
00023   template<class T>
00024   class polygon_segment : public std::vector<coord_vector<T,2> > {
00025       // vertices are enumerated in counter-clockwise 
00026       // (mathematically positive) order
00027       // boolean operations depend on this
00028     public:
00029       typedef coord_vector<T,2>      vertex_2d;
00030 
00031     private:
00032       typedef std::vector<vertex_2d>      super;
00033 
00034     public:
00035       polygon_segment() {
00036         }
00037       polygon_segment(rectangle<T> const &src);
00038       polygon_segment(polygon_segment const &src) 
00039         : super(src) {
00040         }
00041   
00042       void push_back_c(T x,T y);
00043       void insert_c(super::iterator it,T x,T y);
00044 
00045       bool isPointInside(T x,T y);
00046       
00047       void removeCrossings();
00048       void makeConvexHull(polygon_segment &dest) const;
00049       void smooth(polygon_segment &dest) const;
00050       void subdivide(polygon_segment &dest) const;
00051       void translate(T x,T y);
00052   
00053       rectangle<T> getBoundingBox() const;
00054       vertex_2d getCenter() const;
00055       vertex_2d getWeightedCenter() const;
00056       vertex_2d getPointOnOutside() const;
00057     };
00058 
00059 
00060 
00061 
00062   template<class T>
00063   class polygon : public std::vector<polygon_segment<T> *> {
00064       typedef std::vector<polygon_segment<T> *>      super;
00065       
00066     public:
00067       typedef polygon_segment<T>::vertex_2d     vertex_2d;
00068 
00069     public:
00070       polygon() {
00071         }
00072       polygon(polygon const &src);
00073       polygon &operator=(polygon const &src);
00074       ~polygon();
00075   
00076       void clear();
00077       
00078       bool isPointInside(T x,T y);
00079 
00080       void smooth();
00081       void subdivide();
00082       void translate(T x,T y);
00083   
00084       void unite(polygon &dest,polygon const &src) const;
00085       void intersect(polygon &dest,polygon const &src) const;
00086       void subtract(polygon &dest,polygon const &subtrahend) const;
00087   
00088       rectangle<T> getBoundingBox() const;
00089       vertex_2d getCenter() const;
00090       vertex_2d getWeightedCenter() const;
00091   
00092       template<class HLineRoutine>
00093       void drawScanlines(HLineRoutine const &hlr,T step = 1) const;
00094       
00095     private:
00096       void freeSegments();
00097     };
00098   }
00099 
00100 
00101 
00102 
00103 #endif

Generated on Wed Oct 31 17:12:24 2001 for ixlib by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001