1 /**
2 * \file
3 * \brief \todo brief description
4 *
5 * Authors:
6 * ? <?@?.?>
7 *
8 * Copyright ?-? authors
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it either under the terms of the GNU Lesser General Public
12 * License version 2.1 as published by the Free Software Foundation
13 * (the "LGPL") or, at your option, under the terms of the Mozilla
14 * Public License Version 1.1 (the "MPL"). If you do not alter this
15 * notice, a recipient may use your version of this file under either
16 * the MPL or the LGPL.
17 *
18 * You should have received a copy of the LGPL along with this library
19 * in the file COPYING-LGPL-2.1; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * You should have received a copy of the MPL along with this library
22 * in the file COPYING-MPL-1.1
23 *
24 * The contents of this file are subject to the Mozilla Public License
25 * Version 1.1 (the "License"); you may not use this file except in
26 * compliance with the License. You may obtain a copy of the License at
27 * http://www.mozilla.org/MPL/
28 *
29 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
30 * OF ANY KIND, either express or implied. See the LGPL or the MPL for
31 * the specific language governing rights and limitations.
32 *
33 */
35 #ifndef __2GEOM_SHAPE_H
36 #define __2GEOM_SHAPE_H
38 #include <vector>
39 #include <set>
41 #include <2geom/region.h>
43 //TODO: BBOX optimizations
45 namespace Geom {
47 enum {
48 BOOLOP_JUST_A = 1,
49 BOOLOP_JUST_B = 2,
50 BOOLOP_BOTH = 4,
51 BOOLOP_NEITHER = 8
52 };
54 enum {
55 BOOLOP_NULL = 0,
56 BOOLOP_INTERSECT = BOOLOP_BOTH,
57 BOOLOP_SUBTRACT_A_B = BOOLOP_JUST_B,
58 BOOLOP_IDENTITY_A = BOOLOP_JUST_A | BOOLOP_BOTH,
59 BOOLOP_SUBTRACT_B_A = BOOLOP_JUST_A,
60 BOOLOP_IDENTITY_B = BOOLOP_JUST_B | BOOLOP_BOTH,
61 BOOLOP_EXCLUSION = BOOLOP_JUST_A | BOOLOP_JUST_B,
62 BOOLOP_UNION = BOOLOP_JUST_A | BOOLOP_JUST_B | BOOLOP_BOTH
63 };
65 class Shape {
66 Regions content;
67 mutable bool fill;
68 //friend Shape shape_region_boolean(bool rev, Shape const & a, Region const & b);
69 friend CrossingSet crossings_between(Shape const &a, Shape const &b);
70 friend Shape shape_boolean(bool rev, Shape const &, Shape const &, CrossingSet const &);
71 friend Shape boolop(Shape const &a, Shape const &b, unsigned);
72 friend Shape boolop(Shape const &a, Shape const &b, unsigned, CrossingSet const &);
73 friend void add_to_shape(Shape &s, Path const &p, bool);
74 public:
75 Shape() : fill(true) {}
76 explicit Shape(Region const & r) {
77 content = Regions(1, r);
78 fill = r.fill;
79 }
80 explicit Shape(Regions const & r) : content(r) { update_fill(); }
81 explicit Shape(bool f) : fill(f) {}
82 Shape(Regions const & r, bool f) : content(r), fill(f) {}
84 Regions getContent() const { return content; }
85 bool isFill() const { return fill; }
87 unsigned size() const { return content.size(); }
88 const Region &operator[](unsigned ix) const { return content[ix]; }
90 Shape inverse() const;
91 Shape operator*(Matrix const &m) const;
93 bool contains(Point const &p) const;
95 bool inside_invariants() const; //semi-slow & easy to violate : checks that the insides are inside, the outsides are outside
96 bool region_invariants() const; //semi-slow : checks for self crossing
97 bool cross_invariants() const; //slow : checks that everything is disjoint
98 bool invariants() const; //vera slow (combo, checks the above)
100 private:
101 std::vector<unsigned> containment_list(Point p) const;
102 void update_fill() const {
103 unsigned ix = outer_index(content);
104 if(ix < size())
105 fill = content[ix].fill;
106 else if(size() > 0)
107 fill = content.front().fill;
108 else
109 fill = true;
110 }
111 };
113 inline CrossingSet crossings_between(Shape const &a, Shape const &b) { return crossings(paths_from_regions(a.content), paths_from_regions(b.content)); }
115 Shape shape_boolean(bool rev, Shape const &, Shape const &, CrossingSet const &);
116 Shape shape_boolean(bool rev, Shape const &, Shape const &);
118 //unsigned pick_coincident(unsigned ix, unsigned jx, bool &rev, std::vector<Path> const &ps, CrossingSet const &crs);
119 //void outer_crossing(unsigned &ix, unsigned &jx, bool & dir, std::vector<Path> const & ps, CrossingSet const & crs);
120 void crossing_dual(unsigned &i, unsigned &j, CrossingSet const & crs);
121 unsigned crossing_along(double t, unsigned ix, unsigned jx, bool dir, Crossings const & crs);
123 Shape boolop(Shape const &, Shape const &, unsigned flags);
124 Shape boolop(Shape const &, Shape const &, unsigned flags, CrossingSet &);
126 Shape sanitize(std::vector<Path> const &ps);
128 Shape stopgap_cleaner(std::vector<Path> const &ps);
130 inline std::vector<Path> desanitize(Shape const & s) {
131 return paths_from_regions(s.getContent());
132 }
134 }
136 #endif
138 /*
139 Local Variables:
140 mode:c++
141 c-file-style:"stroustrup"
142 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
143 indent-tabs-mode:nil
144 fill-column:99
145 End:
146 */
147 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :