Code

Merge from fe-moved
[inkscape.git] / src / 2geom / region.h
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_REGION_H
36 #define __2GEOM_REGION_H
38 #include <2geom/path.h>
39 #include <2geom/path-intersection.h>
41 namespace Geom {
43 class Shape;
45 class Region {
46     friend Crossings crossings(Region const &a, Region const &b);
47     friend class Shape;
48     friend Shape shape_boolean(bool rev, Shape const & a, Shape const & b, CrossingSet const & crs);
50     Path boundary;
51     mutable OptRect box;
52     bool fill;
53   public:
54     Region() : fill(true) {}
55     explicit Region(Path const &p) : boundary(p) { fill = path_direction(p); }
56     Region(Path const &p, bool dir) : boundary(p), fill(dir) {}
57     Region(Path const &p, OptRect const &b) : boundary(p), box(b) { fill = path_direction(p); }
58     Region(Path const &p, OptRect const &b, bool dir) : boundary(p), box(b), fill(dir) {}
59     
60     unsigned size() const { return boundary.size(); }
61     
62     bool isFill() const { return fill; }    
63     Region asFill() const { if(fill) return Region(*this); else return inverse(); } 
64     Region asHole() const { if(fill) return inverse(); else return Region(*this); }
65     
66     operator Path() const { return boundary; }
67     Rect boundsFast() const {
68         if(!box) box = boundary.boundsFast();  /// \todo this doesn't look right at all...
69         return *box;
70     }
71     
72     bool contains(Point const &p) const {
73         if(box && !box->contains(p)) return false;
74         return Geom::contains(boundary, p);
75     }
76     bool contains(Region const &other) const { return contains(other.boundary.initialPoint()); }
77     
78     bool includes(Point const &p) const {
79         return logical_xor(!fill, contains(p));
80     }
81     
82     Region inverse() const { return Region(boundary.reverse(), box, !fill); }
83     
84     Region operator*(Matrix const &m) const;
85     
86     bool invariants() const;
87 };
89 typedef std::vector<Region> Regions;
91 unsigned outer_index(Regions const &ps);
93 //assumes they're already sanitized somewhat
94 inline Regions regions_from_paths(std::vector<Path> const &ps) {
95     Regions res;
96     for(unsigned i = 0; i < ps.size(); i++)
97         res.push_back(Region(ps[i]));
98     return res;
99 }
101 inline std::vector<Path> paths_from_regions(Regions const &rs) {
102     std::vector<Path> res;
103     for(unsigned i = 0; i < rs.size(); i++)
104         res.push_back(rs[i]);
105     return res;
108 Regions sanitize_path(Path const &p);
110 Regions region_boolean(bool rev, Region const & a, Region const & b, Crossings const &cr);
111 Regions region_boolean(bool rev, Region const & a, Region const & b, Crossings const & cr_a, Crossings const & cr_b);
113 inline Regions region_boolean(bool rev, Region const & a, Region const & b) {
114     return region_boolean(rev, a, b, crossings(a, b));
119 #endif
121 /*
122   Local Variables:
123   mode:c++
124   c-file-style:"stroustrup"
125   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
126   indent-tabs-mode:nil
127   fill-column:99
128   End:
129 */
130 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :