Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
path-intersection.h
Go to the documentation of this file.
1/*
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 */
34
35#ifndef LIB2GEOM_SEEN_PATH_INTERSECTION_H
36#define LIB2GEOM_SEEN_PATH_INTERSECTION_H
37
38#include <2geom/crossing.h>
39#include <2geom/path.h>
40#include <2geom/sweep-bounds.h>
41
42namespace Geom {
43
44int winding(Path const &path, Point const &p);
45bool path_direction(Path const &p);
46
47inline bool contains(Path const & p, Point const &i, bool evenodd = true) {
48 return (evenodd ? winding(p, i) % 2 : winding(p, i)) != 0;
49}
50
51template<typename T>
52Crossings curve_sweep(Path const &a, Path const &b) {
53 T t;
54 Crossings ret;
55 std::vector<Rect> bounds_a = bounds(a), bounds_b = bounds(b);
56 std::vector<std::vector<unsigned> > ixs = sweep_bounds(bounds_a, bounds_b);
57 for(unsigned i = 0; i < a.size(); i++) {
58 for(std::vector<unsigned>::iterator jp = ixs[i].begin(); jp != ixs[i].end(); ++jp) {
59 Crossings cc = t.crossings(a[i], b[*jp]);
60 offset_crossings(cc, i, *jp);
61 ret.insert(ret.end(), cc.begin(), cc.end());
62 }
63 }
64 return ret;
65}
66
67Crossings pair_intersect(Curve const & A, Interval const &Ad,
68 Curve const & B, Interval const &Bd);
69Crossings mono_intersect(Curve const & A, Interval const &Ad,
70 Curve const & B, Interval const &Bd);
71
72struct SimpleCrosser : public Crosser<Path> {
73 Crossings crossings(Curve const &a, Curve const &b);
74 Crossings crossings(Path const &a, Path const &b) override { return curve_sweep<SimpleCrosser>(a, b); }
75 CrossingSet crossings(PathVector const &a, PathVector const &b) override { return Crosser<Path>::crossings(a, b); }
76};
77
78struct MonoCrosser : public Crosser<Path> {
79 Crossings crossings(Path const &a, Path const &b) override { return crossings(PathVector(a), PathVector(b))[0]; }
80 CrossingSet crossings(PathVector const &a, PathVector const &b) override;
81};
82
84
85std::vector<double> path_mono_splits(Path const &p);
86
89
90inline Crossings crossings(Curve const & a, Curve const & b) {
92 return c.crossings(a, b);
93}
94
95inline Crossings crossings(Path const & a, Path const & b) {
97 return c.crossings(a, b);
98}
99
100inline CrossingSet crossings(PathVector const & a, PathVector const & b) {
102 return c.crossings(a, b);
103}
104
105}
106
107#endif
108
109/*
110 Local Variables:
111 mode:c++
112 c-file-style:"stroustrup"
113 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
114 indent-tabs-mode:nil
115 fill-column:99
116 End:
117*/
118// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
Path - a sequence of contiguous curves.
pair< double, double > Point
Definition parser.cpp:7
Geom::IntRect bounds
Definition canvas.cpp:182
Abstract continuous curve on a plane defined on [0,1].
Definition curve.h:78
Sequence of subpaths.
Definition pathvector.h:122
Sequence of contiguous curves, aka spline.
Definition path.h:353
size_type size() const
Natural size of the path.
Definition path.h:490
Two-dimensional point that doubles as a vector.
Definition point.h:66
Path and its polyline approximation.
Definition Path.h:93
Structure representing the intersection of two curves.
double c[8][4]
Various utility functions.
Definition affine.h:22
int winding(Path const &path, Point const &p)
Compute winding number of the path at the specified point.
Crossings curve_sweep(Path const &a, Path const &b)
Crossings pair_intersect(Curve const &A, Interval const &Ad, Curve const &B, Interval const &Bd)
std::vector< double > path_mono_splits(Path const &p)
Finds all the monotonic splits for a path.
SimpleCrosser DefaultCrosser
void offset_crossings(Crossings &cr, double a, double b)
Definition crossing.cpp:136
bool path_direction(Path const &p)
This function should only be applied to simple paths (regions), as otherwise a boolean winding direct...
CrossingSet crossings_among(PathVector const &p)
bool contains(Path const &p, Point const &i, bool evenodd=true)
std::vector< Crossing > Crossings
Definition crossing.h:126
Crossings crossings(Curve const &a, Curve const &b)
std::vector< std::vector< unsigned > > sweep_bounds(std::vector< Rect >, Dim2 dim=X)
Make a list of pairs of self intersections in a list of Rects.
std::vector< Crossings > CrossingSet
Definition crossing.h:128
Crossings mono_intersect(Curve const &A, Interval const &Ad, Curve const &B, Interval const &Bd)
Crossings self_crossings(Path const &a)
virtual Crossings crossings(T const &a, T const &b)
Definition crossing.h:161
Crossings crossings(Path const &a, Path const &b) override
CrossingSet crossings(PathVector const &a, PathVector const &b) override
Crossings crossings(Path const &a, Path const &b) override
Crossings crossings(Curve const &a, Curve const &b)
A simple wrapper around pair_intersect.
Sweepline intersection of groups of rectangles.