/src/geos/src/geom/prep/PreparedLineStringDistance.cpp
Line | Count | Source |
1 | | /********************************************************************** |
2 | | * |
3 | | * GEOS - Geometry Engine Open Source |
4 | | * http://geos.osgeo.org |
5 | | * |
6 | | * Copyright (C) 2020 Sandro Santilli <strk@kbt.io> |
7 | | * |
8 | | * This is free software; you can redistribute and/or modify it under |
9 | | * the terms of the GNU Lesser General Public Licence as published |
10 | | * by the Free Software Foundation. |
11 | | * See the COPYING file for more information. |
12 | | * |
13 | | ********************************************************************** |
14 | | * |
15 | | * Last port: ORIGINAL WORK |
16 | | * |
17 | | **********************************************************************/ |
18 | | |
19 | | |
20 | | #include <geos/geom/prep/PreparedLineString.h> |
21 | | #include <geos/geom/prep/PreparedLineStringDistance.h> |
22 | | |
23 | | namespace geos { |
24 | | namespace geom { // geos.geom |
25 | | namespace prep { // geos.geom.prep |
26 | | |
27 | | double |
28 | | PreparedLineStringDistance::distance(const geom::Geometry* g) const |
29 | 0 | { |
30 | 0 | if ( prepLine.getGeometry().isEmpty() || g->isEmpty() ) |
31 | 0 | { |
32 | 0 | return DoubleInfinity; |
33 | 0 | } |
34 | | |
35 | | /* Compute potential distance from facets */ |
36 | 0 | operation::distance::IndexedFacetDistance *idf = prepLine.getIndexedFacetDistance(); |
37 | 0 | double dist = idf->distance(g); |
38 | 0 | if (dist == 0.0) |
39 | 0 | return 0.0; |
40 | | |
41 | | // If any point from prepLine is contained by g, the distance is zero |
42 | | // Do this last because this PIP test is not indexed. |
43 | 0 | if ( g->getDimension() == 2 |
44 | 0 | && prepLine.isAnyTargetComponentInTest(g)) { |
45 | 0 | return 0.0; |
46 | 0 | } |
47 | 0 | return dist; |
48 | 0 | } |
49 | | |
50 | | bool |
51 | | PreparedLineStringDistance::isWithinDistance(const geom::Geometry* g, double d) const |
52 | 0 | { |
53 | 0 | if ( prepLine.getGeometry().isEmpty() || g->isEmpty() ) |
54 | 0 | { |
55 | 0 | return false; |
56 | 0 | } |
57 | | |
58 | 0 | operation::distance::IndexedFacetDistance *idf = prepLine.getIndexedFacetDistance(); |
59 | 0 | if (idf->isWithinDistance(g, d)) |
60 | 0 | return true; |
61 | | |
62 | | // If any point from prepLine is contained by g, the distance is zero |
63 | | // Do this last because this PIP test is not indexed. |
64 | 0 | if ( g->getDimension() == 2 ) { |
65 | 0 | return prepLine.isAnyTargetComponentInTest(g); |
66 | 0 | } |
67 | 0 | return false; |
68 | 0 | } |
69 | | |
70 | | |
71 | | } // namespace geos.geom.prep |
72 | | } // namespace geos.geom |
73 | | } // namespace geos |