-
Notifications
You must be signed in to change notification settings - Fork 353
/
IndexedFacetDistance.cpp
63 lines (52 loc) · 2.27 KB
/
IndexedFacetDistance.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (C) 2016 Daniel Baston
*
* This is free software; you can redistribute and/or modify it under
* the terms of the GNU Lesser General Public Licence as published
* by the Free Software Foundation.
* See the COPYING file for more information.
*
**********************************************************************
*
* Last port: operation/distance/IndexedFacetDistance.java (f6187ee2 JTS-1.14)
*
**********************************************************************/
#include <geos/index/strtree/STRtree.h>
#include <geos/operation/distance/IndexedFacetDistance.h>
#include <geos/index/ItemVisitor.h>
using namespace geos::geom;
using namespace geos::index::strtree;
namespace geos {
namespace operation {
namespace distance {
struct : public index::ItemVisitor {
void visitItem(void * item) {
delete static_cast<FacetSequence*>(item);
}
} deleter;
double IndexedFacetDistance::distance(const Geometry * g1, const Geometry * g2) {
IndexedFacetDistance ifd(g1);
return ifd.getDistance(g2);
}
double IndexedFacetDistance::getDistance(const Geometry * g) const {
struct : public ItemDistance {
double distance(const ItemBoundable* item1, const ItemBoundable* item2) {
return static_cast<const FacetSequence*>(item1->getItem())->distance(*static_cast<const FacetSequence*>(item2->getItem()));
}
} itemDistance;
std::auto_ptr<STRtree> tree2(FacetSequenceTreeBuilder::build(g));
std::pair<const void*, const void*> obj = cachedTree->nearestNeighbour(tree2.get(), dynamic_cast<ItemDistance*>(&itemDistance));
double distance = static_cast<const FacetSequence*>(obj.first)->distance(*static_cast<const FacetSequence*>(obj.second));
tree2->iterate(deleter);
return distance;
}
IndexedFacetDistance::~IndexedFacetDistance() {
cachedTree->iterate(deleter);
}
}
}
}