File tree Expand file tree Collapse file tree 6 files changed +108
-16
lines changed
Expand file tree Collapse file tree 6 files changed +108
-16
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ set(osm2pgsql_lib_SOURCES
55 dependency-manager.cpp
66 expire-tiles.cpp
77 gazetteer-style.cpp
8+ geom.cpp
89 geometry-processor.cpp
910 input .cpp
1011 logging.cpp
Original file line number Diff line number Diff line change 1+ /* *
2+ * SPDX-License-Identifier: GPL-2.0-or-later
3+ *
4+ * This file is part of osm2pgsql (https://osm2pgsql.org/).
5+ *
6+ * Copyright (C) 2006-2020 by the osm2pgsql developer community.
7+ * For a full list of authors see the git log.
8+ */
9+
10+ #include " geom.hpp"
11+
12+ namespace geom {
13+
14+ double distance (osmium::geom::Coordinates p1,
15+ osmium::geom::Coordinates p2) noexcept
16+ {
17+ double const dx = p1.x - p2.x ;
18+ double const dy = p1.y - p2.y ;
19+ return std::sqrt (dx * dx + dy * dy);
20+ }
21+
22+ osmium::geom::Coordinates interpolate (osmium::geom::Coordinates p1,
23+ osmium::geom::Coordinates p2,
24+ double frac) noexcept
25+ {
26+ return osmium::geom::Coordinates{frac * (p1.x - p2.x ) + p2.x ,
27+ frac * (p1.y - p2.y ) + p2.y };
28+ }
29+
30+ } // namespace geom
31+
Original file line number Diff line number Diff line change 1+ #ifndef OSM2PGSQL_GEOM_HPP
2+ #define OSM2PGSQL_GEOM_HPP
3+
4+ /* *
5+ * SPDX-License-Identifier: GPL-2.0-or-later
6+ *
7+ * This file is part of osm2pgsql (https://osm2pgsql.org/).
8+ *
9+ * Copyright (C) 2006-2020 by the osm2pgsql developer community.
10+ * For a full list of authors see the git log.
11+ */
12+
13+ /* *
14+ * \file
15+ *
16+ * Low level geometry functions and types.
17+ */
18+
19+ #include < osmium/geom/coordinates.hpp>
20+
21+ namespace geom {
22+
23+ double distance (osmium::geom::Coordinates p1,
24+ osmium::geom::Coordinates p2) noexcept ;
25+
26+ osmium::geom::Coordinates interpolate (osmium::geom::Coordinates p1,
27+ osmium::geom::Coordinates p2,
28+ double frac) noexcept ;
29+
30+ } // namespace geom
31+
32+ #endif // OSM2PGSQL_GEOM_HPP
Original file line number Diff line number Diff line change 1414
1515#include < osmium/area/geom_assembler.hpp>
1616
17+ #include " geom.hpp"
1718#include " osmium-builder.hpp"
1819
1920namespace {
2021
21- inline double distance (osmium::geom::Coordinates p1,
22- osmium::geom::Coordinates p2)
23- {
24- double const dx = p1.x - p2.x ;
25- double const dy = p1.y - p2.y ;
26- return std::sqrt (dx * dx + dy * dy);
27- }
28-
29- inline osmium::geom::Coordinates interpolate (osmium::geom::Coordinates p1,
30- osmium::geom::Coordinates p2,
31- double frac) noexcept
32- {
33- return osmium::geom::Coordinates{frac * (p1.x - p2.x ) + p2.x ,
34- frac * (p1.y - p2.y ) + p2.y };
35- }
36-
3722template <typename ITERATOR>
3823void add_nodes_to_builder (osmium::builder::WayNodeListBuilder &builder,
3924 ITERATOR const &begin, ITERATOR const &end,
Original file line number Diff line number Diff line change @@ -43,6 +43,7 @@ set_test(test-db-copy-thread)
4343set_test(test -db-copy-mgr)
4444set_test(test -domain-matcher LABELS NoDB)
4545set_test(test -expire-tiles LABELS NoDB)
46+ set_test(test -geom LABELS NoDB)
4647set_test(test -middle)
4748set_test(test -options -database LABELS NoDB)
4849set_test(test -options -parse LABELS NoDB)
Original file line number Diff line number Diff line change 1+ /* *
2+ * SPDX-License-Identifier: GPL-2.0-or-later
3+ *
4+ * This file is part of osm2pgsql (https://osm2pgsql.org/).
5+ *
6+ * Copyright (C) 2006-2020 by the osm2pgsql developer community.
7+ * For a full list of authors see the git log.
8+ */
9+
10+ #include < catch.hpp>
11+
12+ #include " geom.hpp"
13+
14+ TEST_CASE (" geom::distance" , " [NoDB]" )
15+ {
16+ osmium::geom::Coordinates const p1{10 , 10 };
17+ osmium::geom::Coordinates const p2{20 , 10 };
18+ osmium::geom::Coordinates const p3{13 , 14 };
19+
20+ REQUIRE (geom::distance (p1, p1) == Approx (0.0 ));
21+ REQUIRE (geom::distance (p1, p2) == Approx (10.0 ));
22+ REQUIRE (geom::distance (p1, p3) == Approx (5.0 ));
23+ }
24+
25+ TEST_CASE (" geom::interpolate" , " [NoDB]" )
26+ {
27+ osmium::geom::Coordinates const p1{10 , 10 };
28+ osmium::geom::Coordinates const p2{20 , 10 };
29+
30+ auto const i1 = geom::interpolate (p1, p1, 0.5 );
31+ REQUIRE (i1.x == 10 );
32+ REQUIRE (i1.y == 10 );
33+
34+ auto const i2 = geom::interpolate (p1, p2, 0.5 );
35+ REQUIRE (i2.x == 15 );
36+ REQUIRE (i2.y == 10 );
37+
38+ auto const i3 = geom::interpolate (p2, p1, 0.5 );
39+ REQUIRE (i3.x == 15 );
40+ REQUIRE (i3.y == 10 );
41+ }
42+
You can’t perform that action at this time.
0 commit comments