#ifndef VTR_GEOMETRY_H #define VTR_GEOMETRY_H #include "vtr_range.h" #include #include #include namespace vtr { /* * Forward declarations */ template class Point; template class Rect; template class Line; template class RectUnion; template bool operator==(Point lhs, Point rhs); template bool operator!=(Point lhs, Point rhs); template bool operator<(Point lhs, Point rhs); template bool operator==(const Rect& lhs, const Rect& rhs); template bool operator!=(const Rect& lhs, const Rect& rhs); template bool operator==(const RectUnion& lhs, const RectUnion& rhs); template bool operator!=(const RectUnion& lhs, const RectUnion& rhs); /* * Class Definitions */ //A point in 2D space template class Point { public: //Constructors Point(T x_val, T y_val); Point(); public: //Accessors //Coordinates T x() const; T y() const; friend bool operator== <>(Point lhs, Point rhs); friend bool operator!= <>(Point lhs, Point rhs); friend bool operator< <>(Point lhs, Point rhs); public: //Mutators /* Set x and y values */ void set(T x_val, T y_val); void set_x(T x_val); void set_y(T y_val); /* Swap x and y values */ void swap(); private: T x_; T y_; }; //A 2D rectangle template class Rect { public: //Constructors Rect(T left_val, T bottom_val, T right_val, T top_val); Rect(Point bottom_left_val, Point top_right_val); Rect(); public: //Accessors //Co-ordinates T xmin() const; T xmax() const; T ymin() const; T ymax() const; Point bottom_left() const; Point top_right() const; T width() const; T height() const; //Returns true if the point is fully contained within the rectangle (excluding the top-right edges) bool contains(Point point) const; //Returns true if the point is strictly contained within the region (excluding all edges) bool strictly_contains(Point point) const; //Returns true if the point is coincident with the rectangle (including the top-right edges) bool coincident(Point point) const; friend bool operator== <>(const Rect& lhs, const Rect& rhs); friend bool operator!= <>(const Rect& lhs, const Rect& rhs); public: //Mutators //Co-ordinates void set_xmin(T xmin_val); void set_ymin(T ymin_val); void set_xmax(T xmax_val); void set_ymax(T ymax_val); private: Point bottom_left_; Point top_right_; }; //A 2D line template class Line { public: //Types typedef typename std::vector>::const_iterator point_iter; typedef vtr::Range point_range; public: //Constructors Line(std::vector> line_points); public: //Accessors //Returns the bounding box Rect bounding_box() const; //Returns a range of constituent points point_range points() const; private: std::vector> points_; }; //A union of 2d rectangles template class RectUnion { public: //Types typedef typename std::vector>::const_iterator rect_iter; typedef vtr::Range rect_range; public: //Constructors //Construct from a set of rectangles RectUnion(std::vector> rects); public: //Accessors //Returns the bounding box of all rectangles in the union Rect bounding_box() const; //Returns true if the point is fully contained within the region (excluding top-right edges) bool contains(Point point) const; //Returns true if the point is strictly contained within the region (excluding all edges) bool strictly_contains(Point point) const; //Returns true if the point is coincident with the region (including the top-right edges) bool coincident(Point point) const; //Returns a range of all constituent rectangles rect_range rects() const; //Checks whether two RectUnions have identical representations // Note: does not check whether the representations they are equivalent friend bool operator== <>(const RectUnion& lhs, const RectUnion& rhs); friend bool operator!= <>(const RectUnion& lhs, const RectUnion& rhs); private: //Note that a union of rectanges may have holes and may not be contiguous std::vector> rects_; }; } // namespace vtr #include "vtr_geometry.tpp" #endif