// ---------------------------------------------------------------------------- // Description : Polygon handling // ---------------------------------------------------------------------------- // (c) Copyright 2000 by iXiONmedia, all rights reserved. // ---------------------------------------------------------------------------- #ifndef IXLIB_POLYGON #define IXLIB_POLYGON #include #include namespace ixion { template class polygon_segment : public std::vector > { // vertices are enumerated in counter-clockwise // (mathematically positive) order // boolean operations depend on this public: typedef coord_vector vertex_2d; private: typedef std::vector super; public: polygon_segment() { } polygon_segment(rectangle const &src); polygon_segment(polygon_segment const &src) : super(src) { } void push_back_c(T x,T y); void insert_c(super::iterator it,T x,T y); bool isPointInside(T x,T y); void removeCrossings(); void makeConvexHull(polygon_segment &dest) const; void smooth(polygon_segment &dest) const; void subdivide(polygon_segment &dest) const; void translate(T x,T y); rectangle getBoundingBox() const; vertex_2d getCenter() const; vertex_2d getWeightedCenter() const; vertex_2d getPointOnOutside() const; }; template class polygon : public std::vector *> { typedef std::vector *> super; public: typedef polygon_segment::vertex_2d vertex_2d; public: polygon() { } polygon(polygon const &src); polygon &operator=(polygon const &src); ~polygon(); void clear(); bool isPointInside(T x,T y); void smooth(); void subdivide(); void translate(T x,T y); void unite(polygon &dest,polygon const &src) const; void intersect(polygon &dest,polygon const &src) const; void subtract(polygon &dest,polygon const &subtrahend) const; rectangle getBoundingBox() const; vertex_2d getCenter() const; vertex_2d getWeightedCenter() const; template void drawScanlines(HLineRoutine const &hlr,T step = 1) const; private: void freeSegments(); }; } #endif