9#ifndef _LIMBO_GEOMETRY_GEOMETRY_H
10#define _LIMBO_GEOMETRY_GEOMETRY_H
31enum orientation_2d_enum
41 HORIZONTAL_SLICING = 1,
53 switch (slicing_orient)
55 case HORIZONTAL_SLICING:
56 return "HORIZONTAL_SLICING";
57 case VERTICAL_SLICING:
58 return "VERTICAL_SLICING";
60 return "HOR_VER_SLICING";
62 return "HOR_VER_SA_SLICING";
64 return "HOR_VER_AR_SLICING";
153 typedef int coordinate_type;
154 typedef long area_type;
156 typedef long manhattan_area_type;
157 typedef unsigned long unsigned_area_type;
158 typedef long coordinate_difference;
160 typedef long coordinate_distance;
165#define LIMBO_GEOMETRY_COORDINATE_TRAITS(T, AREA_T, UNSIGNED_AREA_T) \
167struct coordinate_traits<T> \
169 typedef T coordinate_type; \
170 typedef AREA_T area_type; \
171 typedef AREA_T manhattan_area_type; \
172 typedef UNSIGNED_AREA_T unsigned_area_type; \
173 typedef AREA_T coordinate_difference; \
174 typedef AREA_T coordinate_distance; \
177#ifdef __SIZEOF_INT128__
189#undef LIMBO_GEOMETRY_COORDINATE_TRAITS
194template <
typename Po
intType>
198 typedef PointType point_type;
199 typedef typename point_type::coordinate_type coordinate_type;
207 {
return point.get(orient);}
213 {point.set(orient, value);}
218 static point_type
construct(coordinate_type
const& x, coordinate_type
const& y)
219 {
return point_type(x, y);}
225template <
typename RectType>
229 typedef RectType rectangle_type;
230 typedef typename rectangle_type::coordinate_type coordinate_type;
237 static inline coordinate_type
get(rectangle_type
const& rectangle, direction_2d
const& direct)
238 {
return rectangle.get(direct);}
243 static inline void set(rectangle_type& rectangle, direction_2d
const& direct, coordinate_type
const& v)
244 {rectangle.set(direct, v);}
248 static inline rectangle_type
construct(coordinate_type
const& xl, coordinate_type
const& yl,
249 coordinate_type
const& xh, coordinate_type
const& yh)
250 {
return rectangle_type(xl, yl, xh, yh);}
255template <
typename PolygonType>
256struct polygon_90_traits
258 typedef PolygonType polygon_type;
259 typedef typename polygon_type::point_type point_type;
260 typedef typename point_type::coordinate_type coordinate_type;
261 typedef typename polygon_type::vertex_iterator_type vertex_iterator_type;
264 static inline vertex_iterator_type begin_vertex(polygon_type
const& p)
265 {
return p.begin_vertex();}
268 static inline vertex_iterator_type end_vertex(polygon_type
const& p)
269 {
return p.end_vertex();}
272 static inline winding_direction winding(polygon_type
const&)
273 {
return UNKNOWN_WINDING;}
280template <
typename ContainerType>
284 typedef ContainerType container_type;
285 typedef typename container_type::value_type value_type;
286 typedef typename container_type::const_iterator const_iterator_type;
287 typedef typename container_type::iterator iterator_type;
291 static void insert(container_type& container, value_type
const& v) {container.insert(v);}
293 static void insert(container_type& container, iterator_type it, value_type
const& v) {container.insert(it, v);}
295 static void erase(container_type& container, value_type
const& v) {container.erase(v);}
297 static void erase(container_type& container, iterator_type it) {container.erase(it);}
299 template <
typename Po
intCompareType>
300 static container_type
construct(PointCompareType
const& comp)
301 {
return container_type(comp);}
310 typedef std::vector<T> container_type;
311 typedef typename container_type::value_type value_type;
312 typedef typename container_type::const_iterator const_iterator_type;
313 typedef typename container_type::iterator iterator_type;
317 static void insert(container_type& container, value_type
const& v) {container.push_back(v);}
319 static void insert(container_type& container, iterator_type it, value_type
const& v) {container.insert(it, v);}
321 static void erase(container_type& container, iterator_type it) {container.erase(it);}
324 template <
typename Po
intCompareType>
325 static container_type
construct(PointCompareType
const&)
326 {
return container_type();}
334 typedef std::list<T> container_type;
335 typedef typename container_type::value_type value_type;
336 typedef typename container_type::const_iterator const_iterator_type;
337 typedef typename container_type::iterator iterator_type;
341 static void insert(container_type& container, value_type
const& v) {container.push_back(v);}
343 static void insert(container_type& container, iterator_type it, value_type
const& v) {container.insert(it, v);}
345 static void erase(container_type& container, iterator_type it) {container.erase(it);}
348 template <
typename Po
intCompareType>
349 static container_type
construct(PointCompareType
const&)
350 {
return container_type();}
355template <
typename Po
intSet>
356inline typename coordinate_traits<typename point_traits<typename container_traits<PointSet>::value_type>::coordinate_type>::area_type
359 typedef typename container_traits<PointSet>::const_iterator_type const_iterator_type;
360 typedef typename container_traits<PointSet>::value_type point_type;
361 typedef typename point_traits<point_type>::coordinate_type
coordinate_type;
365 for (const_iterator_type itCur = vPoint.begin(); itCur != vPoint.end(); ++itCur)
367 const_iterator_type itNext = itCur;
369 if (itNext == vPoint.end()) itNext = vPoint.begin();
#define LIMBO_GEOMETRY_COORDINATE_TRAITS(T, AREA_T, UNSIGNED_AREA_T)
macro to define coordinate_traits for other integer types
a class denoting orientation of lines
int to_int() const
convert orientation to integer
bool operator!=(orientation_2d const &rhs) const
inequality operator
friend bool operator<(orientation_2d const &ori1, orientation_2d const &ori2)
less than operator
bool valid() const
check whether the orientation is valid
int m_orient
enum type of orientation in integer representation
orientation_2d()
constructor
bool operator==(orientation_2d const &rhs) const
equality operator
orientation_2d(const orientation_2d &ori)
copy constructor
void turn_90()
turn 90 degree
orientation_2d get_perpendicular() const
get perpendicular orientation
orientation_2d(orientation_2d_enum const &ori)
constructor
orientation_2d & operator=(const orientation_2d &ori)
assignment
namespace for Limbo.Geometry
std::string to_string(slicing_orientation_2d slicing_orient)
convert enum type of slicing orientation to string
coordinate_traits< typenamepoint_traits< typenamecontainer_traits< PointSet >::value_type >::coordinate_type >::area_type area(PointSet const &vPoint)
calculate signed area of a polygon, the result is positive if its winding is CLOCKWISE
@ HOR_VER_SLICING
horizontal/vertical slicing and choose rectangle with larger area every time
@ HOR_VER_AR_SLICING
horizontal/vertical slicing and choose rectangle with better aspect ratio every time
@ HOR_VER_SA_SLICING
horizontal/vertical slicing and choose rectangle with smaller area every time
static void insert(container_type &container, iterator_type it, value_type const &v)
insert value to container with hint of iterator
static container_type construct(PointCompareType const &)
a default construct function
static void insert(container_type &container, value_type const &v)
endnowarn
static void erase(container_type &container, iterator_type it)
erase an element from container with iterator
static container_type construct(PointCompareType const &)
a default construct function
static void insert(container_type &container, value_type const &v)
insert value to container
static void erase(container_type &container, iterator_type it)
erase an element from container with iterator
static void insert(container_type &container, iterator_type it, value_type const &v)
insert value to container with hint of iterator
type traits for containers such as vector, list, multiset
static void insert(container_type &container, value_type const &v)
insert value to container
static container_type construct(PointCompareType const &comp)
a default construct function is necessary, because std::set needs a compare function,...
static void insert(container_type &container, iterator_type it, value_type const &v)
insert value to container with hint of iterator
static void erase(container_type &container, value_type const &v)
erase value from iterator
static void erase(container_type &container, iterator_type it)
erase an element from container with iterator
type traits for coordinates
static coordinate_type get(const point_type &point, orientation_2d const &orient)
get coordinate from point
static point_type construct(coordinate_type const &x, coordinate_type const &y)
construct point from coordinates
static void set(point_type &point, orientation_2d const &orient, coordinate_type const &value)
set coordinate for point
type traits for rectangle
static coordinate_type get(rectangle_type const &rectangle, direction_2d const &direct)
get coordinate from rectangle
static void set(rectangle_type &rectangle, direction_2d const &direct, coordinate_type const &v)
set coordinate for rectangle
static rectangle_type construct(coordinate_type const &xl, coordinate_type const &yl, coordinate_type const &xh, coordinate_type const &yh)
construct rectangle from coordinates