///|/ Copyright (c) Prusa Research 2020 - 2023 Tomáš Mészáros @tamasmeszaros ///|/ ///|/ PrusaSlicer is released under the terms of the AGPLv3 or higher ///|/ #ifndef SLA_BOOSTADAPTER_HPP #define SLA_BOOSTADAPTER_HPP #include #include #include #include #include namespace boost { namespace geometry { namespace traits { /* ************************************************************************** */ /* Point concept adaptation ************************************************* */ /* ************************************************************************** */ template<> struct tag { using type = point_tag; }; template<> struct coordinate_type { using type = coord_t; }; template<> struct coordinate_system { using type = cs::cartesian; }; template<> struct dimension: boost::mpl::int_<2> {}; template struct access { static inline coord_t get(Slic3r::Point const& a) { return a(d); } static inline void set(Slic3r::Point& a, coord_t const& value) { a(d) = value; } }; // For Vec /////////////////////////////////////////////////////////////// template struct tag> { using type = point_tag; }; template struct coordinate_type> { using type = T; }; template struct coordinate_system> { using type = cs::cartesian; }; template struct dimension>: boost::mpl::int_ {}; template struct access, d> { static inline T get(Slic3r::Vec const& a) { return a(d); } static inline void set(Slic3r::Vec& a, T const& value) { a(d) = value; } }; /* ************************************************************************** */ /* Box concept adaptation *************************************************** */ /* ************************************************************************** */ template<> struct tag { using type = box_tag; }; template<> struct point_type { using type = Slic3r::Point; }; template struct indexed_access { static inline coord_t get(Slic3r::BoundingBox const& box) { return box.min(d); } static inline void set(Slic3r::BoundingBox &box, coord_t const& coord) { box.min(d) = coord; } }; template struct indexed_access { static inline coord_t get(Slic3r::BoundingBox const& box) { return box.max(d); } static inline void set(Slic3r::BoundingBox &box, coord_t const& coord) { box.max(d) = coord; } }; template using BB3 = Slic3r::BoundingBox3Base>; template struct tag> { using type = box_tag; }; template struct point_type> { using type = Slic3r::Vec<3, T>; }; template struct indexed_access, 0, d> { static inline coord_t get(BB3 const& box) { return box.min(d); } static inline void set(BB3 &box, coord_t const& coord) { box.min(d) = coord; } }; template struct indexed_access, 1, d> { static inline coord_t get(BB3 const& box) { return box.max(d); } static inline void set(BB3 &box, coord_t const& coord) { box.max(d) = coord; } }; /* ************************************************************************** */ /* Segment concept adaptaion ************************************************ */ /* ************************************************************************** */ template<> struct tag { using type = segment_tag; }; template<> struct point_type { using type = Slic3r::Point; }; template<> struct indexed_access { static inline coord_t get(Slic3r::Line const& l) { return l.a.x(); } static inline void set(Slic3r::Line &l, coord_t c) { l.a.x() = c; } }; template<> struct indexed_access { static inline coord_t get(Slic3r::Line const& l) { return l.a.y(); } static inline void set(Slic3r::Line &l, coord_t c) { l.a.y() = c; } }; template<> struct indexed_access { static inline coord_t get(Slic3r::Line const& l) { return l.b.x(); } static inline void set(Slic3r::Line &l, coord_t c) { l.b.x() = c; } }; template<> struct indexed_access { static inline coord_t get(Slic3r::Line const& l) { return l.b.y(); } static inline void set(Slic3r::Line &l, coord_t c) { l.b.y() = c; } }; /* ************************************************************************** */ /* Polyline concept adaptation ********************************************** */ /* ************************************************************************** */ template<> struct tag { using type = linestring_tag; }; /* ************************************************************************** */ /* Polygon concept adaptation *********************************************** */ /* ************************************************************************** */ // Ring implementation ///////////////////////////////////////////////////////// // Boost would refer to ClipperLib::Path (alias Slic3r::ExPolygon) as a ring template<> struct tag { using type = ring_tag; }; template<> struct point_order { static const order_selector value = counterclockwise; }; // All our Paths should be closed for the bin packing application template<> struct closure { static const constexpr closure_selector value = closure_selector::open; }; // Polygon implementation ////////////////////////////////////////////////////// template<> struct tag { using type = polygon_tag; }; template<> struct exterior_ring { static inline Slic3r::Polygon& get(Slic3r::ExPolygon& p) { return p.contour; } static inline Slic3r::Polygon const& get(Slic3r::ExPolygon const& p) { return p.contour; } }; template<> struct ring_const_type { using type = const Slic3r::Polygon&; }; template<> struct ring_mutable_type { using type = Slic3r::Polygon&; }; template<> struct interior_const_type { using type = const Slic3r::Polygons&; }; template<> struct interior_mutable_type { using type = Slic3r::Polygons&; }; template<> struct interior_rings { static inline Slic3r::Polygons& get(Slic3r::ExPolygon& p) { return p.holes; } static inline const Slic3r::Polygons& get(Slic3r::ExPolygon const& p) { return p.holes; } }; /* ************************************************************************** */ /* MultiPolygon concept adaptation ****************************************** */ /* ************************************************************************** */ template<> struct tag { using type = multi_polygon_tag; }; }} // namespace geometry::traits template<> struct range_value> { using type = Slic3r::Vec2d; }; template<> struct range_value { using type = Slic3r::Point; }; // This is an addition to the ring implementation of Polygon concept template<> struct range_value { using type = Slic3r::Point; }; template<> struct range_value { using type = Slic3r::Polygon; }; template<> struct range_value { using type = Slic3r::ExPolygon; }; } // namespace boost #endif // SLABOOSTADAPTER_HPP