path-intersection.h revision 76addc201c409e81eaaa73fe27cc0f79c4db097c
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen/**
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen * \file
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen * \brief Path intersection
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen *//*
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen * Authors:
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen * ? <?@?.?>
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen *
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen * Copyright ?-? authors
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen *
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen * This library is free software; you can redistribute it and/or
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen * modify it either under the terms of the GNU Lesser General Public
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen * License version 2.1 as published by the Free Software Foundation
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen * (the "LGPL") or, at your option, under the terms of the Mozilla
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen * Public License Version 1.1 (the "MPL"). If you do not alter this
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen * notice, a recipient may use your version of this file under either
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen * the MPL or the LGPL.
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen *
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen * You should have received a copy of the LGPL along with this library
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen * in the file COPYING-LGPL-2.1; if not, write to the Free Software
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen * You should have received a copy of the MPL along with this library
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen * in the file COPYING-MPL-1.1
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen *
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen * The contents of this file are subject to the Mozilla Public License
475f79972f5d3572c0a3c98161ce8e406dd8b3daJohan Engelen * Version 1.1 (the "License"); you may not use this file except in
475f79972f5d3572c0a3c98161ce8e406dd8b3daJohan Engelen * compliance with the License. You may obtain a copy of the License at
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen * http://www.mozilla.org/MPL/
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen *
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen * OF ANY KIND, either express or implied. See the LGPL or the MPL for
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen * the specific language governing rights and limitations.
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen *
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen */
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen#ifndef LIB2GEOM_SEEN_PATH_INTERSECTION_H
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen#define LIB2GEOM_SEEN_PATH_INTERSECTION_H
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen#include <2geom/path.h>
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen#include <2geom/crossing.h>
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen#include <2geom/sweep.h>
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen
d2218db71152598971a13b08777cc0589d7f2592Johan Engelennamespace Geom {
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen
475f79972f5d3572c0a3c98161ce8e406dd8b3daJohan Engelenint winding(Path const &path, Point const &p);
475f79972f5d3572c0a3c98161ce8e406dd8b3daJohan Engelenbool path_direction(Path const &p);
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen
d2218db71152598971a13b08777cc0589d7f2592Johan Engeleninline bool contains(Path const & p, Point const &i, bool evenodd = true) {
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen return (evenodd ? winding(p, i) % 2 : winding(p, i)) != 0;
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen}
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen
d2218db71152598971a13b08777cc0589d7f2592Johan Engelentemplate<typename T>
d2218db71152598971a13b08777cc0589d7f2592Johan EngelenCrossings curve_sweep(Path const &a, Path const &b) {
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen T t;
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen Crossings ret;
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen std::vector<Rect> bounds_a = bounds(a), bounds_b = bounds(b);
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen std::vector<std::vector<unsigned> > ixs = sweep_bounds(bounds_a, bounds_b);
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen for(unsigned i = 0; i < a.size(); i++) {
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen for(std::vector<unsigned>::iterator jp = ixs[i].begin(); jp != ixs[i].end(); ++jp) {
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen Crossings cc = t.crossings(a[i], b[*jp]);
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen offset_crossings(cc, i, *jp);
d2218db71152598971a13b08777cc0589d7f2592Johan Engelen ret.insert(ret.end(), cc.begin(), cc.end());
}
}
return ret;
}
Crossings pair_intersect(Curve const & A, Interval const &Ad,
Curve const & B, Interval const &Bd);
Crossings mono_intersect(Curve const & A, Interval const &Ad,
Curve const & B, Interval const &Bd);
struct SimpleCrosser : public Crosser<Path> {
Crossings crossings(Curve const &a, Curve const &b);
Crossings crossings(Path const &a, Path const &b) { return curve_sweep<SimpleCrosser>(a, b); }
CrossingSet crossings(PathVector const &a, PathVector const &b) { return Crosser<Path>::crossings(a, b); }
};
struct MonoCrosser : public Crosser<Path> {
Crossings crossings(Path const &a, Path const &b) { return crossings(PathVector(a), PathVector(b))[0]; }
CrossingSet crossings(PathVector const &a, PathVector const &b);
};
typedef SimpleCrosser DefaultCrosser;
std::vector<double> path_mono_splits(Path const &p);
CrossingSet crossings_among(PathVector const & p);
Crossings self_crossings(Path const & a);
inline Crossings crossings(Curve const & a, Curve const & b) {
DefaultCrosser c = DefaultCrosser();
return c.crossings(a, b);
}
inline Crossings crossings(Path const & a, Path const & b) {
DefaultCrosser c = DefaultCrosser();
return c.crossings(a, b);
}
inline CrossingSet crossings(PathVector const & a, PathVector const & b) {
DefaultCrosser c = DefaultCrosser();
return c.crossings(a, b);
}
}
#endif
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :