forked from lduchesne/cmatopo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.cpp
More file actions
112 lines (92 loc) · 1.82 KB
/
types.cpp
File metadata and controls
112 lines (92 loc) · 1.82 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include <types.h>
#include <zones.h>
#include <cassert>
namespace cma {
extern GEOSContextHandle_t hdl;
GEOSWKBReader* geom_container::s_wkbr = nullptr;
}
namespace cma {
zone::zone()
{
}
zone::zone(int id, OGREnvelope envelope)
: _id(id)
, _envelope(envelope)
{
}
zone::~zone()
{
if (_geom) {
GEOSGeom_destroy_r(hdl, _geom);
}
}
int zone::id() const
{
return _id;
}
int zone::count() const
{
return _count;
}
void zone::count(int c)
{
_count = c;
}
const OGREnvelope& zone::envelope() const
{
return _envelope;
}
GEOSGeometry* zone::geom()
{
if (!_geom) {
_geom = OGREnvelope2GEOSGeom(_envelope);
}
return _geom;
}
const GEOSPreparedGeometry* geom_container::prepared()
{
assert (geom);
if (!_prepared) {
_prepared = GEOSPrepare_r(hdl, geom);
}
return _prepared;
}
const GEOSGeometry* geom_container::envelope()
{
if (!geom) {
return nullptr;
}
if (!_envelope) {
_envelope = GEOSEnvelope_r(hdl, geom);
}
return _envelope;
}
geom_container::~geom_container()
{
if (_prepared) {
GEOSPreparedGeom_destroy_r(hdl, _prepared);
}
if (_envelope) {
GEOSGeom_destroy_r(hdl, _envelope);
}
if (geom) {
GEOSGeom_destroy_r(hdl, geom);
}
}
bool geom_container::intersects(const GEOSGeometry* geom)
{
return GEOSIntersects_r(hdl, envelope(), geom) == 1;
}
bool node::intersects(const GEOSGeometry* geom)
{
if (GEOSGeomTypeId_r(hdl, geom) == GEOS_POINT) {
double x1, y1, x2, y2;
GEOSGeomGetX_r(hdl, this->geom, &x1);
GEOSGeomGetY_r(hdl, this->geom, &y1);
GEOSGeomGetX_r(hdl, this->geom, &x2);
GEOSGeomGetY_r(hdl, this->geom, &y2);
return x1 == x2 && y1 == y2;
}
return geom_container::intersects(geom);
}
} // namespace cma