Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
intersection-graph.h
Go to the documentation of this file.
1/*
5 * Authors:
6 * Krzysztof Kosiński <tweenk.pl@gmail.com>
7 *
8 * Copyright 2015 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
34#ifndef SEEN_LIB2GEOM_INTERSECTION_GRAPH_H
35#define SEEN_LIB2GEOM_INTERSECTION_GRAPH_H
36
37#include <set>
38#include <vector>
39#include <boost/ptr_container/ptr_vector.hpp>
40#include <boost/intrusive/list.hpp>
41#include <2geom/forward.h>
42#include <2geom/pathvector.h>
43
44namespace Geom {
45
64{
65 // this is called PathIntersectionGraph so that we can also have a class for polygons,
66 // e.g. PolygonIntersectionGraph, which is going to be significantly faster
67public:
75 PathIntersectionGraph(PathVector const &a, PathVector const &b, Coord precision = EPSILON);
76
85
94
103
112
123
125 std::size_t size() const;
126
137 std::vector<Point> intersectionPoints(bool defective = false) const;
138
147 std::vector<Point> windingPoints() const {
148 return _winding_points;
149 }
150
151 void fragments(PathVector &in, PathVector &out) const;
152
153
154 bool valid() const { return _graph_valid; }
155
156private:
162
164 boost::intrusive::list_member_hook<> _hook;
165 boost::intrusive::list_member_hook<> _proc_hook;
174 unsigned which;
179 };
180
181 typedef boost::intrusive::list
183 , boost::intrusive::member_hook
185 , boost::intrusive::list_member_hook<>
187 >
189
190 typedef boost::intrusive::list
192 , boost::intrusive::member_hook
194 , boost::intrusive::list_member_hook<>
196 >
198
200 struct PathData {
202 std::size_t path_index;
203 int which;
208
209 PathData(int w, std::size_t pi)
210 : path_index(pi)
211 , which(w)
212 , status(BOTH)
213 {}
214 };
215
216 struct IntersectionVertexLess;
217 typedef IntersectionList::iterator ILIter;
218 typedef IntersectionList::const_iterator CILIter;
219
220 PathVector _getResult(bool enter_a, bool enter_b);
221 void _handleNonintersectingPaths(PathVector &result, unsigned which, bool inside);
222 void _prepareArguments();
223 bool _prepareIntersectionLists(Coord precision);
224 void _assignEdgeWindingParities(Coord precision);
227 void _verify();
228
231
233 boost::ptr_vector<IntersectionVertex> _xs;
234 boost::ptr_vector<PathData> _components[2];
240 std::vector<Point> _winding_points;
241
242 friend std::ostream &operator<<(std::ostream &, PathIntersectionGraph const &);
243};
244
245std::ostream &operator<<(std::ostream &os, PathIntersectionGraph const &pig);
246
247} // namespace Geom
248
249#endif // SEEN_LIB2GEOM_PATH_GRAPH_H
250/*
251 Local Variables:
252 mode:c++
253 c-file-style:"stroustrup"
254 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
255 indent-tabs-mode:nil
256 fill-column:99
257 End:
258*/
259// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
Intermediate data for computing Boolean operations on paths.
boost::intrusive::list< IntersectionVertex, boost::intrusive::member_hook< IntersectionVertex, boost::intrusive::list_member_hook<>, &IntersectionVertex::_hook > > IntersectionList
void _assignEdgeWindingParities(Coord precision)
Determine whether path portions between consecutive intersections lie inside or outside of the other ...
void _removeDegenerateIntersections()
Remove intersections that don't change between in/out.
IntersectionList::const_iterator CILIter
boost::ptr_vector< IntersectionVertex > _xs
Stores all crossings between the two shapes.
PathVector getAminusB()
Get the difference of the shapes, A ∖ B.
PathVector getXOR()
Get the symmetric difference of the shapes, A ∆ B.
void _handleNonintersectingPaths(PathVector &result, unsigned which, bool inside)
Select intersection-free path components ahead of a boolean operation based on whether they should be...
PathVector getIntersection()
Get the intersection of the shapes, A ∩ B.
boost::ptr_vector< PathData > _components[2]
Stores the crossing information for the operands.
void _assignComponentStatusFromDegenerateIntersections()
Detect the situation where a path is either entirely inside or entirely outside of the other path-vec...
void fragments(PathVector &in, PathVector &out) const
void _prepareArguments()
Prepare the operands stored in PathIntersectionGraph::_pv by closing all of their constituent paths a...
boost::intrusive::list< IntersectionVertex, boost::intrusive::member_hook< IntersectionVertex, boost::intrusive::list_member_hook<>, &IntersectionVertex::_proc_hook > > UnprocessedList
friend std::ostream & operator<<(std::ostream &, PathIntersectionGraph const &)
Format the PathIntersectionGraph for output.
UnprocessedList _ulist
Temporarily holds all unprocessed during a boolean operation.
std::vector< Point > _winding_points
Stores sample points located on paths of the operand path-vectors, between consecutive intersections.
bool _graph_valid
Whether all intersections are regular.
std::size_t size() const
Returns the number of intersections used when computing Boolean operations.
std::vector< Point > windingPoints() const
Get the geometric points located on path portions between consecutive intersections.
std::vector< Point > intersectionPoints(bool defective=false) const
Get the geometric points where the two path-vectors intersect.
ILIter _getNeighbor(ILIter iter)
Get an iterator to the corresponding crossing on the other path-vector.
void _verify()
Verify that all paths contain an even number of intersections and that the intersection graph does no...
PathVector _pv[2]
Stores the two operand path-vectors, A at _pv[0] and B at _pv[1].
PathData & _getPathData(ILIter iter)
Get the path data for the path containing the intersection given an iterator to the intersection.
PathVector getUnion()
Get the union of the shapes, A ∪ B.
IntersectionList::iterator ILIter
bool _prepareIntersectionLists(Coord precision)
Compute the lists of intersections between the constituent paths of both operands.
PathVector _getResult(bool enter_a, bool enter_b)
Compute the partial result of a boolean operation by looking at components containing intersections a...
PathVector getBminusA()
Get the opposite difference of the shapes, B ∖ A.
Sequence of subpaths.
Definition pathvector.h:122
Two-dimensional point that doubles as a vector.
Definition point.h:66
const double w
Definition conic-4.cpp:19
Css & result
Contains forward declarations of 2geom types.
double Coord
Floating point type used to store coordinates.
Definition coord.h:76
constexpr Coord EPSILON
Default "acceptably small" value.
Definition coord.h:84
Various utility functions.
Definition affine.h:22
std::ostream & operator<<(std::ostream &os, const Bezier &b)
Definition bezier.h:372
PathVector - a sequence of subpaths.
InOutFlag next_edge
Tells us whether the edge originating at this intersection lies inside or outside of the shape given ...
IntersectionVertex * neighbor
A pointer to the corresponding vertex on the other shape.
unsigned which
Index of the operand path-vector that this intersection vertex lies on.
bool defective
Whether the intersection is defective, which means that for some reason the paths neither cross trans...
Point p
Geometric position of the intersection point; guarantees that endpoints are exact.
boost::intrusive::list_member_hook _proc_hook
Stores processed intersection information for a single path in an operand path-vector.
IntersectionList xlist
List of crossings on this particular path.
int which
Index of the path-vector (in PathIntersectionGraph::_pv) that the path belongs to.
std::size_t path_index
Index of the path in its path-vector.
InOutFlag status
Whether this path as a whole is contained INSIDE or OUTSIDE relative to the other path-vector.
Generalized time value in the path vector.
Definition pathvector.h:58