src/panda/Geos/Helper.cc

filter: Statementstmt 88.8% 64 / 72 Branchbran 55.7% 58 / 104 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 69.3% 122 / 176 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« xsi/noding/SegmentNode.xsi ↑ Summary xsi/noding/Noder.xsi »
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 ▶ if (idx == 0) return c->x;
Branch: 1 branch
BranchTrueFalseTotal
if (idx == 0) return c->x; 184 184 368
10 184 ▶ if (idx == 1) return c->y;
Branch: 1 branch
BranchTrueFalseTotal
if (idx == 1) return c->y; 184 0 184
11 0 ▶ if (idx == 2) return c->z;
Branch: 1 branch
BranchTrueFalseTotal
if (idx == 2) return c->z; 0 0 0
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 ▶ if (!coords) throw("wrong argument");
Branch: 1 branch
BranchTrueFalseTotal
if (!coords) throw("wrong argument"); 0 57 57
17 57 auto size = coords.size();
18 57 Helper::CoordinateSequence* seq = factory.getCoordinateSequenceFactory()->create(size, dims);
19 241 ▶ for(size_t i = 0; i < size; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for(size_t i = 0; i < size; ++i) { 184 57 241
20 184 ▶ auto& coord = xs::in<Coordinate&>(coords[i]);
Branch: 2 branches
BranchTrueFalseTotal
auto& coord = xs::in<Coordinate&>(coords[i]); 184 0 184
auto& coord = xs::in<Coordinate&>(coords[i]); 184 0 184
21 552 ▶ for(size_t j = 0; j < dims; ++j) {
Branch: 1 branch
BranchTrueFalseTotal
for(size_t j = 0; j < dims; ++j) { 368 184 552
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 ▶ for(size_t idx = 0; idx < size; ++idx) {
Branch: 1 branch
BranchTrueFalseTotal
for(size_t idx = 0; idx < size; ++idx) { 56 15 71
32 56 ▶ Coordinate native_coord;
Branch: 1 branch
BranchTrueFalseTotal
Coordinate native_coord; 56 0 56
33 56 ▶ seq->getAt(idx, native_coord);
Branch: 1 branch
BranchTrueFalseTotal
seq->getAt(idx, native_coord); 56 0 56
34 56 ▶ Coordinate* copy_coord = new Coordinate(native_coord);
Branch: 1 branch
BranchTrueFalseTotal
Coordinate* copy_coord = new Coordinate(native_coord); 56 0 56
35 56 ▶ auto coord = xs::out<Coordinate*>(copy_coord);
Branch: 1 branch
BranchTrueFalseTotal
auto coord = xs::out<Coordinate*>(copy_coord); 56 0 56
36 56 ▶ arr.push(coord);
Branch: 1 branch
BranchTrueFalseTotal
arr.push(coord); 56 0 56
37 56 }
38 15 return arr;
39 }
40  
41 32 Helper::CoordinateArraySequence Helper::convert_coords(Helper::Array coords) {
42 32 CoordinateArraySequence seq;
43 134 ▶ for(const auto& c: coords) {
Branch: 4 branches
BranchTrueFalseTotal
for(const auto& c: coords) { 32 0 32
for(const auto& c: coords) { 32 0 32
for(const auto& c: coords) { 102 0 102
for(const auto& c: coords) { 102 32 134
44 102 ▶ seq.add( xs::in<Coordinate&>(c) );
Branch: 2 branches
BranchTrueFalseTotal
seq.add( xs::in<Coordinate&>(c) ); 102 0 102
seq.add( xs::in<Coordinate&>(c) ); 102 0 102
45 102 }
46 32 return seq;
47 }
48  
49  
50 18 Helper::Geometries Helper::convert_geometries(Helper::Array geometries) {
51 18 Geometries result;
52 18 ▶ result.reserve(geometries.size());
Branch: 2 branches
BranchTrueFalseTotal
result.reserve(geometries.size()); 18 0 18
result.reserve(geometries.size()); 18 0 18
53 26 ▶ for(const auto& item: geometries) {
Branch: 4 branches
BranchTrueFalseTotal
for(const auto& item: geometries) { 18 0 18
for(const auto& item: geometries) { 18 0 18
for(const auto& item: geometries) { 8 0 8
for(const auto& item: geometries) { 8 18 26
54 8 ▶ auto& g = xs::in<Geometry&>(item);
Branch: 1 branch
BranchTrueFalseTotal
auto& g = xs::in<Geometry&>(item); 8 0 8
55 8 ▶ result.push_back(&g);
Branch: 1 branch
BranchTrueFalseTotal
result.push_back(&g); 8 0 8
56 8 }
57 18 return result;
58 }
59  
60 11 xs::Array Helper::wrap_inc_SVs(std::vector<void*>* v, Helper::lookup_map_t& lookup_map) {
61 11 ▶ if (v) {
Branch: 1 branch
BranchTrueFalseTotal
if (v) { 11 0 11
62 11 ▶ Array result = Array::create(v->size());
Branch: 1 branch
BranchTrueFalseTotal
Array result = Array::create(v->size()); 11 0 11
63 26 ▶ for(auto it: *v) {
Branch: 1 branch
BranchTrueFalseTotal
for(auto it: *v) { 15 11 26
64 15 SV* key = static_cast<SV*>(it);
65 15 ▶ HE* he = hv_fetch_ent(lookup_map, key, 0, 0);
Branch: 1 branch
BranchTrueFalseTotal
HE* he = hv_fetch_ent(lookup_map, key, 0, 0); 15 0 15
66 15 ▶ if (!he) throw ("Cannot lookup key in map");
Branch: 1 branch
BranchTrueFalseTotal
if (!he) throw ("Cannot lookup key in map"); 0 15 15
67 15 ▶ result.push(Sv(HeVAL(he)));
Branch: 1 branch
BranchTrueFalseTotal
result.push(Sv(HeVAL(he))); 15 0 15
68 }
69 11 return result;
70 11 }
71 0 return Array{};
72 }
73  
74 16 SV* Helper::store_sv(SV* item, lookup_map_t& lookup_map) {
75 SV* value;
76 16 HE* he = hv_fetch_ent(lookup_map, item, 0, 0);
77 16 ▶ if (he) {
Branch: 1 branch
BranchTrueFalseTotal
if (he) { 0 16 16
78 0 value = HeVAL(he);
79 }
80 else {
81 16 value = newSVsv(item);
82 16 auto result = hv_store_ent(lookup_map, value, value, 0);
83 16 ▶ if (!result) {
Branch: 1 branch
BranchTrueFalseTotal
if (!result) { 0 16 16
84 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 10 ▶ case GEOS_POINT: return xs::out<>(dyn_cast<geos::geom::Point*>(g));
Branch: 2 branches
BranchTrueFalseTotal
case GEOS_POINT: return xs::out<>(dyn_cast<geos::geom::Point*>(g)); 5 0 5
case GEOS_POINT: return xs::out<>(dyn_cast<geos::geom::Point*>(g)); 5 0 5
95 28 ▶ case GEOS_LINESTRING: return xs::out<>(dyn_cast<geos::geom::LineString*>(g));
Branch: 2 branches
BranchTrueFalseTotal
case GEOS_LINESTRING: return xs::out<>(dyn_cast<geos::geom::LineString*>(g)); 14 0 14
case GEOS_LINESTRING: return xs::out<>(dyn_cast<geos::geom::LineString*>(g)); 14 0 14
96 6 ▶ case GEOS_LINEARRING: return xs::out<>(dyn_cast<geos::geom::LinearRing*>(g));
Branch: 2 branches
BranchTrueFalseTotal
case GEOS_LINEARRING: return xs::out<>(dyn_cast<geos::geom::LinearRing*>(g)); 3 0 3
case GEOS_LINEARRING: return xs::out<>(dyn_cast<geos::geom::LinearRing*>(g)); 3 0 3
97 118 ▶ case GEOS_POLYGON: return xs::out<>(dyn_cast<geos::geom::Polygon*>(g));
Branch: 2 branches
BranchTrueFalseTotal
case GEOS_POLYGON: return xs::out<>(dyn_cast<geos::geom::Polygon*>(g)); 59 0 59
case GEOS_POLYGON: return xs::out<>(dyn_cast<geos::geom::Polygon*>(g)); 59 0 59
98 12 ▶ case GEOS_MULTIPOINT: return xs::out<>(dyn_cast<geos::geom::MultiPoint*>(g));
Branch: 2 branches
BranchTrueFalseTotal
case GEOS_MULTIPOINT: return xs::out<>(dyn_cast<geos::geom::MultiPoint*>(g)); 6 0 6
case GEOS_MULTIPOINT: return xs::out<>(dyn_cast<geos::geom::MultiPoint*>(g)); 6 0 6
99 20 ▶ case GEOS_MULTILINESTRING: return xs::out<>(dyn_cast<geos::geom::MultiLineString*>(g));
Branch: 2 branches
BranchTrueFalseTotal
case GEOS_MULTILINESTRING: return xs::out<>(dyn_cast<geos::geom::MultiLineString*>(g)); 10 0 10
case GEOS_MULTILINESTRING: return xs::out<>(dyn_cast<geos::geom::MultiLineString*>(g)); 10 0 10
100 28 ▶ case GEOS_MULTIPOLYGON: return xs::out<>(dyn_cast<geos::geom::MultiPolygon*>(g));
Branch: 2 branches
BranchTrueFalseTotal
case GEOS_MULTIPOLYGON: return xs::out<>(dyn_cast<geos::geom::MultiPolygon*>(g)); 14 0 14
case GEOS_MULTIPOLYGON: return xs::out<>(dyn_cast<geos::geom::MultiPolygon*>(g)); 14 0 14
101 40 ▶ case GEOS_GEOMETRYCOLLECTION: return xs::out<>(dyn_cast<geos::geom::GeometryCollection*>(g));
Branch: 2 branches
BranchTrueFalseTotal
case GEOS_GEOMETRYCOLLECTION: return xs::out<>(dyn_cast<geos::geom::GeometryCollection*>(g)); 20 0 20
case GEOS_GEOMETRYCOLLECTION: return xs::out<>(dyn_cast<geos::geom::GeometryCollection*>(g)); 20 0 20
102 0 default:
103 0 throw "unknown geometry type";
104 }
105 }
« xsi/noding/SegmentNode.xsi ↑ Summary xsi/noding/Noder.xsi »