line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#include "Helper.h" |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
using namespace Geo::Geos; |
4
|
|
|
|
|
|
|
using namespace xs; |
5
|
|
|
|
|
|
|
using namespace geos::geom; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
368
|
|
|
|
|
|
static double get_ordinate(const ::geos::geom::Coordinate* c, size_t idx) { |
9
|
368
|
100
|
|
|
|
|
if (idx == 0) return c->x; |
10
|
184
|
50
|
|
|
|
|
if (idx == 1) return c->y; |
11
|
0
|
0
|
|
|
|
|
if (idx == 2) return c->z; |
12
|
0
|
|
|
|
|
|
throw "unknown ordinate"; |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
57
|
|
|
|
|
|
Helper::CoordinateSequence* Helper::convert_copy(Helper::GeometryFactory& factory, Helper::Array coords, size_t dims) { |
16
|
57
|
50
|
|
|
|
|
if (!coords) throw("wrong argument"); |
17
|
57
|
|
|
|
|
|
auto size = coords.size(); |
18
|
57
|
|
|
|
|
|
Helper::CoordinateSequence* seq = factory.getCoordinateSequenceFactory()->create(size, dims); |
19
|
241
|
100
|
|
|
|
|
for(size_t i = 0; i < size; ++i) { |
20
|
184
|
50
|
|
|
|
|
auto& coord = xs::in(coords[i]); |
21
|
552
|
100
|
|
|
|
|
for(size_t j = 0; j < dims; ++j) { |
22
|
368
|
|
|
|
|
|
seq->setOrdinate(i, j, get_ordinate(&coord, j)); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
} |
25
|
57
|
|
|
|
|
|
return seq; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
15
|
|
|
|
|
|
Helper::Array Helper::convert_copy(const Helper::CoordinateSequence* seq) { |
29
|
15
|
|
|
|
|
|
auto size = seq->size(); |
30
|
15
|
|
|
|
|
|
auto arr = xs::Array::create(size); |
31
|
71
|
100
|
|
|
|
|
for(size_t idx = 0; idx < size; ++idx) { |
32
|
56
|
50
|
|
|
|
|
Coordinate native_coord; |
33
|
56
|
50
|
|
|
|
|
seq->getAt(idx, native_coord); |
34
|
56
|
50
|
|
|
|
|
Coordinate* copy_coord = new Coordinate(native_coord); |
35
|
112
|
50
|
|
|
|
|
auto coord = xs::out(copy_coord); |
36
|
56
|
50
|
|
|
|
|
arr.push(coord); |
37
|
|
|
|
|
|
|
} |
38
|
15
|
|
|
|
|
|
return arr; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
32
|
|
|
|
|
|
Helper::CoordinateArraySequence Helper::convert_coords(Helper::Array coords) { |
42
|
32
|
|
|
|
|
|
CoordinateArraySequence seq; |
43
|
133
|
50
|
|
|
|
|
for(const auto& c: coords) { |
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
44
|
101
|
50
|
|
|
|
|
seq.add( xs::in(c) ); |
|
|
50
|
|
|
|
|
|
45
|
|
|
|
|
|
|
} |
46
|
32
|
|
|
|
|
|
return seq; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
18
|
|
|
|
|
|
Helper::Geometries Helper::convert_geometries(Helper::Array geometries) { |
51
|
18
|
|
|
|
|
|
Geometries result; |
52
|
18
|
50
|
|
|
|
|
result.reserve(geometries.size()); |
|
|
50
|
|
|
|
|
|
53
|
26
|
50
|
|
|
|
|
for(const auto& item: geometries) { |
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
54
|
8
|
50
|
|
|
|
|
auto& g = xs::in(item); |
55
|
8
|
50
|
|
|
|
|
result.push_back(&g); |
56
|
|
|
|
|
|
|
} |
57
|
18
|
|
|
|
|
|
return result; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
11
|
|
|
|
|
|
xs::Array Helper::wrap_inc_SVs(std::vector* v, Helper::lookup_map_t& lookup_map) { |
61
|
11
|
50
|
|
|
|
|
if (v) { |
62
|
22
|
50
|
|
|
|
|
Array result = Array::create(v->size()); |
63
|
26
|
100
|
|
|
|
|
for(auto it: *v) { |
64
|
15
|
|
|
|
|
|
SV* key = static_cast(it); |
65
|
15
|
50
|
|
|
|
|
HE* he = hv_fetch_ent(lookup_map, key, 0, 0); |
66
|
15
|
50
|
|
|
|
|
if (!he) throw ("Cannot lookup key in map"); |
67
|
15
|
50
|
|
|
|
|
result.push(Sv(HeVAL(he))); |
68
|
|
|
|
|
|
|
} |
69
|
11
|
|
|
|
|
|
return result; |
70
|
|
|
|
|
|
|
} |
71
|
11
|
|
|
|
|
|
return Array{}; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
16
|
|
|
|
|
|
SV* Helper::store_sv(SV* item, lookup_map_t& lookup_map) { |
75
|
|
|
|
|
|
|
SV* value; |
76
|
16
|
50
|
|
|
|
|
HE* he = hv_fetch_ent(lookup_map, item, 0, 0); |
77
|
16
|
50
|
|
|
|
|
if (he) { |
78
|
0
|
|
|
|
|
|
value = HeVAL(he); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
else { |
81
|
16
|
50
|
|
|
|
|
value = newSVsv(item); |
82
|
16
|
50
|
|
|
|
|
auto result = hv_store_ent(lookup_map, value, value, 0); |
83
|
16
|
50
|
|
|
|
|
if (!result) { |
84
|
0
|
0
|
|
|
|
|
SvREFCNT_dec(value); |
85
|
0
|
|
|
|
|
|
throw "cannot store value in hash"; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
16
|
|
|
|
|
|
return value; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
131
|
|
|
|
|
|
Sv Helper::uplift(::geos::geom::Geometry* g) { |
92
|
|
|
|
|
|
|
using namespace panda; |
93
|
131
|
|
|
|
|
|
switch (g->getGeometryTypeId()) { |
94
|
5
|
50
|
|
|
|
|
case GEOS_POINT: return xs::out<>(dyn_cast(g)); |
|
|
50
|
|
|
|
|
|
95
|
14
|
50
|
|
|
|
|
case GEOS_LINESTRING: return xs::out<>(dyn_cast(g)); |
|
|
50
|
|
|
|
|
|
96
|
3
|
50
|
|
|
|
|
case GEOS_LINEARRING: return xs::out<>(dyn_cast(g)); |
|
|
50
|
|
|
|
|
|
97
|
59
|
50
|
|
|
|
|
case GEOS_POLYGON: return xs::out<>(dyn_cast(g)); |
|
|
50
|
|
|
|
|
|
98
|
6
|
50
|
|
|
|
|
case GEOS_MULTIPOINT: return xs::out<>(dyn_cast(g)); |
|
|
50
|
|
|
|
|
|
99
|
10
|
50
|
|
|
|
|
case GEOS_MULTILINESTRING: return xs::out<>(dyn_cast(g)); |
|
|
50
|
|
|
|
|
|
100
|
14
|
50
|
|
|
|
|
case GEOS_MULTIPOLYGON: return xs::out<>(dyn_cast(g)); |
|
|
50
|
|
|
|
|
|
101
|
20
|
50
|
|
|
|
|
case GEOS_GEOMETRYCOLLECTION: return xs::out<>(dyn_cast(g)); |
|
|
50
|
|
|
|
|
|
102
|
|
|
|
|
|
|
default: |
103
|
131
|
|
|
|
|
|
throw "unknown geometry type"; |
104
|
|
|
|
|
|
|
} |
105
|
184
|
50
|
|
|
|
|
} |
|
|
50
|
|
|
|
|
|