| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /** | ||
| 2 | * \file | ||
| 3 | * \brief Path intersection | ||
| 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 | */ | ||
| 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 | |||
| 42 | namespace Geom { | ||
| 43 | |||
| 44 | int winding(Path const &path, Point const &p); | ||
| 45 | bool path_direction(Path const &p); | ||
| 46 | |||
| 47 | inline bool contains(Path const & p, Point const &i, bool evenodd = true) { | ||
| 48 | return (evenodd ? winding(p, i) % 2 : winding(p, i)) != 0; | ||
| 49 | } | ||
| 50 | |||
| 51 | template<typename T> | ||
| 52 | ✗ | Crossings 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 | |||
| 67 | Crossings pair_intersect(Curve const & A, Interval const &Ad, | ||
| 68 | Curve const & B, Interval const &Bd); | ||
| 69 | Crossings mono_intersect(Curve const & A, Interval const &Ad, | ||
| 70 | Curve const & B, Interval const &Bd); | ||
| 71 | |||
| 72 | struct 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 | |||
| 78 | struct 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 | |||
| 83 | typedef SimpleCrosser DefaultCrosser; | ||
| 84 | |||
| 85 | std::vector<double> path_mono_splits(Path const &p); | ||
| 86 | |||
| 87 | CrossingSet crossings_among(PathVector const & p); | ||
| 88 | Crossings self_crossings(Path const & a); | ||
| 89 | |||
| 90 | inline Crossings crossings(Curve const & a, Curve const & b) { | ||
| 91 | DefaultCrosser c = DefaultCrosser(); | ||
| 92 | return c.crossings(a, b); | ||
| 93 | } | ||
| 94 | |||
| 95 | inline Crossings crossings(Path const & a, Path const & b) { | ||
| 96 | DefaultCrosser c = DefaultCrosser(); | ||
| 97 | return c.crossings(a, b); | ||
| 98 | } | ||
| 99 | |||
| 100 | inline CrossingSet crossings(PathVector const & a, PathVector const & b) { | ||
| 101 | DefaultCrosser c = DefaultCrosser(); | ||
| 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 : | ||
| 119 |