1 #ifndef __2GEOM_REGION_H
2 #define __2GEOM_REGION_H
5 #include "path-intersection.h"
12 friend Crossings crossings(
Region const &a,
Region const &b);
14 friend Shape shape_boolean(
bool rev,
Shape const & a,
Shape const & b, CrossingSet
const & crs);
17 mutable boost::optional<Rect> box;
21 explicit Region(
Path const &p) : boundary(p) { fill = path_direction(p); }
22 Region(
Path const &p,
bool dir) : boundary(p), fill(dir) {}
23 Region(
Path const &p, boost::optional<Rect>
const &b) : boundary(p), box(b) { fill = path_direction(p); }
24 Region(
Path const &p, boost::optional<Rect>
const &b,
bool dir) : boundary(p), box(b), fill(dir) {}
26 unsigned size()
const {
return boundary.size(); }
28 bool isFill()
const {
return fill; }
29 Region asFill()
const {
if(fill)
return Region(*
this);
else return inverse(); }
30 Region asHole()
const {
if(fill)
return inverse();
else return Region(*
this); }
32 operator Path()
const {
return boundary; }
33 Rect boundsFast()
const {
34 if(!box) box = boost::optional<Rect>(boundary.boundsFast());
38 bool contains(
Point const &p)
const {
39 if(box && !box->contains(p))
return false;
40 return Geom::contains(boundary, p);
42 bool contains(
Region const &other)
const {
return contains(other.boundary.initialPoint()); }
44 bool includes(
Point const &p)
const {
45 return logical_xor(!fill, contains(p));
48 Region inverse()
const {
return Region(boundary.reverse(), box, !fill); }
52 bool invariants()
const;
55 typedef std::vector<Region> Regions;
57 unsigned outer_index(Regions
const &ps);
60 inline Regions regions_from_paths(std::vector<Path>
const &ps) {
62 for(
unsigned i = 0; i < ps.size(); i++)
63 res.push_back(
Region(ps[i]));
67 inline std::vector<Path> paths_from_regions(Regions
const &rs) {
68 std::vector<Path> res;
69 for(
unsigned i = 0; i < rs.size(); i++)
74 Regions sanitize_path(Path
const &p);
76 Regions region_boolean(
bool rev, Region
const & a, Region
const & b, Crossings
const &cr);
77 Regions region_boolean(
bool rev, Region
const & a, Region
const & b, Crossings
const & cr_a, Crossings
const & cr_b);
79 inline Regions region_boolean(
bool rev, Region
const & a, Region
const & b) {
80 return region_boolean(rev, a, b, crossings(a, b));
Cartesian point.
Definition: point.h:20