From bcce5ec894186e785d55ec811850131ac6b05715 Mon Sep 17 00:00:00 2001 From: lbartoletti Date: Tue, 19 Dec 2023 10:41:42 +0000 Subject: [PATCH] [Clang-tidy] Apply a new round of clang-tidy fix --- script/apply_clang_tidy.sh | 41 + src/Coordinate.cpp | 32 +- src/Coordinate.h | 2 + src/Envelope.cpp | 24 +- src/GeometryCollection.cpp | 7 +- src/Kernel.h | 3 +- src/LineString.cpp | 9 +- src/MultiLineString.cpp | 2 +- src/MultiPoint.cpp | 2 +- src/MultiPolygon.cpp | 2 +- src/MultiSolid.cpp | 2 +- src/Polygon.cpp | 16 +- src/PolyhedralSurface.cpp | 20 +- src/Surface.cpp | 2 +- src/Triangle.cpp | 4 +- src/TriangulatedSurface.cpp | 19 +- src/algorithm/BoundaryVisitor.cpp | 32 +- .../ConsistentOrientationBuilder.cpp | 17 +- src/algorithm/Intersection2D.cpp | 61 +- src/algorithm/Intersection3D.cpp | 85 +- src/algorithm/alphaShapes.cpp | 7 +- src/algorithm/area.cpp | 31 +- src/algorithm/collect.cpp | 15 +- src/algorithm/collectionExtract.cpp | 6 +- src/algorithm/collectionHomogenize.cpp | 6 +- src/algorithm/collectionToMulti.cpp | 8 +- src/algorithm/connection.cpp | 21 +- src/algorithm/convexHull.cpp | 55 +- src/algorithm/covers.cpp | 49 +- src/algorithm/difference.cpp | 41 +- src/algorithm/differencePrimitives.cpp | 6 +- src/algorithm/distance.cpp | 39 +- src/algorithm/distance3d.cpp | 63 +- src/algorithm/extrude.cpp | 26 +- src/algorithm/extrude.h | 7 +- src/algorithm/force2D.cpp | 6 +- src/algorithm/force3D.cpp | 6 +- src/algorithm/intersection.cpp | 25 +- src/algorithm/intersects.cpp | 121 +- src/algorithm/isValid.cpp | 56 +- src/algorithm/length.cpp | 14 +- src/algorithm/lineSubstring.cpp | 33 +- src/algorithm/minkowskiSum.cpp | 19 +- src/algorithm/offset.cpp | 37 +- src/algorithm/orientation.cpp | 6 +- src/algorithm/partition_2.cpp | 14 +- src/algorithm/straightSkeleton.cpp | 89 +- src/algorithm/tesselate.cpp | 9 +- src/algorithm/translate.cpp | 10 +- src/algorithm/translate.h | 4 +- src/algorithm/union.cpp | 158 ++- src/algorithm/visibility.cpp | 53 +- src/algorithm/volume.cpp | 8 +- src/capi/sfcgal_c.cpp | 76 +- src/detail/EnvelopeVisitor.cpp | 6 +- src/detail/ForceValidityVisitor.cpp | 6 +- src/detail/GeometrySet.cpp | 151 +-- src/detail/GetPointsVisitor.cpp | 6 +- src/detail/Interval.cpp | 9 +- src/detail/Interval.h | 4 - src/detail/algorithm/coversPoints.cpp | 17 +- src/detail/generator/building.cpp | 24 +- src/detail/generator/disc.cpp | 14 +- src/detail/generator/hoch.cpp | 17 +- src/detail/generator/sierpinski.cpp | 12 +- src/detail/graph/Edge.cpp | 6 +- src/detail/graph/Vertex.cpp | 6 +- src/detail/io/Serialization.cpp | 32 +- src/detail/io/WkbReader.cpp | 24 +- src/detail/io/WktReader.cpp | 62 +- src/detail/io/WktWriter.cpp | 12 +- src/detail/polygonSetToMultiPolygon.cpp | 11 +- src/detail/tools/CharArrayBuffer.cpp | 6 +- src/detail/tools/Registry.cpp | 19 +- src/detail/transform/AffineTransform2.cpp | 9 +- src/detail/transform/AffineTransform3.cpp | 9 +- src/detail/transform/Force2D.cpp | 9 +- src/detail/transform/ForceOrderPoints.cpp | 8 +- src/detail/transform/ForceZ.cpp | 11 +- src/detail/transform/ForceZOrderPoints.cpp | 9 +- src/detail/transform/RoundTransform.cpp | 6 +- .../ConstraintDelaunayTriangulation.cpp | 13 +- .../triangulate/triangulateInGeometrySet.cpp | 20 +- src/io/ewkt.cpp | 12 +- src/io/wkt.cpp | 10 +- src/numeric.cpp | 22 +- src/numeric.h | 1 + src/triangulate/triangulate2DZ.cpp | 12 +- src/triangulate/triangulatePolygon.cpp | 16 +- test/bench/Bench.cpp | 53 +- test/bench/Bench.h | 97 +- test/bench/BenchArea.cpp | 60 +- test/bench/BenchContainer.cpp | 30 +- test/bench/BenchMinkowski.cpp | 101 +- test/bench/BenchPredicate.cpp | 56 +- test/bench/BenchStraightSkeleton.cpp | 518 +++++++- test/bench/BenchTriangulation.cpp | 205 ++- test/bench/BenchWKT.cpp | 124 +- test/bench/IntersectionPerfTest.cpp | 74 +- test/bench/KernelPerfTest.cpp | 71 +- test/bench/TestModule.cpp | 11 +- test/regress/convex_hull/main.cpp | 328 +++-- test/regress/polygon_triangulator/main.cpp | 406 +++--- test/regress/standalone/SFCGAL/AreaTest.cpp | 106 +- .../ConstraintDelaunayTriangulationTest.cpp | 65 +- .../standalone/SFCGAL/DistanceTest.cpp | 147 +-- .../standalone/SFCGAL/IntersectionTest.cpp | 63 +- .../standalone/SFCGAL/IntersectsTest.cpp | 102 +- .../SFCGAL/StraightSkeletonTest.cpp | 254 ++-- .../SFCGAL/TriangulatePolygonTest.cpp | 139 +- .../standalone/SFCGAL/WaveFrontObjTest.cpp | 34 +- test/regress/standalone/SFCGAL/WktTest.cpp | 64 +- test/regress/standalone/TestModule.cpp | 11 +- test/unit/SFCGAL/CoordinateTest.cpp | 28 +- test/unit/SFCGAL/EnvelopeTest.cpp | 141 +- test/unit/SFCGAL/GeometryCollectionTest.cpp | 197 ++- test/unit/SFCGAL/GeometryTest.cpp | 94 +- test/unit/SFCGAL/GeometryVisitorTest.cpp | 203 +-- test/unit/SFCGAL/KernelTest.cpp | 105 +- test/unit/SFCGAL/LineStringTest.cpp | 524 ++++---- test/unit/SFCGAL/MultiLineStringTest.cpp | 67 +- test/unit/SFCGAL/MultiPointTest.cpp | 71 +- test/unit/SFCGAL/MultiPolygonTest.cpp | 76 +- test/unit/SFCGAL/MultiSolidTest.cpp | 81 +- test/unit/SFCGAL/NumericTest.cpp | 47 +- test/unit/SFCGAL/PointTest.cpp | 349 +++-- test/unit/SFCGAL/PolygonTest.cpp | 336 +++-- test/unit/SFCGAL/SolidTest.cpp | 133 +- test/unit/SFCGAL/TriangleTest.cpp | 292 ++--- test/unit/SFCGAL/TriangulatedSurfaceTest.cpp | 284 ++--- .../unit/SFCGAL/algorithm/AlphaShapesTest.cpp | 58 +- .../algorithm/ApproximateMedialAxis.cpp | 212 +-- test/unit/SFCGAL/algorithm/AreaTest.cpp | 253 ++-- test/unit/SFCGAL/algorithm/BoundaryTest.cpp | 194 ++- test/unit/SFCGAL/algorithm/ConnectedTest.cpp | 72 +- .../ConsistentOrientationBuilderTest.cpp | 106 +- test/unit/SFCGAL/algorithm/ConvexHullTest.cpp | 210 ++- .../SFCGAL/algorithm/CoversPointsTest.cpp | 84 +- test/unit/SFCGAL/algorithm/CoversTest.cpp | 162 +-- test/unit/SFCGAL/algorithm/DifferenceTest.cpp | 614 +++++---- test/unit/SFCGAL/algorithm/DistanceTest.cpp | 228 ++-- test/unit/SFCGAL/algorithm/ExtrudeTest.cpp | 237 ++-- test/unit/SFCGAL/algorithm/Force3DTest.cpp | 90 +- .../SFCGAL/algorithm/IntersectionTest.cpp | 379 +++--- test/unit/SFCGAL/algorithm/IntersectsTest.cpp | 154 +-- test/unit/SFCGAL/algorithm/IsValidTest.cpp | 88 +- test/unit/SFCGAL/algorithm/LengthTest.cpp | 102 +- .../SFCGAL/algorithm/LineSubstringTest.cpp | 1132 +++++++---------- .../SFCGAL/algorithm/MinkowskiSumTest.cpp | 191 +-- test/unit/SFCGAL/algorithm/NormalTest.cpp | 157 +-- test/unit/SFCGAL/algorithm/OffsetTest.cpp | 66 +- .../unit/SFCGAL/algorithm/OrientationTest.cpp | 244 ++-- test/unit/SFCGAL/algorithm/Partition_2.cpp | 75 +- test/unit/SFCGAL/algorithm/PlaneTest.cpp | 143 ++- .../SFCGAL/algorithm/StraightSkeletonTest.cpp | 132 +- test/unit/SFCGAL/algorithm/TesselateTest.cpp | 111 +- test/unit/SFCGAL/algorithm/TranslateTest.cpp | 53 +- test/unit/SFCGAL/algorithm/UnionTest.cpp | 599 +++++---- test/unit/SFCGAL/algorithm/Visibility.cpp | 121 +- test/unit/SFCGAL/algorithm/VolumeTest.cpp | 12 +- test/unit/SFCGAL/capi/sfcgal_cTest.cpp | 176 +-- .../SFCGAL/detail/ComplexComparatorTest.cpp | 31 +- test/unit/SFCGAL/detail/IntervalTest.cpp | 172 ++- .../SFCGAL/graph/GeometryGraphBuilderTest.cpp | 100 +- test/unit/SFCGAL/graph/GeometryGraphTest.cpp | 149 +-- .../SFCGAL/graph/algorithm/IsHalfEdgeTest.cpp | 95 +- test/unit/SFCGAL/io/SerializationTest.cpp | 233 ++-- test/unit/SFCGAL/io/WkbWriterTest.cpp | 2 +- test/unit/SFCGAL/io/WktReaderTest.cpp | 352 +++-- .../SFCGAL/transform/AffineTransform2Test.cpp | 33 +- .../transform/ForceZOrderPointsTest.cpp | 35 +- test/unit/SFCGAL/transform/RoundTest.cpp | 45 +- .../ConstraintDelaunayTriangulationTest.cpp | 142 +-- .../SFCGAL/triangulate/Triangulate2DZTest.cpp | 130 +- test/unit/TestModule.cpp | 21 +- 175 files changed, 8314 insertions(+), 7945 deletions(-) create mode 100755 script/apply_clang_tidy.sh diff --git a/script/apply_clang_tidy.sh b/script/apply_clang_tidy.sh new file mode 100755 index 00000000..c21f1c66 --- /dev/null +++ b/script/apply_clang_tidy.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +# This script generates a commit for each clang-tidy check using various clang utilities. +# +# By default, it uses Linux paths. +# You can execute it by defining the variables CLANG_TIDY_BIN, RUN_CLANG_TIDY_BIN, +# and APPLY_CLANG_TIDY_BIN when running the script: +# +# > env CLANG_TIDY_BIN=/usr/local/bin/clang-tidy15 \ +# RUN_CLANG_TIDY_BIN=/usr/local/bin/run-clang-tidy15 \ +# APPLY_CLANG_TIDY_BIN=/usr/local/bin/clang-apply-replacements15 \ +# ./apply_clang_tidy.sh +# +# There isn't a clang-tidy CI in this project as of now. +# This script is useful for potential changes in .clang-tidy. +# We encourage developers to apply the fixes suggested by clang-tidy. + + +CLANG_TIDY_BIN=${CLANG_TIDY_BIN:-/usr/bin/clang-tidy} +RUN_CLANG_TIDY_BIN=${RUN_CLANG_TIDY_BIN:-/usr/bin/run-clang-tidy} +APPLY_CLANG_TIDY_BIN=${APPLY_CLANG_TIDY_BIN:-/usr/bin/clang-apply-replacements} + +run_clang_tidy() { + checks=$(${CLANG_TIDY_BIN} --list-checks | awk '/ /{print $1}') + + # Iterate over each check and run clang-tidy with fixes + while IFS= read -r check; do + ${RUN_CLANG_TIDY_BIN} -p build -clang-tidy-binary=${CLANG_TIDY_BIN} -clang-apply-replacements-binary=${APPLY_CLANG_TIDY_BIN} -checks="-=*,$check" -fix + + # Check if changes were made + if [ -n "$(git status -s)" ]; then + # Commit the changes with a relevant message + git add . + git commit -m "Fix clang-tidy check: $check" + else + echo "No changes for clang-tidy check: $check" + fi + done <<< "$checks" +} + +run_clang_tidy diff --git a/src/Coordinate.cpp b/src/Coordinate.cpp index 81a51912..7c3fed6e 100644 --- a/src/Coordinate.cpp +++ b/src/Coordinate.cpp @@ -87,17 +87,17 @@ Coordinate::~Coordinate() = default; class CoordinateDimensionVisitor : public boost::static_visitor { public: auto - operator()(const Coordinate::Empty &) const -> int + operator()(const Coordinate::Empty & /*unused*/) const -> int { return 0; } auto - operator()(const Kernel::Point_2 &) const -> int + operator()(const Kernel::Point_2 & /*unused*/) const -> int { return 2; } auto - operator()(const Kernel::Point_3 &) const -> int + operator()(const Kernel::Point_3 & /*unused*/) const -> int { return 3; } @@ -134,7 +134,7 @@ Coordinate::is3D() const -> bool class GetXVisitor : public boost::static_visitor { public: auto - operator()(const Coordinate::Empty &) const -> Kernel::FT + operator()(const Coordinate::Empty & /*unused*/) const -> Kernel::FT { BOOST_THROW_EXCEPTION( Exception("trying to get an empty coordinate x value")); @@ -165,7 +165,7 @@ Coordinate::x() const -> Kernel::FT class GetYVisitor : public boost::static_visitor { public: auto - operator()(const Coordinate::Empty &) const -> Kernel::FT + operator()(const Coordinate::Empty & /*unused*/) const -> Kernel::FT { BOOST_THROW_EXCEPTION( Exception("trying to get an empty coordinate y value")); @@ -196,14 +196,14 @@ Coordinate::y() const -> Kernel::FT class GetZVisitor : public boost::static_visitor { public: auto - operator()(const Coordinate::Empty &) const -> Kernel::FT + operator()(const Coordinate::Empty & /*unused*/) const -> Kernel::FT { BOOST_THROW_EXCEPTION( Exception("trying to get an empty coordinate z value")); return 0; } auto - operator()(const Kernel::Point_2 &) const -> Kernel::FT + operator()(const Kernel::Point_2 & /*unused*/) const -> Kernel::FT { return 0; } @@ -231,7 +231,7 @@ class RoundVisitor : public boost::static_visitor<> { RoundVisitor(const long &scaleFactor) : _scaleFactor(scaleFactor) {} void - operator()(Coordinate::Empty &) const + operator()(Coordinate::Empty & /*unused*/) const { } void @@ -249,10 +249,11 @@ class RoundVisitor : public boost::static_visitor<> { private: long _scaleFactor; - auto + [[nodiscard]] auto _roundFT(const Kernel::FT &v) const -> Kernel::FT { -#ifdef CGAL_USE_GMPXX + +#if defined(CGAL_USE_GMPXX) ::mpq_class q(SFCGAL::round(v.exact() * _scaleFactor), _scaleFactor); q.canonicalize(); return Kernel::FT(q); @@ -276,7 +277,7 @@ Coordinate::round(const long &scaleFactor) -> Coordinate & class ToPoint2Visitor : public boost::static_visitor { public: auto - operator()(const Coordinate::Empty &) const -> Kernel::Point_2 + operator()(const Coordinate::Empty & /*unused*/) const -> Kernel::Point_2 { return Kernel::Point_2(CGAL::ORIGIN); } @@ -353,14 +354,16 @@ Coordinate::operator<(const Coordinate &other) const -> bool // comparison along x if (x() < other.x()) { return true; - } else if (other.x() < x()) { + } + if (other.x() < x()) { return false; } // comparison along y if (y() < other.y()) { return true; - } else if (other.y() < y()) { + } + if (other.y() < y()) { return false; } @@ -368,7 +371,8 @@ Coordinate::operator<(const Coordinate &other) const -> bool if (is3D()) { if (z() < other.z()) { return true; - } else if (other.z() < z()) { + } + if (other.z() < z()) { return false; } } diff --git a/src/Coordinate.h b/src/Coordinate.h index 458bf5f7..16f08ce9 100644 --- a/src/Coordinate.h +++ b/src/Coordinate.h @@ -28,6 +28,7 @@ class SFCGAL_API Coordinate { * Empty Coordinate constructor */ Coordinate(); + /** * XY Constructor with exact coordinates */ @@ -36,6 +37,7 @@ class SFCGAL_API Coordinate { * XYZ Constructor with exact coordinates */ Coordinate(const Kernel::FT &x, const Kernel::FT &y, const Kernel::FT &z); + /** * XYZ constructor * @warning x,y,z must not be not be NaN nor inf diff --git a/src/Envelope.cpp b/src/Envelope.cpp index b369cf9f..a4eb7842 100644 --- a/src/Envelope.cpp +++ b/src/Envelope.cpp @@ -143,13 +143,13 @@ auto Envelope::overlaps(const Envelope &a, const Envelope &b) -> bool { if (a.is3D()) { - CGAL::Bbox_3 abox = a.toBbox_3(); - CGAL::Bbox_3 bbox = b.toBbox_3(); + CGAL::Bbox_3 const abox = a.toBbox_3(); + CGAL::Bbox_3 const bbox = b.toBbox_3(); return CGAL::do_overlap(abox, bbox); } - CGAL::Bbox_2 abox = a.toBbox_2(); - CGAL::Bbox_2 bbox = b.toBbox_2(); + CGAL::Bbox_2 const abox = a.toBbox_2(); + CGAL::Bbox_2 const bbox = b.toBbox_2(); return CGAL::do_overlap(abox, bbox); } @@ -195,15 +195,15 @@ Envelope::toShell() const -> std::unique_ptr return shell; } - Point a(xMin(), yMin(), zMin()); - Point b(xMax(), yMin(), zMin()); - Point c(xMax(), yMax(), zMin()); - Point d(xMin(), yMax(), zMin()); + Point const a(xMin(), yMin(), zMin()); + Point const b(xMax(), yMin(), zMin()); + Point const c(xMax(), yMax(), zMin()); + Point const d(xMin(), yMax(), zMin()); - Point e(xMin(), yMin(), zMax()); - Point f(xMax(), yMin(), zMax()); - Point g(xMax(), yMax(), zMax()); - Point h(xMin(), yMax(), zMax()); + Point const e(xMin(), yMin(), zMax()); + Point const f(xMax(), yMin(), zMax()); + Point const g(xMax(), yMax(), zMax()); + Point const h(xMin(), yMax(), zMax()); // bottom : a,d,c,b { diff --git a/src/GeometryCollection.cpp b/src/GeometryCollection.cpp index 5aa2e692..75b9023e 100644 --- a/src/GeometryCollection.cpp +++ b/src/GeometryCollection.cpp @@ -12,7 +12,7 @@ namespace SFCGAL { /// /// /// -GeometryCollection::GeometryCollection() : _geometries() {} +GeometryCollection::GeometryCollection() = default; /// /// @@ -90,9 +90,8 @@ GeometryCollection::coordinateDimension() const -> int { if (isEmpty()) { return 0; - } else { - return _geometries.front().coordinateDimension(); } + return _geometries.front().coordinateDimension(); } /// @@ -181,7 +180,7 @@ GeometryCollection::addGeometry(Geometry const &geometry) /// /// auto -GeometryCollection::isAllowed(Geometry const &) -> bool +GeometryCollection::isAllowed(Geometry const & /*unused*/) -> bool { // GeometryCollection accepts all subtypes return true; diff --git a/src/Kernel.h b/src/Kernel.h index c04a9d3e..05ab7633 100644 --- a/src/Kernel.h +++ b/src/Kernel.h @@ -12,7 +12,8 @@ namespace SFCGAL { /** * default Kernel */ -typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel; + +using Kernel = CGAL::Exact_predicates_exact_constructions_kernel; /** * Quotient type diff --git a/src/LineString.cpp b/src/LineString.cpp index a2127dee..1d43ecbb 100644 --- a/src/LineString.cpp +++ b/src/LineString.cpp @@ -10,12 +10,12 @@ namespace SFCGAL { /// /// /// -LineString::LineString() : Geometry(), _points() {} +LineString::LineString() = default; /// /// /// -LineString::LineString(const std::vector &points) : Geometry(), _points() +LineString::LineString(const std::vector &points) { for (const auto &point : points) { _points.push_back(point.clone()); @@ -26,7 +26,7 @@ LineString::LineString(const std::vector &points) : Geometry(), _points() /// /// LineString::LineString(const Point &startPoint, const Point &endPoint) - : Geometry(), _points() + { _points.push_back(startPoint.clone()); _points.push_back(endPoint.clone()); @@ -154,9 +154,8 @@ LineString::numSegments() const -> size_t { if (_points.empty()) { return 0; - } else { - return _points.size() - 1; } + return _points.size() - 1; } /// diff --git a/src/MultiLineString.cpp b/src/MultiLineString.cpp index f8b7eb89..dc4b86c2 100644 --- a/src/MultiLineString.cpp +++ b/src/MultiLineString.cpp @@ -10,7 +10,7 @@ namespace SFCGAL { /// /// /// -MultiLineString::MultiLineString() : GeometryCollection() {} +MultiLineString::MultiLineString() = default; /// /// diff --git a/src/MultiPoint.cpp b/src/MultiPoint.cpp index a50c437d..ab345a5b 100644 --- a/src/MultiPoint.cpp +++ b/src/MultiPoint.cpp @@ -10,7 +10,7 @@ namespace SFCGAL { /// /// /// -MultiPoint::MultiPoint() : GeometryCollection() {} +MultiPoint::MultiPoint() = default; /// /// diff --git a/src/MultiPolygon.cpp b/src/MultiPolygon.cpp index 066007ce..93e2b219 100644 --- a/src/MultiPolygon.cpp +++ b/src/MultiPolygon.cpp @@ -10,7 +10,7 @@ namespace SFCGAL { /// /// /// -MultiPolygon::MultiPolygon() : GeometryCollection() {} +MultiPolygon::MultiPolygon() = default; /// /// diff --git a/src/MultiSolid.cpp b/src/MultiSolid.cpp index 915d69a8..91a87ebf 100644 --- a/src/MultiSolid.cpp +++ b/src/MultiSolid.cpp @@ -10,7 +10,7 @@ namespace SFCGAL { /// /// /// -MultiSolid::MultiSolid() : GeometryCollection() {} +MultiSolid::MultiSolid() = default; /// /// diff --git a/src/Polygon.cpp b/src/Polygon.cpp index 20f4f60a..4c321ac1 100644 --- a/src/Polygon.cpp +++ b/src/Polygon.cpp @@ -13,12 +13,12 @@ namespace SFCGAL { /// /// /// -Polygon::Polygon() : Surface() { _rings.push_back(new LineString()); } +Polygon::Polygon() { _rings.push_back(new LineString()); } /// /// /// -Polygon::Polygon(const std::vector &rings) : Surface() +Polygon::Polygon(const std::vector &rings) { if (rings.empty()) { _rings.resize(1, new LineString()); @@ -32,7 +32,7 @@ Polygon::Polygon(const std::vector &rings) : Surface() /// /// /// -Polygon::Polygon(const LineString &exteriorRing) : Surface() +Polygon::Polygon(const LineString &exteriorRing) { _rings.push_back(exteriorRing.clone()); } @@ -40,15 +40,12 @@ Polygon::Polygon(const LineString &exteriorRing) : Surface() /// /// /// -Polygon::Polygon(LineString *exteriorRing) : Surface() -{ - _rings.push_back(exteriorRing); -} +Polygon::Polygon(LineString *exteriorRing) { _rings.push_back(exteriorRing); } /// /// /// -Polygon::Polygon(const Triangle &triangle) : Surface() +Polygon::Polygon(const Triangle &triangle) { _rings.push_back(new LineString()); @@ -255,7 +252,8 @@ Polygon::toPolygon_with_holes_2(bool fixOrientation) const holes.push_back(inner); } - CGAL::Polygon_2 outer = exteriorRing().toPolygon_2(fixOrientation); + CGAL::Polygon_2 const outer = + exteriorRing().toPolygon_2(fixOrientation); return CGAL::Polygon_with_holes_2(outer, holes.begin(), holes.end()); } diff --git a/src/PolyhedralSurface.cpp b/src/PolyhedralSurface.cpp index f12bc148..4d27406b 100644 --- a/src/PolyhedralSurface.cpp +++ b/src/PolyhedralSurface.cpp @@ -12,13 +12,13 @@ namespace SFCGAL { /// /// /// -PolyhedralSurface::PolyhedralSurface() : Surface(), _polygons() {} +PolyhedralSurface::PolyhedralSurface() = default; /// /// /// PolyhedralSurface::PolyhedralSurface(const std::vector &polygons) - : Surface() + { for (const auto &polygon : polygons) { _polygons.push_back(polygon.clone()); @@ -35,7 +35,7 @@ PolyhedralSurface::PolyhedralSurface(const PolyhedralSurface &other) /// /// /// -PolyhedralSurface::PolyhedralSurface(const MarkedPolyhedron &poly) : Surface() +PolyhedralSurface::PolyhedralSurface(const MarkedPolyhedron &poly) { for (MarkedPolyhedron::Facet_const_iterator fit = poly.facets_begin(); fit != poly.facets_end(); ++fit) { @@ -57,13 +57,14 @@ PolyhedralSurface::PolyhedralSurface(const MarkedPolyhedron &poly) : Surface() /// /// /// -PolyhedralSurface::PolyhedralSurface(const Mesh &sm) : Surface() +PolyhedralSurface::PolyhedralSurface(const Mesh &sm) { using vertex_descriptor = Mesh::Vertex_index; for (auto face : sm.faces()) { auto *new_face = new LineString(); - for (vertex_descriptor vd : vertices_around_face(sm.halfedge(face), sm)) { + for (vertex_descriptor const vd : + vertices_around_face(sm.halfedge(face), sm)) { new_face->addPoint(Point(sm.point(vd))); } @@ -131,9 +132,8 @@ PolyhedralSurface::coordinateDimension() const -> int { if (isEmpty()) { return 0; - } else { - return _polygons.front().coordinateDimension(); } + return _polygons.front().coordinateDimension(); } /// @@ -153,9 +153,8 @@ PolyhedralSurface::is3D() const -> bool { if (isEmpty()) { return false; - } else { - return _polygons.front().is3D(); } + return _polygons.front().is3D(); } /// @@ -166,9 +165,8 @@ PolyhedralSurface::isMeasured() const -> bool { if (isEmpty()) { return false; - } else { - return _polygons.front().isMeasured(); } + return _polygons.front().isMeasured(); } /// diff --git a/src/Surface.cpp b/src/Surface.cpp index ab1d0571..0275c700 100644 --- a/src/Surface.cpp +++ b/src/Surface.cpp @@ -24,7 +24,7 @@ Surface::dimension() const -> int /// /// /// -Surface::Surface() : Geometry() {} +Surface::Surface() = default; /// /// diff --git a/src/Triangle.cpp b/src/Triangle.cpp index 3c162308..b85ed067 100644 --- a/src/Triangle.cpp +++ b/src/Triangle.cpp @@ -12,7 +12,7 @@ namespace SFCGAL { /// /// /// -Triangle::Triangle() : Surface() +Triangle::Triangle() { _vertices[0] = Point(); _vertices[1] = Point(); @@ -42,7 +42,7 @@ Triangle::Triangle(const Kernel::Triangle_3 &triangle) /// /// /// -Triangle::Triangle(const Point &p, const Point &q, const Point &r) : Surface() +Triangle::Triangle(const Point &p, const Point &q, const Point &r) { _vertices[0] = p; _vertices[1] = q; diff --git a/src/TriangulatedSurface.cpp b/src/TriangulatedSurface.cpp index 03ffd4d9..07595b48 100644 --- a/src/TriangulatedSurface.cpp +++ b/src/TriangulatedSurface.cpp @@ -10,13 +10,13 @@ namespace SFCGAL { /// /// /// -TriangulatedSurface::TriangulatedSurface() : Surface(), _triangles() {} +TriangulatedSurface::TriangulatedSurface() = default; /// /// /// TriangulatedSurface::TriangulatedSurface(const std::vector &triangles) - : Surface() + { for (const auto &triangle : triangles) { _triangles.push_back(triangle.clone()); @@ -91,9 +91,8 @@ TriangulatedSurface::coordinateDimension() const -> int { if (_triangles.empty()) { return 0; - } else { - return _triangles[0].coordinateDimension(); } + return _triangles[0].coordinateDimension(); } /// @@ -219,7 +218,7 @@ class Triangulated2Polyhedron : public CGAL::Modifier_base { // thanks to a binary tree (PointMap) for (size_t i = 0; i < surf.numGeometries(); i++) { for (size_t j = 0; j < 3; j++) { - Point p = surf.geometryN(i).vertex(j).toPoint_3(); + Point const p = surf.geometryN(i).vertex(j).toPoint_3(); if (points.find(p) == points.end()) { B.add_vertex(p); @@ -237,10 +236,10 @@ class Triangulated2Polyhedron : public CGAL::Modifier_base { for (size_t i = 0; i < surf.numGeometries(); i++) { B.begin_facet(); - CGAL::Triangle_3 tri(surf.geometryN(i).toTriangle_3()); - CGAL::Point_3 pa(tri[0]); - CGAL::Point_3 pb(tri[1]); - CGAL::Point_3 pc(tri[2]); + CGAL::Triangle_3 const tri(surf.geometryN(i).toTriangle_3()); + CGAL::Point_3 const pa(tri[0]); + CGAL::Point_3 const pb(tri[1]); + CGAL::Point_3 const pc(tri[2]); if (edges.find(std::make_pair(pa, pb)) != edges.end() || edges.find(std::make_pair(pb, pc)) != edges.end() || @@ -275,7 +274,7 @@ struct Plane_from_facet { auto operator()(typename Polyhedron::Facet &f) -> typename Polyhedron::Plane_3 { - typename Polyhedron::Halfedge_handle h = f.halfedge(); + typename Polyhedron::Halfedge_handle const h = f.halfedge(); return typename Polyhedron::Plane_3(h->vertex()->point(), h->next()->vertex()->point(), h->opposite()->vertex()->point()); diff --git a/src/algorithm/BoundaryVisitor.cpp b/src/algorithm/BoundaryVisitor.cpp index 1c6bfe82..f6045a44 100644 --- a/src/algorithm/BoundaryVisitor.cpp +++ b/src/algorithm/BoundaryVisitor.cpp @@ -21,15 +21,15 @@ #include #include #include +#include -namespace SFCGAL { -namespace algorithm { +namespace SFCGAL::algorithm { /// /// /// void -BoundaryVisitor::visit(const Point &) +BoundaryVisitor::visit(const Point & /*g*/) { _boundary.reset(); } @@ -51,7 +51,7 @@ BoundaryVisitor::visit(const LineString &g) std::unique_ptr boundary(new MultiPoint); boundary->addGeometry(g.startPoint()); boundary->addGeometry(g.endPoint()); - _boundary.reset(boundary.release()); + _boundary = std::move(boundary); } } @@ -75,7 +75,7 @@ BoundaryVisitor::visit(const Polygon &g) boundary->addGeometry(g.ringN(i)); } - _boundary.reset(boundary.release()); + _boundary = std::move(boundary); } } @@ -96,7 +96,7 @@ BoundaryVisitor::visit(const Triangle &g) boundary->addPoint(g.vertex(i)); } - _boundary.reset(boundary.release()); + _boundary = std::move(boundary); } /// @@ -115,7 +115,7 @@ BoundaryVisitor::visit(const Solid &g) /// /// void -BoundaryVisitor::visit(const MultiPoint &) +BoundaryVisitor::visit(const MultiPoint & /*g*/) { _boundary.reset(); } @@ -216,11 +216,10 @@ BoundaryVisitor::visit(const TriangulatedSurface &g) auto BoundaryVisitor::releaseBoundary() -> Geometry * { - if (_boundary.get()) { + if (_boundary != nullptr) { return _boundary.release(); - } else { - return new GeometryCollection(); } + return new GeometryCollection(); } /// @@ -234,7 +233,8 @@ BoundaryVisitor::getBoundaryFromLineStrings(const graph::GeometryGraph &graph) std::vector vertices; - vertex_iterator it, end; + vertex_iterator it; + vertex_iterator end; for (boost::tie(it, end) = graph.vertices(); it != end; ++it) { vertex_descriptor vertex = *it; @@ -255,7 +255,7 @@ BoundaryVisitor::getBoundaryFromLineStrings(const graph::GeometryGraph &graph) boundary->addGeometry(new Point(graph[vertice].coordinate)); } - _boundary.reset(boundary.release()); + _boundary = std::move(boundary); } } @@ -272,7 +272,8 @@ BoundaryVisitor::getBoundaryFromPolygons(const graph::GeometryGraph &g) std::vector boundaryEdges; - edge_iterator it, end; + edge_iterator it; + edge_iterator end; for (boost::tie(it, end) = g.edges(); it != end; ++it) { if (g.edges(g.source(*it), g.target(*it)).size() == 1U) { @@ -294,9 +295,8 @@ BoundaryVisitor::getBoundaryFromPolygons(const graph::GeometryGraph &g) Point(g[target].coordinate))); } - _boundary.reset(boundary.release()); + _boundary = std::move(boundary); } } -} // namespace algorithm -} // namespace SFCGAL +} // namespace SFCGAL::algorithm diff --git a/src/algorithm/ConsistentOrientationBuilder.cpp b/src/algorithm/ConsistentOrientationBuilder.cpp index 689db931..fa50c8c7 100644 --- a/src/algorithm/ConsistentOrientationBuilder.cpp +++ b/src/algorithm/ConsistentOrientationBuilder.cpp @@ -5,14 +5,13 @@ #include #include -namespace SFCGAL { -namespace algorithm { +namespace SFCGAL::algorithm { /// /// /// ConsistentOrientationBuilder::ConsistentOrientationBuilder() - : _graph(), _graphBuilder(_graph), _triangles() + : _graph(), _graphBuilder(_graph) { } @@ -102,8 +101,9 @@ ConsistentOrientationBuilder::_makeOrientationConsistent() // orient neighbors const std::set &neighbors = _neighbors[currentTriangle]; - for (unsigned long neighbor : neighbors) { - bool hasOppositeEdge = false, hasParallelEdge = false; + for (unsigned long const neighbor : neighbors) { + bool hasOppositeEdge = false; + bool hasParallelEdge = false; graph::algorithm::studyOrientation(_graph, _triangles[currentTriangle], _triangles[neighbor], hasOppositeEdge, hasParallelEdge); @@ -151,11 +151,11 @@ ConsistentOrientationBuilder::_computeNeighbors() vertex_descriptor target = _graph.target(j); // get neighbor edges - std::vector neighborEdges = + std::vector const neighborEdges = _graph.edges(source, target); // use marker to fill neighborGraph - for (auto &neighborEdge : neighborEdges) { + for (const auto &neighborEdge : neighborEdges) { auto idOtherTriangle = (size_t)_graph[neighborEdge.first].face; if (idOtherTriangle == i) { @@ -207,5 +207,4 @@ ConsistentOrientationBuilder::_findNextTriangle() -> int return result; } -} // namespace algorithm -} // namespace SFCGAL +} // namespace SFCGAL::algorithm diff --git a/src/algorithm/Intersection2D.cpp b/src/algorithm/Intersection2D.cpp index f4cb083c..5911e87b 100644 --- a/src/algorithm/Intersection2D.cpp +++ b/src/algorithm/Intersection2D.cpp @@ -16,8 +16,7 @@ using namespace SFCGAL::detail; -namespace SFCGAL { -namespace algorithm { +namespace SFCGAL::algorithm { // local function : get the number of intersection points between rings of a // polygon @@ -39,7 +38,8 @@ numIntersectionPoints(const CGAL::Polygon_with_holes_2 &poly) -> int } for (auto hjt = hit; hjt != poly.holes_end(); ++hjt) { - GeometrySet<2> ringJ, inter; + GeometrySet<2> ringJ; + GeometrySet<2> inter; ringJ.addSegments(hjt->edges_begin(), hjt->edges_end()); algorithm::intersection(ringI, ringJ, inter); @@ -54,7 +54,7 @@ numIntersectionPoints(const CGAL::Polygon_with_holes_2 &poly) -> int // must be called with pa's dimension larger than pb's void intersection(const PrimitiveHandle<2> &pa, const PrimitiveHandle<2> &pb, - GeometrySet<2> &output, dim_t<2>) + GeometrySet<2> &output, dim_t<2> /*unused*/) { // everything vs a point if (pb.handle.which() == PrimitivePoint) { @@ -71,19 +71,19 @@ intersection(const PrimitiveHandle<2> &pa, const PrimitiveHandle<2> &pb, poly1->outer_boundary().size() == 3 && poly2->holes_begin() == poly2->holes_end() && poly2->outer_boundary().size() == 3) { - auto vit1 = poly1->outer_boundary().vertices_begin(); - CGAL::Point_2 pa1 = *vit1++; - CGAL::Point_2 pa2 = *vit1++; - CGAL::Point_2 pa3 = *vit1; - CGAL::Triangle_2 tri1(pa1, pa2, pa3); - - auto vit2 = poly2->outer_boundary().vertices_begin(); - CGAL::Point_2 pb1 = *vit2++; - CGAL::Point_2 pb2 = *vit2++; - CGAL::Point_2 pb3 = *vit2; - CGAL::Triangle_2 tri2(pb1, pb2, pb3); - - CGAL::Object interObj = CGAL::intersection(tri1, tri2); + auto vit1 = poly1->outer_boundary().vertices_begin(); + CGAL::Point_2 const pa1 = *vit1++; + CGAL::Point_2 const pa2 = *vit1++; + CGAL::Point_2 const pa3 = *vit1; + CGAL::Triangle_2 const tri1(pa1, pa2, pa3); + + auto vit2 = poly2->outer_boundary().vertices_begin(); + CGAL::Point_2 const pb1 = *vit2++; + CGAL::Point_2 const pb2 = *vit2++; + CGAL::Point_2 const pb3 = *vit2; + CGAL::Triangle_2 const tri2(pb1, pb2, pb3); + + CGAL::Object const interObj = CGAL::intersection(tri1, tri2); output.addPrimitive(interObj, /* pointsAsRing */ true); return; } @@ -91,7 +91,8 @@ intersection(const PrimitiveHandle<2> &pa, const PrimitiveHandle<2> &pb, // CGAL::intersection does not work when the intersection is a point or a // segment We have to call intersection on boundaries first - GeometrySet<2> gpoly1, gpoly2; + GeometrySet<2> gpoly1; + GeometrySet<2> gpoly2; gpoly1.addBoundary(*poly1); gpoly2.addBoundary(*poly2); @@ -114,9 +115,9 @@ intersection(const PrimitiveHandle<2> &pa, const PrimitiveHandle<2> &pb, CGAL::intersection(*poly1, *poly2, std::back_inserter(output.surfaces())); } else if (pa.handle.which() == PrimitiveSegment && pb.handle.which() == PrimitiveSegment) { - const auto *seg1 = pa.as>(); - const auto *seg2 = pb.as>(); - CGAL::Object interObj = CGAL::intersection(*seg1, *seg2); + const auto *seg1 = pa.as>(); + const auto *seg2 = pb.as>(); + CGAL::Object const interObj = CGAL::intersection(*seg1, *seg2); output.addPrimitive(interObj); } else if (pa.handle.which() == PrimitiveSurface && pb.handle.which() == PrimitiveSegment) { @@ -127,18 +128,19 @@ intersection(const PrimitiveHandle<2> &pa, const PrimitiveHandle<2> &pb, if (poly->holes_begin() == poly->holes_end() && poly->outer_boundary().size() == 3) { // no holes and 3 vertices => it is a triangle - auto vit = poly->outer_boundary().vertices_begin(); - CGAL::Point_2 p1(*vit++); - CGAL::Point_2 p2(*vit++); - CGAL::Point_2 p3(*vit++); - CGAL::Triangle_2 tri(p1, p2, p3); - CGAL::Object interObj = CGAL::intersection(tri, *seg); + auto vit = poly->outer_boundary().vertices_begin(); + CGAL::Point_2 const p1(*vit++); + CGAL::Point_2 const p2(*vit++); + CGAL::Point_2 const p3(*vit++); + CGAL::Triangle_2 const tri(p1, p2, p3); + CGAL::Object const interObj = CGAL::intersection(tri, *seg); output.addPrimitive(interObj); return; } // if it s a regulat polygon, triangulate it and recurse call - GeometrySet<2> triangles, g; + GeometrySet<2> triangles; + GeometrySet<2> g; triangulate::triangulate(*poly, triangles); g.addPrimitive(pb); @@ -146,5 +148,4 @@ intersection(const PrimitiveHandle<2> &pa, const PrimitiveHandle<2> &pb, algorithm::intersection(triangles, g, output); } } -} // namespace algorithm -} // namespace SFCGAL +} // namespace SFCGAL::algorithm diff --git a/src/algorithm/Intersection3D.cpp b/src/algorithm/Intersection3D.cpp index e0cb72e9..7ce33761 100644 --- a/src/algorithm/Intersection3D.cpp +++ b/src/algorithm/Intersection3D.cpp @@ -19,8 +19,7 @@ using namespace SFCGAL::detail; -namespace SFCGAL { -namespace algorithm { +namespace SFCGAL::algorithm { void _intersection_solid_segment(const PrimitiveHandle<3> &pa, @@ -35,17 +34,18 @@ _intersection_solid_segment(const PrimitiveHandle<3> &pa, const auto *segment = pb.as>(); auto *ext_poly_nc = const_cast(ext_poly); - CGAL::Side_of_triangle_mesh is_in_ext(*ext_poly_nc); + CGAL::Side_of_triangle_mesh const is_in_ext( + *ext_poly_nc); - GeometrySet<3> triangles; - GeometrySet<3> spoint(segment->source()); - GeometrySet<3> tpoint(segment->target()); + GeometrySet<3> triangles; + GeometrySet<3> const spoint(segment->source()); + GeometrySet<3> const tpoint(segment->target()); triangulate::triangulate(*ext_poly, triangles); - bool source_inside = + bool const source_inside = (is_in_ext(segment->source()) != CGAL::ON_UNBOUNDED_SIDE) || intersects(triangles, spoint); - bool target_inside = + bool const target_inside = (is_in_ext(segment->target()) != CGAL::ON_UNBOUNDED_SIDE) || intersects(triangles, tpoint); @@ -53,7 +53,8 @@ _intersection_solid_segment(const PrimitiveHandle<3> &pa, // the entire segment intersects the volume, return the segment output.addPrimitive(pb); } else { - GeometrySet<3> triangles, g; + GeometrySet<3> triangles; + GeometrySet<3> g; triangulate::triangulate(*ext_poly, triangles); g.addPrimitive(pb); GeometrySet<3> inter; @@ -65,8 +66,8 @@ _intersection_solid_segment(const PrimitiveHandle<3> &pa, // the intersection is a point, build a segment from that point to the // other end if (!source_inside && target_inside) { - CGAL::Segment_3 interSeg(inter.points().begin()->primitive(), - segment->target()); + CGAL::Segment_3 const interSeg( + inter.points().begin()->primitive(), segment->target()); if (interSeg.source() == interSeg.target()) { output.addPrimitive(segment->target()); @@ -74,8 +75,8 @@ _intersection_solid_segment(const PrimitiveHandle<3> &pa, output.addPrimitive(interSeg); } } else if (source_inside && !target_inside) { - CGAL::Segment_3 interSeg(segment->source(), - inter.points().begin()->primitive()); + CGAL::Segment_3 const interSeg( + segment->source(), inter.points().begin()->primitive()); if (interSeg.source() == interSeg.target()) { output.addPrimitive(segment->source()); @@ -114,18 +115,19 @@ _intersection_solid_triangle(const MarkedPolyhedron &pa, MarkedPolyhedron polyb; polyb.make_triangle(tri.vertex(0), tri.vertex(1), tri.vertex(2)); - MarkedPolyhedron polya = pa; - CGAL::Side_of_triangle_mesh side_of_tm(polya); + MarkedPolyhedron polya = pa; + CGAL::Side_of_triangle_mesh const side_of_tm(polya); std::list polylines; CGAL::Polygon_mesh_processing::surface_intersection( polya, polyb, std::back_inserter(polylines)); - if (polylines.size() == 0) { + if (polylines.empty()) { // no surface intersection // if one of the point of the triangle is inside the polyhedron, // the triangle is inside - if (side_of_tm(tri.vertex(0)) != CGAL::ON_UNBOUNDED_SIDE) + if (side_of_tm(tri.vertex(0)) != CGAL::ON_UNBOUNDED_SIDE) { output.addPrimitive(tri); + } return; } @@ -140,14 +142,15 @@ _intersection_solid_triangle(const MarkedPolyhedron &pa, for (const MarkedPolyhedron &mp : ccs) { // check if all vertices are on polya bool all_on = true; - for (auto v : vertices(mp)) + for (auto v : vertices(mp)) { if (side_of_tm(v->point()) != CGAL::ON_BOUNDARY) { all_on = false; break; } - if (all_on) + } + if (all_on) { output.addPrimitive(mp); - else { + } else { hasSurface = true; output.addPrimitive(mp, FLAG_IS_PLANAR); } @@ -157,14 +160,13 @@ _intersection_solid_triangle(const MarkedPolyhedron &pa, return; } - for (std::list::const_iterator lit = polylines.begin(); - lit != polylines.end(); ++lit) { - if (lit->size() == 1) { + for (auto &polyline : polylines) { + if (polyline.size() == 1) { // it's a point - output.addPrimitive((*lit)[0]); + output.addPrimitive(polyline[0]); } else { - for (size_t k = 1; k < lit->size(); ++k) { - CGAL::Segment_3 seg((*lit)[k - 1], (*lit)[k]); + for (size_t k = 1; k < polyline.size(); ++k) { + CGAL::Segment_3 const seg(polyline[k - 1], polyline[k]); output.addPrimitive(seg); } } @@ -181,7 +183,8 @@ _intersection_solid_solid(const MarkedPolyhedron &pa, // (but no surfaces ...) { // call CGAL::intersection on triangles - GeometrySet<3> gsa, gsb; + GeometrySet<3> gsa; + GeometrySet<3> gsb; // convert polyhedra to geometry sets // (no actual triangulation is done if the polyhedra are pure_triangle() triangulate::triangulate(pa, gsa); @@ -192,11 +195,14 @@ _intersection_solid_solid(const MarkedPolyhedron &pa, // 2. find intersections in volumes { - MarkedPolyhedron polya = pa, polyb = pb; + MarkedPolyhedron polya = pa; + MarkedPolyhedron polyb = pb; if (CGAL::Polygon_mesh_processing::corefine_and_compute_intersection( - polya, polyb, polya)) - if (std::next(vertices(polya).first) != vertices(polya).second) + polya, polyb, polya)) { + if (std::next(vertices(polya).first) != vertices(polya).second) { output.addPrimitive(polya); + } + } } } @@ -204,7 +210,7 @@ _intersection_solid_solid(const MarkedPolyhedron &pa, // must be called with pa's dimension larger than pb's void intersection(const PrimitiveHandle<3> &pa, const PrimitiveHandle<3> &pb, - GeometrySet<3> &output, dim_t<3>) + GeometrySet<3> &output, dim_t<3> /*unused*/) { // everything vs a point if (pb.handle.which() == PrimitivePoint) { @@ -214,20 +220,20 @@ intersection(const PrimitiveHandle<3> &pa, const PrimitiveHandle<3> &pb, } } else if (pa.handle.which() == PrimitiveSegment && pb.handle.which() == PrimitiveSegment) { - const auto *seg1 = pa.as>(); - const auto *seg2 = pb.as>(); - CGAL::Object interObj = CGAL::intersection(*seg1, *seg2); + const auto *seg1 = pa.as>(); + const auto *seg2 = pb.as>(); + CGAL::Object const interObj = CGAL::intersection(*seg1, *seg2); output.addPrimitive(interObj); } else if (pa.handle.which() == PrimitiveSurface) { const auto *tri1 = pa.as>(); if (pb.handle.which() == PrimitiveSegment) { - const auto *seg2 = pb.as>(); - CGAL::Object interObj = CGAL::intersection(*tri1, *seg2); + const auto *seg2 = pb.as>(); + CGAL::Object const interObj = CGAL::intersection(*tri1, *seg2); output.addPrimitive(interObj); } else if (pb.handle.which() == PrimitiveSurface) { - const auto *tri2 = pb.as>(); - CGAL::Object interObj = CGAL::intersection(*tri1, *tri2); + const auto *tri2 = pb.as>(); + CGAL::Object const interObj = CGAL::intersection(*tri1, *tri2); output.addPrimitive(interObj, /* pointsAsRing */ true); } } else if (pa.handle.which() == PrimitiveVolume) { @@ -246,5 +252,4 @@ intersection(const PrimitiveHandle<3> &pa, const PrimitiveHandle<3> &pb, } } -} // namespace algorithm -} // namespace SFCGAL +} // namespace SFCGAL::algorithm diff --git a/src/algorithm/alphaShapes.cpp b/src/algorithm/alphaShapes.cpp index 6914be46..5a0fd691 100644 --- a/src/algorithm/alphaShapes.cpp +++ b/src/algorithm/alphaShapes.cpp @@ -26,8 +26,7 @@ #include #include -namespace SFCGAL { -namespace algorithm { +namespace SFCGAL::algorithm { using Vb = CGAL::Alpha_shape_vertex_base_2; using Fb = CGAL::Alpha_shape_face_base_2; @@ -76,6 +75,7 @@ computeAlpha(const Geometry &g, Alpha_shape_2 &alphaShape, double alpha = 0, std::vector points; + points.reserve(getPointVisitor.points.size()); for (auto &point : getPointVisitor.points) { points.push_back(point->toPoint_2()); } @@ -154,5 +154,4 @@ alphaShapes(const Geometry &g, double alpha, bool allow_holes) return alpha_to_geometry(A, allow_holes); } -} // namespace algorithm -} // namespace SFCGAL +} // namespace SFCGAL::algorithm diff --git a/src/algorithm/area.cpp b/src/algorithm/area.cpp index 685da3c3..a4f92c92 100644 --- a/src/algorithm/area.cpp +++ b/src/algorithm/area.cpp @@ -27,8 +27,7 @@ #include #include -namespace SFCGAL { -namespace algorithm { +namespace SFCGAL::algorithm { using Point_2 = CGAL::Point_2; using Triangle_2 = CGAL::Triangle_2; @@ -42,7 +41,7 @@ using Plane_3 = CGAL::Plane_3; /// /// auto -area(const Geometry &g, NoValidityCheck) -> double +area(const Geometry &g, NoValidityCheck /*unused*/) -> double { switch (g.geometryTypeId()) { case TYPE_POINT: @@ -92,7 +91,7 @@ area(const Geometry &g) -> double auto signedArea(const Triangle &g) -> Kernel::FT { - Triangle_2 triangle = g.toTriangle_2(); + Triangle_2 const triangle = g.toTriangle_2(); return triangle.area(); } @@ -123,7 +122,7 @@ area(const Polygon &g) -> double Kernel::RT result = 0.0; for (size_t i = 0; i < g.numRings(); i++) { - Kernel::FT ringArea = CGAL::abs(signedArea(g.ringN(i))); + Kernel::FT const ringArea = CGAL::abs(signedArea(g.ringN(i))); if (i == 0) { // exterior ring @@ -190,7 +189,7 @@ area(const PolyhedralSurface &g) -> double /// /// auto -area3D(const Geometry &g, NoValidityCheck) -> double +area3D(const Geometry &g, NoValidityCheck /*unused*/) -> double { switch (g.geometryTypeId()) { case TYPE_POINT: @@ -241,7 +240,9 @@ area3D(const Polygon &g) -> double return result; } - CGAL::Point_3 a, b, c; + CGAL::Point_3 a; + CGAL::Point_3 b; + CGAL::Point_3 c; algorithm::plane3D(g, a, b, c); /* @@ -255,7 +256,7 @@ area3D(const Polygon &g) -> double CGAL::Vector_3 uz = CGAL::cross_product(ux, a - b); ux = ux / CGAL::sqrt(CGAL::to_double(ux.squared_length())); uz = uz / CGAL::sqrt(CGAL::to_double(uz.squared_length())); - CGAL::Vector_3 uy = CGAL::cross_product(uz, ux); + CGAL::Vector_3 const uy = CGAL::cross_product(uz, ux); /* * compute the area for each ring in the local basis @@ -266,8 +267,9 @@ area3D(const Polygon &g) -> double CGAL::Polygon_2 projectedPolygon; for (size_t j = 0; j < ring.numPoints() - 1; j++) { - CGAL::Point_3 point = ring.pointN(j).toPoint_3(); - CGAL::Point_2 projectedPoint((point - b) * ux, (point - b) * uy); + CGAL::Point_3 const point = ring.pointN(j).toPoint_3(); + CGAL::Point_2 const projectedPoint((point - b) * ux, + (point - b) * uy); projectedPolygon.push_back(projectedPoint); } @@ -289,9 +291,9 @@ area3D(const Polygon &g) -> double auto area3D(const Triangle &g) -> double { - CGAL::Triangle_3 triangle(g.vertex(0).toPoint_3(), - g.vertex(1).toPoint_3(), - g.vertex(2).toPoint_3()); + CGAL::Triangle_3 const triangle(g.vertex(0).toPoint_3(), + g.vertex(1).toPoint_3(), + g.vertex(2).toPoint_3()); return sqrt(CGAL::to_double(triangle.squared_area())); } @@ -340,5 +342,4 @@ area3D(const TriangulatedSurface &g) -> double return result; } -} // namespace algorithm -} // namespace SFCGAL +} // namespace SFCGAL::algorithm diff --git a/src/algorithm/collect.cpp b/src/algorithm/collect.cpp index fceaa462..2b0266f7 100644 --- a/src/algorithm/collect.cpp +++ b/src/algorithm/collect.cpp @@ -10,8 +10,7 @@ #include #include -namespace SFCGAL { -namespace algorithm { +namespace SFCGAL::algorithm { auto collect(const Geometry &ga, const Geometry &gb) -> std::unique_ptr { @@ -21,17 +20,20 @@ collect(const Geometry &ga, const Geometry &gb) -> std::unique_ptr mp->addGeometry(ga); mp->addGeometry(gb); return std::unique_ptr(mp); - } else if (ga.geometryTypeId() == TYPE_LINESTRING) { + } + if (ga.geometryTypeId() == TYPE_LINESTRING) { auto *mls = new MultiLineString(); mls->addGeometry(ga); mls->addGeometry(gb); return std::unique_ptr(mls); - } else if (ga.geometryTypeId() == TYPE_POLYGON) { + } + if (ga.geometryTypeId() == TYPE_POLYGON) { auto *mp = new MultiPolygon(); mp->addGeometry(ga); mp->addGeometry(gb); return std::unique_ptr(mp); - } else if (ga.geometryTypeId() == TYPE_SOLID) { + } + if (ga.geometryTypeId() == TYPE_SOLID) { auto *mp = new MultiSolid(); mp->addGeometry(ga); mp->addGeometry(gb); @@ -45,5 +47,4 @@ collect(const Geometry &ga, const Geometry &gb) -> std::unique_ptr coll->addGeometry(gb); return std::unique_ptr(coll); } -} // namespace algorithm -} // namespace SFCGAL +} // namespace SFCGAL::algorithm diff --git a/src/algorithm/collectionExtract.cpp b/src/algorithm/collectionExtract.cpp index 4cb5b6cf..f67addf7 100644 --- a/src/algorithm/collectionExtract.cpp +++ b/src/algorithm/collectionExtract.cpp @@ -12,8 +12,7 @@ #include -namespace SFCGAL { -namespace algorithm { +namespace SFCGAL::algorithm { // If nothing has to be built, g will be moved to the result without // copying and a new allocation. Otherwise, a new geometry is built and @@ -71,5 +70,4 @@ collectionExtractPolygons(std::unique_ptr g) return std::unique_ptr(ret_geo); } -} // namespace algorithm -} // namespace SFCGAL +} // namespace SFCGAL::algorithm diff --git a/src/algorithm/collectionHomogenize.cpp b/src/algorithm/collectionHomogenize.cpp index 5ba81d6e..ab60d7ca 100644 --- a/src/algorithm/collectionHomogenize.cpp +++ b/src/algorithm/collectionHomogenize.cpp @@ -10,8 +10,7 @@ #include #include -namespace SFCGAL { -namespace algorithm { +namespace SFCGAL::algorithm { // If nothing has to be built, g will be moved to the result without // copying and a new allocation. Otherwise, a new geometry is built and @@ -73,5 +72,4 @@ collectionHomogenize(std::unique_ptr g) -> std::unique_ptr return std::unique_ptr(ret_geo); } -} // namespace algorithm -} // namespace SFCGAL +} // namespace SFCGAL::algorithm diff --git a/src/algorithm/collectionToMulti.cpp b/src/algorithm/collectionToMulti.cpp index 390e6df1..ad3855b9 100644 --- a/src/algorithm/collectionToMulti.cpp +++ b/src/algorithm/collectionToMulti.cpp @@ -12,8 +12,7 @@ #include -namespace SFCGAL { -namespace algorithm { +namespace SFCGAL::algorithm { // If nothing has to be built, g will be moved to the result without // copying and a new allocation. Otherwise, a new geometry is built and @@ -56,7 +55,7 @@ collectionToMulti(std::unique_ptr g) -> std::unique_ptr } } - bool force3d = has2d && has3d; + bool const force3d = has2d && has3d; auto *ret_geo = new MultiPolygon; @@ -104,5 +103,4 @@ collectionToMulti(std::unique_ptr g) -> std::unique_ptr return std::unique_ptr(ret_geo); } -} // namespace algorithm -} // namespace SFCGAL +} // namespace SFCGAL::algorithm diff --git a/src/algorithm/connection.cpp b/src/algorithm/connection.cpp index 4cfe6bd0..ed5280e0 100644 --- a/src/algorithm/connection.cpp +++ b/src/algorithm/connection.cpp @@ -13,8 +13,7 @@ #include -namespace SFCGAL { -namespace algorithm { +namespace SFCGAL::algorithm { const size_t SurfaceGraph::INVALID_INDEX = std::numeric_limits::max(); @@ -31,10 +30,8 @@ SurfaceGraph::addRing(const LineString &ring, FaceIndex faceIndex) // the index of ring // start point instead // of finding it - const CoordinateMap::const_iterator startFound = - _coordinateMap.find(startCoord); - const CoordinateMap::const_iterator endFound = - _coordinateMap.find(endCoord); + const auto startFound = _coordinateMap.find(startCoord); + const auto endFound = _coordinateMap.find(endCoord); BOOST_ASSERT(s + 1 != numSegments || endFound != _coordinateMap.end()); // ring not closed @@ -44,8 +41,7 @@ SurfaceGraph::addRing(const LineString &ring, FaceIndex faceIndex) const VertexIndex startIndex = startFound->second; const VertexIndex endIndex = endFound->second; const std::pair edge(startIndex, endIndex); - const EdgeMap::const_iterator foundEdgeWithBadOrientation = - _edgeMap.find(edge); + const auto foundEdgeWithBadOrientation = _edgeMap.find(edge); if (foundEdgeWithBadOrientation != _edgeMap.end()) { _isValid = Validity::invalid( @@ -58,7 +54,7 @@ SurfaceGraph::addRing(const LineString &ring, FaceIndex faceIndex) const std::pair reversedEdge(endIndex, startIndex); - const EdgeMap::iterator foundEdge = _edgeMap.find(reversedEdge); + const auto foundEdge = _edgeMap.find(reversedEdge); if (foundEdge != _edgeMap.end()) { // edit edge @@ -146,14 +142,14 @@ isConnected(const SurfaceGraph &graph) -> bool std::vector component( boost::num_vertices(graph.faceGraph())); const size_t numComponents = - boost::connected_components(graph.faceGraph(), &component[0]); + boost::connected_components(graph.faceGraph(), component.data()); return 1 == numComponents; } auto isClosed(const SurfaceGraph &graph) -> bool { - const SurfaceGraph::EdgeMap::const_iterator end = graph.edgeMap().end(); + const auto end = graph.edgeMap().end(); for (auto e = graph.edgeMap().begin(); e != end; ++e) { if (e->second.second == SurfaceGraph::INVALID_INDEX) { @@ -164,5 +160,4 @@ isClosed(const SurfaceGraph &graph) -> bool return true; } -} // namespace algorithm -} // namespace SFCGAL +} // namespace SFCGAL::algorithm diff --git a/src/algorithm/convexHull.cpp b/src/algorithm/convexHull.cpp index 00778884..7a87b5ac 100644 --- a/src/algorithm/convexHull.cpp +++ b/src/algorithm/convexHull.cpp @@ -23,8 +23,7 @@ #include #include -namespace SFCGAL { -namespace algorithm { +namespace SFCGAL::algorithm { using Point_3 = CGAL::Point_3; using Segment_3 = CGAL::Segment_3; @@ -50,12 +49,13 @@ convexHull(const Geometry &g) -> std::unique_ptr // collect points - if (getPointVisitor.points.size() == 0) { + if (getPointVisitor.points.empty()) { return std::unique_ptr(new GeometryCollection()); } std::vector points; + points.reserve(getPointVisitor.points.size()); for (auto &point : getPointVisitor.points) { points.push_back(point->toPoint_2()); } @@ -67,33 +67,33 @@ convexHull(const Geometry &g) -> std::unique_ptr if (epoints.size() == 1) { return std::unique_ptr(new Point(*epoints.begin())); - } else if (epoints.size() == 2) { - std::list::const_iterator it = epoints.begin(); + } + if (epoints.size() == 2) { + auto it = epoints.begin(); return std::unique_ptr( new LineString(Point(*it++), Point(*it++))); } // GEOS does not seem to return triangles - else if (epoints.size() == 3) { - std::list::const_iterator it = epoints.begin(); - Point_2 p(*it++); - Point_2 q(*it++); - Point_2 r(*it++); + if (epoints.size() == 3) { + auto it = epoints.begin(); + Point_2 const p(*it++); + Point_2 const q(*it++); + Point_2 const r(*it++); return std::unique_ptr(new Triangle(p, q, r)); - } else if (epoints.size() > 3) { + } + if (epoints.size() > 3) { auto *poly = new Polygon; - for (std::list::const_iterator it = epoints.begin(); - it != epoints.end(); ++it) { - poly->exteriorRing().addPoint(*it); + for (auto &epoint : epoints) { + poly->exteriorRing().addPoint(epoint); } // add back the first point to close the ring poly->exteriorRing().addPoint(*epoints.begin()); return std::unique_ptr(poly); - } else { - BOOST_THROW_EXCEPTION( - Exception("unexpected CGAL output type in CGAL::convex_hull_2")); } + BOOST_THROW_EXCEPTION( + Exception("unexpected CGAL output type in CGAL::convex_hull_2")); } /// @@ -111,6 +111,7 @@ convexHull3D(const Geometry &g) -> std::unique_ptr std::vector points; + points.reserve(getPointVisitor.points.size()); for (auto &point : getPointVisitor.points) { points.push_back(point->toPoint_3()); } @@ -126,16 +127,20 @@ convexHull3D(const Geometry &g) -> std::unique_ptr if (hull.empty()) { return std::unique_ptr(new GeometryCollection()); - } else if (const auto *point = object_cast(&hull)) { + } + if (const auto *point = object_cast(&hull)) { return std::unique_ptr(new Point(*point)); - } else if (const auto *segment = object_cast(&hull)) { + } + if (const auto *segment = object_cast(&hull)) { return std::unique_ptr( new LineString(Point(segment->start()), Point(segment->end()))); - } else if (const auto *triangle = object_cast(&hull)) { + } + if (const auto *triangle = object_cast(&hull)) { return std::unique_ptr(new Triangle(Point(triangle->vertex(0)), Point(triangle->vertex(1)), Point(triangle->vertex(2)))); - } else if (const auto *polyhedron = object_cast(&hull)) { + } + if (const auto *polyhedron = object_cast(&hull)) { std::unique_ptr result(new PolyhedralSurface()); for (Polyhedron_3::Facet_const_iterator it_facet = @@ -156,11 +161,9 @@ convexHull3D(const Geometry &g) -> std::unique_ptr } return std::unique_ptr(result.release()); - } else { - BOOST_THROW_EXCEPTION( - Exception("unexpected CGAL output type in CGAL::convex_hull_3")); } + BOOST_THROW_EXCEPTION( + Exception("unexpected CGAL output type in CGAL::convex_hull_3")); } -} // namespace algorithm -} // namespace SFCGAL +} // namespace SFCGAL::algorithm diff --git a/src/algorithm/covers.cpp b/src/algorithm/covers.cpp index b23e5586..bbaa220a 100644 --- a/src/algorithm/covers.cpp +++ b/src/algorithm/covers.cpp @@ -14,11 +14,11 @@ using namespace SFCGAL::detail; -namespace SFCGAL { -namespace algorithm { +namespace SFCGAL::algorithm { auto -covers(const PrimitiveHandle<3> &, const PrimitiveHandle<3> &) -> bool +covers(const PrimitiveHandle<3> & /*unused*/, + const PrimitiveHandle<3> & /*unused*/) -> bool { return false; } @@ -55,7 +55,9 @@ solidsVolume(const GeometrySet<3> &gs, bool planarSurface = false) -> double BOOST_ASSERT(poly.is_pure_triangle()); - CGAL::Point_3 p1, p2, p3; + CGAL::Point_3 p1; + CGAL::Point_3 p2; + CGAL::Point_3 p3; for (MarkedPolyhedron::Facet_const_iterator fit = poly.facets_begin(); fit != poly.facets_end(); ++fit) { @@ -66,7 +68,7 @@ solidsVolume(const GeometrySet<3> &gs, bool planarSurface = false) -> double p2 = cit->vertex()->point(); cit++; p3 = cit->vertex()->point(); - CGAL::Triangle_3 tri(p1, p2, p3); + CGAL::Triangle_3 const tri(p1, p2, p3); result = result + sqrt(CGAL::to_double(tri.squared_area())); } } @@ -108,7 +110,7 @@ surfacesArea(const GeometrySet<3> &gs) -> double } auto -solidsVolume(const GeometrySet<2> &) -> double +solidsVolume(const GeometrySet<2> & /*unused*/) -> double { return 0.0; } @@ -125,7 +127,7 @@ equalLength(const GeometrySet &a, const GeometrySet &b, int dim) // - area for surfaces // - should be volume for volumes. We use area here - double tol = 1e-9; + double const tol = 1e-9; switch (dim) { case 0: { @@ -138,9 +140,9 @@ equalLength(const GeometrySet &a, const GeometrySet &b, int dim) // // Compare lengths - double lengthA = segmentsLength(a); - double lengthB = segmentsLength(b); - double cmp = (lengthA - lengthB) * (lengthA - lengthB); + double const lengthA = segmentsLength(a); + double const lengthB = segmentsLength(b); + double const cmp = (lengthA - lengthB) * (lengthA - lengthB); if (cmp > tol) { return false; @@ -150,9 +152,9 @@ equalLength(const GeometrySet &a, const GeometrySet &b, int dim) case 2: { // // Compare areas - double areaA = surfacesArea(a); - double areaB = surfacesArea(b); - double cmp = (areaA - areaB) * (areaA - areaB); + double const areaA = surfacesArea(a); + double const areaB = surfacesArea(b); + double const cmp = (areaA - areaB) * (areaA - areaB); if (cmp > tol) { return false; @@ -161,9 +163,9 @@ equalLength(const GeometrySet &a, const GeometrySet &b, int dim) case 3: { // Compare volumes - double volA = solidsVolume(a); - double volB = solidsVolume(b); - double cmp = (volA - volB) * (volA - volB); + double const volA = solidsVolume(a); + double const volB = solidsVolume(b); + double const cmp = (volA - volB) * (volA - volB); if (cmp > tol) { return false; @@ -178,8 +180,8 @@ template auto covers(const GeometrySet &a, const GeometrySet &b) -> bool { - int dimA = a.dimension(); - int dimB = b.dimension(); + int const dimA = a.dimension(); + int const dimB = b.dimension(); if (dimA == -1 || dimB == -1) { return false; @@ -229,8 +231,8 @@ covers(const Geometry &ga, const Geometry &gb) -> bool return false; } - GeometrySet<2> gsa(ga); - GeometrySet<2> gsb(gb); + GeometrySet<2> const gsa(ga); + GeometrySet<2> const gsb(gb); return covers(gsa, gsb); } @@ -242,10 +244,9 @@ covers3D(const Geometry &ga, const Geometry &gb) -> bool return false; } - GeometrySet<3> gsa(ga); - GeometrySet<3> gsb(gb); + GeometrySet<3> const gsa(ga); + GeometrySet<3> const gsb(gb); return covers(gsa, gsb); } -} // namespace algorithm -} // namespace SFCGAL +} // namespace SFCGAL::algorithm diff --git a/src/algorithm/difference.cpp b/src/algorithm/difference.cpp index da4df58c..4f83a47a 100644 --- a/src/algorithm/difference.cpp +++ b/src/algorithm/difference.cpp @@ -21,9 +21,7 @@ using namespace SFCGAL::detail; -namespace SFCGAL { - -namespace algorithm { +namespace SFCGAL::algorithm { template struct CollisionMapper { @@ -222,8 +220,7 @@ difference(const Primitive &primitive, PrimitiveHandleConstIterator begin, for (PrimitiveHandleConstIterator b = begin; b != end; ++b) { std::vector new_primitives; - for (typename std::vector::const_iterator a = primitives.begin(); - a != primitives.end(); ++a) { + for (auto a = primitives.begin(); a != primitives.end(); ++a) { difference(*a, *(*b), std::back_inserter(new_primitives)); } @@ -344,16 +341,19 @@ difference(const GeometrySet &a, const GeometrySet &b, GeometrySet &output) { using BoxCollection = typename SFCGAL::detail::BoxCollection::Type; - typename SFCGAL::detail::HandleCollection::Type ahandles, bhandles; - BoxCollection aboxes, bboxes; + typename SFCGAL::detail::HandleCollection::Type ahandles; + typename SFCGAL::detail::HandleCollection::Type bhandles; + BoxCollection aboxes; + BoxCollection bboxes; a.computeBoundingBoxes(ahandles, aboxes); b.computeBoundingBoxes(bhandles, bboxes); // here we use box_intersection_d to build the list of operations // that actually need to be performed - GeometrySet temp, temp2; + GeometrySet temp; + GeometrySet temp2; typename CollisionMapper::Map map; - CollisionMapper cb(map); + CollisionMapper const cb(map); CGAL::box_intersection_d(aboxes.begin(), aboxes.end(), bboxes.begin(), bboxes.end(), cb); @@ -361,8 +361,8 @@ difference(const GeometrySet &a, const GeometrySet &b, // we can put in the result right away all the primitives // that are not keys in this map { - typename BoxCollection::const_iterator ait = aboxes.begin(); - const typename BoxCollection::const_iterator end = aboxes.end(); + auto ait = aboxes.begin(); + const auto end = aboxes.end(); for (; ait != end; ++ait) { if (map.find(ait->handle()) == map.end()) { @@ -373,8 +373,8 @@ difference(const GeometrySet &a, const GeometrySet &b, // then we delegate the operations according to type { - typename CollisionMapper::Map::const_iterator cbit = map.begin(); - const typename CollisionMapper::Map::const_iterator end = map.end(); + auto cbit = map.begin(); + const auto end = map.end(); for (; cbit != end; ++cbit) { appendDifference(*cbit->first, cbit->second.begin(), cbit->second.end(), @@ -394,10 +394,12 @@ difference<3>(const GeometrySet<3> &a, const GeometrySet<3> &b, GeometrySet<3> &); auto -difference(const Geometry &ga, const Geometry &gb, NoValidityCheck) +difference(const Geometry &ga, const Geometry &gb, NoValidityCheck /*unused*/) -> std::unique_ptr { - GeometrySet<2> gsa(ga), gsb(gb), output; + GeometrySet<2> const gsa(ga); + GeometrySet<2> const gsb(gb); + GeometrySet<2> output; algorithm::difference(gsa, gsb, output); GeometrySet<2> filtered; @@ -415,10 +417,12 @@ difference(const Geometry &ga, const Geometry &gb) -> std::unique_ptr } auto -difference3D(const Geometry &ga, const Geometry &gb, NoValidityCheck) +difference3D(const Geometry &ga, const Geometry &gb, NoValidityCheck /*unused*/) -> std::unique_ptr { - GeometrySet<3> gsa(ga), gsb(gb), output; + GeometrySet<3> const gsa(ga); + GeometrySet<3> const gsb(gb); + GeometrySet<3> output; algorithm::difference(gsa, gsb, output); GeometrySet<3> filtered; @@ -436,5 +440,4 @@ difference3D(const Geometry &ga, const Geometry &gb) return difference3D(ga, gb, NoValidityCheck()); } -} // namespace algorithm -} // namespace SFCGAL +} // namespace SFCGAL::algorithm diff --git a/src/algorithm/differencePrimitives.cpp b/src/algorithm/differencePrimitives.cpp index e0f41970..2f487523 100644 --- a/src/algorithm/differencePrimitives.cpp +++ b/src/algorithm/differencePrimitives.cpp @@ -6,13 +6,11 @@ // GOTCHA do not include the header, this is a trick to avoid ambiguous def in // CGAL -namespace SFCGAL { -namespace algorithm { +namespace SFCGAL::algorithm { auto intersection(const CGAL::Triangle_3 &a, const CGAL::Triangle_3 &b) -> CGAL::Object { return CGAL::intersection(a, b); } -} // namespace algorithm -} // namespace SFCGAL +} // namespace SFCGAL::algorithm diff --git a/src/algorithm/distance.cpp b/src/algorithm/distance.cpp index 001b8cbe..20df4404 100644 --- a/src/algorithm/distance.cpp +++ b/src/algorithm/distance.cpp @@ -31,14 +31,14 @@ using Segment_2 = SFCGAL::Kernel::Segment_2; using Polygon_2 = CGAL::Polygon_2; using Polygon_with_holes_2 = CGAL::Polygon_with_holes_2; -namespace SFCGAL { -namespace algorithm { +namespace SFCGAL::algorithm { /// /// /// auto -distance(const Geometry &gA, const Geometry &gB, NoValidityCheck) -> double +distance(const Geometry &gA, const Geometry &gB, NoValidityCheck /*unused*/) + -> double { switch (gA.geometryTypeId()) { case TYPE_POINT: @@ -145,12 +145,12 @@ distancePointLineString(const Point &gA, const LineString &gB) -> double return std::numeric_limits::infinity(); } - size_t numSegments = gB.numSegments(); + size_t const numSegments = gB.numSegments(); double dMin = std::numeric_limits::infinity(); for (size_t i = 0; i < numSegments; i++) { - double d = distancePointSegment(gA, gB.pointN(i), gB.pointN(i + 1)); + double const d = distancePointSegment(gA, gB.pointN(i), gB.pointN(i + 1)); if (i == 0 || d < dMin) { dMin = d; @@ -178,7 +178,7 @@ distancePointPolygon(const Point &gA, const Polygon &gB) -> double // check if the point is in the polygon for (size_t i = 0; i < gB.numRings(); i++) { - double d = distancePointLineString(gA, gB.ringN(i)); + double const d = distancePointLineString(gA, gB.ringN(i)); if (i == 0 || d < dMin) { dMin = d; @@ -252,8 +252,8 @@ distanceLineStringLineString(const LineString &gA, const LineString &gB) return std::numeric_limits::infinity(); } - size_t nsA = gA.numSegments(); - size_t nsB = gB.numSegments(); + size_t const nsA = gA.numSegments(); + size_t const nsB = gB.numSegments(); double dMin = std::numeric_limits::infinity(); @@ -285,7 +285,7 @@ distanceLineStringPolygon(const LineString &gA, const Polygon &gB) -> double double dMin = std::numeric_limits::infinity(); for (size_t i = 0; i < gB.numRings(); i++) { - double d = distanceLineStringLineString(gA, gB.ringN(i)); + double const d = distanceLineStringLineString(gA, gB.ringN(i)); if (d < dMin) { dMin = d; @@ -366,7 +366,7 @@ distancePolygonPolygon(const Polygon &gA, const Polygon &gB) -> double for (size_t i = 0; i < gA.numRings(); i++) { for (size_t j = 0; j < gB.numRings(); j++) { - double d = distanceLineStringLineString(gA.ringN(i), gB.ringN(j)); + double const d = distanceLineStringLineString(gA.ringN(i), gB.ringN(j)); if (d < dMin) { dMin = d; @@ -401,18 +401,18 @@ struct Circle { { } Circle() = default; - auto + [[nodiscard]] auto isEmpty() const -> bool { return _empty; } - auto + [[nodiscard]] auto radius() const -> double { BOOST_ASSERT(!_empty); return _radius; } - auto + [[nodiscard]] auto center() const -> const CGAL::Vector_2 & { BOOST_ASSERT(!_empty); @@ -436,19 +436,19 @@ boundingCircle(const Geometry &geom) -> const Circle GetPointsVisitor v; const_cast(geom).accept(v); - if (!v.points.size()) { + if (v.points.empty()) { return Circle(); } using Vector_2 = CGAL::Vector_2; - const GetPointsVisitor::const_iterator end = v.points.end(); + const auto end = v.points.end(); // centroid Vector_2 c(0, 0); int numPoint = 0; - for (GetPointsVisitor::const_iterator x = v.points.begin(); x != end; ++x) { + for (auto x = v.points.begin(); x != end; ++x) { c = c + (*x)->toVector_2(); ++numPoint; } @@ -460,7 +460,7 @@ boundingCircle(const Geometry &geom) -> const Circle Vector_2 f = c; Kernel::FT maxDistanceSq = 0; - for (GetPointsVisitor::const_iterator x = v.points.begin(); x != end; ++x) { + for (auto x = v.points.begin(); x != end; ++x) { const Vector_2 cx = (*x)->toVector_2() - c; const Kernel::FT dSq = cx * cx; @@ -500,7 +500,7 @@ distanceGeometryCollectionToGeometry(const Geometry &gA, const Geometry &gB) bcA.push_back(boundingCircle(gA.geometryN(i))); } - Circle bcB(boundingCircle(gB)); + Circle const bcB(boundingCircle(gB)); if (bcB.isEmpty()) { return std::numeric_limits::infinity(); @@ -591,5 +591,4 @@ distanceSegmentSegment(const Point &a, const Point &b, const Point &c, CGAL::Segment_2(c.toPoint_2(), d.toPoint_2())))); } -} // namespace algorithm -} // namespace SFCGAL +} // namespace SFCGAL::algorithm diff --git a/src/algorithm/distance3d.cpp b/src/algorithm/distance3d.cpp index 29db1971..bda181fd 100644 --- a/src/algorithm/distance3d.cpp +++ b/src/algorithm/distance3d.cpp @@ -33,14 +33,14 @@ using Segment_3 = Kernel::Segment_3; using Triangle_3 = Kernel::Triangle_3; using Plane_3 = Kernel::Plane_3; -namespace SFCGAL { -namespace algorithm { +namespace SFCGAL::algorithm { /// /// /// auto -distance3D(const Geometry &gA, const Geometry &gB, NoValidityCheck) -> double +distance3D(const Geometry &gA, const Geometry &gB, NoValidityCheck /*unused*/) + -> double { // SFCGAL_DEBUG( boost::format("dispatch distance3D(%s,%s)") % gA.asText() % // gB.asText() ); @@ -269,8 +269,8 @@ distanceLineStringLineString3D(const LineString &gA, const LineString &gB) return std::numeric_limits::infinity(); } - size_t nsA = gA.numSegments(); - size_t nsB = gB.numSegments(); + size_t const nsA = gA.numSegments(); + size_t const nsB = gB.numSegments(); double dMin = std::numeric_limits::infinity(); @@ -504,18 +504,18 @@ struct Sphere { { } Sphere() = default; - auto + [[nodiscard]] auto isEmpty() const -> bool { return _empty; } - auto + [[nodiscard]] auto radius() const -> double { BOOST_ASSERT(!_empty); return _radius; } - auto + [[nodiscard]] auto center() const -> const CGAL::Vector_3 & { BOOST_ASSERT(!_empty); @@ -539,19 +539,19 @@ boundingSphere(const Geometry &geom) -> const Sphere GetPointsVisitor v; const_cast(geom).accept(v); - if (!v.points.size()) { + if (v.points.empty()) { return Sphere(); } using Vector_3 = CGAL::Vector_3; - const GetPointsVisitor::const_iterator end = v.points.end(); + const auto end = v.points.end(); // centroid Vector_3 c(0, 0, 0); int numPoint = 0; - for (GetPointsVisitor::const_iterator x = v.points.begin(); x != end; ++x) { + for (auto x = v.points.begin(); x != end; ++x) { c = c + (*x)->toVector_3(); ++numPoint; } @@ -563,7 +563,7 @@ boundingSphere(const Geometry &geom) -> const Sphere Vector_3 f = c; Kernel::FT maxDistanceSq = 0; - for (GetPointsVisitor::const_iterator x = v.points.begin(); x != end; ++x) { + for (auto x = v.points.begin(); x != end; ++x) { const Vector_3 cx = (*x)->toVector_3() - c; const Kernel::FT dSq = cx * cx; @@ -607,7 +607,7 @@ distanceGeometryCollectionToGeometry3D(const Geometry &gA, const Geometry &gB) bsA.push_back(boundingSphere(gA.geometryN(i))); } - Sphere bsB(boundingSphere(gB)); + Sphere const bsB(boundingSphere(gB)); if (bsB.isEmpty()) { return std::numeric_limits::infinity(); @@ -727,10 +727,10 @@ distancePointTriangle3D(const Point &p_, const Point &a_, const Point &b_, BOOST_ASSERT(!b_.isEmpty()); BOOST_ASSERT(!c_.isEmpty()); - Point_3 p = p_.toPoint_3(); - Triangle_3 abc(a_.toPoint_3(), b_.toPoint_3(), c_.toPoint_3()); + Point_3 const p = p_.toPoint_3(); + Triangle_3 const abc(a_.toPoint_3(), b_.toPoint_3(), c_.toPoint_3()); - squared_distance_t dMin = squaredDistancePointTriangle3D(p, abc); + squared_distance_t const dMin = squaredDistancePointTriangle3D(p, abc); return CGAL::sqrt(CGAL::to_double(dMin)); } @@ -761,8 +761,9 @@ squaredDistanceSegmentTriangle3D(const Segment_3 &sAB, const Triangle_3 &tABC) /* * If [sAsB] intersects the triangle (tA,tB,tC), distance is 0.0 */ - if (CGAL::do_intersect(sAB, tABC)) + if (CGAL::do_intersect(sAB, tABC)) { return 0.0; + } /* * else, distance is the min of the following values : @@ -796,16 +797,16 @@ distanceSegmentTriangle3D(const Point &sA_, const Point &sB_, const Point &tA_, BOOST_ASSERT(!tB_.isEmpty()); BOOST_ASSERT(!tC_.isEmpty()); - Point_3 sA = sA_.toPoint_3(); - Point_3 sB = sB_.toPoint_3(); - Segment_3 sAB(sA, sB); + Point_3 const sA = sA_.toPoint_3(); + Point_3 const sB = sB_.toPoint_3(); + Segment_3 const sAB(sA, sB); - Point_3 tA = tA_.toPoint_3(); - Point_3 tB = tB_.toPoint_3(); - Point_3 tC = tC_.toPoint_3(); - Triangle_3 tABC(tA, tB, tC); + Point_3 const tA = tA_.toPoint_3(); + Point_3 const tB = tB_.toPoint_3(); + Point_3 const tC = tC_.toPoint_3(); + Triangle_3 const tABC(tA, tB, tC); - squared_distance_t dMin = squaredDistanceSegmentTriangle3D(sAB, tABC); + squared_distance_t const dMin = squaredDistanceSegmentTriangle3D(sAB, tABC); return CGAL::sqrt(CGAL::to_double(dMin)); } @@ -817,8 +818,9 @@ squaredDistanceTriangleTriangle3D(const Triangle_3 &triangleA, const Triangle_3 &triangleB) -> squared_distance_t { - if (CGAL::do_intersect(triangleA, triangleB)) + if (CGAL::do_intersect(triangleA, triangleB)) { return {0}; + } /* * min of distance from A segments to B triangle and B segments to A triangle @@ -856,13 +858,12 @@ distanceTriangleTriangle3D(const Triangle &gA, const Triangle &gB) -> double return std::numeric_limits::infinity(); } - Triangle_3 triangleA = gA.toTriangle_3(); - Triangle_3 triangleB = gB.toTriangle_3(); + Triangle_3 const triangleA = gA.toTriangle_3(); + Triangle_3 const triangleB = gB.toTriangle_3(); - squared_distance_t dMin = + squared_distance_t const dMin = squaredDistanceTriangleTriangle3D(triangleA, triangleB); return CGAL::sqrt(CGAL::to_double(dMin)); } -} // namespace algorithm -} // namespace SFCGAL +} // namespace SFCGAL::algorithm diff --git a/src/algorithm/extrude.cpp b/src/algorithm/extrude.cpp index 6a305f4a..df6688a9 100644 --- a/src/algorithm/extrude.cpp +++ b/src/algorithm/extrude.cpp @@ -28,8 +28,7 @@ #include -namespace SFCGAL { -namespace algorithm { +namespace SFCGAL::algorithm { //-- private interface @@ -81,8 +80,8 @@ extrude(const Point &g, const Kernel::Vector_3 &v) -> LineString * return new LineString(); } - Kernel::Point_3 a = g.toPoint_3(); - Kernel::Point_3 b = a + v; + Kernel::Point_3 const a = g.toPoint_3(); + Kernel::Point_3 const b = a + v; return new LineString(Point(a), Point(b)); } @@ -103,8 +102,8 @@ extrude(const LineString &g, const Kernel::Vector_3 &v) -> PolyhedralSurface * for (size_t i = 0; i < g.numPoints() - 1; i++) { std::unique_ptr ring(new LineString); - Kernel::Point_3 a = g.pointN(i).toPoint_3(); - Kernel::Point_3 b = g.pointN(i + 1).toPoint_3(); + Kernel::Point_3 const a = g.pointN(i).toPoint_3(); + Kernel::Point_3 const b = g.pointN(i + 1).toPoint_3(); ring->addPoint(new Point(a)); ring->addPoint(new Point(b)); ring->addPoint(new Point(b + v)); @@ -127,7 +126,7 @@ extrude(const Polygon &g, const Kernel::Vector_3 &v, bool addTop) -> Solid * return new Solid(); } - bool reverseOrientation = (v * normal3D(g)) > 0; + bool const reverseOrientation = (v * normal3D(g)) > 0; // resulting shell PolyhedralSurface polyhedralSurface; @@ -365,18 +364,18 @@ extrude(const Geometry &g, const Kernel::Vector_3 &v) /// auto extrude(const Geometry &g, const Kernel::FT &dx, const Kernel::FT &dy, - const Kernel::FT &dz, NoValidityCheck) -> std::unique_ptr + const Kernel::FT &dz, NoValidityCheck /*unused*/) + -> std::unique_ptr { return extrude(g, Kernel::Vector_3(dx, dy, dz)); } auto -extrude(const Geometry &g, Kernel::FT dx, Kernel::FT dy, Kernel::FT dz) - -> std::unique_ptr +extrude(const Geometry &g, const Kernel::FT &dx, const Kernel::FT &dy, + const Kernel::FT &dz) -> std::unique_ptr { SFCGAL_ASSERT_GEOMETRY_VALIDITY(g); - std::unique_ptr result(extrude(g, std::move(dx), std::move(dy), - std::move(dz), NoValidityCheck())); + std::unique_ptr result(extrude(g, dx, dy, dz, NoValidityCheck())); propagateValidityFlag(*result, true); return result; } @@ -405,5 +404,4 @@ extrude(const Polygon &g, const double &height) -> std::unique_ptr return std::unique_ptr( extrude(g, Kernel::Vector_3(0.0, 0.0, height), false)); } -} // namespace algorithm -} // namespace SFCGAL +} // namespace SFCGAL::algorithm diff --git a/src/algorithm/extrude.h b/src/algorithm/extrude.h index e426e47b..626cd5ae 100644 --- a/src/algorithm/extrude.h +++ b/src/algorithm/extrude.h @@ -37,7 +37,8 @@ struct NoValidityCheck; * @ingroup public_api */ SFCGAL_API std::unique_ptr -extrude(const Geometry &g, Kernel::FT dx, Kernel::FT dy, Kernel::FT dz); +extrude(const Geometry &g, const Kernel::FT &dx, const Kernel::FT &dy, + const Kernel::FT &dz); /** * @brief Returns a Geometry equal to the specified Geometry, @@ -62,8 +63,8 @@ extrude(const Geometry &g, Kernel::FT dx, Kernel::FT dy, Kernel::FT dz); * @warning No actual validity check is conducted. */ SFCGAL_API std::unique_ptr -extrude(const Geometry &g, Kernel::FT &dx, Kernel::FT &dy, Kernel::FT &dz, - NoValidityCheck &nvc); +extrude(const Geometry &g, const Kernel::FT &dx, const Kernel::FT &dy, + const Kernel::FT &dz, NoValidityCheck &nvc); /** * @brief Returns a Geometry equal to the specified Geometry, diff --git a/src/algorithm/force2D.cpp b/src/algorithm/force2D.cpp index a0353903..abdafbd1 100644 --- a/src/algorithm/force2D.cpp +++ b/src/algorithm/force2D.cpp @@ -5,8 +5,7 @@ #include #include -namespace SFCGAL { -namespace algorithm { +namespace SFCGAL::algorithm { /// /// @@ -18,5 +17,4 @@ force2D(Geometry &g) g.accept(t); } -} // namespace algorithm -} // namespace SFCGAL +} // namespace SFCGAL::algorithm diff --git a/src/algorithm/force3D.cpp b/src/algorithm/force3D.cpp index e4be8b4d..a9c90946 100644 --- a/src/algorithm/force3D.cpp +++ b/src/algorithm/force3D.cpp @@ -5,8 +5,7 @@ #include #include -namespace SFCGAL { -namespace algorithm { +namespace SFCGAL::algorithm { /// /// @@ -18,5 +17,4 @@ force3D(Geometry &g, const Kernel::FT &defaultZ) g.accept(t); } -} // namespace algorithm -} // namespace SFCGAL +} // namespace SFCGAL::algorithm diff --git a/src/algorithm/intersection.cpp b/src/algorithm/intersection.cpp index 20dafc38..df901bb6 100644 --- a/src/algorithm/intersection.cpp +++ b/src/algorithm/intersection.cpp @@ -128,13 +128,16 @@ void intersection(const GeometrySet &a, const GeometrySet &b, GeometrySet &output) { - typename SFCGAL::detail::HandleCollection::Type ahandles, bhandles; - typename SFCGAL::detail::BoxCollection::Type aboxes, bboxes; + typename SFCGAL::detail::HandleCollection::Type ahandles; + typename SFCGAL::detail::HandleCollection::Type bhandles; + typename SFCGAL::detail::BoxCollection::Type aboxes; + typename SFCGAL::detail::BoxCollection::Type bboxes; a.computeBoundingBoxes(ahandles, aboxes); b.computeBoundingBoxes(bhandles, bboxes); - GeometrySet temp, temp2; - intersection_cb cb(temp); + GeometrySet temp; + GeometrySet temp2; + intersection_cb const cb(temp); CGAL::box_intersection_d(aboxes.begin(), aboxes.end(), bboxes.begin(), bboxes.end(), cb); @@ -150,10 +153,12 @@ intersection<3>(const GeometrySet<3> &a, const GeometrySet<3> &b, GeometrySet<3> &); auto -intersection(const Geometry &ga, const Geometry &gb, NoValidityCheck) +intersection(const Geometry &ga, const Geometry &gb, NoValidityCheck /*unused*/) -> std::unique_ptr { - GeometrySet<2> gsa(ga), gsb(gb), output; + GeometrySet<2> const gsa(ga); + GeometrySet<2> const gsb(gb); + GeometrySet<2> output; algorithm::intersection(gsa, gsb, output); GeometrySet<2> filtered; @@ -172,10 +177,12 @@ intersection(const Geometry &ga, const Geometry &gb) } auto -intersection3D(const Geometry &ga, const Geometry &gb, NoValidityCheck) - -> std::unique_ptr +intersection3D(const Geometry &ga, const Geometry &gb, + NoValidityCheck /*unused*/) -> std::unique_ptr { - GeometrySet<3> gsa(ga), gsb(gb), output; + GeometrySet<3> const gsa(ga); + GeometrySet<3> const gsb(gb); + GeometrySet<3> output; algorithm::intersection(gsa, gsb, output); GeometrySet<3> filtered; diff --git a/src/algorithm/intersects.cpp b/src/algorithm/intersects.cpp index 161edea9..caa408aa 100644 --- a/src/algorithm/intersects.cpp +++ b/src/algorithm/intersects.cpp @@ -26,8 +26,7 @@ using namespace SFCGAL::detail; -namespace SFCGAL { -namespace algorithm { +namespace SFCGAL::algorithm { // // Type of pa must be of larger dimension than type of pb auto @@ -47,8 +46,8 @@ _intersects(const PrimitiveHandle<2> &pa, const PrimitiveHandle<2> &pb) -> bool // Segment vs. Point // - else if (pa.handle.which() == PrimitiveSegment && - pb.handle.which() == PrimitivePoint) { + if (pa.handle.which() == PrimitiveSegment && + pb.handle.which() == PrimitivePoint) { const auto *seg = pa.as>(); const auto *pt = pb.as>(); return seg->has_on(*pt); @@ -58,8 +57,8 @@ _intersects(const PrimitiveHandle<2> &pa, const PrimitiveHandle<2> &pb) -> bool // Segment vs. Segment // - else if (pa.handle.which() == PrimitiveSegment && - pb.handle.which() == PrimitiveSegment) { + if (pa.handle.which() == PrimitiveSegment && + pb.handle.which() == PrimitiveSegment) { const auto *seg1 = pa.as>(); const auto *seg2 = pb.as>(); return CGAL::do_intersect(*seg1, *seg2); @@ -69,13 +68,13 @@ _intersects(const PrimitiveHandle<2> &pa, const PrimitiveHandle<2> &pb) -> bool // Polygon vs. Point // - else if (pa.handle.which() == PrimitiveSurface && - pb.handle.which() == PrimitivePoint) { + if (pa.handle.which() == PrimitiveSurface && + pb.handle.which() == PrimitivePoint) { // Polygon versus Point const auto *poly = pa.as>(); const auto *pt = pb.as>(); - int b1 = poly->outer_boundary().bounded_side(*pt); + int const b1 = poly->outer_boundary().bounded_side(*pt); if (b1 == CGAL::ON_BOUNDARY) { return true; @@ -85,7 +84,7 @@ _intersects(const PrimitiveHandle<2> &pa, const PrimitiveHandle<2> &pb) -> bool CGAL::Polygon_with_holes_2::Hole_const_iterator it; for (it = poly->holes_begin(); it != poly->holes_end(); ++it) { - int b = it->bounded_side(*pt); + int const b = it->bounded_side(*pt); if (b == CGAL::ON_BOUNDED_SIDE) { return false; @@ -102,8 +101,8 @@ _intersects(const PrimitiveHandle<2> &pa, const PrimitiveHandle<2> &pb) -> bool // Polygon vs. Segment // - else if (pa.handle.which() == PrimitiveSurface && - pb.handle.which() == PrimitiveSegment) { + if (pa.handle.which() == PrimitiveSurface && + pb.handle.which() == PrimitiveSegment) { const auto *poly = pa.as>(); const auto *seg = pb.as>(); @@ -135,9 +134,9 @@ _intersects(const PrimitiveHandle<2> &pa, const PrimitiveHandle<2> &pb) -> bool } // 2. call the polygon, point version - CGAL::Point_2 pt = seg->source(); - PrimitiveHandle<2> ppoly(poly); - PrimitiveHandle<2> ppt(&pt); + CGAL::Point_2 const pt = seg->source(); + PrimitiveHandle<2> const ppoly(poly); + PrimitiveHandle<2> const ppt(&pt); return intersects(ppoly, ppt); } @@ -145,8 +144,8 @@ _intersects(const PrimitiveHandle<2> &pa, const PrimitiveHandle<2> &pb) -> bool // Polygon vs. Polygon // - else if (pa.handle.which() == PrimitiveSurface && - pb.handle.which() == PrimitiveSurface) { + if (pa.handle.which() == PrimitiveSurface && + pb.handle.which() == PrimitiveSurface) { const auto *poly1 = pa.as>(); const auto *poly2 = pb.as>(); @@ -154,7 +153,8 @@ _intersects(const PrimitiveHandle<2> &pa, const PrimitiveHandle<2> &pb) -> bool // 2. else, if poly1 is inside poly2 or poly1 inside poly2 (but not in // holes), returns true - GeometrySet<2> rings1, rings2; + GeometrySet<2> rings1; + GeometrySet<2> rings2; rings1.addSegments(poly1->outer_boundary().edges_begin(), poly1->outer_boundary().edges_end()); @@ -175,19 +175,21 @@ _intersects(const PrimitiveHandle<2> &pa, const PrimitiveHandle<2> &pb) -> bool } // 2. - CGAL::Bbox_2 box1, box2; + CGAL::Bbox_2 box1; + CGAL::Bbox_2 box2; box1 = poly1->bbox(); box2 = poly2->bbox(); - Envelope e1(box1.xmin(), box1.xmax(), box1.ymin(), box1.ymax()); - Envelope e2(box2.xmin(), box2.xmax(), box2.ymin(), box2.ymax()); + Envelope const e1(box1.xmin(), box1.xmax(), box1.ymin(), box1.ymax()); + Envelope const e2(box2.xmin(), box2.xmax(), box2.ymin(), box2.ymax()); // if pa is inside pb if (Envelope::contains(e2, e1)) { // is pa inside one of pb's holes ? - CGAL::Point_2 pt = *poly1->outer_boundary().vertices_begin(); + CGAL::Point_2 const pt = + *poly1->outer_boundary().vertices_begin(); for (auto it = poly2->holes_begin(); it != poly2->holes_end(); ++it) { - CGAL::Bounded_side b2 = it->bounded_side(pt); + CGAL::Bounded_side const b2 = it->bounded_side(pt); if (b2 == CGAL::ON_BOUNDED_SIDE) { return false; @@ -200,10 +202,11 @@ _intersects(const PrimitiveHandle<2> &pa, const PrimitiveHandle<2> &pb) -> bool // if pb is inside pa if (Envelope::contains(e1, e2)) { // is pa inside one of pb's holes ? - CGAL::Point_2 pt = *poly2->outer_boundary().vertices_begin(); + CGAL::Point_2 const pt = + *poly2->outer_boundary().vertices_begin(); for (auto it = poly1->holes_begin(); it != poly1->holes_end(); ++it) { - CGAL::Bounded_side b2 = it->bounded_side(pt); + CGAL::Bounded_side const b2 = it->bounded_side(pt); if (b2 == CGAL::ON_BOUNDED_SIDE) { return false; @@ -240,7 +243,7 @@ struct intersects_volume_x : public boost::static_visitor { // this test is needed only if its a volume // if the polyhedron is not closed, this is not a volume, actually - CGAL::Side_of_triangle_mesh is_in_poly( + CGAL::Side_of_triangle_mesh const is_in_poly( *polyhedron); GeometrySet<3> points; @@ -275,13 +278,15 @@ _intersects(const PrimitiveHandle<3> &pa, const PrimitiveHandle<3> &pb) -> bool pb.handle.which() == PrimitivePoint) { return *boost::get *>(pa.handle) == *boost::get *>(pb.handle); - } else if (pa.handle.which() == PrimitiveSegment && - pb.handle.which() == PrimitivePoint) { + } + if (pa.handle.which() == PrimitiveSegment && + pb.handle.which() == PrimitivePoint) { const auto *seg = pa.as>(); const auto *pt = pb.as>(); return seg->has_on(*pt); - } else if (pa.handle.which() == PrimitiveSegment && - pb.handle.which() == PrimitiveSegment) { + } + if (pa.handle.which() == PrimitiveSegment && + pb.handle.which() == PrimitiveSegment) { const auto *sega = pa.as>(); const auto *segb = pb.as>(); return CGAL::do_intersect(*sega, *segb); @@ -326,9 +331,8 @@ dispatch_intersects_sym(const PrimitiveHandle &pa, // assume types are ordered by dimension within the boost::variant if (pa.handle.which() >= pb.handle.which()) { return _intersects(pa, pb); - } else { - return _intersects(pb, pa); } + return _intersects(pb, pa); } template @@ -357,13 +361,15 @@ template auto intersects(const GeometrySet &a, const GeometrySet &b) -> bool { - typename SFCGAL::detail::HandleCollection::Type ahandles, bhandles; - typename SFCGAL::detail::BoxCollection::Type aboxes, bboxes; + typename SFCGAL::detail::HandleCollection::Type ahandles; + typename SFCGAL::detail::HandleCollection::Type bhandles; + typename SFCGAL::detail::BoxCollection::Type aboxes; + typename SFCGAL::detail::BoxCollection::Type bboxes; a.computeBoundingBoxes(ahandles, aboxes); b.computeBoundingBoxes(bhandles, bboxes); try { - intersects_cb cb; + intersects_cb const cb; CGAL::box_intersection_d(aboxes.begin(), aboxes.end(), bboxes.begin(), bboxes.end(), cb); } catch (found_an_intersection &e) { @@ -389,8 +395,8 @@ intersects(const Geometry &ga, const Geometry &gb) -> bool SFCGAL_ASSERT_GEOMETRY_VALIDITY_2D(ga); SFCGAL_ASSERT_GEOMETRY_VALIDITY_2D(gb); - GeometrySet<2> gsa(ga); - GeometrySet<2> gsb(gb); + GeometrySet<2> const gsa(ga); + GeometrySet<2> const gsb(gb); return intersects(gsa, gsb); } @@ -401,26 +407,28 @@ intersects3D(const Geometry &ga, const Geometry &gb) -> bool SFCGAL_ASSERT_GEOMETRY_VALIDITY_3D(ga); SFCGAL_ASSERT_GEOMETRY_VALIDITY_3D(gb); - GeometrySet<3> gsa(ga); - GeometrySet<3> gsb(gb); + GeometrySet<3> const gsa(ga); + GeometrySet<3> const gsb(gb); return intersects(gsa, gsb); } auto -intersects(const Geometry &ga, const Geometry &gb, NoValidityCheck) -> bool +intersects(const Geometry &ga, const Geometry &gb, NoValidityCheck /*unused*/) + -> bool { - GeometrySet<2> gsa(ga); - GeometrySet<2> gsb(gb); + GeometrySet<2> const gsa(ga); + GeometrySet<2> const gsb(gb); return intersects(gsa, gsb); } auto -intersects3D(const Geometry &ga, const Geometry &gb, NoValidityCheck) -> bool +intersects3D(const Geometry &ga, const Geometry &gb, NoValidityCheck /*unused*/) + -> bool { - GeometrySet<3> gsa(ga); - GeometrySet<3> gsb(gb); + GeometrySet<3> const gsa(ga); + GeometrySet<3> const gsb(gb); return intersects(gsa, gsb); } @@ -491,12 +499,12 @@ selfIntersectsImpl(const LineString &line) -> bool if (inter.get() && inter->is()) { return true; // segments overlap - } else if (inter.get() && inter->is() && - !(i + 1 == - j) // one contact point between consecutive segments is ok - && !((i == 0) && (j + 1 == numSegments) && - inter->as() == l.startPoint() && - inter->as() == l.endPoint())) { + } + if (inter.get() && inter->is() && + !(i + 1 == j) // one contact point between consecutive segments is ok + && !((i == 0) && (j + 1 == numSegments) && + inter->as() == l.startPoint() && + inter->as() == l.endPoint())) { return true; // contact point that is not a contact between startPoint // and endPoint } @@ -522,7 +530,7 @@ auto selfIntersectsImpl(const PolyhedralSurface &s, const SurfaceGraph &graph) -> bool { - size_t numPolygons = s.numPolygons(); + size_t const numPolygons = s.numPolygons(); for (size_t pi = 0; pi != numPolygons; ++pi) { for (size_t pj = pi + 1; pj < numPolygons; ++pj) { @@ -535,7 +543,7 @@ selfIntersectsImpl(const PolyhedralSurface &s, const SurfaceGraph &graph) // - neighbors can have a line as intersection // - non neighbors can only have a point or a set of points using Iterator = SurfaceGraph::FaceGraph::adjacency_iterator; - std::pair neighbors = + std::pair const neighbors = boost::adjacent_vertices(pi, graph.faceGraph()); if (neighbors.second != @@ -576,7 +584,7 @@ auto selfIntersectsImpl(const TriangulatedSurface &tin, const SurfaceGraph &graph) -> bool { - size_t numTriangles = tin.numTriangles(); + size_t const numTriangles = tin.numTriangles(); for (size_t ti = 0; ti != numTriangles; ++ti) { for (size_t tj = ti + 1; tj < numTriangles; ++tj) { @@ -589,7 +597,7 @@ selfIntersectsImpl(const TriangulatedSurface &tin, const SurfaceGraph &graph) // - neighbors can have a line as intersection // - non neighbors can only have a point or a set of points using Iterator = SurfaceGraph::FaceGraph::adjacency_iterator; - std::pair neighbors = + std::pair const neighbors = boost::adjacent_vertices(ti, graph.faceGraph()); if (neighbors.second != @@ -625,5 +633,4 @@ selfIntersects3D(const TriangulatedSurface &tin, const SurfaceGraph &g) -> bool return selfIntersectsImpl<3>(tin, g); } -} // namespace algorithm -} // namespace SFCGAL +} // namespace SFCGAL::algorithm diff --git a/src/algorithm/isValid.cpp b/src/algorithm/isValid.cpp index ddd3a368..cd75a7f2 100644 --- a/src/algorithm/isValid.cpp +++ b/src/algorithm/isValid.cpp @@ -109,7 +109,7 @@ struct LoopDetector : public boost::dfs_visitor<> { template void - back_edge(Edge, const Graph &) + back_edge(Edge /*unused*/, const Graph & /*unused*/) { _hasLoop = true; } @@ -206,8 +206,9 @@ isValid(const Polygon &p, const double &toleranceAbs) -> const Validity const LineString &ring = p.ringN(r); const Point &start = ring.startPoint(); size_t i = 0; - for (; i < ring.numPoints() && start == ring.pointN(i); i++) + for (; i < ring.numPoints() && start == ring.pointN(i); i++) { ; // noop + } if (i == ring.numPoints()) { return Validity::invalid( (boost::format("ring %d degenerated to a point") % r).str()); @@ -272,7 +273,8 @@ isValid(const Polygon &p, const double &toleranceAbs) -> const Validity return Validity::invalid( (boost::format("intersection between ring %d and %d") % ri % rj) .str()); - } else if (!inter->isEmpty() && inter->is()) { + } + if (!inter->isEmpty() && inter->is()) { touchingRings.emplace_back(ri, rj); } } @@ -286,8 +288,8 @@ isValid(const Polygon &p, const double &toleranceAbs) -> const Validity Graph g(touchingRings.begin(), touchingRings.end(), numRings); - bool hasLoop = false; - LoopDetector vis(hasLoop); + bool hasLoop = false; + LoopDetector const vis(hasLoop); undirected_dfs(g, root_vertex(vertex_t(0)) .visitor(vis) .edge_color_map(get(edge_color, g))); @@ -350,12 +352,13 @@ isValid(const MultiLineString &ml, const double &toleranceAbs) -> const Validity const size_t numLineString = ml.numGeometries(); for (size_t l = 0; l != numLineString; ++l) { - Validity v = isValid(ml.lineStringN(l), toleranceAbs); + Validity const v = isValid(ml.lineStringN(l), toleranceAbs); - if (!v) + if (!v) { return Validity::invalid( (boost::format("LineString %d is invalid: %s") % l % v.reason()) .str()); + } } return Validity::valid(); @@ -371,11 +374,12 @@ isValid(const MultiPolygon &mp, const double &toleranceAbs) -> const Validity const size_t numPolygons = mp.numGeometries(); for (size_t p = 0; p != numPolygons; ++p) { - Validity v = isValid(mp.polygonN(p), toleranceAbs); + Validity const v = isValid(mp.polygonN(p), toleranceAbs); - if (!v) + if (!v) { return Validity::invalid( (boost::format("Polygon %d is invalid: %s") % p % v.reason()).str()); + } } for (size_t pi = 0; pi != numPolygons; ++pi) { @@ -407,12 +411,13 @@ isValid(const GeometryCollection &gc, const double &toleranceAbs) const size_t numGeom = gc.numGeometries(); for (size_t g = 0; g != numGeom; ++g) { - Validity v = isValid(gc.geometryN(g), toleranceAbs); + Validity const v = isValid(gc.geometryN(g), toleranceAbs); - if (!v) + if (!v) { return Validity::invalid((boost::format("%s %d is invalid: %s") % gc.geometryN(g).geometryType() % g % v.reason()) .str()); + } } return Validity::valid(); @@ -426,14 +431,15 @@ isValid(const TriangulatedSurface &tin, const SurfaceGraph &graph, return Validity::valid(); } - size_t numTriangles = tin.numTriangles(); + size_t const numTriangles = tin.numTriangles(); for (size_t t = 0; t != numTriangles; ++t) { - Validity v = isValid(tin.triangleN(t), toleranceAbs); + Validity const v = isValid(tin.triangleN(t), toleranceAbs); - if (!v) + if (!v) { return Validity::invalid( (boost::format("Triangle %d is invalid: %s") % t % v.reason()).str()); + } } if (!isConnected(graph)) { @@ -467,14 +473,15 @@ isValid(const PolyhedralSurface &s, const SurfaceGraph &graph, return Validity::valid(); } - size_t numPolygons = s.numPolygons(); + size_t const numPolygons = s.numPolygons(); for (size_t p = 0; p != numPolygons; ++p) { - Validity v = isValid(s.polygonN(p), toleranceAbs); + Validity const v = isValid(s.polygonN(p), toleranceAbs); - if (!v) + if (!v) { return Validity::invalid( (boost::format("Polygon %d is invalid: %s") % p % v.reason()).str()); + } } if (!isConnected(graph)) { @@ -511,21 +518,23 @@ isValid(const Solid &solid, const double &toleranceAbs) -> const Validity for (size_t s = 0; s != numShells; ++s) { const SurfaceGraph graph(solid.shellN(s)); - Validity v = isValid(solid.shellN(s), graph, toleranceAbs); + Validity const v = isValid(solid.shellN(s), graph, toleranceAbs); - if (!v) + if (!v) { return Validity::invalid( (boost::format("PolyhedralSurface (shell) %d is invalid: %s") % s % v.reason()) .str()); + } - if (!isClosed(graph)) + if (!isClosed(graph)) { return Validity::invalid( (boost::format("PolyhedralSurface (shell) %d is not closed") % s) .str()); + } } - if (solid.numInteriorShells()) { + if (solid.numInteriorShells() != 0U) { BOOST_THROW_EXCEPTION( Exception("function is not fully implemented (orientation, covering " "and intersections of interior shells missing")); @@ -544,11 +553,12 @@ isValid(const MultiSolid &ms, const double &toleranceAbs) -> const Validity const size_t numMultiSolid = ms.numGeometries(); for (size_t s = 0; s != numMultiSolid; ++s) { - Validity v = isValid(ms.solidN(s), toleranceAbs); + Validity const v = isValid(ms.solidN(s), toleranceAbs); - if (!v) + if (!v) { return Validity::invalid( (boost::format("Solid %d is invalid: %s") % s % v.reason()).str()); + } } return Validity::valid(); diff --git a/src/algorithm/length.cpp b/src/algorithm/length.cpp index 51510210..ac3a3449 100644 --- a/src/algorithm/length.cpp +++ b/src/algorithm/length.cpp @@ -9,8 +9,7 @@ #include -namespace SFCGAL { -namespace algorithm { +namespace SFCGAL::algorithm { /// /// @@ -21,8 +20,8 @@ length(const LineString &g) -> double double result = 0.0; for (size_t i = 0; i < g.numSegments(); i++) { - Kernel::Segment_2 segment(g.pointN(i).toPoint_2(), - g.pointN(i + 1).toPoint_2()); + Kernel::Segment_2 const segment(g.pointN(i).toPoint_2(), + g.pointN(i + 1).toPoint_2()); result += CGAL::sqrt(CGAL::to_double(segment.squared_length())); } @@ -92,8 +91,8 @@ length3D(const LineString &g) -> double double result = 0.0; for (size_t i = 0; i < g.numSegments(); i++) { - Kernel::Segment_3 segment(g.pointN(i).toPoint_3(), - g.pointN(i + 1).toPoint_3()); + Kernel::Segment_3 const segment(g.pointN(i).toPoint_3(), + g.pointN(i + 1).toPoint_3()); result += CGAL::sqrt(CGAL::to_double(segment.squared_length())); } @@ -152,5 +151,4 @@ length3D(const Geometry &g) -> double return 0.0; } -} // namespace algorithm -} // namespace SFCGAL +} // namespace SFCGAL::algorithm diff --git a/src/algorithm/lineSubstring.cpp b/src/algorithm/lineSubstring.cpp index b70dd24d..c2ea4be1 100644 --- a/src/algorithm/lineSubstring.cpp +++ b/src/algorithm/lineSubstring.cpp @@ -12,18 +12,15 @@ #include #include -namespace SFCGAL { - -namespace algorithm { +namespace SFCGAL::algorithm { namespace { -static const double tol = 1.0e-9; +const double tol = 1.0e-9; auto find_position(const LineString &ls, const long N, const double target_length, - const double offset, const double tol, const bool find_start, - std::size_t &idx, double &frac, bool &on_point, - double &len_to_idx) -> Point + const double offset, const double tol, std::size_t &idx, + double &frac, bool &on_point, double &len_to_idx) -> Point { BOOST_ASSERT(!(offset < 0.0)); BOOST_ASSERT(!(target_length < 0.0)); @@ -64,7 +61,8 @@ find_position(const LineString &ls, const long N, const double target_length, on_point = true; break; - } else if (cur_length > target_length) { + } + if (cur_length > target_length) { // We went too far. Subtract seg_length so // cur_length is the distance along ls // to the idx'th point. @@ -196,21 +194,18 @@ lineSubstring(const LineString &ls, double start, double end) double start_frac = 0.0; bool on_start = false; double len_to_start_idx = 0.0; - Point pstart = - find_position(ls, N, len * start, 0.0, tol, true // Find start. - , - start_idx, start_frac, on_start, len_to_start_idx); + Point pstart = find_position(ls, N, len * start, 0.0, tol, start_idx, + start_frac, on_start, len_to_start_idx); // Find Point immediately before/on end position. std::size_t end_idx = start_idx; // Must initialise first. double end_frac = 0.0; bool on_end = false; double len_to_end_idx = 0.0; - Point pend = find_position( - ls, N, len * end, len_to_start_idx, tol, false // Find end. - , - end_idx, end_frac, on_end, len_to_end_idx // This result is not used. - ); + Point pend = + find_position(ls, N, len * end, len_to_start_idx, tol, end_idx, end_frac, + on_end, len_to_end_idx // This result is not used. + ); if (reverse && closed) { // For closed lines we always want to follow the @@ -289,6 +284,4 @@ lineSubstring(const LineString &ls, double start, double end) return substring; } -} // namespace algorithm - -} // namespace SFCGAL +} // namespace SFCGAL::algorithm diff --git a/src/algorithm/minkowskiSum.cpp b/src/algorithm/minkowskiSum.cpp index 4778fd72..db734c66 100644 --- a/src/algorithm/minkowskiSum.cpp +++ b/src/algorithm/minkowskiSum.cpp @@ -27,8 +27,7 @@ using Polygon_2 = CGAL::Polygon_2; using Polygon_with_holes_2 = CGAL::Polygon_with_holes_2; using Polygon_set_2 = CGAL::Polygon_set_2; -namespace SFCGAL { -namespace algorithm { +namespace SFCGAL::algorithm { //-- private interface @@ -119,8 +118,8 @@ minkowskiSum(const Point &gA, const Polygon_2 &gB, Polygon_set_2 &polygonSet) { BOOST_ASSERT(gB.size()); - CGAL::Aff_transformation_2 translate(CGAL::TRANSLATION, - gA.toVector_2()); + CGAL::Aff_transformation_2 const translate(CGAL::TRANSLATION, + gA.toVector_2()); Polygon_2 sum; @@ -150,7 +149,7 @@ minkowskiSum(const LineString &gA, const Polygon_2 &gB, return; } - int npt = gA.numPoints(); + int const npt = gA.numPoints(); for (int i = 0; i < npt - 1; i++) { Polygon_2 P; @@ -165,7 +164,8 @@ minkowskiSum(const LineString &gA, const Polygon_2 &gB, #if CGAL_VERSION_NR < 1040701000 // version 4.7 Polygon_with_holes_2 part = minkowski_sum_2(P, gB); #else - Polygon_with_holes_2 part = minkowski_sum_by_full_convolution_2(P, gB); + Polygon_with_holes_2 const part = + minkowski_sum_by_full_convolution_2(P, gB); #endif // merge into a polygon set @@ -191,7 +191,7 @@ minkowskiSum(const Polygon &gA, const Polygon_2 &gB, Polygon_set_2 &polygonSet) * Invoke minkowski_sum_2 for exterior ring */ { - Polygon_with_holes_2 sum = + Polygon_with_holes_2 const sum = minkowski_sum_2(gA.exteriorRing().toPolygon_2(), gB); if (polygonSet.is_empty()) { @@ -255,7 +255,7 @@ minkowskiSumCollection(const Geometry &gA, const Polygon_2 &gB, } auto -minkowskiSum(const Geometry &gA, const Polygon &gB, NoValidityCheck) +minkowskiSum(const Geometry &gA, const Polygon &gB, NoValidityCheck /*unused*/) -> std::unique_ptr { if (gB.isEmpty()) { @@ -284,5 +284,4 @@ minkowskiSum(const Geometry &gA, const Polygon &gB) -> std::unique_ptr return result; } -} // namespace algorithm -} // namespace SFCGAL +} // namespace SFCGAL::algorithm diff --git a/src/algorithm/offset.cpp b/src/algorithm/offset.cpp index 5e3e82b5..e5199eb7 100644 --- a/src/algorithm/offset.cpp +++ b/src/algorithm/offset.cpp @@ -40,8 +40,7 @@ using Offset_polygon_set_2 = CGAL::General_polygon_set_2; #define SFCGAL_OFFSET_ASSERT_FINITE_RADIUS(r) \ if (!std::isfinite(r)) \ BOOST_THROW_EXCEPTION(NonFiniteValueException("radius is non finite")); -namespace SFCGAL { -namespace algorithm { +namespace SFCGAL::algorithm { //-- private interface @@ -95,8 +94,9 @@ approximate(const Offset_polygon_2 &polygon, const int &n = 0) -> Polygon_2 } // remove duplicated last point - if (pair_list.size() > 0) + if (!pair_list.empty()) { pair_list.pop_back(); + } /* * convertr to polygon @@ -106,10 +106,8 @@ approximate(const Offset_polygon_2 &polygon, const int &n = 0) -> Polygon_2 bool isFirst = true; Kernel::Point_2 last; - for (std::list>::const_iterator it = - pair_list.begin(); - it != pair_list.end(); ++it) { - Kernel::Point_2 point(it->first, it->second); + for (auto &it : pair_list) { + Kernel::Point_2 const point(it.first, it.second); if (isFirst) { isFirst = false; @@ -152,9 +150,8 @@ polygonSetToMultiPolygon(const Offset_polygon_set_2 &polygonSet, const int &n) std::unique_ptr result(new MultiPolygon); - for (std::list::const_iterator it = res.begin(); - it != res.end(); ++it) { - result->addGeometry(new Polygon(approximate(*it, n))); + for (auto &re : res) { + result->addGeometry(new Polygon(approximate(re, n))); } return result; @@ -169,8 +166,8 @@ circleToPolygon(const Kernel::Circle_2 &circle) -> Offset_polygon_2 /* * convert the circle into Offset_x_monotone_curve_2 (exactly 2) */ - Gps_traits_2 traits; - Offset_curve_2 curve(circle); + Gps_traits_2 const traits; + Offset_curve_2 const curve(circle); std::list parts; traits.make_x_monotone_2_object()(curve, std::back_inserter(parts)); @@ -179,10 +176,9 @@ circleToPolygon(const Kernel::Circle_2 &circle) -> Offset_polygon_2 // Construct the polygon. Offset_polygon_2 result; - for (std::list::const_iterator it = parts.begin(); - it != parts.end(); ++it) { + for (auto &part : parts) { Offset_x_monotone_curve_2 arc; - CGAL::assign(arc, *it); + CGAL::assign(arc, part); result.push_back(arc); } @@ -196,7 +192,7 @@ void offset(const Point &gA, const double &radius, Offset_polygon_set_2 &polygonSet) { SFCGAL_OFFSET_ASSERT_FINITE_RADIUS(radius); - Kernel::Circle_2 circle(gA.toPoint_2(), radius * radius); + Kernel::Circle_2 const circle(gA.toPoint_2(), radius * radius); if (polygonSet.is_empty()) { polygonSet.insert(circleToPolygon(circle)); @@ -218,7 +214,7 @@ offset(const LineString &lineString, const double &radius, Polygon_2 P; P.push_back(lineString.pointN(i).toPoint_2()); P.push_back(lineString.pointN(i + 1).toPoint_2()); - Offset_polygon_with_holes_2 offset = + Offset_polygon_with_holes_2 const offset = CGAL::approximated_offset_2(P, radius, SFCGAL_OFFSET_ACCURACY); if (polygonSet.is_empty()) { @@ -245,7 +241,7 @@ offset(const Polygon &g, const double &radius, Offset_polygon_set_2 &polygonSet) * Invoke minkowski_sum_2 for exterior ring */ { - Offset_polygon_with_holes_2 offset = CGAL::approximated_offset_2( + Offset_polygon_with_holes_2 const offset = CGAL::approximated_offset_2( g.exteriorRing().toPolygon_2(), radius, SFCGAL_OFFSET_ACCURACY); if (polygonSet.is_empty()) { @@ -346,7 +342,7 @@ offset(const Geometry &g, const double &radius, /// /// auto -offset(const Geometry &g, const double &r, NoValidityCheck) +offset(const Geometry &g, const double &r, NoValidityCheck /*unused*/) -> std::unique_ptr { SFCGAL_OFFSET_ASSERT_FINITE_RADIUS(r); @@ -363,5 +359,4 @@ offset(const Geometry &g, const double &r) -> std::unique_ptr return offset(g, r, NoValidityCheck()); } -} // namespace algorithm -} // namespace SFCGAL +} // namespace SFCGAL::algorithm diff --git a/src/algorithm/orientation.cpp b/src/algorithm/orientation.cpp index 69a95ca3..f196182e 100644 --- a/src/algorithm/orientation.cpp +++ b/src/algorithm/orientation.cpp @@ -12,8 +12,7 @@ #include -namespace SFCGAL { -namespace algorithm { +namespace SFCGAL::algorithm { /// /// @@ -156,5 +155,4 @@ isCounterClockWiseOriented(const Polygon &poly) -> bool return isCounterClockWiseOriented(poly.exteriorRing()); } -} // namespace algorithm -} // namespace SFCGAL +} // namespace SFCGAL::algorithm diff --git a/src/algorithm/partition_2.cpp b/src/algorithm/partition_2.cpp index be7337f1..82688afc 100644 --- a/src/algorithm/partition_2.cpp +++ b/src/algorithm/partition_2.cpp @@ -19,8 +19,7 @@ #include #include -namespace SFCGAL { -namespace algorithm { +namespace SFCGAL::algorithm { using Traits = CGAL::Partition_traits_2; using TPoint_2 = Traits::Point_2; @@ -44,12 +43,12 @@ toTPolygon_2(const Polygon &poly) -> CGAL::Partition_traits_2::Polygon_2 pit != pend; ++pit) { if (pit == poly.exteriorRing().begin()) { lastP = *pit; - TPoint_2 point2(pit->coordinate().x(), pit->coordinate().y()); + TPoint_2 const point2(pit->coordinate().x(), pit->coordinate().y()); points.push_back(point2); } if (lastP != *pit) { - TPoint_2 point2(pit->coordinate().x(), pit->coordinate().y()); + TPoint_2 const point2(pit->coordinate().x(), pit->coordinate().y()); points.push_back(point2); } @@ -66,12 +65,12 @@ polygons_to_geometry(const std::list &polys) -> std::unique_ptr { - GeometryCollection *geoms = new GeometryCollection; + auto *geoms = new GeometryCollection; std::list::const_iterator poly_it; for (poly_it = polys.begin(); poly_it != polys.end(); ++poly_it) { auto *poly = new Polygon; - for (TPoint_2 p : poly_it->container()) { + for (const TPoint_2 &p : poly_it->container()) { poly->exteriorRing().addPoint(p); } poly->exteriorRing().addPoint(*(poly_it->vertices_begin())); @@ -120,5 +119,4 @@ partition_2(const Geometry &g, PartitionAlgorithm alg) return polygons_to_geometry(partition_polys); } -} // namespace algorithm -} // namespace SFCGAL +} // namespace SFCGAL::algorithm diff --git a/src/algorithm/straightSkeleton.cpp b/src/algorithm/straightSkeleton.cpp index 1db7b996..8dd1f642 100644 --- a/src/algorithm/straightSkeleton.cpp +++ b/src/algorithm/straightSkeleton.cpp @@ -29,8 +29,7 @@ #include -namespace SFCGAL { -namespace algorithm { +namespace SFCGAL::algorithm { using Point_2 = Kernel::Point_2; using Point_3 = Kernel::Point_3; @@ -54,8 +53,8 @@ straightSkeletonToMultiLineString(const CGAL::Straight_skeleton_2 &ss, using Halfedge_const_handle = typename Ss::Halfedge_const_handle; using Halfedge_const_iterator = typename Ss::Halfedge_const_iterator; - Halfedge_const_handle null_halfedge; - Vertex_const_handle null_vertex; + Halfedge_const_handle const null_halfedge; + Vertex_const_handle const null_vertex; for (Halfedge_const_iterator it = ss.halfedges_begin(); it != ss.halfedges_end(); ++it) { @@ -96,17 +95,20 @@ straightSkeletonToMultiLineString(const CGAL::Straight_skeleton_2 &ss, /** * Return abc angle in radians */ -static auto +auto angle(const Point &a, const Point &b, const Point &c) -> double { - Point ab(to_double(b.x() - a.x()), to_double(b.y() - a.y())); - Point cb(to_double(b.x() - c.x()), to_double(b.y() - c.y())); + Point const ab(CGAL::to_double(b.x() - a.x()), + CGAL::to_double(b.y() - a.y())); + Point const cb(CGAL::to_double(b.x() - c.x()), + CGAL::to_double(b.y() - c.y())); - double dot = (to_double(ab.x() * cb.x() + ab.y() * cb.y())); /* dot product */ - double cross = - (to_double(ab.x() * cb.y() - ab.y() * cb.x())); /* cross product */ + double const dot = + (CGAL::to_double(ab.x() * cb.x() + ab.y() * cb.y())); /* dot product */ + double const cross = + (CGAL::to_double(ab.x() * cb.y() - ab.y() * cb.x())); /* cross product */ - double alpha = std::atan2(cross, dot); + double const alpha = std::atan2(cross, dot); return alpha; } @@ -162,10 +164,11 @@ straightSkeletonToMedialAxis(const CGAL::Straight_skeleton_2 &ss, const Point &p2 = de1->vertex()->point(); const Point &p3 = de1->opposite()->vertex()->point(); - double ang = angle(p1, p2, p3); + double const ang = angle(p1, p2, p3); - if (ang > maxTouchingAngle) + if (ang > maxTouchingAngle) { continue; + } } std::unique_ptr ls( @@ -180,14 +183,15 @@ auto straightSkeleton(const Polygon_with_holes_2 &poly) -> boost::shared_ptr { - boost::shared_ptr> sk = + boost::shared_ptr> const sk = CGAL::create_interior_straight_skeleton_2( poly.outer_boundary().vertices_begin(), poly.outer_boundary().vertices_end(), poly.holes_begin(), poly.holes_end(), CGAL::Epick()); boost::shared_ptr ret; - if (sk) + if (sk) { ret = CGAL::convert_straight_skeleton_2(*sk); + } return ret; } @@ -223,8 +227,8 @@ preparePolygon(const Polygon &poly, Kernel::Vector_2 &trans) -> Polygon_with_holes_2 { checkNoTouchingHoles(poly); - Envelope env = poly.envelope(); - trans = Kernel::Vector_2(-env.xMin(), -env.yMin()); + Envelope const env = poly.envelope(); + trans = Kernel::Vector_2(-env.xMin(), -env.yMin()); // @todo: avoid cloning ! std::unique_ptr cloned(poly.clone()); @@ -263,9 +267,10 @@ extractPolygons(const Geometry &g, std::vector &vect) /// /// auto -straightSkeleton(const Geometry &g, bool autoOrientation, NoValidityCheck, - bool innerOnly, bool outputDistanceInM, - const double &toleranceAbs) -> std::unique_ptr +straightSkeleton(const Geometry &g, bool autoOrientation, + NoValidityCheck /*unused*/, bool innerOnly, + bool outputDistanceInM, const double & /*toleranceAbs*/) + -> std::unique_ptr { switch (g.geometryTypeId()) { case TYPE_TRIANGLE: @@ -287,7 +292,7 @@ straightSkeleton(const Geometry &g, bool autoOrientation, NoValidityCheck, auto straightSkeleton(const Geometry &g, bool autoOrientation, bool innerOnly, - bool outputDistanceInM, const double &toleranceAbs) + bool outputDistanceInM, const double & /*toleranceAbs*/) -> std::unique_ptr { SFCGAL_ASSERT_GEOMETRY_VALIDITY_2D(g); @@ -311,20 +316,22 @@ straightSkeleton(const Polygon &g, bool /*autoOrientation*/, bool innerOnly, return result; } - Kernel::Vector_2 trans; - Polygon_with_holes_2 polygon = preparePolygon(g, trans); - boost::shared_ptr skeleton = straightSkeleton(polygon); + Kernel::Vector_2 trans; + Polygon_with_holes_2 const polygon = preparePolygon(g, trans); + boost::shared_ptr const skeleton = + straightSkeleton(polygon); - if (!skeleton.get()) { + if (skeleton == nullptr) { BOOST_THROW_EXCEPTION(Exception("CGAL failed to create straightSkeleton")); } - if (outputDistanceInM) + if (outputDistanceInM) { straightSkeletonToMultiLineString( *skeleton, *result, innerOnly, trans, toleranceAbs); - else + } else { straightSkeletonToMultiLineString( *skeleton, *result, innerOnly, trans, toleranceAbs); + } return result; } @@ -339,21 +346,23 @@ straightSkeleton(const MultiPolygon &g, bool /*autoOrientation*/, std::unique_ptr result(new MultiLineString); for (size_t i = 0; i < g.numGeometries(); i++) { - Kernel::Vector_2 trans; - Polygon_with_holes_2 polygon = preparePolygon(g.polygonN(i), trans); - boost::shared_ptr skeleton = straightSkeleton(polygon); + Kernel::Vector_2 trans; + Polygon_with_holes_2 const polygon = preparePolygon(g.polygonN(i), trans); + boost::shared_ptr const skeleton = + straightSkeleton(polygon); - if (!skeleton.get()) { + if (skeleton == nullptr) { BOOST_THROW_EXCEPTION( Exception("CGAL failed to create straightSkeleton")); } - if (outputDistanceInM) + if (outputDistanceInM) { straightSkeletonToMultiLineString( *skeleton, *result, innerOnly, trans, toleranceAbs); - else + } else { straightSkeletonToMultiLineString( *skeleton, *result, innerOnly, trans, toleranceAbs); + } } return result; @@ -370,11 +379,12 @@ approximateMedialAxis(const Geometry &g) -> std::unique_ptr extractPolygons(g, polys); for (auto &poly : polys) { - Kernel::Vector_2 trans; - Polygon_with_holes_2 polygon = preparePolygon(poly, trans); - boost::shared_ptr skeleton = straightSkeleton(polygon); + Kernel::Vector_2 trans; + Polygon_with_holes_2 const polygon = preparePolygon(poly, trans); + boost::shared_ptr const skeleton = + straightSkeleton(polygon); - if (!skeleton.get()) { + if (skeleton == nullptr) { BOOST_THROW_EXCEPTION( Exception("CGAL failed to create straightSkeleton")); } @@ -419,7 +429,7 @@ extrudeStraightSkeleton(const Geometry &g, double building_height, double roof_height) -> std::unique_ptr { - std::unique_ptr roof{ + std::unique_ptr const roof{ extrudeStraightSkeleton(g, roof_height)}; translate(*roof, 0.0, 0.0, building_height); std::unique_ptr building(extrude(g.as(), building_height)); @@ -428,5 +438,4 @@ extrudeStraightSkeleton(const Geometry &g, double building_height, result->addPolygons(*roof); return result; }; -} // namespace algorithm -} // namespace SFCGAL +} // namespace SFCGAL::algorithm diff --git a/src/algorithm/tesselate.cpp b/src/algorithm/tesselate.cpp index 987d39f0..d6ac8496 100644 --- a/src/algorithm/tesselate.cpp +++ b/src/algorithm/tesselate.cpp @@ -9,14 +9,14 @@ #include #include -namespace SFCGAL { -namespace algorithm { +namespace SFCGAL::algorithm { /// /// /// auto -tesselate(const Geometry &g, NoValidityCheck) -> std::unique_ptr +tesselate(const Geometry &g, NoValidityCheck /*unused*/) + -> std::unique_ptr { switch (g.geometryTypeId()) { case TYPE_POINT: @@ -75,5 +75,4 @@ tesselate(const Geometry &g) -> std::unique_ptr return tesselate(g, NoValidityCheck()); } -} // namespace algorithm -} // namespace SFCGAL +} // namespace SFCGAL::algorithm diff --git a/src/algorithm/translate.cpp b/src/algorithm/translate.cpp index b441bba9..db00b7d2 100644 --- a/src/algorithm/translate.cpp +++ b/src/algorithm/translate.cpp @@ -20,8 +20,7 @@ #include #include -namespace SFCGAL { -namespace algorithm { +namespace SFCGAL::algorithm { /// /// @@ -49,8 +48,8 @@ translate(Geometry &g, const Kernel::Vector_2 &v) /// /// void -translate(Geometry &g, const Kernel::FT dx, const Kernel::FT dy, - const Kernel::FT dz) +translate(Geometry &g, const Kernel::FT &dx, const Kernel::FT &dy, + const Kernel::FT &dz) { translate(g, Kernel::Vector_3(dx, dy, dz)); } @@ -68,5 +67,4 @@ translate(Geometry &g, const double &dx, const double &dy, const double &dz) return translate(g, Kernel::FT(dx), Kernel::FT(dy), Kernel::FT(dz)); } -} // namespace algorithm -} // namespace SFCGAL +} // namespace SFCGAL::algorithm diff --git a/src/algorithm/translate.h b/src/algorithm/translate.h index 46bf6dc7..3831867c 100644 --- a/src/algorithm/translate.h +++ b/src/algorithm/translate.h @@ -33,8 +33,8 @@ translate(Geometry &g, const Kernel::Vector_2 &v); * @todo unittest */ SFCGAL_API void -translate(Geometry &g, const Kernel::FT dx, const Kernel::FT dy, - const Kernel::FT dz); +translate(Geometry &g, const Kernel::FT &dx, const Kernel::FT &dy, + const Kernel::FT &dz); /** * @brief translate a geometry from double-coordinates diff --git a/src/algorithm/union.cpp b/src/algorithm/union.cpp index 4fc6ac37..acb92785 100644 --- a/src/algorithm/union.cpp +++ b/src/algorithm/union.cpp @@ -15,9 +15,7 @@ if (0) \ std::cerr << __FILE__ << ":" << __LINE__ << " debug: " -namespace SFCGAL { - -namespace algorithm { +namespace SFCGAL::algorithm { struct EmptyPrimitive {}; @@ -51,7 +49,7 @@ struct Segment_d : detail::Segment_d::Type { } template - auto + [[nodiscard]] [[nodiscard]] auto pieces(OutputIterator out) const -> OutputIterator { PointVector points(1, this->source()); @@ -60,14 +58,14 @@ struct Segment_d : detail::Segment_d::Type { std::sort(points.begin() + 1, points.end() - 1, Nearer(this->source())); - for (typename PointVector::const_iterator p = points.begin(), q = p + 1; - q != points.end(); ++p, q++) { + for (auto p = points.begin(), q = p + 1; q != points.end(); ++p, q++) { if (*p != *q) { - PointType m = CGAL::midpoint(*p, *q); - auto r = _remove.begin(); + PointType const m = CGAL::midpoint(*p, *q); + auto r = _remove.begin(); - for (; r != _remove.end() && !r->has_on(m); ++r) + for (; r != _remove.end() && !r->has_on(m); ++r) { ; + } if (r == _remove.end()) { *out++ = SegmentType(*p, *q); @@ -78,7 +76,7 @@ struct Segment_d : detail::Segment_d::Type { return out; } - auto + [[nodiscard]] auto pieces() const -> SegmentVector { SegmentVector result; @@ -127,7 +125,8 @@ struct Surface_d<3> : Triangle_3 { return; } - Point3Iterator s = begin, t = s + 1; + Point3Iterator s = begin; + Point3Iterator t = s + 1; for (; t != end; ++t, ++s) { _split.push_back(Segment_2(_plane.to_2d(*s), _plane.to_2d(*t))); @@ -193,19 +192,18 @@ struct Surface_d<3> : Triangle_3 { { std::vector> lines(_split.begin(), _split.begin() + 3); - for (typename SegmentVector::const_iterator c = _split.begin() + 3; - c != _split.end(); ++c) { + for (auto c = _split.begin() + 3; c != _split.end(); ++c) { Segment_d<2> current(*c); for (auto &line : lines) { - CGAL::Object inter = CGAL::intersection(line, current); - const auto *p = CGAL::object_cast(&inter); - const auto *s = CGAL::object_cast(&inter); + CGAL::Object const inter = CGAL::intersection(line, current); + const auto *p = CGAL::object_cast(&inter); + const auto *s = CGAL::object_cast(&inter); - if (p) { + if (p != nullptr) { current.splitAt(*p); line.splitAt(*p); - } else if (s) { + } else if (s != nullptr) { current.remove(*s); line.splitAt(s->source()); line.splitAt(s->target()); @@ -215,9 +213,8 @@ struct Surface_d<3> : Triangle_3 { lines.push_back(current); } - for (std::vector>::const_iterator l = lines.begin(); - l != lines.end(); ++l) { - l->pieces(std::back_inserter(filtered)); + for (auto &line : lines) { + line.pieces(std::back_inserter(filtered)); } } @@ -230,10 +227,9 @@ struct Surface_d<3> : Triangle_3 { triangulate::ConstraintDelaunayTriangulation::Vertex_handle; triangulate::ConstraintDelaunayTriangulation cdt; - for (std::vector::const_iterator f = filtered.begin(); - f != filtered.end(); ++f) { - Vertex_handle s = cdt.addVertex(f->source()); - Vertex_handle t = cdt.addVertex(f->target()); + for (auto &f : filtered) { + Vertex_handle const s = cdt.addVertex(f.source()); + Vertex_handle const t = cdt.addVertex(f.target()); cdt.addConstraint(s, t); } @@ -251,13 +247,14 @@ struct Surface_d<3> : Triangle_3 { const Point_2 point(a + (Vector_2(a, b) + Vector_2(a, c)) / 3); // find if triangle is in a removed spot - SurfaceVector::const_iterator r = _remove.begin(); + auto r = _remove.begin(); for (; r != _remove.end() && CGAL::bounded_side_2(r->begin(), r->end(), point, Kernel()) == CGAL::ON_UNBOUNDED_SIDE; - ++r) + ++r) { ; + } if (r == _remove.end()) { res.emplace_back(_plane.to_3d(a), _plane.to_3d(b), _plane.to_3d(c)); @@ -295,7 +292,7 @@ struct Surface_d<2> : PolygonWH_2 { _split.insert(_split.end(), other._split.begin(), other._split.end()); } - auto + [[nodiscard]] auto pieces() const -> std::vector { std::vector res; @@ -524,7 +521,7 @@ auto compute_bboxes(const detail::GeometrySet &gs, OutputIterator out) -> OutputIterator { - typename HandledBox::Vector bboxes; + typename HandledBox::Vector const bboxes; for (auto it = gs.points().begin(); it != gs.points().end(); ++it) { *out++ = typename HandledBox::Type(it->primitive().bbox(), @@ -588,7 +585,7 @@ union_point_surface(Handle<3> a, Handle<3> b) } void -union_point_volume(const Handle<2> &, const Handle<2> &) +union_point_volume(const Handle<2> & /*unused*/, const Handle<2> & /*unused*/) { BOOST_ASSERT(false); // there shouldn't be any volume in 2D } @@ -598,7 +595,7 @@ union_point_volume(Handle<3> a, Handle<3> b) { //@todo put is in poly in a struct derived from MarkedPolyhedron to avoid // rebuilding point inside every time - CGAL::Side_of_triangle_mesh is_in_poly( + CGAL::Side_of_triangle_mesh const is_in_poly( b.asVolume()); if (CGAL::ON_UNBOUNDED_SIDE != is_in_poly(a.asPoint())) { @@ -613,9 +610,9 @@ union_segment_segment(Handle a, Handle b) using SegmentType = typename detail::TypeForDimension::Segment; using PointType = typename detail::TypeForDimension::Point; - CGAL::Object inter = CGAL::intersection(a.asSegment(), b.asSegment()); - const auto *p = CGAL::object_cast(&inter); - const auto *s = CGAL::object_cast(&inter); + CGAL::Object const inter = CGAL::intersection(a.asSegment(), b.asSegment()); + const auto *p = CGAL::object_cast(&inter); + const auto *s = CGAL::object_cast(&inter); if (p) { b.asSegment().splitAt(*p); @@ -656,13 +653,13 @@ union_segment_surface(Handle<2> a, Handle<2> b) : *(target - 1), *target); - CGAL::Object inter = CGAL::intersection(a.asSegment(), sc); - const auto *p = CGAL::object_cast(&inter); - const auto *s = CGAL::object_cast(&inter); + CGAL::Object const inter = CGAL::intersection(a.asSegment(), sc); + const auto *p = CGAL::object_cast(&inter); + const auto *s = CGAL::object_cast(&inter); - if (p) { + if (p != nullptr) { points.push_back(*p); - } else if (s) { + } else if (s != nullptr) { a.asSegment().remove(*s); } } @@ -675,8 +672,7 @@ union_segment_surface(Handle<2> a, Handle<2> b) // cut segment with pieces that have length and wich midpoint is inside // polygon - for (std::vector::const_iterator p = points.begin(), q = p + 1; - q != points.end(); ++p, ++q) { + for (auto p = points.begin(), q = p + 1; q != points.end(); ++p, ++q) { if (*p != *q && do_intersect(CGAL::midpoint(*p, *q), b.asSurface())) { const Segment_2 s(*p, *q); a.asSegment().remove(s); @@ -688,17 +684,17 @@ union_segment_surface(Handle<2> a, Handle<2> b) void union_segment_surface(Handle<3> a, Handle<3> b) { - CGAL::Object inter = CGAL::intersection(a.asSegment(), b.asSurface()); - const auto *s = CGAL::object_cast(&inter); + CGAL::Object const inter = CGAL::intersection(a.asSegment(), b.asSurface()); + const auto *s = CGAL::object_cast(&inter); - if (s) { + if (s != nullptr) { a.asSegment().remove(*s); b.asSurface().splitAt(*s); } } void -union_segment_volume(const Handle<2> &, const Handle<2> &) +union_segment_volume(const Handle<2> & /*unused*/, const Handle<2> & /*unused*/) { BOOST_ASSERT(false); // there shouldn't be any volume in 2D } @@ -719,13 +715,14 @@ union_segment_volume(Handle<3> a, Handle<3> b) // it's not // used anyway FaceSegmentCollide::CollisionVector collisions; - FaceSegmentCollide cb(collisions); + FaceSegmentCollide const cb(collisions); CGAL::box_intersection_d(bbox.begin(), bbox.end(), bboxes.begin(), bboxes.end(), cb); - CGAL::Side_of_triangle_mesh is_in_poly(polyhedron); + CGAL::Side_of_triangle_mesh const is_in_poly( + polyhedron); - if (!collisions.size()) { + if (collisions.empty()) { // completely in or out, we just test one point if (CGAL::ON_UNBOUNDED_SIDE != is_in_poly(segment.source())) { @@ -736,9 +733,8 @@ union_segment_volume(Handle<3> a, Handle<3> b) collidingTriangles(collisions, std::back_inserter(triangles)); // first step, substract faces - for (std::vector::const_iterator tri = triangles.begin(); - tri != triangles.end(); ++tri) { - Handle<3> h(*tri); + for (auto &triangle : triangles) { + Handle<3> const h(triangle); union_segment_surface(a, h); } @@ -746,24 +742,22 @@ union_segment_volume(Handle<3> a, Handle<3> b) // middle point to know if it's in or out std::vector points; - for (std::vector::const_iterator tri = triangles.begin(); - tri != triangles.end(); ++tri) { - CGAL::Object inter = CGAL::intersection(segment, *tri); - const auto *p = CGAL::object_cast(&inter); + for (auto &triangle : triangles) { + CGAL::Object const inter = CGAL::intersection(segment, triangle); + const auto *p = CGAL::object_cast(&inter); - if (p) { + if (p != nullptr) { points.push_back(*p); } } - if (points.size()) { + if (static_cast(!points.empty()) != 0U) { std::sort(points.begin(), points.end(), Nearer(segment.source())); // mark segments pieces that have length and wich midpoint is inside // polyhedron - for (std::vector::const_iterator p = points.begin(), q = p + 1; - q != points.end(); ++p, ++q) { + for (auto p = points.begin(), q = p + 1; q != points.end(); ++p, ++q) { if (*p != *q && CGAL::ON_UNBOUNDED_SIDE != is_in_poly(CGAL::midpoint(*p, *q))) { a.asSegment().remove(Segment_3(*p, *q)); @@ -792,29 +786,29 @@ union_surface_surface(Handle<2> a, Handle<2> b) void union_surface_surface(Handle<3> a, Handle<3> b) { - CGAL::Object inter = intersection(a.asSurface(), b.asSurface()); - const auto *p = CGAL::object_cast(&inter); - const auto *s = CGAL::object_cast(&inter); - const auto *t = CGAL::object_cast(&inter); - const auto *v = CGAL::object_cast>(&inter); + CGAL::Object const inter = intersection(a.asSurface(), b.asSurface()); + const auto *p = CGAL::object_cast(&inter); + const auto *s = CGAL::object_cast(&inter); + const auto *t = CGAL::object_cast(&inter); + const auto *v = CGAL::object_cast>(&inter); - if (p) { + if (p != nullptr) { a.asSurface().splitAt(*p); b.asSurface().splitAt(*p); - } else if (s) { + } else if (s != nullptr) { a.asSurface().splitAt(*s); b.asSurface().splitAt(*s); - } else if (t) { + } else if (t != nullptr) { a.asSurface().splitAt(*t); b.asSurface().remove(*t); - } else if (v) { + } else if (v != nullptr) { a.asSurface().splitAt(*v); b.asSurface().remove(*v); } } void -union_surface_volume(const Handle<2> &, const Handle<2> &) +union_surface_volume(const Handle<2> & /*unused*/, const Handle<2> & /*unused*/) { BOOST_ASSERT(false); // there shouldn't be any volume in 2D } @@ -825,15 +819,13 @@ union_surface_volume(Handle<3> a, Handle<3> b) detail::GeometrySet<3> res; _intersection_solid_triangle(b.asVolume(), a.asSurface(), res); - for (detail::GeometrySet<3>::SurfaceCollection::const_iterator it = - res.surfaces().begin(); - it != res.surfaces().end(); ++it) { - a.asSurface().remove(it->primitive()); + for (auto &it : res.surfaces()) { + a.asSurface().remove(it.primitive()); } } void -union_volume_volume(const Handle<2> &, const Handle<2> &) +union_volume_volume(const Handle<2> & /*unused*/, const Handle<2> & /*unused*/) { BOOST_ASSERT(false); // there shouldn't be any volume in 2D } @@ -853,10 +845,11 @@ union_volume_volume(Handle<3> a, Handle<3> b) intersection(detail::GeometrySet<3>(a.asVolume()), detail::GeometrySet<3>(b.asVolume()), inter); - if (inter.volumes().size() || inter.surfaces().size()) { + if ((static_cast(!inter.volumes().empty()) != 0U) || + (static_cast(!inter.surfaces().empty()) != 0U)) { MarkedPolyhedron output; - bool res = + bool const res = CGAL::Polygon_mesh_processing::corefine_and_compute_union(p, q, output); if (res && std::next(vertices(output).first) != vertices(output).second) { @@ -1019,7 +1012,7 @@ collectPrimitives(const typename HandledBox::Vector &boxes, } auto -union_(const Geometry &ga, const Geometry &gb, NoValidityCheck) +union_(const Geometry &ga, const Geometry &gb, NoValidityCheck /*unused*/) -> std::unique_ptr { HandledBox<2>::Vector boxes; @@ -1046,7 +1039,7 @@ union_(const Geometry &ga, const Geometry &gb) -> std::unique_ptr } auto -union3D(const Geometry &ga, const Geometry &gb, NoValidityCheck) +union3D(const Geometry &ga, const Geometry &gb, NoValidityCheck /*unused*/) -> std::unique_ptr { HandledBox<3>::Vector boxes; @@ -1075,12 +1068,11 @@ union3D(const Geometry &ga, const Geometry &gb) -> std::unique_ptr void handleLeakTest() { - Handle<2> h0(Point_2(0, 0)); - Handle<2> h1(Point_2(1, 1)); - Handle<2> empty; + Handle<2> const h0(Point_2(0, 0)); + Handle<2> h1(Point_2(1, 1)); + Handle<2> empty; empty.registerObservers(empty); empty.registerObservers(h0); h1.registerObservers(h0); } -} // namespace algorithm -} // namespace SFCGAL +} // namespace SFCGAL::algorithm diff --git a/src/algorithm/visibility.cpp b/src/algorithm/visibility.cpp index 4a55c8ac..aaf9cbc9 100644 --- a/src/algorithm/visibility.cpp +++ b/src/algorithm/visibility.cpp @@ -14,8 +14,7 @@ #include #include -namespace SFCGAL { -namespace algorithm { +namespace SFCGAL::algorithm { using Point_2 = Kernel::Point_2; using Polygon_2 = CGAL::Polygon_2; @@ -40,12 +39,15 @@ query_visibility(Face_handle fh, Halfedge_const_handle he) Arrangement_2::Ccb_halfedge_circulator curr = fh->outer_ccb(); // find the right halfedge first - if (he != Halfedge_const_handle()) - while (++curr != fh->outer_ccb()) - if (curr->source()->point() == he->source()->point()) + if (he != Halfedge_const_handle()) { + while (++curr != fh->outer_ccb()) { + if (curr->source()->point() == he->source()->point()) { break; + } + } + } - Arrangement_2::Ccb_halfedge_circulator first = curr; + Arrangement_2::Ccb_halfedge_circulator const first = curr; extRing->addPoint(Point(curr->source()->point())); // Save the points from the visibility polygon @@ -76,12 +78,12 @@ visibility(const Geometry &polygon, const Geometry &point) } auto -visibility(const Geometry &polygon, const Geometry &point, NoValidityCheck) - -> std::unique_ptr +visibility(const Geometry &polygon, const Geometry &point, + NoValidityCheck /*unused*/) -> std::unique_ptr { - Point_2 queryPoint{point.as().toPoint_2()}; - std::unique_ptr extRing{new LineString()}; + Point_2 const queryPoint{point.as().toPoint_2()}; + std::unique_ptr const extRing{new LineString()}; // insert geometry into the arrangement CGAL::Polygon_with_holes_2 pwh{ @@ -91,12 +93,13 @@ visibility(const Geometry &polygon, const Geometry &point, NoValidityCheck) CGAL::insert(arr, pwh.outer_boundary().edges_begin(), pwh.outer_boundary().edges_end()); // the holes - for (PolygonWithHoles::Hole_const_iterator hit = pwh.holes_begin(); - hit != pwh.holes_end(); ++hit) + for (auto hit = pwh.holes_begin(); hit != pwh.holes_end(); ++hit) { CGAL::insert(arr, hit->edges_begin(), hit->edges_end()); + } // Find the face - CGAL::Arr_naive_point_location pl(arr); + Arrangement_2::Face_const_handle *face; + CGAL::Arr_naive_point_location const pl(arr); CGAL::Arr_point_location_result::Type obj = pl.locate(queryPoint); @@ -104,7 +107,7 @@ visibility(const Geometry &polygon, const Geometry &point, NoValidityCheck) Face_handle fh; // Create Triangular Expansion Visibility object. - TEV tev(arr); + TEV const tev(arr); if (obj.which() == 0) { @@ -170,12 +173,13 @@ visibility(const Geometry &polygon, const Geometry &pointA, auto visibility(const Geometry &polygon, const Geometry &pointA, - const Geometry &pointB, NoValidityCheck) -> std::unique_ptr + const Geometry &pointB, NoValidityCheck /*unused*/) + -> std::unique_ptr { - Point_2 startPoint{pointA.as().toPoint_2()}; - Point_2 endPoint{pointB.as().toPoint_2()}; - Point_2 queryPoint{pointB.as().toPoint_2()}; + Point_2 const startPoint{pointA.as().toPoint_2()}; + Point_2 const endPoint{pointB.as().toPoint_2()}; + Point_2 const queryPoint{pointB.as().toPoint_2()}; // insert geometry into the arrangement CGAL::Polygon_with_holes_2 pwh{ @@ -184,9 +188,9 @@ visibility(const Geometry &polygon, const Geometry &pointA, CGAL::insert(arr, pwh.outer_boundary().edges_begin(), pwh.outer_boundary().edges_end()); - for (PolygonWithHoles::Hole_const_iterator hit = pwh.holes_begin(); - hit != pwh.holes_end(); ++hit) + for (auto hit = pwh.holes_begin(); hit != pwh.holes_end(); ++hit) { CGAL::insert(arr, hit->edges_begin(), hit->edges_end()); + } // If the point is in a boundary segment, find the corresponding half edge Halfedge_const_handle he = arr.halfedges_begin(); @@ -208,12 +212,11 @@ visibility(const Geometry &polygon, const Geometry &pointA, } // visibility query - Arrangement_2 output_arr; - TEV tev(arr); - Face_handle fh = tev.compute_visibility(endPoint, he, output_arr); + Arrangement_2 output_arr; + TEV const tev(arr); + Face_handle const fh = tev.compute_visibility(endPoint, he, output_arr); return query_visibility(fh, he); } -} // namespace algorithm -} // namespace SFCGAL +} // namespace SFCGAL::algorithm diff --git a/src/algorithm/volume.cpp b/src/algorithm/volume.cpp index e593a3d2..ab866cfe 100644 --- a/src/algorithm/volume.cpp +++ b/src/algorithm/volume.cpp @@ -8,11 +8,10 @@ #include #include -namespace SFCGAL { -namespace algorithm { +namespace SFCGAL::algorithm { auto -volume(const Solid &solid, NoValidityCheck) -> const Kernel::FT +volume(const Solid &solid, NoValidityCheck /*unused*/) -> const Kernel::FT { Kernel::FT vol = 0; const CGAL::Point_3 origin(0, 0, 0); @@ -77,5 +76,4 @@ volume(const Geometry &g) -> const Kernel::FT return 0; // to avoid warning } -} // namespace algorithm -} // namespace SFCGAL +} // namespace SFCGAL::algorithm diff --git a/src/capi/sfcgal_c.cpp b/src/capi/sfcgal_c.cpp index d61ea42e..e80c4508 100644 --- a/src/capi/sfcgal_c.cpp +++ b/src/capi/sfcgal_c.cpp @@ -184,28 +184,31 @@ sfcgal_geometry_is_valid_detail(const sfcgal_geometry_t *geom, sfcgal_geometry_t **invalidity_location) -> int { // invalidity location is not supported for now - if (invalidity_location) + if (invalidity_location != nullptr) { *invalidity_location = nullptr; + } // set to null for now - if (invalidity_reason) + if (invalidity_reason != nullptr) { *invalidity_reason = nullptr; + } const auto *g = reinterpret_cast(geom); - if (g->hasValidityFlag()) - return true; + if (g->hasValidityFlag()) { + return 1; + } bool is_valid = false; try { - SFCGAL::Validity validity = SFCGAL::algorithm::isValid(*g); - is_valid = validity; - if (!is_valid && invalidity_reason) { + SFCGAL::Validity const validity = SFCGAL::algorithm::isValid(*g); + is_valid = validity; + if (!is_valid && (invalidity_reason != nullptr)) { *invalidity_reason = strdup(validity.reason().c_str()); } } catch (SFCGAL::Exception &e) { - if (invalidity_reason) { + if (invalidity_reason != nullptr) { *invalidity_reason = strdup(e.what()); } } - return is_valid; + return static_cast(is_valid); } extern "C" auto @@ -771,7 +774,7 @@ extern "C" auto sfcgal_io_read_binary_prepared(const char *str, size_t len) -> sfcgal_prepared_geometry_t * { - std::string sstr(str, len); + std::string const sstr(str, len); std::unique_ptr g; try { @@ -1282,11 +1285,11 @@ sfcgal_geometry_line_sub_string(const sfcgal_geometry_t *geom, double start, } #if !_MSC_VER -extern "C" sfcgal_geometry_t * +extern "C" auto sfcgal_geometry_alpha_shapes(const sfcgal_geometry_t *geom, double alpha, - bool allow_holes) + bool allow_holes) -> sfcgal_geometry_t * { - const SFCGAL::Geometry *g1 = reinterpret_cast(geom); + const auto *g1 = reinterpret_cast(geom); std::unique_ptr result; try { @@ -1297,39 +1300,41 @@ sfcgal_geometry_alpha_shapes(const sfcgal_geometry_t *geom, double alpha, SFCGAL_WARNING(" with A: %s", ((const SFCGAL::Geometry *)(geom))->asText().c_str()); SFCGAL_ERROR("%s", e.what()); - return 0; + return nullptr; } return result.release(); } -extern "C" sfcgal_geometry_t * +extern "C" auto sfcgal_geometry_optimal_alpha_shapes(const sfcgal_geometry_t *geom, bool allow_holes, size_t nb_components) + -> sfcgal_geometry_t * { - const SFCGAL::Geometry *g1 = reinterpret_cast(geom); + const auto *g1 = reinterpret_cast(geom); std::unique_ptr result; try { result = SFCGAL::algorithm::optimal_alpha_shapes( g1->as(), allow_holes, nb_components); } catch (std::exception &e) { - SFCGAL_WARNING("During optimal_alpha_shapes(A, %g %g):", allow_holes, - nb_components); + SFCGAL_WARNING("During optimal_alpha_shapes(A, %g %g):", + static_cast(allow_holes), nb_components); SFCGAL_WARNING(" with A: %s", ((const SFCGAL::Geometry *)(geom))->asText().c_str()); SFCGAL_ERROR("%s", e.what()); - return 0; + return nullptr; } return result.release(); } #endif -extern "C" sfcgal_geometry_t * +extern "C" auto sfcgal_y_monotone_partition_2(const sfcgal_geometry_t *geom) + -> sfcgal_geometry_t * { - const SFCGAL::Geometry *g1 = reinterpret_cast(geom); + const auto *g1 = reinterpret_cast(geom); std::unique_ptr result; try { @@ -1340,16 +1345,17 @@ sfcgal_y_monotone_partition_2(const sfcgal_geometry_t *geom) SFCGAL_WARNING(" with A: %s", ((const SFCGAL::Geometry *)(geom))->asText().c_str()); SFCGAL_ERROR("%s", e.what()); - return 0; + return nullptr; } return result.release(); } -extern "C" sfcgal_geometry_t * +extern "C" auto sfcgal_approx_convex_partition_2(const sfcgal_geometry_t *geom) + -> sfcgal_geometry_t * { - const SFCGAL::Geometry *g1 = reinterpret_cast(geom); + const auto *g1 = reinterpret_cast(geom); std::unique_ptr result; try { @@ -1360,16 +1366,17 @@ sfcgal_approx_convex_partition_2(const sfcgal_geometry_t *geom) SFCGAL_WARNING(" with A: %s", ((const SFCGAL::Geometry *)(geom))->asText().c_str()); SFCGAL_ERROR("%s", e.what()); - return 0; + return nullptr; } return result.release(); } -extern "C" sfcgal_geometry_t * +extern "C" auto sfcgal_greene_approx_convex_partition_2(const sfcgal_geometry_t *geom) + -> sfcgal_geometry_t * { - const SFCGAL::Geometry *g1 = reinterpret_cast(geom); + const auto *g1 = reinterpret_cast(geom); std::unique_ptr result; try { @@ -1381,15 +1388,16 @@ sfcgal_greene_approx_convex_partition_2(const sfcgal_geometry_t *geom) SFCGAL_WARNING(" with A: %s", ((const SFCGAL::Geometry *)(geom))->asText().c_str()); SFCGAL_ERROR("%s", e.what()); - return 0; + return nullptr; } return result.release(); } -extern "C" sfcgal_geometry_t * +extern "C" auto sfcgal_optimal_convex_partition_2(const sfcgal_geometry_t *geom) + -> sfcgal_geometry_t * { - const SFCGAL::Geometry *g1 = reinterpret_cast(geom); + const auto *g1 = reinterpret_cast(geom); std::unique_ptr result; try { @@ -1400,15 +1408,16 @@ sfcgal_optimal_convex_partition_2(const sfcgal_geometry_t *geom) SFCGAL_WARNING(" with A: %s", ((const SFCGAL::Geometry *)(geom))->asText().c_str()); SFCGAL_ERROR("%s", e.what()); - return 0; + return nullptr; } return result.release(); } -extern "C" sfcgal_geometry_t * +extern "C" auto sfcgal_geometry_visibility_point(const sfcgal_geometry_t *polygon, const sfcgal_geometry_t *point) + -> sfcgal_geometry_t * { const auto *poly = reinterpret_cast(polygon); @@ -1439,10 +1448,11 @@ sfcgal_geometry_visibility_point(const sfcgal_geometry_t *polygon, return result.release(); } -extern "C" sfcgal_geometry_t * +extern "C" auto sfcgal_geometry_visibility_segment(const sfcgal_geometry_t *polygon, const sfcgal_geometry_t *pointA, const sfcgal_geometry_t *pointB) + -> sfcgal_geometry_t * { const auto *poly = reinterpret_cast(polygon); const auto *ptA = reinterpret_cast(pointA); diff --git a/src/detail/EnvelopeVisitor.cpp b/src/detail/EnvelopeVisitor.cpp index 3fdde2e2..1625a639 100644 --- a/src/detail/EnvelopeVisitor.cpp +++ b/src/detail/EnvelopeVisitor.cpp @@ -17,8 +17,7 @@ #include #include -namespace SFCGAL { -namespace detail { +namespace SFCGAL::detail { /// /// @@ -155,5 +154,4 @@ EnvelopeVisitor::visit(const TriangulatedSurface &g) } } -} // namespace detail -} // namespace SFCGAL +} // namespace SFCGAL::detail diff --git a/src/detail/ForceValidityVisitor.cpp b/src/detail/ForceValidityVisitor.cpp index debd1a5e..a1eb7366 100644 --- a/src/detail/ForceValidityVisitor.cpp +++ b/src/detail/ForceValidityVisitor.cpp @@ -17,8 +17,7 @@ #include #include -namespace SFCGAL { -namespace detail { +namespace SFCGAL::detail { /// /// @@ -161,5 +160,4 @@ ForceValidityVisitor::visit(TriangulatedSurface &g) } } -} // namespace detail -} // namespace SFCGAL +} // namespace SFCGAL::detail diff --git a/src/detail/GeometrySet.cpp b/src/detail/GeometrySet.cpp index 571b10f8..1bf2abba 100644 --- a/src/detail/GeometrySet.cpp +++ b/src/detail/GeometrySet.cpp @@ -52,12 +52,12 @@ operator<(const CGAL::Segment_3 &sega, return sega.source() < segb.source(); } -namespace SFCGAL { -namespace detail { +namespace SFCGAL::detail { void _decompose_triangle(const Triangle &tri, - GeometrySet<2>::SurfaceCollection &surfaces, dim_t<2>) + GeometrySet<2>::SurfaceCollection &surfaces, + dim_t<2> /*unused*/) { CGAL::Polygon_2 outer; outer.push_back(tri.vertex(0).toPoint_2()); @@ -72,24 +72,27 @@ _decompose_triangle(const Triangle &tri, } void _decompose_triangle(const Triangle &tri, - GeometrySet<3>::SurfaceCollection &surfaces, dim_t<3>) + GeometrySet<3>::SurfaceCollection &surfaces, + dim_t<3> /*unused*/) { - CGAL::Triangle_3 outtri(tri.vertex(0).toPoint_3(), - tri.vertex(1).toPoint_3(), - tri.vertex(2).toPoint_3()); + CGAL::Triangle_3 const outtri(tri.vertex(0).toPoint_3(), + tri.vertex(1).toPoint_3(), + tri.vertex(2).toPoint_3()); surfaces.push_back(outtri); } void _decompose_polygon(const Polygon &poly, - GeometrySet<2>::SurfaceCollection &surfaces, dim_t<2>) + GeometrySet<2>::SurfaceCollection &surfaces, + dim_t<2> /*unused*/) { BOOST_ASSERT(!poly.isEmpty()); surfaces.push_back(poly.toPolygon_with_holes_2()); } void _decompose_polygon(const Polygon &poly, - GeometrySet<3>::SurfaceCollection &surfaces, dim_t<3>) + GeometrySet<3>::SurfaceCollection &surfaces, + dim_t<3> /*unused*/) { BOOST_ASSERT(!poly.isEmpty()); TriangulatedSurface surf; @@ -104,12 +107,14 @@ _decompose_polygon(const Polygon &poly, } void -_decompose_solid(const Solid &, GeometrySet<2>::VolumeCollection &, dim_t<2>) +_decompose_solid(const Solid & /*unused*/, + GeometrySet<2>::VolumeCollection & /*unused*/, + dim_t<2> /*unused*/) { } void _decompose_solid(const Solid &solid, GeometrySet<3>::VolumeCollection &volumes, - dim_t<3>) + dim_t<3> /*unused*/) { BOOST_ASSERT(!solid.isEmpty()); // volume orientation test @@ -262,7 +267,7 @@ GeometrySet<3>::addPrimitive(const CGAL::Object &o, bool pointsAsRing) // close the ring ls.addPoint((*pts)[0]); - Polygon poly(ls); + Polygon const poly(ls); _decompose_polygon(poly, _surfaces, dim_t<3>()); } else { std::copy(pts->begin(), pts->end(), @@ -298,7 +303,7 @@ GeometrySet<2>::addPrimitive(const CGAL::Object &o, bool pointsAsRing) poly.push_back(pt); } - CGAL::Polygon_with_holes_2 polyh(poly); + CGAL::Polygon_with_holes_2 const polyh(poly); _surfaces.push_back(polyh); } else { std::copy(pts->begin(), pts->end(), @@ -311,7 +316,7 @@ GeometrySet<2>::addPrimitive(const CGAL::Object &o, bool pointsAsRing) poly.push_back(tri->vertex(0)); poly.push_back(tri->vertex(1)); poly.push_back(tri->vertex(2)); - CGAL::Polygon_with_holes_2 polyh(poly); + CGAL::Polygon_with_holes_2 const polyh(poly); _surfaces.push_back(polyh); } else if (const auto *p = CGAL::object_cast(&o)) { _segments.insert(TSegment(*p)); @@ -372,7 +377,9 @@ GeometrySet<3>::addPrimitive(const TypeForDimension<3>::Volume &p, int flags) } else { // it is an unclosed volume, i.e. a surface BOOST_ASSERT(p.is_pure_triangle()); - CGAL::Point_3 p1, p2, p3; + CGAL::Point_3 p1; + CGAL::Point_3 p2; + CGAL::Point_3 p3; for (MarkedPolyhedron::Facet_const_iterator fit = p.facets_begin(); fit != p.facets_end(); ++fit) { @@ -383,7 +390,7 @@ GeometrySet<3>::addPrimitive(const TypeForDimension<3>::Volume &p, int flags) p2 = cit->vertex()->point(); cit++; p3 = cit->vertex()->point(); - CGAL::Triangle_3 tri(p1, p2, p3); + CGAL::Triangle_3 const tri(p1, p2, p3); _surfaces.push_back(tri); } } @@ -479,7 +486,7 @@ GeometrySet::_decompose(const Geometry &g) const auto &ls = g.as(); for (size_t i = 0; i < ls.numPoints() - 1; ++i) { - typename TypeForDimension::Segment seg( + typename TypeForDimension::Segment const seg( ls.pointN(i).toPoint_d(), ls.pointN(i + 1).toPoint_d()); _segments.insert(seg); } @@ -538,7 +545,7 @@ GeometrySet::computeBoundingBoxes( for (auto it = _points.begin(); it != _points.end(); ++it) { const typename TypeForDimension::Point *pt = &(it->primitive()); - PrimitiveHandle h(pt); + PrimitiveHandle const h(pt); handles.push_back(h); boxes.push_back(typename PrimitiveBox::Type(it->primitive().bbox(), &handles.back())); @@ -566,15 +573,14 @@ GeometrySet::computeBoundingBoxes( template void recompose_points(const typename GeometrySet::PointCollection &points, - std::vector &rpoints, dim_t) + std::vector &rpoints, dim_t /*unused*/) { if (points.empty()) { return; // rpoints.push_back( new Point() ); - } else { - for (auto it = points.begin(); it != points.end(); ++it) { - rpoints.push_back(new Point(it->primitive())); - } + } + for (auto it = points.begin(); it != points.end(); ++it) { + rpoints.push_back(new Point(it->primitive())); } } @@ -599,7 +605,7 @@ struct ComparePoints { template void recompose_segments(const typename GeometrySet::SegmentCollection &segments, - std::vector &lines, dim_t) + std::vector &lines, dim_t /*unused*/) { if (segments.empty()) { // lines.push_back( new LineString ); @@ -618,11 +624,9 @@ recompose_segments(const typename GeometrySet::SegmentCollection &segments, PointMap pointMap; for (auto it = segments.begin(); it != segments.end(); ++it) { - const typename PointMap::const_iterator foundSource = - pointMap.find(it->primitive().source()); - const typename PointMap::const_iterator foundTarget = - pointMap.find(it->primitive().target()); - const int sourceId = + const auto foundSource = pointMap.find(it->primitive().source()); + const auto foundTarget = pointMap.find(it->primitive().target()); + const int sourceId = foundSource != pointMap.end() ? foundSource->second : points.size(); if (foundSource == pointMap.end()) { @@ -649,7 +653,8 @@ recompose_segments(const typename GeometrySet::SegmentCollection &segments, // now we find all branches without bifurcations, - boost::graph_traits::edge_iterator ei, ei_end; + boost::graph_traits::edge_iterator ei; + boost::graph_traits::edge_iterator ei_end; for (boost::tie(ei, ei_end) = boost::edges(g); ei != ei_end; ++ei) { if (boost::get(boost::edge_color, g)[*ei] == boost::white_color) { @@ -657,7 +662,8 @@ recompose_segments(const typename GeometrySet::SegmentCollection &segments, // or no connections or self (in case of a loop) boost::graph_traits::edge_descriptor root = *ei; { - boost::graph_traits::in_edge_iterator ej, ek; + boost::graph_traits::in_edge_iterator ej; + boost::graph_traits::in_edge_iterator ek; for (boost::tie(ej, ek) = boost::in_edges(boost::source(root, g), g); ek - ej == 1 && *ej != *ei; @@ -673,7 +679,8 @@ recompose_segments(const typename GeometrySet::SegmentCollection &segments, line->addPoint(points[boost::target(root, g)]); boost::get(boost::edge_color, g)[root] = boost::black_color; - boost::graph_traits::out_edge_iterator ej, ek; + boost::graph_traits::out_edge_iterator ej; + boost::graph_traits::out_edge_iterator ek; for (boost::tie(ej, ek) = boost::out_edges(boost::target(root, g), g); ek - ej == 1 && *ej != root; @@ -687,15 +694,15 @@ recompose_segments(const typename GeometrySet::SegmentCollection &segments, void recompose_surfaces(const GeometrySet<2>::SurfaceCollection &surfaces, - std::vector &output, dim_t<2>) + std::vector &output, dim_t<2> /*unused*/) { for (const auto &surface : surfaces) { if (surface.primitive().holes_begin() == surface.primitive().holes_end() && surface.primitive().outer_boundary().size() == 3) { auto vit = surface.primitive().outer_boundary().vertices_begin(); - CGAL::Point_2 p1(*vit++); - CGAL::Point_2 p2(*vit++); - CGAL::Point_2 p3(*vit++); + CGAL::Point_2 const p1(*vit++); + CGAL::Point_2 const p2(*vit++); + CGAL::Point_2 const p3(*vit++); output.push_back(new Triangle(CGAL::Triangle_2(p1, p2, p3))); } else { output.push_back(new Polygon(surface.primitive())); @@ -705,7 +712,7 @@ recompose_surfaces(const GeometrySet<2>::SurfaceCollection &surfaces, void recompose_surfaces(const GeometrySet<3>::SurfaceCollection &surfaces, - std::vector &output, dim_t<3>) + std::vector &output, dim_t<3> /*unused*/) { if (surfaces.empty()) { return; @@ -723,11 +730,11 @@ recompose_surfaces(const GeometrySet<3>::SurfaceCollection &surfaces, tri->addTriangle(new Triangle(surface.primitive())); } - algorithm::SurfaceGraph graph(*tri); - std::vector component(boost::num_vertices(graph.faceGraph())); + algorithm::SurfaceGraph const graph(*tri); + std::vector component(boost::num_vertices(graph.faceGraph())); BOOST_ASSERT(tri->numTriangles() == component.size()); const size_t numComponents = - boost::connected_components(graph.faceGraph(), &component[0]); + boost::connected_components(graph.faceGraph(), component.data()); if (1 == numComponents) { output.push_back(tri.release()); @@ -748,21 +755,21 @@ recompose_surfaces(const GeometrySet<3>::SurfaceCollection &surfaces, } void -recompose_volumes(const GeometrySet<2>::VolumeCollection &, - std::vector &, dim_t<2>) +recompose_volumes(const GeometrySet<2>::VolumeCollection & /*unused*/, + std::vector & /*unused*/, dim_t<2> /*unused*/) { } void recompose_volumes(const GeometrySet<3>::VolumeCollection &volumes, - std::vector &output, dim_t<3>) + std::vector &output, dim_t<3> /*unused*/) { if (volumes.empty()) { return; } for (const auto &volume : volumes) { - if (volume.flags() & FLAG_IS_PLANAR) { + if ((volume.flags() & FLAG_IS_PLANAR) != 0) { // extract the boundary std::list> boundary; @@ -773,14 +780,14 @@ recompose_volumes(const GeometrySet<3>::VolumeCollection &volumes, continue; } - CGAL::Point_3 p1 = it->prev()->vertex()->point(); - CGAL::Point_3 p2 = it->vertex()->point(); + CGAL::Point_3 const p1 = it->prev()->vertex()->point(); + CGAL::Point_3 const p2 = it->vertex()->point(); // TODO: test for colinearity // Temporary vertice may have been introduced during triangulations // and since we expect here a planar surface, it is safe to simplify the // boundary by eliminating collinear points. - if (boundary.size() == 0) { + if (boundary.empty()) { boundary.push_back(p1); boundary.push_back(p2); } else if (boundary.back() == p1) { @@ -793,8 +800,8 @@ recompose_volumes(const GeometrySet<3>::VolumeCollection &volumes, if (boundary.size() == 3) { // It is a triangle - Point p[3]; - std::list>::const_iterator it = boundary.begin(); + Point p[3]; + auto it = boundary.begin(); for (size_t i = 0; i < 3; ++i, ++it) { p[i] = *it; @@ -805,10 +812,8 @@ recompose_volumes(const GeometrySet<3>::VolumeCollection &volumes, // Else it is a polygon auto *ls = new LineString; - for (std::list>::const_iterator it = - boundary.begin(); - it != boundary.end(); ++it) { - ls->addPoint(*it); + for (auto &it : boundary) { + ls->addPoint(it); } output.push_back(new Polygon(ls)); @@ -842,8 +847,8 @@ GeometrySet::recompose() const -> std::unique_ptr } // else we have a mix of different types - bool hasCommonType = true; - int commonType = geometries[0]->geometryTypeId(); + bool hasCommonType = true; + int const commonType = geometries[0]->geometryTypeId(); for (auto &geometrie : geometries) { if (geometrie->geometryTypeId() != commonType) { @@ -906,7 +911,8 @@ _collect_points(const CGAL::Triangle_3 &tri, } void -_collect_points(const NoVolume &, GeometrySet<2>::PointCollection &) +_collect_points(const NoVolume & /*unused*/, + GeometrySet<2>::PointCollection & /*unused*/) { } @@ -981,7 +987,7 @@ _filter_covered(IT ibegin, IT iend, GeometrySet &output) // if its not covered by another primitive if (!v1_covered) { // and not covered by another already inserted primitive - bool b = algorithm::covers(output, v1); + bool const b = algorithm::covers(output, v1); if (!b) { output.addPrimitive(it->primitive(), it->flags()); @@ -1004,7 +1010,7 @@ GeometrySet<2>::addBoundary(const TypeForDimension<2>::Surface &surface) template <> void -GeometrySet<3>::addBoundary(const TypeForDimension<3>::Surface &) +GeometrySet<3>::addBoundary(const TypeForDimension<3>::Surface & /*unused*/) { // TODO } @@ -1071,15 +1077,16 @@ auto operator<<(std::ostream &ostr, const GeometrySet<2> &g) -> std::ostream & { ostr << "points: "; - std::ostream_iterator::Type>> out_pt(ostr, ", "); + std::ostream_iterator::Type>> const out_pt(ostr, + ", "); std::copy(g.points().begin(), g.points().end(), out_pt); ostr << std::endl << "segments: "; - std::ostream_iterator::Type>> out_seg(ostr, - ", "); + std::ostream_iterator::Type>> const out_seg( + ostr, ", "); std::copy(g.segments().begin(), g.segments().end(), out_seg); ostr << std::endl << "surfaces: "; - std::ostream_iterator::Type>> out_surf(ostr, - ", "); + std::ostream_iterator::Type>> const out_surf( + ostr, ", "); std::copy(g.surfaces().begin(), g.surfaces().end(), out_surf); ostr << std::endl; return ostr; @@ -1089,19 +1096,20 @@ auto operator<<(std::ostream &ostr, const GeometrySet<3> &g) -> std::ostream & { ostr << "points: "; - std::ostream_iterator::Type>> out_pt(ostr, ", "); + std::ostream_iterator::Type>> const out_pt(ostr, + ", "); std::copy(g.points().begin(), g.points().end(), out_pt); ostr << std::endl << "segments: "; - std::ostream_iterator::Type>> out_seg(ostr, - ", "); + std::ostream_iterator::Type>> const out_seg( + ostr, ", "); std::copy(g.segments().begin(), g.segments().end(), out_seg); ostr << std::endl << "surfaces: "; - std::ostream_iterator::Type>> out_surf(ostr, - ", "); + std::ostream_iterator::Type>> const out_surf( + ostr, ", "); std::copy(g.surfaces().begin(), g.surfaces().end(), out_surf); ostr << std::endl << "volumes: "; - std::ostream_iterator::Type>> out_vol(ostr, - ", "); + std::ostream_iterator::Type>> const out_vol( + ostr, ", "); std::copy(g.volumes().begin(), g.volumes().end(), out_vol); ostr << std::endl; return ostr; @@ -1109,5 +1117,4 @@ operator<<(std::ostream &ostr, const GeometrySet<3> &g) -> std::ostream & template class GeometrySet<2>; template class GeometrySet<3>; -} // namespace detail -} // namespace SFCGAL +} // namespace SFCGAL::detail diff --git a/src/detail/GetPointsVisitor.cpp b/src/detail/GetPointsVisitor.cpp index 24eb203a..b5da36b4 100644 --- a/src/detail/GetPointsVisitor.cpp +++ b/src/detail/GetPointsVisitor.cpp @@ -17,8 +17,7 @@ #include #include -namespace SFCGAL { -namespace detail { +namespace SFCGAL::detail { /// /// @@ -150,5 +149,4 @@ GetPointsVisitor::visit(const TriangulatedSurface &g) } } -} // namespace detail -} // namespace SFCGAL +} // namespace SFCGAL::detail diff --git a/src/detail/Interval.cpp b/src/detail/Interval.cpp index 271d8b05..ca95e195 100644 --- a/src/detail/Interval.cpp +++ b/src/detail/Interval.cpp @@ -7,8 +7,7 @@ #include -namespace SFCGAL { -namespace detail { +namespace SFCGAL::detail { /// /// @@ -44,7 +43,6 @@ Interval::operator=(const Interval &other) -> Interval & = default; /// /// /// -Interval::~Interval() = default; /// /// @@ -118,7 +116,7 @@ Interval::intersects(const Interval &other) const -> bool return false; } - return !(_lower > other._upper || _upper < other._lower); + return _lower <= other._upper && _upper >= other._lower; } /// @@ -143,5 +141,4 @@ Interval::operator!=(const Interval &other) const -> bool return !((*this) == other); } -} // namespace detail -} // namespace SFCGAL +} // namespace SFCGAL::detail diff --git a/src/detail/Interval.h b/src/detail/Interval.h index cf425bde..a7c23b13 100644 --- a/src/detail/Interval.h +++ b/src/detail/Interval.h @@ -36,10 +36,6 @@ class SFCGAL_API Interval { */ Interval & operator=(const Interval &other); - /** - * destructor - */ - ~Interval(); /** * indicates if the interval is empty diff --git a/src/detail/algorithm/coversPoints.cpp b/src/detail/algorithm/coversPoints.cpp index 72b11dbe..eca7b87b 100644 --- a/src/detail/algorithm/coversPoints.cpp +++ b/src/detail/algorithm/coversPoints.cpp @@ -9,9 +9,7 @@ #include #include -namespace SFCGAL { -namespace detail { -namespace algorithm { +namespace SFCGAL::detail::algorithm { template auto _coversPoints(const Geometry &ga, const Geometry &gb) -> bool @@ -20,18 +18,15 @@ _coversPoints(const Geometry &ga, const Geometry &gb) -> bool return false; } - GeometrySet gsa(ga); + GeometrySet const gsa(ga); // get all points of gb; detail::GetPointsVisitor visitor; gb.accept(visitor); - for (detail::GetPointsVisitor::const_iterator it = visitor.points.begin(); - it != visitor.points.end(); ++it) { - const Point *ppt = *it; - + for (const auto *ppt : visitor.points) { // a geometry set of one point - GeometrySet gsp(*ppt); + GeometrySet const gsp(*ppt); if (!SFCGAL::algorithm::intersects(gsp, gsa)) { return false; @@ -52,6 +47,4 @@ coversPoints3D(const Geometry &ga, const Geometry &gb) -> bool { return _coversPoints<3>(ga, gb); } -} // namespace algorithm -} // namespace detail -} // namespace SFCGAL +} // namespace SFCGAL::detail::algorithm diff --git a/src/detail/generator/building.cpp b/src/detail/generator/building.cpp index 5465d9b1..2a27cdbd 100644 --- a/src/detail/generator/building.cpp +++ b/src/detail/generator/building.cpp @@ -16,8 +16,7 @@ #include -namespace SFCGAL { -namespace generator { +namespace SFCGAL::generator { using Point_2 = Kernel::Point_2; using Point_3 = Kernel::Point_3; @@ -42,7 +41,7 @@ void _buildingWall(const Polygon_2 &ring, const Kernel::FT &wallHeight, PolyhedralSurface &shell) { - size_t npt = ring.size(); + size_t const npt = ring.size(); for (size_t i = 0; i < npt; i++) { const Point_2 &a = ring.vertex(i); @@ -77,7 +76,7 @@ building(const Polygon &g, const Kernel::FT &wallHeight, // fix orientation algorithm::makeValidOrientation(polygon); - boost::shared_ptr skeleton = + boost::shared_ptr const skeleton = create_interior_straight_skeleton_2( polygon.outer_boundary().vertices_begin(), polygon.outer_boundary().vertices_end(), polygon.holes_begin(), @@ -98,8 +97,7 @@ building(const Polygon &g, const Kernel::FT &wallHeight, _buildingWall(polygon.outer_boundary(), wallHeight, *shell); // interior rings - for (Polygon_with_holes_2::Hole_const_iterator it = polygon.holes_begin(); - it != polygon.holes_end(); ++it) { + for (auto it = polygon.holes_begin(); it != polygon.holes_end(); ++it) { _buildingWall(*it, wallHeight, *shell); } } @@ -109,15 +107,16 @@ building(const Polygon &g, const Kernel::FT &wallHeight, for (Face_const_iterator it = skeleton->faces_begin(); it != skeleton->faces_end(); ++it) { - LineString roofFaceRing; - Halfedge_const_handle h = it->halfedge(), done(h); - bool infiniteTimeFound = false; + LineString roofFaceRing; + Halfedge_const_handle h = it->halfedge(); + Halfedge_const_handle const done(h); + bool infiniteTimeFound = false; do { infiniteTimeFound = infiniteTimeFound || h->has_infinite_time(); - Point_2 point = h->vertex()->point(); - Kernel::FT zPoint = wallHeight + h->vertex()->time() * roofSlope; + Point_2 const point = h->vertex()->point(); + Kernel::FT const zPoint = wallHeight + h->vertex()->time() * roofSlope; roofFaceRing.addPoint(Point(point.x(), point.y(), zPoint)); @@ -174,5 +173,4 @@ building(const Geometry &g, const Kernel::FT &wallHeight, } } -} // namespace generator -} // namespace SFCGAL +} // namespace SFCGAL::generator diff --git a/src/detail/generator/disc.cpp b/src/detail/generator/disc.cpp index bb329f05..7f4d8be6 100644 --- a/src/detail/generator/disc.cpp +++ b/src/detail/generator/disc.cpp @@ -13,10 +13,10 @@ #include #include +#include #include -namespace SFCGAL { -namespace generator { +namespace SFCGAL::generator { /// /// @@ -29,10 +29,11 @@ disc(const Point ¢er, const double &radius, std::unique_ptr exteriorRing(new LineString()); - double dTheta = M_PI_4 / nQuadrantSegments; + double const dTheta = M_PI_4 / nQuadrantSegments; - for (size_t i = 0; i < nQuadrantSegments * 4; i++) { - Kernel::Vector_2 p = + for (size_t i = 0; i < static_cast(nQuadrantSegments) * 4; + i++) { + Kernel::Vector_2 const p = center.toVector_2() + radius * Kernel::Vector_2(cos(i * dTheta), sin(i * dTheta)); exteriorRing->addPoint(new Point(p.x(), p.y())); @@ -43,5 +44,4 @@ disc(const Point ¢er, const double &radius, return std::make_unique(exteriorRing.release()); } -} // namespace generator -} // namespace SFCGAL +} // namespace SFCGAL::generator diff --git a/src/detail/generator/hoch.cpp b/src/detail/generator/hoch.cpp index f7daeb1d..8c5af916 100644 --- a/src/detail/generator/hoch.cpp +++ b/src/detail/generator/hoch.cpp @@ -7,8 +7,7 @@ #include #include -namespace SFCGAL { -namespace generator { +namespace SFCGAL::generator { auto _hoch(const std::vector &points) @@ -16,14 +15,14 @@ _hoch(const std::vector &points) { std::vector result; result.reserve(points.size() * 2); - size_t numPoints = points.size(); + size_t const numPoints = points.size(); for (size_t i = 0; i < numPoints; i++) { const Kernel::Vector_2 &a = points[i]; const Kernel::Vector_2 &b = points[(i + 1) % numPoints]; - Kernel::Vector_2 ab = b - a; - Kernel::Vector_2 normal(-ab.y(), ab.x()); + Kernel::Vector_2 const ab = b - a; + Kernel::Vector_2 const normal(-ab.y(), ab.x()); result.push_back(a); result.push_back(a + ab / 3); @@ -52,9 +51,8 @@ hoch(const unsigned int &order) -> std::unique_ptr std::unique_ptr result(new Polygon()); std::unique_ptr ring(new LineString()); - for (std::vector::const_iterator it = points.begin(); - it != points.end(); ++it) { - ring->addPoint(new Point(it->x(), it->y())); + for (auto &point : points) { + ring->addPoint(new Point(point.x(), point.y())); } ring->addPoint(new Point(points.front().x(), points.front().y())); @@ -64,5 +62,4 @@ hoch(const unsigned int &order) -> std::unique_ptr return result; } -} // namespace generator -} // namespace SFCGAL +} // namespace SFCGAL::generator diff --git a/src/detail/generator/sierpinski.cpp b/src/detail/generator/sierpinski.cpp index 25e36cd9..62acfc81 100644 --- a/src/detail/generator/sierpinski.cpp +++ b/src/detail/generator/sierpinski.cpp @@ -7,8 +7,7 @@ #include #include -namespace SFCGAL { -namespace generator { +namespace SFCGAL::generator { auto _sierpinski(const std::vector &triangles) @@ -22,9 +21,9 @@ _sierpinski(const std::vector &triangles) const Kernel::Point_2 &b = triangle.vertex(1); const Kernel::Point_2 &c = triangle.vertex(2); - Kernel::Point_2 iAB = a + (b - a) / 2; - Kernel::Point_2 iBC = b + (c - b) / 2; - Kernel::Point_2 iCA = c + (a - c) / 2; + Kernel::Point_2 const iAB = a + (b - a) / 2; + Kernel::Point_2 const iBC = b + (c - b) / 2; + Kernel::Point_2 const iCA = c + (a - c) / 2; result.emplace_back(a, iAB, iCA); result.emplace_back(b, iBC, iAB); @@ -57,5 +56,4 @@ sierpinski(const unsigned int &order) -> std::unique_ptr return result; } -} // namespace generator -} // namespace SFCGAL +} // namespace SFCGAL::generator diff --git a/src/detail/graph/Edge.cpp b/src/detail/graph/Edge.cpp index 84e0c8cb..39b3fbb9 100644 --- a/src/detail/graph/Edge.cpp +++ b/src/detail/graph/Edge.cpp @@ -4,13 +4,11 @@ #include -namespace SFCGAL { -namespace graph { +namespace SFCGAL::graph { /// /// /// Edge::Edge(const int &face_) : face(face_) {} -} // namespace graph -} // namespace SFCGAL +} // namespace SFCGAL::graph diff --git a/src/detail/graph/Vertex.cpp b/src/detail/graph/Vertex.cpp index ae3e54e4..d6f2d856 100644 --- a/src/detail/graph/Vertex.cpp +++ b/src/detail/graph/Vertex.cpp @@ -4,13 +4,11 @@ #include -namespace SFCGAL { -namespace graph { +namespace SFCGAL::graph { /// /// /// Vertex::Vertex(const Coordinate &coordinate_) : coordinate(coordinate_) {} -} // namespace graph -} // namespace SFCGAL +} // namespace SFCGAL::graph diff --git a/src/detail/io/Serialization.cpp b/src/detail/io/Serialization.cpp index 548b420c..6bc9946f 100644 --- a/src/detail/io/Serialization.cpp +++ b/src/detail/io/Serialization.cpp @@ -17,8 +17,7 @@ #include #include -namespace SFCGAL { -namespace io { +namespace SFCGAL::io { BinarySerializer::BinarySerializer(std::ostream &ostr) : boost::archive::binary_oarchive(ostr) @@ -108,10 +107,8 @@ readBinaryPrepared(const std::string &str) -> std::unique_ptr iarc >> pg; return std::unique_ptr(pg); } -} // namespace io -} // namespace SFCGAL -namespace boost { -namespace serialization { +} // namespace SFCGAL::io +namespace boost::serialization { void save(boost::archive::text_oarchive &ar, const CGAL::Gmpz &z, @@ -119,7 +116,7 @@ save(boost::archive::text_oarchive &ar, const CGAL::Gmpz &z, { std::ostringstream ostr; ostr << z; - std::string str = ostr.str(); + std::string const str = ostr.str(); ar << str; } @@ -128,10 +125,10 @@ void save(boost::archive::binary_oarchive &ar, const CGAL::Gmpz &z, const unsigned int /* version*/) { - const mpz_t &mpz = z.mpz(); - int32_t size = mpz->_mp_size; - ar &size; - uint32_t rsize = size >= 0 ? size : -size; + const mpz_t &mpz = z.mpz(); + int32_t const size = mpz->_mp_size; + ar &size; + uint32_t const rsize = size >= 0 ? size : -size; for (uint32_t i = 0; i < rsize; ++i) { ar & mpz->_mp_d[i]; @@ -173,7 +170,7 @@ save(boost::archive::text_oarchive &ar, const mpz_class &z, { std::ostringstream ostr; ostr << z; - std::string str = ostr.str(); + std::string const str = ostr.str(); ar << str; } @@ -182,10 +179,10 @@ void save(boost::archive::binary_oarchive &ar, const mpz_class &z, const unsigned int /* version*/) { - mpz_srcptr mpz = z.get_mpz_t(); - int32_t size = mpz->_mp_size; - ar &size; - uint32_t rsize = size >= 0 ? size : -size; + mpz_srcptr mpz = z.get_mpz_t(); + int32_t const size = mpz->_mp_size; + ar &size; + uint32_t const rsize = size >= 0 ? size : -size; for (uint32_t i = 0; i < rsize; ++i) { ar & mpz->_mp_d[i]; @@ -221,5 +218,4 @@ load(boost::archive::binary_iarchive &ar, mpz_class &z, } #endif -} // namespace serialization -} // namespace boost +} // namespace boost::serialization diff --git a/src/detail/io/WkbReader.cpp b/src/detail/io/WkbReader.cpp index 3d96f383..12e7fe94 100644 --- a/src/detail/io/WkbReader.cpp +++ b/src/detail/io/WkbReader.cpp @@ -27,15 +27,15 @@ namespace SFCGAL::detail::io { auto WkbReader::readInnerPoint() -> Point { - double x{read()}; - double y{read()}; + double const x{read()}; + double const y{read()}; if (!(std::isfinite(x) && std::isfinite(y))) { return {}; } if (_is3D && _isMeasured) { - double z{read()}; - double m{read()}; + double const z{read()}; + double const m{read()}; if (!(std::isfinite(z) && std::isfinite(m))) { return {}; @@ -43,7 +43,7 @@ WkbReader::readInnerPoint() -> Point return SFCGAL::Point{x, y, z, m}; } if (_is3D) { - double z{read()}; + double const z{read()}; if (!(std::isfinite(z))) { return {}; } @@ -51,7 +51,7 @@ WkbReader::readInnerPoint() -> Point } if (_isMeasured) { - double m{read()}; + double const m{read()}; if (!(std::isfinite(m))) { return {}; } @@ -91,7 +91,7 @@ WkbReader::readInnerPolygon() -> Polygon try { const uint32_t numRings{read()}; for (uint32_t i = 0; i < numRings; ++i) { - SFCGAL::LineString ls{readInnerLineString()}; + SFCGAL::LineString const ls{readInnerLineString()}; if (i == 0) { result.setExteriorRing(ls); @@ -163,7 +163,7 @@ WkbReader::readInnerGeometryCollection() -> GeometryCollection const uint32_t numGeoms{read()}; for (uint32_t i = 0; i < numGeoms; ++i) { readWkb(); - if (_geometry.get() != nullptr) { + if (_geometry != nullptr) { result.addGeometry(_geometry.release()); } } @@ -185,8 +185,8 @@ WkbReader::readInnerTriangulatedSurface() -> TriangulatedSurface const uint32_t numGeoms{read()}; for (uint32_t i = 0; i < numGeoms; ++i) { readWkb(); - if (_geometry.get() != nullptr) { - SFCGAL::Triangle geom{_geometry->as()}; + if (_geometry != nullptr) { + SFCGAL::Triangle const geom{_geometry->as()}; result.addTriangle(geom); } } @@ -208,7 +208,7 @@ WkbReader::readInnerPolyhedralSurface() -> PolyhedralSurface const uint32_t numGeoms{read()}; for (uint32_t i = 0; i < numGeoms; ++i) { readWkb(); - if (_geometry.get() != nullptr) { + if (_geometry != nullptr) { geoms.push_back(_geometry->as()); } } @@ -216,7 +216,7 @@ WkbReader::readInnerPolyhedralSurface() -> PolyhedralSurface std::cerr << e.what(); return {}; } - SFCGAL::PolyhedralSurface result{geoms}; + SFCGAL::PolyhedralSurface const result{geoms}; return result; } diff --git a/src/detail/io/WktReader.cpp b/src/detail/io/WktReader.cpp index 01174e59..bd8af048 100644 --- a/src/detail/io/WktReader.cpp +++ b/src/detail/io/WktReader.cpp @@ -21,9 +21,7 @@ #include -namespace SFCGAL { -namespace detail { -namespace io { +namespace SFCGAL::detail::io { /// /// @@ -54,9 +52,9 @@ WktReader::readSRID() -> srid_t auto WktReader::readGeometry() -> Geometry * { - GeometryType geometryType = readGeometryType(); - _is3D = _reader.imatch("Z"); - _isMeasured = _reader.imatch("M"); + GeometryType const geometryType = readGeometryType(); + _is3D = _reader.imatch("Z"); + _isMeasured = _reader.imatch("M"); switch (geometryType) { case TYPE_POINT: { @@ -143,29 +141,40 @@ WktReader::readGeometryType() -> GeometryType { if (_reader.imatch("POINT")) { return TYPE_POINT; - } else if (_reader.imatch("LINESTRING")) { + } + if (_reader.imatch("LINESTRING")) { return TYPE_LINESTRING; - } else if (_reader.imatch("POLYGON")) { + } + if (_reader.imatch("POLYGON")) { return TYPE_POLYGON; - } else if (_reader.imatch("TRIANGLE")) { + } + if (_reader.imatch("TRIANGLE")) { // not official return TYPE_TRIANGLE; - } else if (_reader.imatch("MULTIPOINT")) { + } + if (_reader.imatch("MULTIPOINT")) { return TYPE_MULTIPOINT; - } else if (_reader.imatch("MULTILINESTRING")) { + } + if (_reader.imatch("MULTILINESTRING")) { return TYPE_MULTILINESTRING; - } else if (_reader.imatch("MULTIPOLYGON")) { + } + if (_reader.imatch("MULTIPOLYGON")) { return TYPE_MULTIPOLYGON; - } else if (_reader.imatch("GEOMETRYCOLLECTION")) { + } + if (_reader.imatch("GEOMETRYCOLLECTION")) { return TYPE_GEOMETRYCOLLECTION; - } else if (_reader.imatch("TIN")) { + } + if (_reader.imatch("TIN")) { return TYPE_TRIANGULATEDSURFACE; - } else if (_reader.imatch("POLYHEDRALSURFACE")) { + } + if (_reader.imatch("POLYHEDRALSURFACE")) { return TYPE_POLYHEDRALSURFACE; - } else if (_reader.imatch("SOLID")) { + } + if (_reader.imatch("SOLID")) { // not official return TYPE_SOLID; - } else if (_reader.imatch("MULTISOLID")) { + } + if (_reader.imatch("MULTISOLID")) { // not official return TYPE_MULTISOLID; } @@ -355,8 +364,9 @@ WktReader::readInnerMultiPoint(MultiPoint &g) } } - if (!p->isEmpty()) + if (!p->isEmpty()) { g.addGeometry(p.release()); + } // break if not followed by another points if (!_reader.match(',')) { @@ -387,8 +397,9 @@ WktReader::readInnerMultiLineString(MultiLineString &g) std::unique_ptr lineString(new LineString()); readInnerLineString(*lineString); - if (!lineString->isEmpty()) + if (!lineString->isEmpty()) { g.addGeometry(lineString.release()); + } // break if not followed by another points if (!_reader.match(',')) { @@ -419,8 +430,9 @@ WktReader::readInnerMultiPolygon(MultiPolygon &g) std::unique_ptr polygon(new Polygon()); readInnerPolygon(*polygon); - if (!polygon->isEmpty()) + if (!polygon->isEmpty()) { g.addGeometry(polygon.release()); + } // break if not followed by another points if (!_reader.match(',')) { @@ -451,8 +463,9 @@ WktReader::readInnerGeometryCollection(GeometryCollection &g) // read a full wkt geometry ex : POINT(2.0 6.0) Geometry *gg = readGeometry(); - if (!gg->isEmpty()) + if (!gg->isEmpty()) { g.addGeometry(gg); + } // break if not followed by another points if (!_reader.match(',')) { @@ -578,8 +591,9 @@ WktReader::readInnerMultiSolid(MultiSolid &g) std::unique_ptr solid(new Solid()); readInnerSolid(*solid); - if (!solid->isEmpty()) + if (!solid->isEmpty()) { g.addGeometry(solid.release()); + } // break if not followed by another points if (!_reader.match(',')) { @@ -661,6 +675,4 @@ WktReader::parseErrorMessage() -> std::string return oss.str(); } -} // namespace io -} // namespace detail -} // namespace SFCGAL +} // namespace SFCGAL::detail::io diff --git a/src/detail/io/WktWriter.cpp b/src/detail/io/WktWriter.cpp index 280ba498..59b56cc3 100644 --- a/src/detail/io/WktWriter.cpp +++ b/src/detail/io/WktWriter.cpp @@ -20,9 +20,7 @@ #include #include -namespace SFCGAL { -namespace detail { -namespace io { +namespace SFCGAL::detail::io { namespace impl { auto @@ -130,8 +128,8 @@ WktWriter::writeCoordinateType(const Geometry &g) } } -static double -fixZeroNeg(double val, int precision) +static auto +fixZeroNeg(double val, int precision) -> double { if (std::abs(val) < std::pow(10, -precision)) { return 0; @@ -542,6 +540,4 @@ WktWriter::writeInner(const Solid &g) _s << ")"; // end SOLID } -} // namespace io -} // namespace detail -} // namespace SFCGAL +} // namespace SFCGAL::detail::io diff --git a/src/detail/polygonSetToMultiPolygon.cpp b/src/detail/polygonSetToMultiPolygon.cpp index a7ae5456..ed463856 100644 --- a/src/detail/polygonSetToMultiPolygon.cpp +++ b/src/detail/polygonSetToMultiPolygon.cpp @@ -8,8 +8,7 @@ #include -namespace SFCGAL { -namespace detail { +namespace SFCGAL::detail { /// /// @@ -25,13 +24,11 @@ polygonSetToMultiPolygon(const CGAL::Polygon_set_2 &polygonSet) std::unique_ptr result(new MultiPolygon); - for (std::list::const_iterator it = res.begin(); - it != res.end(); ++it) { - result->addGeometry(new Polygon(*it)); + for (auto &re : res) { + result->addGeometry(new Polygon(re)); } return result; } -} // namespace detail -} // namespace SFCGAL +} // namespace SFCGAL::detail diff --git a/src/detail/tools/CharArrayBuffer.cpp b/src/detail/tools/CharArrayBuffer.cpp index 662bf92e..c9df2754 100644 --- a/src/detail/tools/CharArrayBuffer.cpp +++ b/src/detail/tools/CharArrayBuffer.cpp @@ -20,7 +20,7 @@ CharArrayBuffer::CharArrayBuffer(const char *str) auto CharArrayBuffer::seekoff(std::streamoff off, std::ios_base::seekdir way, - std::ios_base::openmode) -> std::streampos + std::ios_base::openmode /*__which*/) -> std::streampos { if (way == std::ios_base::cur) { if (current_ + off < end_) { @@ -40,8 +40,8 @@ CharArrayBuffer::seekoff(std::streamoff off, std::ios_base::seekdir way, } auto -CharArrayBuffer::seekpos(std::streampos pos, std::ios_base::openmode) - -> std::streampos +CharArrayBuffer::seekpos(std::streampos pos, + std::ios_base::openmode /*__which*/) -> std::streampos { if (begin_ + pos >= end_) { return -1; diff --git a/src/detail/tools/Registry.cpp b/src/detail/tools/Registry.cpp index de5d150d..81e81384 100644 --- a/src/detail/tools/Registry.cpp +++ b/src/detail/tools/Registry.cpp @@ -21,8 +21,7 @@ #include #include -namespace SFCGAL { -namespace tools { +namespace SFCGAL::tools { Registry *Registry::_instance = nullptr; @@ -43,7 +42,7 @@ void Registry::addPrototype(const Geometry &g) { // find prototype by name - const_prototype_iterator it = _prototypes.begin(); + auto it = _prototypes.begin(); for (; it != _prototypes.end(); ++it) { if ((*it)->geometryTypeId() == g.geometryTypeId()) { @@ -66,7 +65,8 @@ Registry::getGeometryTypes() const -> std::vector { std::vector names; - for (auto _prototype : _prototypes) { + names.reserve(_prototypes.size()); + for (auto *_prototype : _prototypes) { names.push_back(_prototype->geometryType()); } @@ -80,7 +80,7 @@ auto Registry::newGeometryByTypeName(const std::string &geometryTypeName) const -> Geometry * { - for (auto _prototype : _prototypes) { + for (auto *_prototype : _prototypes) { if (geometryTypeName == _prototype->geometryType()) { return _prototype->clone(); } @@ -98,7 +98,7 @@ Registry::newGeometryByTypeName(const std::string &geometryTypeName) const auto Registry::newGeometryByTypeId(int typeId) const -> Geometry * { - for (auto _prototype : _prototypes) { + for (auto *_prototype : _prototypes) { if (typeId == _prototype->geometryTypeId()) { return _prototype->clone(); } @@ -116,7 +116,7 @@ Registry::newGeometryByTypeId(int typeId) const -> Geometry * auto Registry::instance() -> Registry & { - if (!Registry::_instance) { + if (Registry::_instance == nullptr) { Registry::_instance = new Registry(); } @@ -126,7 +126,7 @@ Registry::instance() -> Registry & /// /// /// -Registry::Registry() : _prototypes() +Registry::Registry() { addPrototype(Point()); addPrototype(LineString()); @@ -145,5 +145,4 @@ Registry::Registry() : _prototypes() addPrototype(PolyhedralSurface()); } -} // namespace tools -} // namespace SFCGAL +} // namespace SFCGAL::tools diff --git a/src/detail/transform/AffineTransform2.cpp b/src/detail/transform/AffineTransform2.cpp index ebefb1be..5bd4a7c3 100644 --- a/src/detail/transform/AffineTransform2.cpp +++ b/src/detail/transform/AffineTransform2.cpp @@ -8,8 +8,7 @@ #include -namespace SFCGAL { -namespace transform { +namespace SFCGAL::transform { /// /// @@ -28,11 +27,11 @@ AffineTransform2::transform(Point &p) if (!p.isEmpty()) { // FIXME add a Point::Point( Kernel::Point_2&, double m ); Point pt(p.toPoint_2().transform(_transform)); - if (p.isMeasured()) + if (p.isMeasured()) { pt.setM(p.m()); + } p = pt; } } -} // namespace transform -} // namespace SFCGAL +} // namespace SFCGAL::transform diff --git a/src/detail/transform/AffineTransform3.cpp b/src/detail/transform/AffineTransform3.cpp index 8eafcd83..d2de2d09 100644 --- a/src/detail/transform/AffineTransform3.cpp +++ b/src/detail/transform/AffineTransform3.cpp @@ -22,8 +22,7 @@ #include -namespace SFCGAL { -namespace transform { +namespace SFCGAL::transform { /// /// @@ -41,8 +40,9 @@ AffineTransform3::transform(Point &p) { if (!p.isEmpty()) { Point pt(p.toPoint_3().transform(_transform)); - if (p.isMeasured()) + if (p.isMeasured()) { pt.setM(p.m()); + } p = pt; } } @@ -117,5 +117,4 @@ AffineTransform3::transform(Solid &solid) } } -} // namespace transform -} // namespace SFCGAL +} // namespace SFCGAL::transform diff --git a/src/detail/transform/Force2D.cpp b/src/detail/transform/Force2D.cpp index 0a285c22..49c5ae07 100644 --- a/src/detail/transform/Force2D.cpp +++ b/src/detail/transform/Force2D.cpp @@ -5,8 +5,7 @@ #include #include -namespace SFCGAL { -namespace transform { +namespace SFCGAL::transform { /// /// @@ -16,11 +15,11 @@ Force2D::transform(Point &p) { if (!p.isEmpty() && p.is3D()) { Point pt(p.x(), p.y()); - if (p.isMeasured()) + if (p.isMeasured()) { pt.setM(p.m()); + } p = pt; } } -} // namespace transform -} // namespace SFCGAL +} // namespace SFCGAL::transform diff --git a/src/detail/transform/ForceOrderPoints.cpp b/src/detail/transform/ForceOrderPoints.cpp index 87a823c2..77a3bcf7 100644 --- a/src/detail/transform/ForceOrderPoints.cpp +++ b/src/detail/transform/ForceOrderPoints.cpp @@ -8,8 +8,7 @@ #include #include -namespace SFCGAL { -namespace transform { +namespace SFCGAL::transform { /// /// @@ -20,7 +19,7 @@ ForceOrderPoints::ForceOrderPoints(bool orientCCW) : _orientCCW(orientCCW) {} /// /// void -ForceOrderPoints::transform(Point &) +ForceOrderPoints::transform(Point & /*p*/) { } @@ -82,5 +81,4 @@ ForceOrderPoints::visit(Polygon &p) } } -} // namespace transform -} // namespace SFCGAL +} // namespace SFCGAL::transform diff --git a/src/detail/transform/ForceZ.cpp b/src/detail/transform/ForceZ.cpp index f860e1c2..b47140c2 100644 --- a/src/detail/transform/ForceZ.cpp +++ b/src/detail/transform/ForceZ.cpp @@ -7,13 +7,12 @@ #include -namespace SFCGAL { -namespace transform { +namespace SFCGAL::transform { /// /// /// -ForceZ::ForceZ(const Kernel::FT defaultZ) : _defaultZ(std::move(defaultZ)) {} +ForceZ::ForceZ(Kernel::FT defaultZ) : _defaultZ(defaultZ) {} /// /// @@ -23,11 +22,11 @@ ForceZ::transform(Point &p) { if (!p.isEmpty() && !p.is3D()) { Point pt(p.x(), p.y(), _defaultZ); - if (p.isMeasured()) + if (p.isMeasured()) { pt.setM(p.m()); + } p = pt; } } -} // namespace transform -} // namespace SFCGAL +} // namespace SFCGAL::transform diff --git a/src/detail/transform/ForceZOrderPoints.cpp b/src/detail/transform/ForceZOrderPoints.cpp index 10f7ab94..52e409c7 100644 --- a/src/detail/transform/ForceZOrderPoints.cpp +++ b/src/detail/transform/ForceZOrderPoints.cpp @@ -10,14 +10,12 @@ #include -namespace SFCGAL { -namespace transform { +namespace SFCGAL::transform { /// /// /// -ForceZOrderPoints::ForceZOrderPoints(Kernel::FT defaultZ) - : _defaultZ(std::move(defaultZ)) +ForceZOrderPoints::ForceZOrderPoints(Kernel::FT defaultZ) : _defaultZ(defaultZ) { } @@ -72,5 +70,4 @@ ForceZOrderPoints::visit(Polygon &p) } } -} // namespace transform -} // namespace SFCGAL +} // namespace SFCGAL::transform diff --git a/src/detail/transform/RoundTransform.cpp b/src/detail/transform/RoundTransform.cpp index 912220ac..ba4a8d8f 100644 --- a/src/detail/transform/RoundTransform.cpp +++ b/src/detail/transform/RoundTransform.cpp @@ -6,8 +6,7 @@ #include -namespace SFCGAL { -namespace transform { +namespace SFCGAL::transform { /// /// @@ -23,5 +22,4 @@ RoundTransform::transform(Point &p) p.coordinate().round(_scale); } -} // namespace transform -} // namespace SFCGAL +} // namespace SFCGAL::transform diff --git a/src/detail/triangulate/ConstraintDelaunayTriangulation.cpp b/src/detail/triangulate/ConstraintDelaunayTriangulation.cpp index cde757d9..4da4712e 100644 --- a/src/detail/triangulate/ConstraintDelaunayTriangulation.cpp +++ b/src/detail/triangulate/ConstraintDelaunayTriangulation.cpp @@ -9,13 +9,12 @@ #include -namespace SFCGAL { -namespace triangulate { +namespace SFCGAL::triangulate { /// /// /// -ConstraintDelaunayTriangulation::ConstraintDelaunayTriangulation() : _cdt() {} +ConstraintDelaunayTriangulation::ConstraintDelaunayTriangulation() = default; /// /// @@ -97,10 +96,9 @@ ConstraintDelaunayTriangulation::projectionPlane() const -> Kernel::Plane_3 { if (_projectionPlane) { return *_projectionPlane; - } else { - return Kernel::Plane_3(Kernel::RT(0), Kernel::RT(0), Kernel::RT(1), - Kernel::RT(0)); } + return Kernel::Plane_3(Kernel::RT(0), Kernel::RT(0), Kernel::RT(1), + Kernel::RT(0)); } /// @@ -153,5 +151,4 @@ ConstraintDelaunayTriangulation::getTriangulatedSurface() const return result; } -} // namespace triangulate -} // namespace SFCGAL +} // namespace SFCGAL::triangulate diff --git a/src/detail/triangulate/triangulateInGeometrySet.cpp b/src/detail/triangulate/triangulateInGeometrySet.cpp index 9d5fd678..7b3615c9 100644 --- a/src/detail/triangulate/triangulateInGeometrySet.cpp +++ b/src/detail/triangulate/triangulateInGeometrySet.cpp @@ -13,8 +13,7 @@ using namespace SFCGAL::detail; -namespace SFCGAL { -namespace triangulate { +namespace SFCGAL::triangulate { /** * vertex information with original coordinates @@ -51,7 +50,7 @@ triangulate(const MarkedPolyhedron &polyhedron, GeometrySet<3> &geometry) ++pit; const CGAL::Point_3 &pt3 = pit->vertex()->point(); - CGAL::Triangle_3 tri(pt1, pt2, pt3); + CGAL::Triangle_3 const tri(pt1, pt2, pt3); geometry.addPrimitive(tri); } @@ -66,17 +65,17 @@ triangulate(const MarkedPolyhedron &polyhedron, GeometrySet<3> &geometry) triangulation.clear(); - CGAL::Plane_3 plane = fit->plane(); + CGAL::Plane_3 const plane = fit->plane(); BOOST_ASSERT(!plane.is_degenerate()); pit = fit->facet_begin(); do { const CGAL::Point_3 &pt3 = pit->vertex()->point(); - CGAL::Point_2 pt2 = plane.to_2d(pt3); + CGAL::Point_2 const pt2 = plane.to_2d(pt3); - Triangulation::Vertex_handle vh = triangulation.insert(pt2); - vh->info().original = &pt3; + Triangulation::Vertex_handle const vh = triangulation.insert(pt2); + vh->info().original = &pt3; pit++; } while (pit != fit->facet_begin()); @@ -88,7 +87,7 @@ triangulate(const MarkedPolyhedron &polyhedron, GeometrySet<3> &geometry) const CGAL::Point_3 *b = tit->vertex(1)->info().original; const CGAL::Point_3 *c = tit->vertex(2)->info().original; - CGAL::Triangle_3 tri(*a, *b, *c); + CGAL::Triangle_3 const tri(*a, *b, *c); geometry.addPrimitive(tri); } } @@ -102,7 +101,7 @@ triangulate(const CGAL::Polygon_with_holes_2 &polygon, GeometrySet<2> &output) { // FIXME: lots of copies here, can we avoid this ? - Polygon poly(polygon); + Polygon const poly(polygon); TriangulatedSurface surf; triangulatePolygon3D(poly, surf); @@ -111,5 +110,4 @@ triangulate(const CGAL::Polygon_with_holes_2 &polygon, } } -} // namespace triangulate -} // namespace SFCGAL +} // namespace SFCGAL::triangulate diff --git a/src/io/ewkt.cpp b/src/io/ewkt.cpp index ace58d5b..76c833c5 100644 --- a/src/io/ewkt.cpp +++ b/src/io/ewkt.cpp @@ -12,8 +12,7 @@ using namespace SFCGAL::detail::io; -namespace SFCGAL { -namespace io { +namespace SFCGAL::io { /// /// @@ -22,7 +21,7 @@ auto readEwkt(std::istream &s) -> std::unique_ptr { WktReader wktReader(s); - srid_t srid = wktReader.readSRID(); + srid_t const srid = wktReader.readSRID(); std::unique_ptr g(wktReader.readGeometry()); std::unique_ptr uptr( new PreparedGeometry(std::move(g), srid)); @@ -37,7 +36,7 @@ readEwkt(const std::string &s) -> std::unique_ptr { std::istringstream iss(s); WktReader wktReader(iss); - srid_t srid = wktReader.readSRID(); + srid_t const srid = wktReader.readSRID(); std::unique_ptr g(wktReader.readGeometry()); return std::make_unique(std::move(g), srid); } @@ -51,10 +50,9 @@ readEwkt(const char *str, size_t len) -> std::unique_ptr CharArrayBuffer buf(str, str + len); std::istream istr(&buf); WktReader wktReader(istr); - srid_t srid = wktReader.readSRID(); + srid_t const srid = wktReader.readSRID(); std::unique_ptr g(wktReader.readGeometry()); return std::make_unique(std::move(g), srid); } -} // namespace io -} // namespace SFCGAL +} // namespace SFCGAL::io diff --git a/src/io/wkt.cpp b/src/io/wkt.cpp index b3e70828..c81b7c63 100644 --- a/src/io/wkt.cpp +++ b/src/io/wkt.cpp @@ -11,8 +11,7 @@ using namespace SFCGAL::detail::io; -namespace SFCGAL { -namespace io { +namespace SFCGAL::io { /// /// @@ -36,7 +35,7 @@ readWkt(const std::string &s) -> std::unique_ptr char extra = 0; if (iss >> extra) { - std::string remaining(s.substr(int(iss.tellg()) - 1)); + std::string const remaining(s.substr(int(iss.tellg()) - 1)); throw WktParseException("Extra characters in WKT: " + remaining); } return geom; @@ -54,11 +53,10 @@ readWkt(const char *str, size_t len) -> std::unique_ptr std::unique_ptr geom(wktReader.readGeometry()); char extra = 0; if (istr >> extra) { - std::string remaining(str + int(istr.tellg()) - 1, str + len); + std::string const remaining(str + int(istr.tellg()) - 1, str + len); throw WktParseException("Extra characters in WKT: " + remaining); } return geom; } -} // namespace io -} // namespace SFCGAL +} // namespace SFCGAL::io diff --git a/src/numeric.cpp b/src/numeric.cpp index 55113299..76f3484b 100644 --- a/src/numeric.cpp +++ b/src/numeric.cpp @@ -35,12 +35,11 @@ round(const CGAL::Gmpq &v) -> CGAL::Gmpz if (v < 0) { // ceil( v - 0.5 ) ; return ceil(v - CGAL::Gmpq(1, 2)); - } else if (v == 0) { - return 0; - } else { - // floor( v + 0.5 ) ; - return floor(v + CGAL::Gmpq(1, 2)); } + if (v == 0) { + return 0; + } // floor( v + 0.5 ) ; + return floor(v + CGAL::Gmpq(1, 2)); } #ifdef CGAL_USE_GMPXX @@ -73,15 +72,14 @@ round(const mpq_class &v) -> mpz_class { if (v < 0) { // ceil( v - 0.5 ) ; - mpq_class tmp = v - mpq_class(1, 2); + mpq_class const tmp = v - mpq_class(1, 2); return ceil(tmp); - } else if (v == 0) { - return 0; - } else { - // floor( v + 0.5 ) ; - mpq_class tmp = v + mpq_class(1, 2); - return floor(tmp); } + if (v == 0) { + return 0; + } // floor( v + 0.5 ) ; + mpq_class const tmp = v + mpq_class(1, 2); + return floor(tmp); } #endif diff --git a/src/numeric.h b/src/numeric.h index 3aaa6d96..da7494aa 100644 --- a/src/numeric.h +++ b/src/numeric.h @@ -63,6 +63,7 @@ almostEqual(const Kernel::FT &a, const Kernel::FT &b, const Kernel::FT &epsilon) return diff <= epsilon * std::max(absA, absB); // adaptative epsilon } + #if defined(__clang__) #pragma clang diagnostic pop #elif defined(__GCC__) diff --git a/src/triangulate/triangulate2DZ.cpp b/src/triangulate/triangulate2DZ.cpp index d3989e39..4841f2f9 100644 --- a/src/triangulate/triangulate2DZ.cpp +++ b/src/triangulate/triangulate2DZ.cpp @@ -12,8 +12,7 @@ #include #include -namespace SFCGAL { -namespace triangulate { +namespace SFCGAL::triangulate { using Vertex_handle = ConstraintDelaunayTriangulation::Vertex_handle; @@ -35,7 +34,8 @@ triangulate2DZ(const LineString &g, Vertex_handle last; for (size_t i = 0; i < g.numPoints(); i++) { - Vertex_handle vertex = triangulation.addVertex(g.pointN(i).coordinate()); + Vertex_handle const vertex = + triangulation.addVertex(g.pointN(i).coordinate()); if (i != 0) { triangulation.addConstraint(last, vertex); @@ -64,7 +64,8 @@ triangulate2DZ(const Triangle &g, Vertex_handle last; for (size_t i = 0; i < 4; i++) { - Vertex_handle vertex = triangulation.addVertex(g.vertex(i).coordinate()); + Vertex_handle const vertex = + triangulation.addVertex(g.vertex(i).coordinate()); if (i != 0) { triangulation.addConstraint(last, vertex); @@ -151,5 +152,4 @@ triangulate2DZ(const Geometry &g) -> ConstraintDelaunayTriangulation return triangulation; } -} // namespace triangulate -} // namespace SFCGAL +} // namespace SFCGAL::triangulate diff --git a/src/triangulate/triangulatePolygon.cpp b/src/triangulate/triangulatePolygon.cpp index 7b55cd20..b0edbed4 100644 --- a/src/triangulate/triangulatePolygon.cpp +++ b/src/triangulate/triangulatePolygon.cpp @@ -17,8 +17,7 @@ #include -namespace SFCGAL { -namespace triangulate { +namespace SFCGAL::triangulate { using Vertex_handle = ConstraintDelaunayTriangulation::Vertex_handle; @@ -140,7 +139,7 @@ triangulatePolygon3D(const Polygon &polygon, /* * find polygon plane */ - Kernel::Plane_3 polygonPlane = + Kernel::Plane_3 const polygonPlane = algorithm::plane3D(polygon, algorithm::Plane3DInexactUnsafe()); cdt.setProjectionPlane(polygonPlane); @@ -155,15 +154,15 @@ triangulatePolygon3D(const Polygon &polygon, * note, we do not include the last point, since it's equal to the last and * that */ - if (!ring.numPoints()) { + if (ring.numPoints() == 0U) { continue; } - Vertex_handle v_prev = cdt.addVertex(ring.pointN(0).coordinate()); - Vertex_handle v_0 = v_prev; + Vertex_handle v_prev = cdt.addVertex(ring.pointN(0).coordinate()); + Vertex_handle const v_0 = v_prev; for (size_t j = 1; j < ring.numPoints() - 1; j++) { - Vertex_handle vh = cdt.addVertex(ring.pointN(j).coordinate()); + Vertex_handle const vh = cdt.addVertex(ring.pointN(j).coordinate()); cdt.addConstraint(v_prev, vh); v_prev = vh; } @@ -201,5 +200,4 @@ triangulatePolygon3D(const Solid &g, TriangulatedSurface &triangulatedSurface) } } -} // namespace triangulate -} // namespace SFCGAL +} // namespace SFCGAL::triangulate diff --git a/test/bench/Bench.cpp b/test/bench/Bench.cpp index 55ba68ce..0f357856 100644 --- a/test/bench/Bench.cpp +++ b/test/bench/Bench.cpp @@ -15,75 +15,72 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include "Bench.h" - namespace SFCGAL { /// /// /// -Bench::~Bench() -{ - -} +Bench::~Bench() {} /// /// /// -void Bench::start( const std::string& description ) +void +Bench::start(const std::string &description) { - _timers.push( std::make_pair( description, timer_t() ) ); - _timers.top().second.start(); + _timers.push(std::make_pair(description, timer_t())); + _timers.top().second.start(); } /// /// /// -void Bench::start( const boost::basic_format& description ) +void +Bench::start(const boost::basic_format &description) { - start( description.str() ); + start(description.str()); } /// /// /// -void Bench::stop() +void +Bench::stop() { - BOOST_ASSERT( ! _timers.empty() ) ; - _timers.top().second.stop(); - s() << _timers.top().first << "\t" << ( _timers.top().second.elapsed().wall * 1.0e-9 ) << std::endl ; - _timers.pop() ; + BOOST_ASSERT(!_timers.empty()); + _timers.top().second.stop(); + s() << _timers.top().first << "\t" + << (_timers.top().second.elapsed().wall * 1.0e-9) << std::endl; + _timers.pop(); } /// /// /// -Bench& Bench::instance() +Bench & +Bench::instance() { - static Bench bench ; - return bench ; + static Bench bench; + return bench; } /// /// /// -std::ostream& Bench::s() +std::ostream & +Bench::s() { - return *_s ; + return *_s; } /// /// /// -Bench::Bench(): - _s( &std::cout ) -{ - -} - +Bench::Bench() : _s(&std::cout) {} } // namespace SFCGAL - diff --git a/test/bench/Bench.h b/test/bench/Bench.h index 50fee5a8..712c9bbe 100644 --- a/test/bench/Bench.h +++ b/test/bench/Bench.h @@ -15,7 +15,8 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #ifndef _SFCGAL_BENCH_H_ #define _SFCGAL_BENCH_H_ @@ -34,64 +35,70 @@ namespace SFCGAL { */ class Bench { public: - typedef boost::timer::cpu_timer timer_t ; + typedef boost::timer::cpu_timer timer_t; - /** - * destructor - */ - ~Bench(); + /** + * destructor + */ + ~Bench(); - /** - * start a bench - */ - void start( const std::string& description ) ; - /** - * start a bench - */ - void start( const boost::basic_format& description ) ; - /** - * stop a bench - */ - void stop() ; + /** + * start a bench + */ + void + start(const std::string &description); + /** + * start a bench + */ + void + start(const boost::basic_format &description); + /** + * stop a bench + */ + void + stop(); - /** - * get bench instance - */ - static Bench& instance() ; + /** + * get bench instance + */ + static Bench & + instance(); + + /** + * Get output stream + */ + std::ostream & + s(); - /** - * Get output stream - */ - std::ostream& s() ; private: - /** - * default constructor - */ - Bench(); - /** - * copy constructor - */ - Bench( const Bench& bench ); + /** + * default constructor + */ + Bench(); + /** + * copy constructor + */ + Bench(const Bench &bench); - /** - * output stream to write bench result (default is std::cout) - */ - std::ostream* _s ; - /** - * timer stack with description - */ - std::stack< std::pair< std::string, timer_t > > _timers ; + /** + * output stream to write bench result (default is std::cout) + */ + std::ostream *_s; + /** + * timer stack with description + */ + std::stack> _timers; }; /** * @Get bench instance */ -inline Bench& bench() +inline Bench & +bench() { - return Bench::instance() ; + return Bench::instance(); } } // namespace SFCGAL #endif - diff --git a/test/bench/BenchArea.cpp b/test/bench/BenchArea.cpp index 94e84222..5356e763 100644 --- a/test/bench/BenchArea.cpp +++ b/test/bench/BenchArea.cpp @@ -15,23 +15,23 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include - -#include -#include -#include -#include -#include -#include -#include #include -#include +#include #include +#include #include #include +#include +#include +#include +#include +#include +#include #include "../test_config.h" #include "Bench.h" @@ -42,41 +42,35 @@ #include -using namespace boost::unit_test ; -using namespace SFCGAL ; - -BOOST_AUTO_TEST_SUITE( SFCGAL_BenchArea ) +using namespace boost::unit_test; +using namespace SFCGAL; +BOOST_AUTO_TEST_SUITE(SFCGAL_BenchArea) -BOOST_AUTO_TEST_CASE( testAreaSierpinski ) +BOOST_AUTO_TEST_CASE(testAreaSierpinski) { - std::unique_ptr< MultiPolygon > fractal( generator::sierpinski( 9 ) ) ; + std::unique_ptr fractal(generator::sierpinski(9)); - bench().start( "area sierpinski" ) ; + bench().start("area sierpinski"); - for ( int i = 0; i < 10; i++ ) { - algorithm::area( *fractal ) ; - } + for (int i = 0; i < 10; i++) { + algorithm::area(*fractal); + } - bench().stop(); + bench().stop(); } -BOOST_AUTO_TEST_CASE( testAreaSierpinski3D ) +BOOST_AUTO_TEST_CASE(testAreaSierpinski3D) { - std::unique_ptr< MultiPolygon > fractal( generator::sierpinski( 9 ) ) ; + std::unique_ptr fractal(generator::sierpinski(9)); - bench().start( "area sierpinski" ) ; + bench().start("area sierpinski"); - for ( int i = 0; i < 10; i++ ) { - algorithm::area3D( *fractal ) ; - } + for (int i = 0; i < 10; i++) { + algorithm::area3D(*fractal); + } - bench().stop() ; + bench().stop(); } - BOOST_AUTO_TEST_SUITE_END() - - - - diff --git a/test/bench/BenchContainer.cpp b/test/bench/BenchContainer.cpp index 2f00c876..251186ca 100644 --- a/test/bench/BenchContainer.cpp +++ b/test/bench/BenchContainer.cpp @@ -15,20 +15,21 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ -#include -#include -#include -#include -#include -#include -#include #include -#include +#include #include +#include #include #include +#include +#include +#include +#include +#include +#include #include #include "../test_config.h" @@ -37,11 +38,10 @@ #include +using namespace boost::unit_test; +using namespace SFCGAL; -using namespace boost::unit_test ; -using namespace SFCGAL ; - -BOOST_AUTO_TEST_SUITE( SFCGAL_BenchContainer ) +BOOST_AUTO_TEST_SUITE(SFCGAL_BenchContainer) #if 0 @@ -173,7 +173,3 @@ BOOST_AUTO_TEST_CASE( testPtrVectorOfPoint ) #endif BOOST_AUTO_TEST_SUITE_END() - - - - diff --git a/test/bench/BenchMinkowski.cpp b/test/bench/BenchMinkowski.cpp index ea8b591f..9d651ca9 100644 --- a/test/bench/BenchMinkowski.cpp +++ b/test/bench/BenchMinkowski.cpp @@ -15,62 +15,85 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ -#include -#include -#include -#include -#include -#include -#include #include -#include +#include #include +#include #include #include -#include +#include +#include +#include +#include +#include +#include #include +#include #include "../test_config.h" #include "Bench.h" #include +using namespace boost::unit_test; +using namespace SFCGAL; -using namespace boost::unit_test ; -using namespace SFCGAL ; - -BOOST_AUTO_TEST_SUITE( SFCGAL_BenchMinkowskiSum ) +BOOST_AUTO_TEST_SUITE(SFCGAL_BenchMinkowskiSum) - -BOOST_AUTO_TEST_CASE( testPolygonWithHoles ) +BOOST_AUTO_TEST_CASE(testPolygonWithHoles) { - std::unique_ptr< Geometry > gA( io::readWkt( "MULTIPOLYGON(((11.795461 32.713032,11.381695 35.857648,15.188336 38.091981,28.428825 38.257487,30.994170 33.788822,30.580405 29.816675,26.773764 22.617159,11.050683 18.562259,-0.534745 21.044851,-3.513855 26.837565,3.520155 26.506553,4.099426 24.685985,4.678698 22.782665,6.582018 21.541369,8.899104 21.458616,16.098620 21.706875,18.332952 25.016998,17.919187 27.499589,16.429632 27.830601,14.360805 26.175540,13.036756 24.520479,10.885177 23.527442,8.733597 23.527442,6.002747 24.603232,4.595945 26.506553,1.203069 27.830601,1.368575 30.892465,2.113353 34.202587,4.678698 36.519672,6.664771 36.188660,8.071573 34.699105,7.409549 32.630279,5.837240 31.968254,5.919993 30.064934,7.575055 28.740885,10.802424 27.582342,12.126473 27.913355,13.781534 28.740885,14.443558 29.816675,14.691818 31.306230,14.278052 33.126797,13.450522 34.119834,11.795461 32.713032),(21.477568 36.188660,15.684854 36.271413,14.609065 28.161614,15.022830 27.582342,20.401779 29.816675,29.339109 32.133760,21.477568 36.188660)))" ) ); - std::unique_ptr< Geometry > gB( io::readWkt( "POLYGON((-1 0,0 -1,1 0,0 1,-1 0))" ) ); - - bench().start( "minkowski polygon with hole" ) ; - - for ( int i = 0; i < 1000; i++ ) { - std::unique_ptr< Geometry > sum( algorithm::minkowskiSum( *gA, gB->as< Polygon >() ) ); - } - - bench().stop(); + std::unique_ptr gA(io::readWkt( + "MULTIPOLYGON(((11.795461 32.713032,11.381695 35.857648,15.188336 " + "38.091981,28.428825 38.257487,30.994170 33.788822,30.580405 " + "29.816675,26.773764 22.617159,11.050683 18.562259,-0.534745 " + "21.044851,-3.513855 26.837565,3.520155 26.506553,4.099426 " + "24.685985,4.678698 22.782665,6.582018 21.541369,8.899104 " + "21.458616,16.098620 21.706875,18.332952 25.016998,17.919187 " + "27.499589,16.429632 27.830601,14.360805 26.175540,13.036756 " + "24.520479,10.885177 23.527442,8.733597 23.527442,6.002747 " + "24.603232,4.595945 26.506553,1.203069 27.830601,1.368575 " + "30.892465,2.113353 34.202587,4.678698 36.519672,6.664771 " + "36.188660,8.071573 34.699105,7.409549 32.630279,5.837240 " + "31.968254,5.919993 30.064934,7.575055 28.740885,10.802424 " + "27.582342,12.126473 27.913355,13.781534 28.740885,14.443558 " + "29.816675,14.691818 31.306230,14.278052 33.126797,13.450522 " + "34.119834,11.795461 32.713032),(21.477568 36.188660,15.684854 " + "36.271413,14.609065 28.161614,15.022830 27.582342,20.401779 " + "29.816675,29.339109 32.133760,21.477568 36.188660)))")); + std::unique_ptr gB( + io::readWkt("POLYGON((-1 0,0 -1,1 0,0 1,-1 0))")); + + bench().start("minkowski polygon with hole"); + + for (int i = 0; i < 1000; i++) { + std::unique_ptr sum( + algorithm::minkowskiSum(*gA, gB->as())); + } + + bench().stop(); } - - BOOST_AUTO_TEST_SUITE_END() - - - - - -//BOOST_AUTO_TEST_CASE( testTemp ){ -// std::unique_ptr< Geometry > gA( io::readWkt("MULTIPOLYGON(((11.795461 32.713032,11.381695 35.857648,15.188336 38.091981,28.428825 38.257487,30.994170 33.788822,30.580405 29.816675,26.773764 22.617159,11.050683 18.562259,-0.534745 21.044851,-3.513855 26.837565,3.520155 26.506553,4.099426 24.685985,4.678698 22.782665,6.582018 21.541369,8.899104 21.458616,16.098620 21.706875,18.332952 25.016998,17.919187 27.499589,16.429632 27.830601,14.360805 26.175540,13.036756 24.520479,10.885177 23.527442,8.733597 23.527442,6.002747 24.603232,4.595945 26.506553,1.203069 27.830601,1.368575 30.892465,2.113353 34.202587,4.678698 36.519672,6.664771 36.188660,8.071573 34.699105,7.409549 32.630279,5.837240 31.968254,5.919993 30.064934,7.575055 28.740885,10.802424 27.582342,12.126473 27.913355,13.781534 28.740885,14.443558 29.816675,14.691818 31.306230,14.278052 33.126797,13.450522 34.119834,11.795461 32.713032),(21.477568 36.188660,15.684854 36.271413,14.609065 28.161614,15.022830 27.582342,20.401779 29.816675,29.339109 32.133760,21.477568 36.188660)))") ); -// std::unique_ptr< Geometry > gB( io::readWkt( "POLYGON((-1 0,0 -1,1 0,0 1,-1 0))" ) ); +// BOOST_AUTO_TEST_CASE( testTemp ){ +// std::unique_ptr< Geometry > gA( +// io::readWkt("MULTIPOLYGON(((11.795461 32.713032,11.381695 35.857648,15.188336 38.091981,28.428825 +// 38.257487,30.994170 33.788822,30.580405 29.816675,26.773764 22.617159,11.050683 +// 18.562259,-0.534745 21.044851,-3.513855 26.837565,3.520155 26.506553,4.099426 24.685985,4.678698 +// 22.782665,6.582018 21.541369,8.899104 21.458616,16.098620 21.706875,18.332952 25.016998,17.919187 +// 27.499589,16.429632 27.830601,14.360805 26.175540,13.036756 24.520479,10.885177 +// 23.527442,8.733597 23.527442,6.002747 24.603232,4.595945 26.506553,1.203069 27.830601,1.368575 +// 30.892465,2.113353 34.202587,4.678698 36.519672,6.664771 36.188660,8.071573 34.699105,7.409549 +// 32.630279,5.837240 31.968254,5.919993 30.064934,7.575055 28.740885,10.802424 27.582342,12.126473 +// 27.913355,13.781534 28.740885,14.443558 29.816675,14.691818 31.306230,14.278052 +// 33.126797,13.450522 34.119834,11.795461 32.713032),(21.477568 36.188660,15.684854 +// 36.271413,14.609065 28.161614,15.022830 27.582342,20.401779 29.816675,29.339109 +// 32.133760,21.477568 36.188660)))") ); std::unique_ptr< Geometry > gB( +// io::readWkt( "POLYGON((-1 0,0 -1,1 0,0 1,-1 0))" ) ); // -// std::unique_ptr< Geometry > sum( algorithm::minkowskiSum( *gA, gB->as< Polygon >() ) ); -// std::cout << sum->asText(6) << std::endl ; -//} +// std::unique_ptr< Geometry > sum( algorithm::minkowskiSum( *gA, gB->as< +// Polygon >() ) ); std::cout << sum->asText(6) << std::endl ; +// } diff --git a/test/bench/BenchPredicate.cpp b/test/bench/BenchPredicate.cpp index b9f4f85f..f959e691 100644 --- a/test/bench/BenchPredicate.cpp +++ b/test/bench/BenchPredicate.cpp @@ -15,7 +15,8 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include "../test_config.h" #include "Bench.h" @@ -23,51 +24,46 @@ #include #include -#include #include +#include -using namespace boost::unit_test ; -using namespace SFCGAL ; - -BOOST_AUTO_TEST_SUITE( SFCGAL_BenchPredicate ) +using namespace boost::unit_test; +using namespace SFCGAL; +BOOST_AUTO_TEST_SUITE(SFCGAL_BenchPredicate) -double randf() +double +randf() { - return double(rand()) / RAND_MAX; + return double(rand()) / RAND_MAX; } -BOOST_AUTO_TEST_CASE( testPointCompare ) +BOOST_AUTO_TEST_CASE(testPointCompare) { - std::vector > points; - for ( size_t i = 0; i < 10000; i++ ) { - points.push_back( CGAL::Point_3( randf(), randf(), randf() ) ); - } + std::vector> points; + for (size_t i = 0; i < 10000; i++) { + points.push_back(CGAL::Point_3(randf(), randf(), randf())); + } - bench().start( "xyz" ) ; + bench().start("xyz"); - for ( size_t i = 0; i < points.size(); i++ ) { - for ( size_t j = 0; j < points.size(); j++ ) { - points[i].x() < points[j].x(); - } + for (size_t i = 0; i < points.size(); i++) { + for (size_t j = 0; j < points.size(); j++) { + points[i].x() < points[j].x(); } + } - bench().stop(); - + bench().stop(); - bench().start( "compare" ) ; + bench().start("compare"); - for ( size_t i = 0; i < points.size(); i++ ) { - for ( size_t j = 0; j < points.size(); j++ ) { - CGAL::compare_x( points[i], points[j] ); - } + for (size_t i = 0; i < points.size(); i++) { + for (size_t j = 0; j < points.size(); j++) { + CGAL::compare_x(points[i], points[j]); } + } - bench().stop(); + bench().stop(); } BOOST_AUTO_TEST_SUITE_END() - - - - diff --git a/test/bench/BenchStraightSkeleton.cpp b/test/bench/BenchStraightSkeleton.cpp index 282770d9..29657ddd 100644 --- a/test/bench/BenchStraightSkeleton.cpp +++ b/test/bench/BenchStraightSkeleton.cpp @@ -14,82 +14,504 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ -#include -#include -#include -#include -#include -#include -#include #include -#include +#include #include +#include #include #include -#include +#include +#include +#include +#include +#include +#include #include +#include #include "../test_config.h" #include "Bench.h" #include +using namespace boost::unit_test; +using namespace SFCGAL; -using namespace boost::unit_test ; -using namespace SFCGAL ; - -BOOST_AUTO_TEST_SUITE( SFCGAL_BenchStraightSkeleton ) - +BOOST_AUTO_TEST_SUITE(SFCGAL_BenchStraightSkeleton) // See https://github.com/Oslandia/SFCGAL/issues/80 -BOOST_AUTO_TEST_CASE( testPolygon80 ) +BOOST_AUTO_TEST_CASE(testPolygon80) { - std::unique_ptr< Geometry > g( io::readWkt( -"POLYGON((1684000 5402672.31399816,1683946.034501 5402654.436405,1683891.240865 5402626.55208,1683828.852807 5402603.566759,1683763.966259 5402588.179891,1683710.005454 5402593.368835,1683643.321311 5402617.6139,1683558.455081 5402667.62372,1683479.657793 5402723.692308,1683393.274328 5402782.790279,1683344.780518 5402828.261023,1683302.347403 5402879.780536,1683275.07015 5402920.702207,1683275.07015 5402961.61388,1683285.674306 5403005.564933,1683312.951559 5403060.123828,1683325.081196 5403107.104265,1683319.0205 5403163.172853,1683291.735002 5403213.182673,1683214.454949 5403316.231698,1683131.097709 5403404.133806,1683071.999743 5403438.986712,1682985.616278 5403446.565169,1682940.462035 5403442.675961,1682880.415797 5403428.688808,1682817.343333 5403380.938527,1682774.09388 5403321.470632,1682729.94563 5403243.986403,1682692.10545 5403159.283644,1682682.878351 5403080.789622,1682680.67671 5403039.198087,1682654.257025 5402965.563076,1682628.876316 5402937.928701,1682608.979094 5402917.832791,1682537.124807 5402882.669948,1682377.221394 5402803.686025,1682327.432986 5402778.391174,1682247.745147 5402720.312996,1682225.349434 5402712.624561,1682183.51002 5402714.684141,1682145.917216 5402727.481536,1682113.964569 5402740.648856,1682089.985654 5402764.224058,1682069.700877 5402801.616447,1682051.708445 5402871.502221,1682004.624674 5402975.481057,1681970.354945 5403065.972638,1681952.560413 5403113.362991,1681928.037272 5403171.901076,1681920.830404 5403207.043923,1681928.936069 5403248.485488,1681963.684057 5403315.911763,1681985.700461 5403387.247243,1681982.097027 5403427.788991,1681972.696765 5403453.58374,1681959.998165 5403485.977147,1681917.119774 5403543.165506,1681871.734647 5403590.355901,1681801.356366 5403642.355317,1681698.275067 5403702.603053,1681626.709384 5403743.754677,1681565.82207 5403762.980764,1681486.530031 5403783.696547,1681395.528893 5403795.414162,1681308.13119 5403794.514345,1681281.134295 5403807.881624,1681309.029987 5403814.330312,1681347.777209 5403821.538844,1681443.280578 5403812.530678,1681535.188758 5403799.913246,1681627.995736 5403769.279482,1681693.294577 5403734.146633,1681743.478785 5403709.551639,1681819.010719 5403658.462038,1681882.981979 5403607.092494,1681939.746371 5403555.732948,1681968.582088 5403515.1912,1681992.008532 5403477.348903,1682001.920037 5403427.788991,1682003.725877 5403371.030544,1681981.181738 5403316.111723,1681950.564919 5403242.18677,1681946.961485 5403179.109609,1682053.819381 5402931.490011,1682074.706105 5402867.003137,1682087.000658 5402829.21083,1682109.882876 5402779.320985,1682132.47649 5402759.525014,1682162.573821 5402744.718028,1682197.659889 5402742.418496,1682230.057811 5402752.7164,1682274.948187 5402775.501762,1682361.422357 5402825.011685,1682456.810283 5402864.263695,1682563.989768 5402917.532852,1682603.784212 5402945.227215,1682636.380035 5402982.409647,1682648.855997 5403036.748586,1682663.269733 5403154.78456,1682694.397795 5403228.449566,1682727.240993 5403287.227602,1682756.07671 5403341.296596,1682792.11105 5403388.14706,1682830.858272 5403421.480275,1682900.37074 5403459.87246,1682942.762625 5403465.171382,1682975.012122 5403470.810234,1683049.26595 5403469.290543,1683114.432858 5403443.535786,1683203.842547 5403370.790593,1683279.613611 5403273.800335,1683328.107421 5403210.15329,1683356.901909 5403151.045321,1683353.875684 5403104.074882,1683331.141892 5403043.457221,1683309.925334 5402970.712028,1683311.44257 5402916.263111,1683346.297753 5402870.692386,1683408.43019 5402805.525651,1683487.235724 5402746.42768,1683575.128178 5402690.349095,1683641.804075 5402647.917731,1683706.970983 5402616.094209,1683741.826167 5402610.035442,1683781.26604 5402615.764276,1683816.261403 5402623.462709,1683915.838219 5402676.741864,1684000 5402711.41802501,1684020.618162 5402719.913077,1684068.00703 5402732.710472,1684222.971181 5402746.287709,1684311.424353 5402765.24385,1684450.572976 5402802.756215,1684578.837084 5402854.785624,1684651.433497 5402882.619959,1684708.305085 5402894.717496,1684763.964534 5402883.829712,1684819.632229 5402849.946609,1684837.781332 5402820.902521,1684835.357054 5402777.341388,1684817.207951 5402736.199762,1684749.451848 5402674.492322,1684704.676914 5402623.672666,1684682.899639 5402545.018676,1684682.899639 5402476.052714,1684692.58026 5402430.072073,1684739.771227 5402376.822912,1684837.781332 5402305.437442,1684921.270506 5402277.603108,1684981.770265 5402275.1836,1685015.652439 5402295.759412,1685031.38551 5402317.53498,1685032.589404 5402344.159561,1685010.812129 5402370.774143,1684991.450886 5402409.496261,1684989.026608 5402463.955177,1684972.089644 5402600.687345,1684985.398437 5402732.580499,1684986.610576 5402973.371486,1684959.984745 5403060.493753,1684920.058367 5403131.88922,1684881.335882 5403191.177153,1684863.186778 5403244.416316,1684864.398918 5403295.235972,1684898.281092 5403346.055628,1684949.10023 5403360.582671,1684989.991372 5403370.170719,1685072.524028 5403369.050947,1685162.065651 5403366.631439,1685254.023306 5403340.006859,1685345.989208 5403307.333509,1685395.596207 5403272.25065,1685445.211452 5403216.581982,1685470.616898 5403177.869861,1685479.085381 5403110.103655,1685482.045639 5403068.682086,1685463.360556 5403033.869172,1685454.883828 5402967.322718,1685471.829038 5402909.244539,1685532.328797 5402824.54178,1685646.071973 5402744.678036,1685708.996011 5402691.438873,1685723.508697 5402658.765523,1685736.825736 5402615.20439,1685746.506357 5402540.189659,1685759.81515 5402501.467541,1685788.857013 5402491.789511,1685819.10277 5402497.83828,1685850.568912 5402523.243109,1685873.558326 5402570.433503,1685896.54774 5402610.355377,1685964.303842 5402718.053456,1686003.026327 5402812.434245,1686041.748812 5402911.654049,1686076.843125 5402947.956659,1686111.929193 5402947.956659,1686147.023506 5402931.010109,1686182.109574 5402901.976019,1686202.682955 5402819.692767,1686214.779609 5402689.009367,1686209.939298 5402592.209071,1686193.002334 5402489.360005,1686178.481402 5402415.54503,1686177.269263 5402357.466852,1686222.044197 5402317.53498,1686324.894613 5402263.086063,1686418.064408 5402230.412713,1686484.616617 5402243.720005,1686519.710931 5402271.554339,1686541.488206 5402312.695965,1686559.637309 5402416.754784,1686598.359794 5402483.311237,1686663.699864 5402560.745475,1686704.838381 5402610.355377,1686724.199623 5402659.965279,1686748.401176 5402754.356066,1686777.44304 5402892.297989,1686816.165525 5402980.630009,1686864.560385 5403039.917941,1686942.005355 5403090.737597,1687020.654218 5403104.054886,1687121.088601 5403129.459715,1687190.056843 5403153.664788,1687232.440482 5403171.661125,1687258.83543 5403191.157157,1687296.032434 5403231.338978,1687323.334424 5403271.630776,1687350.331318 5403336.817508,1687355.138646 5403374.309876,1687354.940745 5403406.803263,1687349.539717 5403432.697992,1687329.213711 5403462.211984,1687315.904918 5403514.241394,1687305.012158 5403550.544005,1687302.868239 5403577.968422,1687302.58788 5403647.344301,1687337.682193 5403723.578784,1687378.82071 5403747.773859,1687485.299298 5403757.461887,1687540.966993 5403757.461887,1687609.935234 5403746.564105,1687666.509972 5403770.889154,1687709.800655 5403791.874882,1687749.595099 5403819.559247,1687766.993831 5403837.255645,1687789.191643 5403882.346467,1687788.993743 5403907.341379,1687781.30037 5403937.335274,1687766.103279 5403964.729698,1687735.915243 5403994.523634,1687698.231735 5404019.328585,1687665.635913 5404034.025593,1687635.645777 5404041.324108,1687597.558222 5404039.734431,1687563.065855 5404038.334716,1687503.176288 5404027.946831,1687339.207674 5403984.07576,1687303.42071 5403984.07576,1687268.425347 5403991.384273,1687241.733549 5404002.382034,1687194.897153 5404036.974993,1687157.386808 5404074.487357,1687138.025565 5404115.628983,1687142.865876 5404156.770609,1687175.535911 5404259.619674,1687225.14291 5404338.273664,1687369.140089 5404431.4447,1687438.108331 5404471.376572,1687479.246848 5404489.522878,1687531.888318 5404490.732632,1687547.802798 5404451.100699,1687563.304985 5404415.957852,1687535.508244 5404415.757893,1687520.517299 5404420.656896,1687488.020426 5404417.967443,1687440.631559 5404400.071086,1687393.242692 5404374.786232,1687306.15833 5404316.708054,1687273.859358 5404283.914729,1687256.559577 5404251.321363,1687221.861064 5404213.539054,1687212.254656 5404148.452302,1687219.956274 5404128.556352,1687250.14431 5404101.261907,1687282.731887 5404083.95543,1687317.8262 5404074.157425,1687360.317036 5404071.957872,1687385.31019 5404077.146816,1687462.697439 5404102.731608,1687512.683747 5404103.031547,1687550.169355 5404095.823015,1687628.084338 5404107.160707,1687687.743021 5404083.215581,1687762.219487 5404046.013153,1687805.402973 5404008.720744,1687854.358551 5403919.598884,1687851.934273 5403865.149967,1687851.934273 5403840.944894,1687834.997309 5403804.652281,1687819.264238 5403765.930163,1687790.271849 5403734.876484,1687732.987969 5403696.994195,1687695.593065 5403681.697309,1687658.099211 5403673.908894,1687625.610584 5403673.708935,1687580.621258 5403678.417976,1687512.939368 5403697.914008,1687467.950041 5403697.624067,1687447.953869 5403692.525105,1687410.558965 5403672.239234,1687393.259184 5403649.643833,1687380.956384 5403612.051485,1687380.420404 5403608.582191,1687367.92795 5403548.124497,1687370.352228 5403520.290163,1687389.738208 5403461.882051,1687404.737399 5403458.482743,1687417.229853 5403434.787566,1687417.518458 5403387.297233,1687430.316008 5403344.805882,1687430.711809 5403292.316566,1687420.9075 5403262.222691,1687406.106209 5403237.127799,1687366.311765 5403194.346507,1687339.01802 5403174.150618,1687244.33099 5403120.971443,1687211.941314 5403108.284025,1687167.042691 5403080.489683,1687108.860014 5403058.404178,1687067.366926 5403044.806946,1687056.465919 5403042.517412,1686997.664804 5403038.708187,1686939.581076 5403022.981388,1686857.304042 5402935.859122,1686793.176111 5402754.356066,1686775.018762 5402684.170352,1686745.985144 5402628.511682,1686720.571452 5402588.57981,1686652.807104 5402515.974588,1686611.668586 5402447.008626,1686585.051001 5402405.867,1686575.37038 5402357.466852,1686563.26548 5402299.388674,1686537.860034 5402250.988525,1686499.137549 5402218.315176,1686427.745029 5402205.007884,1686361.19282 5402213.476161,1686295.85275 5402249.768774,1686220.832058 5402293.329907,1686173.641091 5402324.793502,1686154.279849 5402369.564389,1686154.279849 5402424.013307,1686182.109574 5402528.082124,1686189.374162 5402658.755525,1686189.374162 5402799.126953,1686160.332299 5402897.137004,1686125.237985 5402923.751586,1686081.683436 5402923.751586,1686046.589123 5402881.400207,1686009.078777 5402770.082865,1685950.99505 5402647.867742,1685913.484704 5402586.160302,1685859.037394 5402499.048033,1685819.10277 5402477.262468,1685802.165806 5402472.423453,1685768.283632 5402472.423453,1685734.401458 5402491.789511,1685727.145115 5402524.452862,1685717.464493 5402605.52636,1685693.26294 5402678.131582,1685585.572214 5402755.56582,1685504.499073 5402820.912519,1685460.936277 5402880.200451,1685433.106553 5402935.859122,1685431.894414 5402993.947298,1685460.936277 5403084.698826,1685460.936277 5403142.777004,1685408.905 5403229.899271,1685337.51248 5403281.92868,1685229.821753 5403319.441045,1685108.822234 5403347.265381,1685005.971818 5403344.845874,1684916.430195 5403326.699567,1684889.804364 5403294.026218,1684899.484985 5403226.27001,1684946.675952 5403143.986758,1684981.770265 5403067.752275,1685003.54754 5402989.098285,1685019.280611 5402887.458974,1685015.652439 5402772.512371,1685007.175712 5402592.219069,1685019.280611 5402466.374684,1685031.38551 5402392.559709,1685042.270025 5402371.983897,1685054.374924 5402341.740053,1685054.374924 5402318.744734,1685045.906442 5402289.710643,1685007.183957 5402259.456802,1684949.10023 5402241.300497,1684875.291678 5402258.247048,1684795.430676 5402294.549659,1684711.941502 5402363.515621,1684667.166568 5402415.54503,1684650.229604 5402485.730744,1684663.538396 5402594.628578,1684697.420571 5402662.394785,1684771.229123 5402726.521732,1684808.739469 5402774.92188,1684812.36764 5402816.063506,1684780.909744 5402851.156363,1684740.97512 5402870.512423,1684690.155982 5402868.092915,1684630.868361 5402843.89784,1684517.61169 5402795.847621,1684435.32641 5402765.263846,1684290.578859 5402730.590904,1684228.067113 5402721.292796,1684133.289379 5402698.207495,1684030.810026 5402682.520688,1684000 5402672.31399816))" - ) ); + std::unique_ptr g( + io::readWkt("POLYGON((1684000 5402672.31399816,1683946.034501 " + "5402654.436405,1683891.240865 5402626.55208,1683828.852807 " + "5402603.566759,1683763.966259 5402588.179891,1683710.005454 " + "5402593.368835,1683643.321311 5402617.6139,1683558.455081 " + "5402667.62372,1683479.657793 5402723.692308,1683393.274328 " + "5402782.790279,1683344.780518 5402828.261023,1683302.347403 " + "5402879.780536,1683275.07015 5402920.702207,1683275.07015 " + "5402961.61388,1683285.674306 5403005.564933,1683312.951559 " + "5403060.123828,1683325.081196 5403107.104265,1683319.0205 " + "5403163.172853,1683291.735002 5403213.182673,1683214.454949 " + "5403316.231698,1683131.097709 5403404.133806,1683071.999743 " + "5403438.986712,1682985.616278 5403446.565169,1682940.462035 " + "5403442.675961,1682880.415797 5403428.688808,1682817.343333 " + "5403380.938527,1682774.09388 5403321.470632,1682729.94563 " + "5403243.986403,1682692.10545 5403159.283644,1682682.878351 " + "5403080.789622,1682680.67671 5403039.198087,1682654.257025 " + "5402965.563076,1682628.876316 5402937.928701,1682608.979094 " + "5402917.832791,1682537.124807 5402882.669948,1682377.221394 " + "5402803.686025,1682327.432986 5402778.391174,1682247.745147 " + "5402720.312996,1682225.349434 5402712.624561,1682183.51002 " + "5402714.684141,1682145.917216 5402727.481536,1682113.964569 " + "5402740.648856,1682089.985654 5402764.224058,1682069.700877 " + "5402801.616447,1682051.708445 5402871.502221,1682004.624674 " + "5402975.481057,1681970.354945 5403065.972638,1681952.560413 " + "5403113.362991,1681928.037272 5403171.901076,1681920.830404 " + "5403207.043923,1681928.936069 5403248.485488,1681963.684057 " + "5403315.911763,1681985.700461 5403387.247243,1681982.097027 " + "5403427.788991,1681972.696765 5403453.58374,1681959.998165 " + "5403485.977147,1681917.119774 5403543.165506,1681871.734647 " + "5403590.355901,1681801.356366 5403642.355317,1681698.275067 " + "5403702.603053,1681626.709384 5403743.754677,1681565.82207 " + "5403762.980764,1681486.530031 5403783.696547,1681395.528893 " + "5403795.414162,1681308.13119 5403794.514345,1681281.134295 " + "5403807.881624,1681309.029987 5403814.330312,1681347.777209 " + "5403821.538844,1681443.280578 5403812.530678,1681535.188758 " + "5403799.913246,1681627.995736 5403769.279482,1681693.294577 " + "5403734.146633,1681743.478785 5403709.551639,1681819.010719 " + "5403658.462038,1681882.981979 5403607.092494,1681939.746371 " + "5403555.732948,1681968.582088 5403515.1912,1681992.008532 " + "5403477.348903,1682001.920037 5403427.788991,1682003.725877 " + "5403371.030544,1681981.181738 5403316.111723,1681950.564919 " + "5403242.18677,1681946.961485 5403179.109609,1682053.819381 " + "5402931.490011,1682074.706105 5402867.003137,1682087.000658 " + "5402829.21083,1682109.882876 5402779.320985,1682132.47649 " + "5402759.525014,1682162.573821 5402744.718028,1682197.659889 " + "5402742.418496,1682230.057811 5402752.7164,1682274.948187 " + "5402775.501762,1682361.422357 5402825.011685,1682456.810283 " + "5402864.263695,1682563.989768 5402917.532852,1682603.784212 " + "5402945.227215,1682636.380035 5402982.409647,1682648.855997 " + "5403036.748586,1682663.269733 5403154.78456,1682694.397795 " + "5403228.449566,1682727.240993 5403287.227602,1682756.07671 " + "5403341.296596,1682792.11105 5403388.14706,1682830.858272 " + "5403421.480275,1682900.37074 5403459.87246,1682942.762625 " + "5403465.171382,1682975.012122 5403470.810234,1683049.26595 " + "5403469.290543,1683114.432858 5403443.535786,1683203.842547 " + "5403370.790593,1683279.613611 5403273.800335,1683328.107421 " + "5403210.15329,1683356.901909 5403151.045321,1683353.875684 " + "5403104.074882,1683331.141892 5403043.457221,1683309.925334 " + "5402970.712028,1683311.44257 5402916.263111,1683346.297753 " + "5402870.692386,1683408.43019 5402805.525651,1683487.235724 " + "5402746.42768,1683575.128178 5402690.349095,1683641.804075 " + "5402647.917731,1683706.970983 5402616.094209,1683741.826167 " + "5402610.035442,1683781.26604 5402615.764276,1683816.261403 " + "5402623.462709,1683915.838219 5402676.741864,1684000 " + "5402711.41802501,1684020.618162 " + "5402719.913077,1684068.00703 5402732.710472,1684222.971181 " + "5402746.287709,1684311.424353 5402765.24385,1684450.572976 " + "5402802.756215,1684578.837084 5402854.785624,1684651.433497 " + "5402882.619959,1684708.305085 5402894.717496,1684763.964534 " + "5402883.829712,1684819.632229 5402849.946609,1684837.781332 " + "5402820.902521,1684835.357054 5402777.341388,1684817.207951 " + "5402736.199762,1684749.451848 5402674.492322,1684704.676914 " + "5402623.672666,1684682.899639 5402545.018676,1684682.899639 " + "5402476.052714,1684692.58026 5402430.072073,1684739.771227 " + "5402376.822912,1684837.781332 5402305.437442,1684921.270506 " + "5402277.603108,1684981.770265 5402275.1836,1685015.652439 " + "5402295.759412,1685031.38551 5402317.53498,1685032.589404 " + "5402344.159561,1685010.812129 5402370.774143,1684991.450886 " + "5402409.496261,1684989.026608 5402463.955177,1684972.089644 " + "5402600.687345,1684985.398437 5402732.580499,1684986.610576 " + "5402973.371486,1684959.984745 5403060.493753,1684920.058367 " + "5403131.88922,1684881.335882 5403191.177153,1684863.186778 " + "5403244.416316,1684864.398918 5403295.235972,1684898.281092 " + "5403346.055628,1684949.10023 5403360.582671,1684989.991372 " + "5403370.170719,1685072.524028 5403369.050947,1685162.065651 " + "5403366.631439,1685254.023306 5403340.006859,1685345.989208 " + "5403307.333509,1685395.596207 5403272.25065,1685445.211452 " + "5403216.581982,1685470.616898 5403177.869861,1685479.085381 " + "5403110.103655,1685482.045639 5403068.682086,1685463.360556 " + "5403033.869172,1685454.883828 5402967.322718,1685471.829038 " + "5402909.244539,1685532.328797 5402824.54178,1685646.071973 " + "5402744.678036,1685708.996011 5402691.438873,1685723.508697 " + "5402658.765523,1685736.825736 5402615.20439,1685746.506357 " + "5402540.189659,1685759.81515 5402501.467541,1685788.857013 " + "5402491.789511,1685819.10277 5402497.83828,1685850.568912 " + "5402523.243109,1685873.558326 5402570.433503,1685896.54774 " + "5402610.355377,1685964.303842 5402718.053456,1686003.026327 " + "5402812.434245,1686041.748812 5402911.654049,1686076.843125 " + "5402947.956659,1686111.929193 5402947.956659,1686147.023506 " + "5402931.010109,1686182.109574 5402901.976019,1686202.682955 " + "5402819.692767,1686214.779609 5402689.009367,1686209.939298 " + "5402592.209071,1686193.002334 5402489.360005,1686178.481402 " + "5402415.54503,1686177.269263 5402357.466852,1686222.044197 " + "5402317.53498,1686324.894613 5402263.086063,1686418.064408 " + "5402230.412713,1686484.616617 5402243.720005,1686519.710931 " + "5402271.554339,1686541.488206 5402312.695965,1686559.637309 " + "5402416.754784,1686598.359794 5402483.311237,1686663.699864 " + "5402560.745475,1686704.838381 5402610.355377,1686724.199623 " + "5402659.965279,1686748.401176 5402754.356066,1686777.44304 " + "5402892.297989,1686816.165525 5402980.630009,1686864.560385 " + "5403039.917941,1686942.005355 5403090.737597,1687020.654218 " + "5403104.054886,1687121.088601 5403129.459715,1687190.056843 " + "5403153.664788,1687232.440482 5403171.661125,1687258.83543 " + "5403191.157157,1687296.032434 5403231.338978,1687323.334424 " + "5403271.630776,1687350.331318 5403336.817508,1687355.138646 " + "5403374.309876,1687354.940745 5403406.803263,1687349.539717 " + "5403432.697992,1687329.213711 5403462.211984,1687315.904918 " + "5403514.241394,1687305.012158 5403550.544005,1687302.868239 " + "5403577.968422,1687302.58788 5403647.344301,1687337.682193 " + "5403723.578784,1687378.82071 5403747.773859,1687485.299298 " + "5403757.461887,1687540.966993 5403757.461887,1687609.935234 " + "5403746.564105,1687666.509972 5403770.889154,1687709.800655 " + "5403791.874882,1687749.595099 5403819.559247,1687766.993831 " + "5403837.255645,1687789.191643 5403882.346467,1687788.993743 " + "5403907.341379,1687781.30037 5403937.335274,1687766.103279 " + "5403964.729698,1687735.915243 5403994.523634,1687698.231735 " + "5404019.328585,1687665.635913 5404034.025593,1687635.645777 " + "5404041.324108,1687597.558222 5404039.734431,1687563.065855 " + "5404038.334716,1687503.176288 5404027.946831,1687339.207674 " + "5403984.07576,1687303.42071 5403984.07576,1687268.425347 " + "5403991.384273,1687241.733549 5404002.382034,1687194.897153 " + "5404036.974993,1687157.386808 5404074.487357,1687138.025565 " + "5404115.628983,1687142.865876 5404156.770609,1687175.535911 " + "5404259.619674,1687225.14291 5404338.273664,1687369.140089 " + "5404431.4447,1687438.108331 5404471.376572,1687479.246848 " + "5404489.522878,1687531.888318 5404490.732632,1687547.802798 " + "5404451.100699,1687563.304985 5404415.957852,1687535.508244 " + "5404415.757893,1687520.517299 5404420.656896,1687488.020426 " + "5404417.967443,1687440.631559 5404400.071086,1687393.242692 " + "5404374.786232,1687306.15833 5404316.708054,1687273.859358 " + "5404283.914729,1687256.559577 5404251.321363,1687221.861064 " + "5404213.539054,1687212.254656 5404148.452302,1687219.956274 " + "5404128.556352,1687250.14431 5404101.261907,1687282.731887 " + "5404083.95543,1687317.8262 5404074.157425,1687360.317036 " + "5404071.957872,1687385.31019 5404077.146816,1687462.697439 " + "5404102.731608,1687512.683747 5404103.031547,1687550.169355 " + "5404095.823015,1687628.084338 5404107.160707,1687687.743021 " + "5404083.215581,1687762.219487 5404046.013153,1687805.402973 " + "5404008.720744,1687854.358551 5403919.598884,1687851.934273 " + "5403865.149967,1687851.934273 5403840.944894,1687834.997309 " + "5403804.652281,1687819.264238 5403765.930163,1687790.271849 " + "5403734.876484,1687732.987969 5403696.994195,1687695.593065 " + "5403681.697309,1687658.099211 5403673.908894,1687625.610584 " + "5403673.708935,1687580.621258 5403678.417976,1687512.939368 " + "5403697.914008,1687467.950041 5403697.624067,1687447.953869 " + "5403692.525105,1687410.558965 5403672.239234,1687393.259184 " + "5403649.643833,1687380.956384 5403612.051485,1687380.420404 " + "5403608.582191,1687367.92795 5403548.124497,1687370.352228 " + "5403520.290163,1687389.738208 5403461.882051,1687404.737399 " + "5403458.482743,1687417.229853 5403434.787566,1687417.518458 " + "5403387.297233,1687430.316008 5403344.805882,1687430.711809 " + "5403292.316566,1687420.9075 5403262.222691,1687406.106209 " + "5403237.127799,1687366.311765 5403194.346507,1687339.01802 " + "5403174.150618,1687244.33099 5403120.971443,1687211.941314 " + "5403108.284025,1687167.042691 5403080.489683,1687108.860014 " + "5403058.404178,1687067.366926 5403044.806946,1687056.465919 " + "5403042.517412,1686997.664804 5403038.708187,1686939.581076 " + "5403022.981388,1686857.304042 5402935.859122,1686793.176111 " + "5402754.356066,1686775.018762 5402684.170352,1686745.985144 " + "5402628.511682,1686720.571452 5402588.57981,1686652.807104 " + "5402515.974588,1686611.668586 5402447.008626,1686585.051001 " + "5402405.867,1686575.37038 5402357.466852,1686563.26548 " + "5402299.388674,1686537.860034 5402250.988525,1686499.137549 " + "5402218.315176,1686427.745029 5402205.007884,1686361.19282 " + "5402213.476161,1686295.85275 5402249.768774,1686220.832058 " + "5402293.329907,1686173.641091 5402324.793502,1686154.279849 " + "5402369.564389,1686154.279849 5402424.013307,1686182.109574 " + "5402528.082124,1686189.374162 5402658.755525,1686189.374162 " + "5402799.126953,1686160.332299 5402897.137004,1686125.237985 " + "5402923.751586,1686081.683436 5402923.751586,1686046.589123 " + "5402881.400207,1686009.078777 5402770.082865,1685950.99505 " + "5402647.867742,1685913.484704 5402586.160302,1685859.037394 " + "5402499.048033,1685819.10277 5402477.262468,1685802.165806 " + "5402472.423453,1685768.283632 5402472.423453,1685734.401458 " + "5402491.789511,1685727.145115 5402524.452862,1685717.464493 " + "5402605.52636,1685693.26294 5402678.131582,1685585.572214 " + "5402755.56582,1685504.499073 5402820.912519,1685460.936277 " + "5402880.200451,1685433.106553 5402935.859122,1685431.894414 " + "5402993.947298,1685460.936277 5403084.698826,1685460.936277 " + "5403142.777004,1685408.905 5403229.899271,1685337.51248 " + "5403281.92868,1685229.821753 5403319.441045,1685108.822234 " + "5403347.265381,1685005.971818 5403344.845874,1684916.430195 " + "5403326.699567,1684889.804364 5403294.026218,1684899.484985 " + "5403226.27001,1684946.675952 5403143.986758,1684981.770265 " + "5403067.752275,1685003.54754 5402989.098285,1685019.280611 " + "5402887.458974,1685015.652439 5402772.512371,1685007.175712 " + "5402592.219069,1685019.280611 5402466.374684,1685031.38551 " + "5402392.559709,1685042.270025 5402371.983897,1685054.374924 " + "5402341.740053,1685054.374924 5402318.744734,1685045.906442 " + "5402289.710643,1685007.183957 5402259.456802,1684949.10023 " + "5402241.300497,1684875.291678 5402258.247048,1684795.430676 " + "5402294.549659,1684711.941502 5402363.515621,1684667.166568 " + "5402415.54503,1684650.229604 5402485.730744,1684663.538396 " + "5402594.628578,1684697.420571 5402662.394785,1684771.229123 " + "5402726.521732,1684808.739469 5402774.92188,1684812.36764 " + "5402816.063506,1684780.909744 5402851.156363,1684740.97512 " + "5402870.512423,1684690.155982 5402868.092915,1684630.868361 " + "5402843.89784,1684517.61169 5402795.847621,1684435.32641 " + "5402765.263846,1684290.578859 5402730.590904,1684228.067113 " + "5402721.292796,1684133.289379 5402698.207495,1684030.810026 " + "5402682.520688,1684000 5402672.31399816))")); - bench().start( "StraightSkeleton of polygon - issue #80" ) ; + bench().start("StraightSkeleton of polygon - issue #80"); - int iterations = 1; - for ( int i = 0; i < iterations; i++ ) { - std::unique_ptr< Geometry > sum( algorithm::straightSkeleton( *g ) ); - } + int iterations = 1; + for (int i = 0; i < iterations; i++) { + std::unique_ptr sum(algorithm::straightSkeleton(*g)); + } - bench().stop(); + bench().stop(); } // See https://github.com/Oslandia/SFCGAL/issues/80 -BOOST_AUTO_TEST_CASE( testMultiPolygon80 ) +BOOST_AUTO_TEST_CASE(testMultiPolygon80) { - std::unique_ptr< Geometry > g( io::readWkt( -"MULTIPOLYGON(((1684000 5402672.31399816,1683946.034501 5402654.436405,1683891.240865 5402626.55208,1683828.852807 5402603.566759,1683763.966259 5402588.179891,1683710.005454 5402593.368835,1683643.321311 5402617.6139,1683558.455081 5402667.62372,1683479.657793 5402723.692308,1683393.274328 5402782.790279,1683344.780518 5402828.261023,1683302.347403 5402879.780536,1683275.07015 5402920.702207,1683275.07015 5402961.61388,1683285.674306 5403005.564933,1683312.951559 5403060.123828,1683325.081196 5403107.104265,1683319.0205 5403163.172853,1683291.735002 5403213.182673,1683214.454949 5403316.231698,1683131.097709 5403404.133806,1683071.999743 5403438.986712,1682985.616278 5403446.565169,1682940.462035 5403442.675961,1682880.415797 5403428.688808,1682817.343333 5403380.938527,1682774.09388 5403321.470632,1682729.94563 5403243.986403,1682692.10545 5403159.283644,1682682.878351 5403080.789622,1682680.67671 5403039.198087,1682654.257025 5402965.563076,1682628.876316 5402937.928701,1682608.979094 5402917.832791,1682537.124807 5402882.669948,1682377.221394 5402803.686025,1682327.432986 5402778.391174,1682247.745147 5402720.312996,1682225.349434 5402712.624561,1682183.51002 5402714.684141,1682145.917216 5402727.481536,1682113.964569 5402740.648856,1682089.985654 5402764.224058,1682069.700877 5402801.616447,1682051.708445 5402871.502221,1682004.624674 5402975.481057,1681970.354945 5403065.972638,1681952.560413 5403113.362991,1681928.037272 5403171.901076,1681920.830404 5403207.043923,1681928.936069 5403248.485488,1681963.684057 5403315.911763,1681985.700461 5403387.247243,1681982.097027 5403427.788991,1681972.696765 5403453.58374,1681959.998165 5403485.977147,1681917.119774 5403543.165506,1681871.734647 5403590.355901,1681801.356366 5403642.355317,1681698.275067 5403702.603053,1681626.709384 5403743.754677,1681565.82207 5403762.980764,1681486.530031 5403783.696547,1681395.528893 5403795.414162,1681308.13119 5403794.514345,1681281.134295 5403807.881624,1681309.029987 5403814.330312,1681347.777209 5403821.538844,1681443.280578 5403812.530678,1681535.188758 5403799.913246,1681627.995736 5403769.279482,1681693.294577 5403734.146633,1681743.478785 5403709.551639,1681819.010719 5403658.462038,1681882.981979 5403607.092494,1681939.746371 5403555.732948,1681968.582088 5403515.1912,1681992.008532 5403477.348903,1682001.920037 5403427.788991,1682003.725877 5403371.030544,1681981.181738 5403316.111723,1681950.564919 5403242.18677,1681946.961485 5403179.109609,1682053.819381 5402931.490011,1682074.706105 5402867.003137,1682087.000658 5402829.21083,1682109.882876 5402779.320985,1682132.47649 5402759.525014,1682162.573821 5402744.718028,1682197.659889 5402742.418496,1682230.057811 5402752.7164,1682274.948187 5402775.501762,1682361.422357 5402825.011685,1682456.810283 5402864.263695,1682563.989768 5402917.532852,1682603.784212 5402945.227215,1682636.380035 5402982.409647,1682648.855997 5403036.748586,1682663.269733 5403154.78456,1682694.397795 5403228.449566,1682727.240993 5403287.227602,1682756.07671 5403341.296596,1682792.11105 5403388.14706,1682830.858272 5403421.480275,1682900.37074 5403459.87246,1682942.762625 5403465.171382,1682975.012122 5403470.810234,1683049.26595 5403469.290543,1683114.432858 5403443.535786,1683203.842547 5403370.790593,1683279.613611 5403273.800335,1683328.107421 5403210.15329,1683356.901909 5403151.045321,1683353.875684 5403104.074882,1683331.141892 5403043.457221,1683309.925334 5402970.712028,1683311.44257 5402916.263111,1683346.297753 5402870.692386,1683408.43019 5402805.525651,1683487.235724 5402746.42768,1683575.128178 5402690.349095,1683641.804075 5402647.917731,1683706.970983 5402616.094209,1683741.826167 5402610.035442,1683781.26604 5402615.764276,1683816.261403 5402623.462709,1683915.838219 5402676.741864,1684000 5402711.41802501,1684020.618162 5402719.913077,1684068.00703 5402732.710472,1684222.971181 5402746.287709,1684311.424353 5402765.24385,1684450.572976 5402802.756215,1684578.837084 5402854.785624,1684651.433497 5402882.619959,1684708.305085 5402894.717496,1684763.964534 5402883.829712,1684819.632229 5402849.946609,1684837.781332 5402820.902521,1684835.357054 5402777.341388,1684817.207951 5402736.199762,1684749.451848 5402674.492322,1684704.676914 5402623.672666,1684682.899639 5402545.018676,1684682.899639 5402476.052714,1684692.58026 5402430.072073,1684739.771227 5402376.822912,1684837.781332 5402305.437442,1684921.270506 5402277.603108,1684981.770265 5402275.1836,1685015.652439 5402295.759412,1685031.38551 5402317.53498,1685032.589404 5402344.159561,1685010.812129 5402370.774143,1684991.450886 5402409.496261,1684989.026608 5402463.955177,1684972.089644 5402600.687345,1684985.398437 5402732.580499,1684986.610576 5402973.371486,1684959.984745 5403060.493753,1684920.058367 5403131.88922,1684881.335882 5403191.177153,1684863.186778 5403244.416316,1684864.398918 5403295.235972,1684898.281092 5403346.055628,1684949.10023 5403360.582671,1684989.991372 5403370.170719,1685072.524028 5403369.050947,1685162.065651 5403366.631439,1685254.023306 5403340.006859,1685345.989208 5403307.333509,1685395.596207 5403272.25065,1685445.211452 5403216.581982,1685470.616898 5403177.869861,1685479.085381 5403110.103655,1685482.045639 5403068.682086,1685463.360556 5403033.869172,1685454.883828 5402967.322718,1685471.829038 5402909.244539,1685532.328797 5402824.54178,1685646.071973 5402744.678036,1685708.996011 5402691.438873,1685723.508697 5402658.765523,1685736.825736 5402615.20439,1685746.506357 5402540.189659,1685759.81515 5402501.467541,1685788.857013 5402491.789511,1685819.10277 5402497.83828,1685850.568912 5402523.243109,1685873.558326 5402570.433503,1685896.54774 5402610.355377,1685964.303842 5402718.053456,1686003.026327 5402812.434245,1686041.748812 5402911.654049,1686076.843125 5402947.956659,1686111.929193 5402947.956659,1686147.023506 5402931.010109,1686182.109574 5402901.976019,1686202.682955 5402819.692767,1686214.779609 5402689.009367,1686209.939298 5402592.209071,1686193.002334 5402489.360005,1686178.481402 5402415.54503,1686177.269263 5402357.466852,1686222.044197 5402317.53498,1686324.894613 5402263.086063,1686418.064408 5402230.412713,1686484.616617 5402243.720005,1686519.710931 5402271.554339,1686541.488206 5402312.695965,1686559.637309 5402416.754784,1686598.359794 5402483.311237,1686663.699864 5402560.745475,1686704.838381 5402610.355377,1686724.199623 5402659.965279,1686748.401176 5402754.356066,1686777.44304 5402892.297989,1686816.165525 5402980.630009,1686864.560385 5403039.917941,1686942.005355 5403090.737597,1687020.654218 5403104.054886,1687121.088601 5403129.459715,1687190.056843 5403153.664788,1687232.440482 5403171.661125,1687258.83543 5403191.157157,1687296.032434 5403231.338978,1687323.334424 5403271.630776,1687350.331318 5403336.817508,1687355.138646 5403374.309876,1687354.940745 5403406.803263,1687349.539717 5403432.697992,1687329.213711 5403462.211984,1687315.904918 5403514.241394,1687305.012158 5403550.544005,1687302.868239 5403577.968422,1687302.58788 5403647.344301,1687337.682193 5403723.578784,1687378.82071 5403747.773859,1687485.299298 5403757.461887,1687540.966993 5403757.461887,1687609.935234 5403746.564105,1687666.509972 5403770.889154,1687709.800655 5403791.874882,1687749.595099 5403819.559247,1687766.993831 5403837.255645,1687789.191643 5403882.346467,1687788.993743 5403907.341379,1687781.30037 5403937.335274,1687766.103279 5403964.729698,1687735.915243 5403994.523634,1687698.231735 5404019.328585,1687665.635913 5404034.025593,1687635.645777 5404041.324108,1687597.558222 5404039.734431,1687563.065855 5404038.334716,1687503.176288 5404027.946831,1687339.207674 5403984.07576,1687303.42071 5403984.07576,1687268.425347 5403991.384273,1687241.733549 5404002.382034,1687194.897153 5404036.974993,1687157.386808 5404074.487357,1687138.025565 5404115.628983,1687142.865876 5404156.770609,1687175.535911 5404259.619674,1687225.14291 5404338.273664,1687369.140089 5404431.4447,1687438.108331 5404471.376572,1687479.246848 5404489.522878,1687531.888318 5404490.732632,1687547.802798 5404451.100699,1687563.304985 5404415.957852,1687535.508244 5404415.757893,1687520.517299 5404420.656896,1687488.020426 5404417.967443,1687440.631559 5404400.071086,1687393.242692 5404374.786232,1687306.15833 5404316.708054,1687273.859358 5404283.914729,1687256.559577 5404251.321363,1687221.861064 5404213.539054,1687212.254656 5404148.452302,1687219.956274 5404128.556352,1687250.14431 5404101.261907,1687282.731887 5404083.95543,1687317.8262 5404074.157425,1687360.317036 5404071.957872,1687385.31019 5404077.146816,1687462.697439 5404102.731608,1687512.683747 5404103.031547,1687550.169355 5404095.823015,1687628.084338 5404107.160707,1687687.743021 5404083.215581,1687762.219487 5404046.013153,1687805.402973 5404008.720744,1687854.358551 5403919.598884,1687851.934273 5403865.149967,1687851.934273 5403840.944894,1687834.997309 5403804.652281,1687819.264238 5403765.930163,1687790.271849 5403734.876484,1687732.987969 5403696.994195,1687695.593065 5403681.697309,1687658.099211 5403673.908894,1687625.610584 5403673.708935,1687580.621258 5403678.417976,1687512.939368 5403697.914008,1687467.950041 5403697.624067,1687447.953869 5403692.525105,1687410.558965 5403672.239234,1687393.259184 5403649.643833,1687380.956384 5403612.051485,1687380.420404 5403608.582191,1687367.92795 5403548.124497,1687370.352228 5403520.290163,1687389.738208 5403461.882051,1687404.737399 5403458.482743,1687417.229853 5403434.787566,1687417.518458 5403387.297233,1687430.316008 5403344.805882,1687430.711809 5403292.316566,1687420.9075 5403262.222691,1687406.106209 5403237.127799,1687366.311765 5403194.346507,1687339.01802 5403174.150618,1687244.33099 5403120.971443,1687211.941314 5403108.284025,1687167.042691 5403080.489683,1687108.860014 5403058.404178,1687067.366926 5403044.806946,1687056.465919 5403042.517412,1686997.664804 5403038.708187,1686939.581076 5403022.981388,1686857.304042 5402935.859122,1686793.176111 5402754.356066,1686775.018762 5402684.170352,1686745.985144 5402628.511682,1686720.571452 5402588.57981,1686652.807104 5402515.974588,1686611.668586 5402447.008626,1686585.051001 5402405.867,1686575.37038 5402357.466852,1686563.26548 5402299.388674,1686537.860034 5402250.988525,1686499.137549 5402218.315176,1686427.745029 5402205.007884,1686361.19282 5402213.476161,1686295.85275 5402249.768774,1686220.832058 5402293.329907,1686173.641091 5402324.793502,1686154.279849 5402369.564389,1686154.279849 5402424.013307,1686182.109574 5402528.082124,1686189.374162 5402658.755525,1686189.374162 5402799.126953,1686160.332299 5402897.137004,1686125.237985 5402923.751586,1686081.683436 5402923.751586,1686046.589123 5402881.400207,1686009.078777 5402770.082865,1685950.99505 5402647.867742,1685913.484704 5402586.160302,1685859.037394 5402499.048033,1685819.10277 5402477.262468,1685802.165806 5402472.423453,1685768.283632 5402472.423453,1685734.401458 5402491.789511,1685727.145115 5402524.452862,1685717.464493 5402605.52636,1685693.26294 5402678.131582,1685585.572214 5402755.56582,1685504.499073 5402820.912519,1685460.936277 5402880.200451,1685433.106553 5402935.859122,1685431.894414 5402993.947298,1685460.936277 5403084.698826,1685460.936277 5403142.777004,1685408.905 5403229.899271,1685337.51248 5403281.92868,1685229.821753 5403319.441045,1685108.822234 5403347.265381,1685005.971818 5403344.845874,1684916.430195 5403326.699567,1684889.804364 5403294.026218,1684899.484985 5403226.27001,1684946.675952 5403143.986758,1684981.770265 5403067.752275,1685003.54754 5402989.098285,1685019.280611 5402887.458974,1685015.652439 5402772.512371,1685007.175712 5402592.219069,1685019.280611 5402466.374684,1685031.38551 5402392.559709,1685042.270025 5402371.983897,1685054.374924 5402341.740053,1685054.374924 5402318.744734,1685045.906442 5402289.710643,1685007.183957 5402259.456802,1684949.10023 5402241.300497,1684875.291678 5402258.247048,1684795.430676 5402294.549659,1684711.941502 5402363.515621,1684667.166568 5402415.54503,1684650.229604 5402485.730744,1684663.538396 5402594.628578,1684697.420571 5402662.394785,1684771.229123 5402726.521732,1684808.739469 5402774.92188,1684812.36764 5402816.063506,1684780.909744 5402851.156363,1684740.97512 5402870.512423,1684690.155982 5402868.092915,1684630.868361 5402843.89784,1684517.61169 5402795.847621,1684435.32641 5402765.263846,1684290.578859 5402730.590904,1684228.067113 5402721.292796,1684133.289379 5402698.207495,1684030.810026 5402682.520688,1684000 5402672.31399816)))" - ) ); + std::unique_ptr g( + io::readWkt("MULTIPOLYGON(((1684000 5402672.31399816,1683946.034501 " + "5402654.436405,1683891.240865 5402626.55208,1683828.852807 " + "5402603.566759,1683763.966259 5402588.179891,1683710.005454 " + "5402593.368835,1683643.321311 5402617.6139,1683558.455081 " + "5402667.62372,1683479.657793 5402723.692308,1683393.274328 " + "5402782.790279,1683344.780518 5402828.261023,1683302.347403 " + "5402879.780536,1683275.07015 5402920.702207,1683275.07015 " + "5402961.61388,1683285.674306 5403005.564933,1683312.951559 " + "5403060.123828,1683325.081196 5403107.104265,1683319.0205 " + "5403163.172853,1683291.735002 5403213.182673,1683214.454949 " + "5403316.231698,1683131.097709 5403404.133806,1683071.999743 " + "5403438.986712,1682985.616278 5403446.565169,1682940.462035 " + "5403442.675961,1682880.415797 5403428.688808,1682817.343333 " + "5403380.938527,1682774.09388 5403321.470632,1682729.94563 " + "5403243.986403,1682692.10545 5403159.283644,1682682.878351 " + "5403080.789622,1682680.67671 5403039.198087,1682654.257025 " + "5402965.563076,1682628.876316 5402937.928701,1682608.979094 " + "5402917.832791,1682537.124807 5402882.669948,1682377.221394 " + "5402803.686025,1682327.432986 5402778.391174,1682247.745147 " + "5402720.312996,1682225.349434 5402712.624561,1682183.51002 " + "5402714.684141,1682145.917216 5402727.481536,1682113.964569 " + "5402740.648856,1682089.985654 5402764.224058,1682069.700877 " + "5402801.616447,1682051.708445 5402871.502221,1682004.624674 " + "5402975.481057,1681970.354945 5403065.972638,1681952.560413 " + "5403113.362991,1681928.037272 5403171.901076,1681920.830404 " + "5403207.043923,1681928.936069 5403248.485488,1681963.684057 " + "5403315.911763,1681985.700461 5403387.247243,1681982.097027 " + "5403427.788991,1681972.696765 5403453.58374,1681959.998165 " + "5403485.977147,1681917.119774 5403543.165506,1681871.734647 " + "5403590.355901,1681801.356366 5403642.355317,1681698.275067 " + "5403702.603053,1681626.709384 5403743.754677,1681565.82207 " + "5403762.980764,1681486.530031 5403783.696547,1681395.528893 " + "5403795.414162,1681308.13119 5403794.514345,1681281.134295 " + "5403807.881624,1681309.029987 5403814.330312,1681347.777209 " + "5403821.538844,1681443.280578 5403812.530678,1681535.188758 " + "5403799.913246,1681627.995736 5403769.279482,1681693.294577 " + "5403734.146633,1681743.478785 5403709.551639,1681819.010719 " + "5403658.462038,1681882.981979 5403607.092494,1681939.746371 " + "5403555.732948,1681968.582088 5403515.1912,1681992.008532 " + "5403477.348903,1682001.920037 5403427.788991,1682003.725877 " + "5403371.030544,1681981.181738 5403316.111723,1681950.564919 " + "5403242.18677,1681946.961485 5403179.109609,1682053.819381 " + "5402931.490011,1682074.706105 5402867.003137,1682087.000658 " + "5402829.21083,1682109.882876 5402779.320985,1682132.47649 " + "5402759.525014,1682162.573821 5402744.718028,1682197.659889 " + "5402742.418496,1682230.057811 5402752.7164,1682274.948187 " + "5402775.501762,1682361.422357 5402825.011685,1682456.810283 " + "5402864.263695,1682563.989768 5402917.532852,1682603.784212 " + "5402945.227215,1682636.380035 5402982.409647,1682648.855997 " + "5403036.748586,1682663.269733 5403154.78456,1682694.397795 " + "5403228.449566,1682727.240993 5403287.227602,1682756.07671 " + "5403341.296596,1682792.11105 5403388.14706,1682830.858272 " + "5403421.480275,1682900.37074 5403459.87246,1682942.762625 " + "5403465.171382,1682975.012122 5403470.810234,1683049.26595 " + "5403469.290543,1683114.432858 5403443.535786,1683203.842547 " + "5403370.790593,1683279.613611 5403273.800335,1683328.107421 " + "5403210.15329,1683356.901909 5403151.045321,1683353.875684 " + "5403104.074882,1683331.141892 5403043.457221,1683309.925334 " + "5402970.712028,1683311.44257 5402916.263111,1683346.297753 " + "5402870.692386,1683408.43019 5402805.525651,1683487.235724 " + "5402746.42768,1683575.128178 5402690.349095,1683641.804075 " + "5402647.917731,1683706.970983 5402616.094209,1683741.826167 " + "5402610.035442,1683781.26604 5402615.764276,1683816.261403 " + "5402623.462709,1683915.838219 5402676.741864,1684000 " + "5402711.41802501,1684020.618162 " + "5402719.913077,1684068.00703 5402732.710472,1684222.971181 " + "5402746.287709,1684311.424353 5402765.24385,1684450.572976 " + "5402802.756215,1684578.837084 5402854.785624,1684651.433497 " + "5402882.619959,1684708.305085 5402894.717496,1684763.964534 " + "5402883.829712,1684819.632229 5402849.946609,1684837.781332 " + "5402820.902521,1684835.357054 5402777.341388,1684817.207951 " + "5402736.199762,1684749.451848 5402674.492322,1684704.676914 " + "5402623.672666,1684682.899639 5402545.018676,1684682.899639 " + "5402476.052714,1684692.58026 5402430.072073,1684739.771227 " + "5402376.822912,1684837.781332 5402305.437442,1684921.270506 " + "5402277.603108,1684981.770265 5402275.1836,1685015.652439 " + "5402295.759412,1685031.38551 5402317.53498,1685032.589404 " + "5402344.159561,1685010.812129 5402370.774143,1684991.450886 " + "5402409.496261,1684989.026608 5402463.955177,1684972.089644 " + "5402600.687345,1684985.398437 5402732.580499,1684986.610576 " + "5402973.371486,1684959.984745 5403060.493753,1684920.058367 " + "5403131.88922,1684881.335882 5403191.177153,1684863.186778 " + "5403244.416316,1684864.398918 5403295.235972,1684898.281092 " + "5403346.055628,1684949.10023 5403360.582671,1684989.991372 " + "5403370.170719,1685072.524028 5403369.050947,1685162.065651 " + "5403366.631439,1685254.023306 5403340.006859,1685345.989208 " + "5403307.333509,1685395.596207 5403272.25065,1685445.211452 " + "5403216.581982,1685470.616898 5403177.869861,1685479.085381 " + "5403110.103655,1685482.045639 5403068.682086,1685463.360556 " + "5403033.869172,1685454.883828 5402967.322718,1685471.829038 " + "5402909.244539,1685532.328797 5402824.54178,1685646.071973 " + "5402744.678036,1685708.996011 5402691.438873,1685723.508697 " + "5402658.765523,1685736.825736 5402615.20439,1685746.506357 " + "5402540.189659,1685759.81515 5402501.467541,1685788.857013 " + "5402491.789511,1685819.10277 5402497.83828,1685850.568912 " + "5402523.243109,1685873.558326 5402570.433503,1685896.54774 " + "5402610.355377,1685964.303842 5402718.053456,1686003.026327 " + "5402812.434245,1686041.748812 5402911.654049,1686076.843125 " + "5402947.956659,1686111.929193 5402947.956659,1686147.023506 " + "5402931.010109,1686182.109574 5402901.976019,1686202.682955 " + "5402819.692767,1686214.779609 5402689.009367,1686209.939298 " + "5402592.209071,1686193.002334 5402489.360005,1686178.481402 " + "5402415.54503,1686177.269263 5402357.466852,1686222.044197 " + "5402317.53498,1686324.894613 5402263.086063,1686418.064408 " + "5402230.412713,1686484.616617 5402243.720005,1686519.710931 " + "5402271.554339,1686541.488206 5402312.695965,1686559.637309 " + "5402416.754784,1686598.359794 5402483.311237,1686663.699864 " + "5402560.745475,1686704.838381 5402610.355377,1686724.199623 " + "5402659.965279,1686748.401176 5402754.356066,1686777.44304 " + "5402892.297989,1686816.165525 5402980.630009,1686864.560385 " + "5403039.917941,1686942.005355 5403090.737597,1687020.654218 " + "5403104.054886,1687121.088601 5403129.459715,1687190.056843 " + "5403153.664788,1687232.440482 5403171.661125,1687258.83543 " + "5403191.157157,1687296.032434 5403231.338978,1687323.334424 " + "5403271.630776,1687350.331318 5403336.817508,1687355.138646 " + "5403374.309876,1687354.940745 5403406.803263,1687349.539717 " + "5403432.697992,1687329.213711 5403462.211984,1687315.904918 " + "5403514.241394,1687305.012158 5403550.544005,1687302.868239 " + "5403577.968422,1687302.58788 5403647.344301,1687337.682193 " + "5403723.578784,1687378.82071 5403747.773859,1687485.299298 " + "5403757.461887,1687540.966993 5403757.461887,1687609.935234 " + "5403746.564105,1687666.509972 5403770.889154,1687709.800655 " + "5403791.874882,1687749.595099 5403819.559247,1687766.993831 " + "5403837.255645,1687789.191643 5403882.346467,1687788.993743 " + "5403907.341379,1687781.30037 5403937.335274,1687766.103279 " + "5403964.729698,1687735.915243 5403994.523634,1687698.231735 " + "5404019.328585,1687665.635913 5404034.025593,1687635.645777 " + "5404041.324108,1687597.558222 5404039.734431,1687563.065855 " + "5404038.334716,1687503.176288 5404027.946831,1687339.207674 " + "5403984.07576,1687303.42071 5403984.07576,1687268.425347 " + "5403991.384273,1687241.733549 5404002.382034,1687194.897153 " + "5404036.974993,1687157.386808 5404074.487357,1687138.025565 " + "5404115.628983,1687142.865876 5404156.770609,1687175.535911 " + "5404259.619674,1687225.14291 5404338.273664,1687369.140089 " + "5404431.4447,1687438.108331 5404471.376572,1687479.246848 " + "5404489.522878,1687531.888318 5404490.732632,1687547.802798 " + "5404451.100699,1687563.304985 5404415.957852,1687535.508244 " + "5404415.757893,1687520.517299 5404420.656896,1687488.020426 " + "5404417.967443,1687440.631559 5404400.071086,1687393.242692 " + "5404374.786232,1687306.15833 5404316.708054,1687273.859358 " + "5404283.914729,1687256.559577 5404251.321363,1687221.861064 " + "5404213.539054,1687212.254656 5404148.452302,1687219.956274 " + "5404128.556352,1687250.14431 5404101.261907,1687282.731887 " + "5404083.95543,1687317.8262 5404074.157425,1687360.317036 " + "5404071.957872,1687385.31019 5404077.146816,1687462.697439 " + "5404102.731608,1687512.683747 5404103.031547,1687550.169355 " + "5404095.823015,1687628.084338 5404107.160707,1687687.743021 " + "5404083.215581,1687762.219487 5404046.013153,1687805.402973 " + "5404008.720744,1687854.358551 5403919.598884,1687851.934273 " + "5403865.149967,1687851.934273 5403840.944894,1687834.997309 " + "5403804.652281,1687819.264238 5403765.930163,1687790.271849 " + "5403734.876484,1687732.987969 5403696.994195,1687695.593065 " + "5403681.697309,1687658.099211 5403673.908894,1687625.610584 " + "5403673.708935,1687580.621258 5403678.417976,1687512.939368 " + "5403697.914008,1687467.950041 5403697.624067,1687447.953869 " + "5403692.525105,1687410.558965 5403672.239234,1687393.259184 " + "5403649.643833,1687380.956384 5403612.051485,1687380.420404 " + "5403608.582191,1687367.92795 5403548.124497,1687370.352228 " + "5403520.290163,1687389.738208 5403461.882051,1687404.737399 " + "5403458.482743,1687417.229853 5403434.787566,1687417.518458 " + "5403387.297233,1687430.316008 5403344.805882,1687430.711809 " + "5403292.316566,1687420.9075 5403262.222691,1687406.106209 " + "5403237.127799,1687366.311765 5403194.346507,1687339.01802 " + "5403174.150618,1687244.33099 5403120.971443,1687211.941314 " + "5403108.284025,1687167.042691 5403080.489683,1687108.860014 " + "5403058.404178,1687067.366926 5403044.806946,1687056.465919 " + "5403042.517412,1686997.664804 5403038.708187,1686939.581076 " + "5403022.981388,1686857.304042 5402935.859122,1686793.176111 " + "5402754.356066,1686775.018762 5402684.170352,1686745.985144 " + "5402628.511682,1686720.571452 5402588.57981,1686652.807104 " + "5402515.974588,1686611.668586 5402447.008626,1686585.051001 " + "5402405.867,1686575.37038 5402357.466852,1686563.26548 " + "5402299.388674,1686537.860034 5402250.988525,1686499.137549 " + "5402218.315176,1686427.745029 5402205.007884,1686361.19282 " + "5402213.476161,1686295.85275 5402249.768774,1686220.832058 " + "5402293.329907,1686173.641091 5402324.793502,1686154.279849 " + "5402369.564389,1686154.279849 5402424.013307,1686182.109574 " + "5402528.082124,1686189.374162 5402658.755525,1686189.374162 " + "5402799.126953,1686160.332299 5402897.137004,1686125.237985 " + "5402923.751586,1686081.683436 5402923.751586,1686046.589123 " + "5402881.400207,1686009.078777 5402770.082865,1685950.99505 " + "5402647.867742,1685913.484704 5402586.160302,1685859.037394 " + "5402499.048033,1685819.10277 5402477.262468,1685802.165806 " + "5402472.423453,1685768.283632 5402472.423453,1685734.401458 " + "5402491.789511,1685727.145115 5402524.452862,1685717.464493 " + "5402605.52636,1685693.26294 5402678.131582,1685585.572214 " + "5402755.56582,1685504.499073 5402820.912519,1685460.936277 " + "5402880.200451,1685433.106553 5402935.859122,1685431.894414 " + "5402993.947298,1685460.936277 5403084.698826,1685460.936277 " + "5403142.777004,1685408.905 5403229.899271,1685337.51248 " + "5403281.92868,1685229.821753 5403319.441045,1685108.822234 " + "5403347.265381,1685005.971818 5403344.845874,1684916.430195 " + "5403326.699567,1684889.804364 5403294.026218,1684899.484985 " + "5403226.27001,1684946.675952 5403143.986758,1684981.770265 " + "5403067.752275,1685003.54754 5402989.098285,1685019.280611 " + "5402887.458974,1685015.652439 5402772.512371,1685007.175712 " + "5402592.219069,1685019.280611 5402466.374684,1685031.38551 " + "5402392.559709,1685042.270025 5402371.983897,1685054.374924 " + "5402341.740053,1685054.374924 5402318.744734,1685045.906442 " + "5402289.710643,1685007.183957 5402259.456802,1684949.10023 " + "5402241.300497,1684875.291678 5402258.247048,1684795.430676 " + "5402294.549659,1684711.941502 5402363.515621,1684667.166568 " + "5402415.54503,1684650.229604 5402485.730744,1684663.538396 " + "5402594.628578,1684697.420571 5402662.394785,1684771.229123 " + "5402726.521732,1684808.739469 5402774.92188,1684812.36764 " + "5402816.063506,1684780.909744 5402851.156363,1684740.97512 " + "5402870.512423,1684690.155982 5402868.092915,1684630.868361 " + "5402843.89784,1684517.61169 5402795.847621,1684435.32641 " + "5402765.263846,1684290.578859 5402730.590904,1684228.067113 " + "5402721.292796,1684133.289379 5402698.207495,1684030.810026 " + "5402682.520688,1684000 5402672.31399816)))")); - bench().start( "StraightSkeleton of multipolygon - issue #80" ) ; + bench().start("StraightSkeleton of multipolygon - issue #80"); - int iterations = 1; - for ( int i = 0; i < iterations; i++ ) { - std::unique_ptr< Geometry > sum( algorithm::straightSkeleton( *g ) ); - } + int iterations = 1; + for (int i = 0; i < iterations; i++) { + std::unique_ptr sum(algorithm::straightSkeleton(*g)); + } - bench().stop(); + bench().stop(); } - - BOOST_AUTO_TEST_SUITE_END() - - - - - -//BOOST_AUTO_TEST_CASE( testTemp ){ -// std::unique_ptr< Geometry > gA( io::readWkt("MULTIPOLYGON(((11.795461 32.713032,11.381695 35.857648,15.188336 38.091981,28.428825 38.257487,30.994170 33.788822,30.580405 29.816675,26.773764 22.617159,11.050683 18.562259,-0.534745 21.044851,-3.513855 26.837565,3.520155 26.506553,4.099426 24.685985,4.678698 22.782665,6.582018 21.541369,8.899104 21.458616,16.098620 21.706875,18.332952 25.016998,17.919187 27.499589,16.429632 27.830601,14.360805 26.175540,13.036756 24.520479,10.885177 23.527442,8.733597 23.527442,6.002747 24.603232,4.595945 26.506553,1.203069 27.830601,1.368575 30.892465,2.113353 34.202587,4.678698 36.519672,6.664771 36.188660,8.071573 34.699105,7.409549 32.630279,5.837240 31.968254,5.919993 30.064934,7.575055 28.740885,10.802424 27.582342,12.126473 27.913355,13.781534 28.740885,14.443558 29.816675,14.691818 31.306230,14.278052 33.126797,13.450522 34.119834,11.795461 32.713032),(21.477568 36.188660,15.684854 36.271413,14.609065 28.161614,15.022830 27.582342,20.401779 29.816675,29.339109 32.133760,21.477568 36.188660)))") ); -// std::unique_ptr< Geometry > gB( io::readWkt( "POLYGON((-1 0,0 -1,1 0,0 1,-1 0))" ) ); +// BOOST_AUTO_TEST_CASE( testTemp ){ +// std::unique_ptr< Geometry > gA( +// io::readWkt("MULTIPOLYGON(((11.795461 32.713032,11.381695 35.857648,15.188336 38.091981,28.428825 +// 38.257487,30.994170 33.788822,30.580405 29.816675,26.773764 22.617159,11.050683 +// 18.562259,-0.534745 21.044851,-3.513855 26.837565,3.520155 26.506553,4.099426 24.685985,4.678698 +// 22.782665,6.582018 21.541369,8.899104 21.458616,16.098620 21.706875,18.332952 25.016998,17.919187 +// 27.499589,16.429632 27.830601,14.360805 26.175540,13.036756 24.520479,10.885177 +// 23.527442,8.733597 23.527442,6.002747 24.603232,4.595945 26.506553,1.203069 27.830601,1.368575 +// 30.892465,2.113353 34.202587,4.678698 36.519672,6.664771 36.188660,8.071573 34.699105,7.409549 +// 32.630279,5.837240 31.968254,5.919993 30.064934,7.575055 28.740885,10.802424 27.582342,12.126473 +// 27.913355,13.781534 28.740885,14.443558 29.816675,14.691818 31.306230,14.278052 +// 33.126797,13.450522 34.119834,11.795461 32.713032),(21.477568 36.188660,15.684854 +// 36.271413,14.609065 28.161614,15.022830 27.582342,20.401779 29.816675,29.339109 +// 32.133760,21.477568 36.188660)))") ); std::unique_ptr< Geometry > gB( +// io::readWkt( "POLYGON((-1 0,0 -1,1 0,0 1,-1 0))" ) ); // -// std::unique_ptr< Geometry > sum( algorithm::minkowskiSum( *gA, gB->as< Polygon >() ) ); -// std::cout << sum->asText(6) << std::endl ; -//} +// std::unique_ptr< Geometry > sum( algorithm::minkowskiSum( *gA, gB->as< +// Polygon >() ) ); std::cout << sum->asText(6) << std::endl ; +// } diff --git a/test/bench/BenchTriangulation.cpp b/test/bench/BenchTriangulation.cpp index 2f95a5bc..a211e67f 100644 --- a/test/bench/BenchTriangulation.cpp +++ b/test/bench/BenchTriangulation.cpp @@ -15,178 +15,169 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include -#include -#include -#include -#include -#include -#include -#include #include -#include +#include #include +#include #include #include -#include -#include +#include +#include +#include +#include +#include +#include #include +#include +#include #include #include #include "../test_config.h" #include "Bench.h" -#include #include +#include #include -using namespace boost::unit_test ; -using namespace SFCGAL ; -using namespace SFCGAL::triangulate ; +using namespace boost::unit_test; +using namespace SFCGAL; +using namespace SFCGAL::triangulate; #define N_POINTS 100000 -typedef CGAL::Creator_uniform_2< double, Kernel::Point_2 > Creator ; - +typedef CGAL::Creator_uniform_2 Creator; -BOOST_AUTO_TEST_SUITE( SFCGAL_BenchTriangulation ) +BOOST_AUTO_TEST_SUITE(SFCGAL_BenchTriangulation) -BOOST_AUTO_TEST_CASE( testMultiPointTriangulation ) +BOOST_AUTO_TEST_CASE(testMultiPointTriangulation) { - CGAL::Random_points_in_disc_2< Kernel::Point_2, Creator > g( 150.0 ); + CGAL::Random_points_in_disc_2 g(150.0); - MultiPoint multiPoint ; + MultiPoint multiPoint; - for ( int i = 0; i < N_POINTS; i++ ) { - Kernel::Point_2 p = *( ++g ) ; - multiPoint.addGeometry( new Point( p ) ) ; - } + for (int i = 0; i < N_POINTS; i++) { + Kernel::Point_2 p = *(++g); + multiPoint.addGeometry(new Point(p)); + } - bench().start( boost::format( "triangulate2DZ %s points" ) % N_POINTS ); - ConstraintDelaunayTriangulation cdt = triangulate2DZ( multiPoint ) ; - bench().stop(); + bench().start(boost::format("triangulate2DZ %s points") % N_POINTS); + ConstraintDelaunayTriangulation cdt = triangulate2DZ(multiPoint); + bench().stop(); } - -BOOST_AUTO_TEST_CASE( testPolygonTriangulationHoch ) +BOOST_AUTO_TEST_CASE(testPolygonTriangulationHoch) { - const int N = 7 ; - std::unique_ptr< Polygon > fractal( generator::hoch( N ) ); - BOOST_CHECK_EQUAL( fractal->exteriorRing().numPoints(), 49153U ); - - bench().start( boost::format( "triangulate hoch(%s)" ) % N ); - TriangulatedSurface triangulatedSurface ; - SFCGAL::triangulate::triangulatePolygon3D( *fractal, triangulatedSurface ) ; - bench().stop() ; + const int N = 7; + std::unique_ptr fractal(generator::hoch(N)); + BOOST_CHECK_EQUAL(fractal->exteriorRing().numPoints(), 49153U); + + bench().start(boost::format("triangulate hoch(%s)") % N); + TriangulatedSurface triangulatedSurface; + SFCGAL::triangulate::triangulatePolygon3D(*fractal, triangulatedSurface); + bench().stop(); } -BOOST_AUTO_TEST_CASE( testPolygonTriangulationHoch_roundingSixDecimal ) +BOOST_AUTO_TEST_CASE(testPolygonTriangulationHoch_roundingSixDecimal) { - const int N = 7 ; - std::unique_ptr< Polygon > fractal( generator::hoch( N ) ); - BOOST_CHECK_EQUAL( fractal->exteriorRing().numPoints(), 49153U ); + const int N = 7; + std::unique_ptr fractal(generator::hoch(N)); + BOOST_CHECK_EQUAL(fractal->exteriorRing().numPoints(), 49153U); - fractal->round( 100000 ) ; + fractal->round(100000); - bench().start( boost::format( "triangulate hoch(%s) (round 6 six decimals)" ) % N ); - TriangulatedSurface triangulatedSurface ; - SFCGAL::triangulate::triangulatePolygon3D( *fractal, triangulatedSurface ) ; - bench().stop() ; + bench().start(boost::format("triangulate hoch(%s) (round 6 six decimals)") % + N); + TriangulatedSurface triangulatedSurface; + SFCGAL::triangulate::triangulatePolygon3D(*fractal, triangulatedSurface); + bench().stop(); } - - -BOOST_AUTO_TEST_CASE( testPolygonTriangulationDisc ) +BOOST_AUTO_TEST_CASE(testPolygonTriangulationDisc) { - const int N = 20000 ; + const int N = 20000; - std::unique_ptr< Polygon > disc( generator::disc( Point( 0.0,0.0 ), 1.0, 8U ) ); -// std::cout << fractal->asText(5) << std::endl ; + std::unique_ptr disc(generator::disc(Point(0.0, 0.0), 1.0, 8U)); + // std::cout << fractal->asText(5) << std::endl ; - bench().start( boost::format( "triangulate disc x %s" ) % N ); + bench().start(boost::format("triangulate disc x %s") % N); - for ( int i = 0; i < N; i++ ) { - TriangulatedSurface triangulatedSurface ; - SFCGAL::triangulate::triangulatePolygon3D( *disc, triangulatedSurface ) ; - } + for (int i = 0; i < N; i++) { + TriangulatedSurface triangulatedSurface; + SFCGAL::triangulate::triangulatePolygon3D(*disc, triangulatedSurface); + } - bench().stop(); + bench().stop(); } - - - -BOOST_AUTO_TEST_CASE( testMultiPointTriangulation2D ) +BOOST_AUTO_TEST_CASE(testMultiPointTriangulation2D) { - CGAL::Random_points_in_disc_2< Kernel::Point_2, Creator > g( 150.0 ); + CGAL::Random_points_in_disc_2 g(150.0); - MultiPoint multiPoint ; + MultiPoint multiPoint; - for ( int i = 0; i < N_POINTS; i++ ) { - Kernel::Point_2 p = *( ++g ) ; - multiPoint.addGeometry( new Point( p ) ) ; - } + for (int i = 0; i < N_POINTS; i++) { + Kernel::Point_2 p = *(++g); + multiPoint.addGeometry(new Point(p)); + } - bench().start( boost::format( "triangulate2D %s points" ) % N_POINTS ); - SFCGAL::triangulate::ConstraintDelaunayTriangulation cdt; - SFCGAL::triangulate::triangulate2DZ( multiPoint, cdt ) ; - bench().stop(); + bench().start(boost::format("triangulate2D %s points") % N_POINTS); + SFCGAL::triangulate::ConstraintDelaunayTriangulation cdt; + SFCGAL::triangulate::triangulate2DZ(multiPoint, cdt); + bench().stop(); } -BOOST_AUTO_TEST_CASE( testPolygonTriangulationHoch2D ) +BOOST_AUTO_TEST_CASE(testPolygonTriangulationHoch2D) { - const int N = 7 ; - std::unique_ptr< Polygon > fractal( generator::hoch( N ) ); -// std::cout << fractal->asText(5) << std::endl ; - - bench().start( boost::format( "triangulate2D hoch(%s)" ) % N ); - SFCGAL::triangulate::ConstraintDelaunayTriangulation cdt; - SFCGAL::triangulate::triangulate2DZ( *fractal, cdt ) ; - bench().stop(); + const int N = 7; + std::unique_ptr fractal(generator::hoch(N)); + // std::cout << fractal->asText(5) << std::endl ; + + bench().start(boost::format("triangulate2D hoch(%s)") % N); + SFCGAL::triangulate::ConstraintDelaunayTriangulation cdt; + SFCGAL::triangulate::triangulate2DZ(*fractal, cdt); + bench().stop(); } -BOOST_AUTO_TEST_CASE( testPolygonTriangulationDisc2D ) +BOOST_AUTO_TEST_CASE(testPolygonTriangulationDisc2D) { - const int N = 20000 ; + const int N = 20000; - std::unique_ptr< Polygon > disc( generator::disc( Point( 0.0,0.0 ), 1.0, 8U ) ) ; -// std::cout << fractal->asText(5) << std::endl ; + std::unique_ptr disc(generator::disc(Point(0.0, 0.0), 1.0, 8U)); + // std::cout << fractal->asText(5) << std::endl ; - bench().start( boost::format( "triangulate2D disc x %s" ) % N ) ; + bench().start(boost::format("triangulate2D disc x %s") % N); - for ( int i = 0; i < N; i++ ) { - SFCGAL::triangulate::ConstraintDelaunayTriangulation cdt; - SFCGAL::triangulate::triangulate2DZ( *disc, cdt ) ; - } + for (int i = 0; i < N; i++) { + SFCGAL::triangulate::ConstraintDelaunayTriangulation cdt; + SFCGAL::triangulate::triangulate2DZ(*disc, cdt); + } - bench().stop() ; + bench().stop(); } -BOOST_AUTO_TEST_CASE( testPolygonTriangulationDisc2D_roundingSixDecimal ) +BOOST_AUTO_TEST_CASE(testPolygonTriangulationDisc2D_roundingSixDecimal) { - const int N = 20000 ; + const int N = 20000; - std::unique_ptr< Polygon > disc( generator::disc( Point( 0.0,0.0 ), 1.0, 8U ) ) ; - disc->round( 100000 ) ; + std::unique_ptr disc(generator::disc(Point(0.0, 0.0), 1.0, 8U)); + disc->round(100000); - bench().start( boost::format( "triangulate2D disc x %s (round 6 six decimals)" ) % N ) ; + bench().start( + boost::format("triangulate2D disc x %s (round 6 six decimals)") % N); - for ( int i = 0; i < N; i++ ) { - SFCGAL::triangulate::ConstraintDelaunayTriangulation cdt; - SFCGAL::triangulate::triangulate2DZ( *disc, cdt ) ; - } + for (int i = 0; i < N; i++) { + SFCGAL::triangulate::ConstraintDelaunayTriangulation cdt; + SFCGAL::triangulate::triangulate2DZ(*disc, cdt); + } - bench().stop() ; + bench().stop(); } - BOOST_AUTO_TEST_SUITE_END() - - - - diff --git a/test/bench/BenchWKT.cpp b/test/bench/BenchWKT.cpp index 22bc6ef8..ad10ca5b 100644 --- a/test/bench/BenchWKT.cpp +++ b/test/bench/BenchWKT.cpp @@ -15,116 +15,122 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include -#include -#include -#include -#include -#include -#include -#include #include -#include +#include #include +#include #include #include +#include +#include +#include +#include +#include +#include #include #include "../test_config.h" #include "Bench.h" -#include #include +#include -using namespace boost::unit_test ; -using namespace SFCGAL ; +using namespace boost::unit_test; +using namespace SFCGAL; -BOOST_AUTO_TEST_SUITE( SFCGAL_BenchWKT ) +BOOST_AUTO_TEST_SUITE(SFCGAL_BenchWKT) // // Test limit case -BOOST_AUTO_TEST_CASE( testReadPoints ) +BOOST_AUTO_TEST_CASE(testReadPoints) { - const int N = 100000 ; + const int N = 100000; - bench().start( boost::format( "READ WKT POINTS" ) ); + bench().start(boost::format("READ WKT POINTS")); - for ( int i = 0; i < N; i++ ) { - io::readWkt( "POINT(50000 50000)" ) ; - } + for (int i = 0; i < N; i++) { + io::readWkt("POINT(50000 50000)"); + } - bench().stop() ; + bench().stop(); } - // // Test limit case -BOOST_AUTO_TEST_CASE( testReadLineString ) +BOOST_AUTO_TEST_CASE(testReadLineString) { - const int N = 100000 ; + const int N = 100000; - bench().start( boost::format( "READ WKT LINESTRING" ) ) ; + bench().start(boost::format("READ WKT LINESTRING")); - for ( int i = 0; i < N; i++ ) { - io::readWkt( "LINESTRING(0 0,0 1000,1000 1000)" ) ; - } + for (int i = 0; i < N; i++) { + io::readWkt("LINESTRING(0 0,0 1000,1000 1000)"); + } - bench().stop() ; + bench().stop(); } // // Test limit case -BOOST_AUTO_TEST_CASE( testReadPolygon ) +BOOST_AUTO_TEST_CASE(testReadPolygon) { - const int N = 100000 ; + const int N = 100000; - bench().start( boost::format( "READ WKT POLYGON" ) ) ; + bench().start(boost::format("READ WKT POLYGON")); - for ( int i = 0; i < N; i++ ) { - io::readWkt( "POLYGON((0 0,0 1000,1000 1000,1000 0,0 0))" ) ; - } + for (int i = 0; i < N; i++) { + io::readWkt("POLYGON((0 0,0 1000,1000 1000,1000 0,0 0))"); + } - bench().stop(); + bench().stop(); } // // Test limit case -BOOST_AUTO_TEST_CASE( testReadTriangle ) +BOOST_AUTO_TEST_CASE(testReadTriangle) { - const int N = 100000 ; + const int N = 100000; - bench().start( boost::format( "READ WKT TRIANGLE" ) ) ; + bench().start(boost::format("READ WKT TRIANGLE")); - for ( int i = 0; i < N; i++ ) { - io::readWkt( "TRIANGLE((0 0,0 1000,1000 1000,0 0))" ) ; - } + for (int i = 0; i < N; i++) { + io::readWkt("TRIANGLE((0 0,0 1000,1000 1000,0 0))"); + } - bench().stop(); + bench().stop(); } // // Test limit case -BOOST_AUTO_TEST_CASE( testReadSolid ) +BOOST_AUTO_TEST_CASE(testReadSolid) { - const int N = 10000 ; - - bench().start( boost::format( "READ WKT SOLID" ) ) ; - - for ( int i = 0; i < N; i++ ) { - io::readWkt( "SOLID((((0.0 0.0 0.0,0.0 1.0 0.0,1.0 1.0 0.0,1.0 0.0 0.0,0.0 0.0 0.0),(0.2 0.2 0.0,0.8 0.2 0.0,0.8 0.8 0.0,0.2 0.8 0.0,0.2 0.2 0.0)),((0.0 0.0 1.0,1.0 0.0 1.0,1.0 1.0 1.0,0.0 1.0 1.0,0.0 0.0 1.0),(0.2 0.2 1.0,0.2 0.8 1.0,0.8 0.8 1.0,0.8 0.2 1.0,0.2 0.2 1.0)),((0.0 0.0 0.0,0.0 0.0 1.0,0.0 1.0 1.0,0.0 1.0 0.0,0.0 0.0 0.0)),((0.0 1.0 0.0,0.0 1.0 1.0,1.0 1.0 1.0,1.0 1.0 0.0,0.0 1.0 0.0)),((1.0 1.0 0.0,1.0 1.0 1.0,1.0 0.0 1.0,1.0 0.0 0.0,1.0 1.0 0.0)),((1.0 0.0 0.0,1.0 0.0 1.0,0.0 0.0 1.0,0.0 0.0 0.0,1.0 0.0 0.0)),((0.2 0.2 0.0,0.2 0.2 1.0,0.8 0.2 1.0,0.8 0.2 0.0,0.2 0.2 0.0)),((0.8 0.2 0.0,0.8 0.2 1.0,0.8 0.8 1.0,0.8 0.8 0.0,0.8 0.2 0.0)),((0.8 0.8 0.0,0.8 0.8 1.0,0.2 0.8 1.0,0.2 0.8 0.0,0.8 0.8 0.0)),((0.2 0.8 0.0,0.2 0.8 1.0,0.2 0.2 1.0,0.2 0.2 0.0,0.2 0.8 0.0))))" ) ; - } - - bench().stop(); + const int N = 10000; + + bench().start(boost::format("READ WKT SOLID")); + + for (int i = 0; i < N; i++) { + io::readWkt( + "SOLID((((0.0 0.0 0.0,0.0 1.0 0.0,1.0 1.0 0.0,1.0 0.0 0.0,0.0 0.0 " + "0.0),(0.2 0.2 0.0,0.8 0.2 0.0,0.8 0.8 0.0,0.2 0.8 0.0,0.2 0.2 " + "0.0)),((0.0 0.0 1.0,1.0 0.0 1.0,1.0 1.0 1.0,0.0 1.0 1.0,0.0 0.0 " + "1.0),(0.2 0.2 1.0,0.2 0.8 1.0,0.8 0.8 1.0,0.8 0.2 1.0,0.2 0.2 " + "1.0)),((0.0 0.0 0.0,0.0 0.0 1.0,0.0 1.0 1.0,0.0 1.0 0.0,0.0 0.0 " + "0.0)),((0.0 1.0 0.0,0.0 1.0 1.0,1.0 1.0 1.0,1.0 1.0 0.0,0.0 1.0 " + "0.0)),((1.0 1.0 0.0,1.0 1.0 1.0,1.0 0.0 1.0,1.0 0.0 0.0,1.0 1.0 " + "0.0)),((1.0 0.0 0.0,1.0 0.0 1.0,0.0 0.0 1.0,0.0 0.0 0.0,1.0 0.0 " + "0.0)),((0.2 0.2 0.0,0.2 0.2 1.0,0.8 0.2 1.0,0.8 0.2 0.0,0.2 0.2 " + "0.0)),((0.8 0.2 0.0,0.8 0.2 1.0,0.8 0.8 1.0,0.8 0.8 0.0,0.8 0.2 " + "0.0)),((0.8 0.8 0.0,0.8 0.8 1.0,0.2 0.8 1.0,0.2 0.8 0.0,0.8 0.8 " + "0.0)),((0.2 0.8 0.0,0.2 0.8 1.0,0.2 0.2 1.0,0.2 0.2 0.0,0.2 0.8 " + "0.0))))"); + } + + bench().stop(); } - - - BOOST_AUTO_TEST_SUITE_END() - - - - diff --git a/test/bench/IntersectionPerfTest.cpp b/test/bench/IntersectionPerfTest.cpp index c718c2df..827cba6c 100644 --- a/test/bench/IntersectionPerfTest.cpp +++ b/test/bench/IntersectionPerfTest.cpp @@ -15,75 +15,71 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include -#include -#include -#include -#include -#include -#include -#include #include -#include +#include #include +#include #include #include -#include +#include +#include +#include +#include +#include +#include +#include #include #include -#include +#include #include "../test_config.h" #include "Bench.h" -#include #include +#include -using namespace boost::unit_test ; -using namespace SFCGAL ; - -BOOST_AUTO_TEST_SUITE( SFCGAL_IntersectionPerfTest ) +using namespace boost::unit_test; +using namespace SFCGAL; +BOOST_AUTO_TEST_SUITE(SFCGAL_IntersectionPerfTest) #define N_POLYGONS 10000 #define N_POINTS 50 // // Test limit case -BOOST_AUTO_TEST_CASE( testIntersectionPerf ) +BOOST_AUTO_TEST_CASE(testIntersectionPerf) { - // - // generate polygons - std::vector polygons; + // + // generate polygons + std::vector polygons; - for ( size_t i = 0; i < N_POLYGONS; ++i ) { - MultiPoint mp; + for (size_t i = 0; i < N_POLYGONS; ++i) { + MultiPoint mp; - for ( size_t j = 0; j < N_POINTS; ++j ) { - double x = ( rand() +.0 ) / RAND_MAX * 10.0; - double y = ( rand() +.0 ) / RAND_MAX * 10.0; - mp.addGeometry( Point( x, y ) ); - } - - std::unique_ptr g( algorithm::convexHull( mp ) ); - polygons.push_back( g.release() ); + for (size_t j = 0; j < N_POINTS; ++j) { + double x = (rand() + .0) / RAND_MAX * 10.0; + double y = (rand() + .0) / RAND_MAX * 10.0; + mp.addGeometry(Point(x, y)); } - bench().start( "intersects convex hull" ); + std::unique_ptr g(algorithm::convexHull(mp)); + polygons.push_back(g.release()); + } - for ( size_t i = 0; i < N_POLYGONS / 2; ++i ) { - algorithm::intersects( *polygons[2*i], *polygons[2*i+1] ); - } + bench().start("intersects convex hull"); - bench().stop(); + for (size_t i = 0; i < N_POLYGONS / 2; ++i) { + algorithm::intersects(*polygons[2 * i], *polygons[2 * i + 1]); + } + + bench().stop(); } BOOST_AUTO_TEST_SUITE_END() - - - - diff --git a/test/bench/KernelPerfTest.cpp b/test/bench/KernelPerfTest.cpp index e49dba69..426a6182 100644 --- a/test/bench/KernelPerfTest.cpp +++ b/test/bench/KernelPerfTest.cpp @@ -15,71 +15,70 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include -#include -#include -#include -#include -#include -#include -#include #include -#include +#include #include +#include #include #include +#include +#include +#include +#include +#include +#include #include -#include #include +#include #include "../test_config.h" #include "Bench.h" -#include #include +#include -using namespace boost::unit_test ; -using namespace SFCGAL ; +using namespace boost::unit_test; +using namespace SFCGAL; -typedef CGAL::Exact_predicates_exact_constructions_kernel ExactKernel; +typedef CGAL::Exact_predicates_exact_constructions_kernel ExactKernel; typedef CGAL::Exact_predicates_inexact_constructions_kernel InexactKernel; -BOOST_AUTO_TEST_SUITE( SFCGAL_KernelPerfTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_KernelPerfTest) #define N_POINTS 10000000 // // Test limit case -BOOST_AUTO_TEST_CASE( testPointCopyPerf ) +BOOST_AUTO_TEST_CASE(testPointCopyPerf) { - bench().start( "Inexact kernel copy" ); - InexactKernel::Point_2 ip2; + bench().start("Inexact kernel copy"); + InexactKernel::Point_2 ip2; - for ( size_t i = 0; i < N_POINTS; ++i ) { - // test copy - InexactKernel::Point_2 p( ( double )rand() / RAND_MAX, ( double )rand() / RAND_MAX ); - ip2 = p; - } + for (size_t i = 0; i < N_POINTS; ++i) { + // test copy + InexactKernel::Point_2 p((double)rand() / RAND_MAX, + (double)rand() / RAND_MAX); + ip2 = p; + } - bench().stop(); + bench().stop(); - bench().start( "Exact kernel copy" ); - ExactKernel::Point_2 ep2; + bench().start("Exact kernel copy"); + ExactKernel::Point_2 ep2; - for ( size_t i = 0; i < N_POINTS; ++i ) { - // test copy - ExactKernel::Point_2 p( ( double )rand() / RAND_MAX, ( double )rand() / RAND_MAX ); - ep2 = p; - } + for (size_t i = 0; i < N_POINTS; ++i) { + // test copy + ExactKernel::Point_2 p((double)rand() / RAND_MAX, + (double)rand() / RAND_MAX); + ep2 = p; + } - bench().stop(); + bench().stop(); } BOOST_AUTO_TEST_SUITE_END() - - - - diff --git a/test/bench/TestModule.cpp b/test/bench/TestModule.cpp index 087b322f..9bb48261 100644 --- a/test/bench/TestModule.cpp +++ b/test/bench/TestModule.cpp @@ -15,15 +15,10 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #define BOOST_TEST_MODULE BenchTestSFCGAL #include -using namespace boost::unit_test ; - - - - - - +using namespace boost::unit_test; diff --git a/test/regress/convex_hull/main.cpp b/test/regress/convex_hull/main.cpp index 678c3167..10592ddf 100644 --- a/test/regress/convex_hull/main.cpp +++ b/test/regress/convex_hull/main.cpp @@ -15,206 +15,200 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ -#include #include +#include -#include #include +#include #include -#include -#include -#include -#include -#include -#include -#include #include -#include +#include #include +#include #include #include +#include +#include +#include +#include +#include +#include -#include #include +#include #include #include -using namespace SFCGAL ; - - -namespace po = boost::program_options ; +using namespace SFCGAL; +namespace po = boost::program_options; /* - * Triangulate each polygon in an input file containing lines in the following format : - * "|" ( | ) + * Triangulate each polygon in an input file containing lines in the following + * format : "|" ( | ) */ -int main( int argc, char* argv[] ) +auto +main(int argc, char *argv[]) -> int { - /* - * declare options - */ - po::options_description desc( "convex hull options : " ); - desc.add_options() - ( "help", "produce help message" ) - ( "progress", "display progress" ) - ( "verbose", "verbose mode" ) - ( "filename", po::value< std::string >(), "input filename (id|wkt_[multi]polygon on each line)" ) - ; - - po::variables_map vm; - po::store( po::parse_command_line( argc, argv, desc ), vm ); - po::notify( vm ); - - if ( vm.count( "help" ) ) { - std::cout << desc << std::endl ; - return 0; + /* + * declare options + */ + po::options_description desc("convex hull options : "); + desc.add_options()("help", "produce help message")( + "progress", "display progress")("verbose", "verbose mode")( + "filename", po::value(), + "input filename (id|wkt_[multi]polygon on each line)"); + + po::variables_map vm; + po::store(po::parse_command_line(argc, argv, desc), vm); + po::notify(vm); + + if (vm.count("help") != 0U) { + std::cout << desc << std::endl; + return 0; + } + + bool const verbose = vm.count("verbose") != 0; + bool const progress = vm.count("progress") != 0; + + std::string filename; + + if (vm.count("filename") != 0U) { + filename = vm["filename"].as(); + } else { + std::cerr << "missing input file" << std::endl; + std::cout << desc << std::endl; + return 1; + } + + /* + * open file + */ + std::ifstream ifs(filename.c_str()); + + if (!ifs.good()) { + std::cerr << "fail to open : " << filename << std::endl; + return 1; + } + + std::string const tri_filename(filename + ".convex.wkt"); + std::ofstream ofs_result(tri_filename.c_str()); + + if (!ofs_result.good()) { + std::cerr << "fail to write : " << tri_filename << std::endl; + return 1; + } + + std::string const error_filename(filename + ".error.wkt"); + std::ofstream ofs_error(error_filename.c_str()); + + if (!ofs_error.good()) { + std::cerr << "fail to write : " << error_filename << std::endl; + return 1; + } + + // boost::timer timer ; + boost::chrono::system_clock::time_point const start = + boost::chrono::system_clock::now(); + + /* + * process file + */ + int lineNumber = 0; + int numFailed = 0; + int numSuccess = 0; + std::string line; + + while (std::getline(ifs, line)) { + lineNumber++; + + boost::algorithm::trim(line); + + if (line.empty()) { + continue; } - bool verbose = vm.count( "verbose" ) != 0 ; - bool progress = vm.count( "progress" ) != 0 ; - - std::string filename ; - - if ( vm.count( "filename" ) ) { - filename = vm["filename"].as< std::string >() ; - } - else { - std::cerr << "missing input file" << std::endl; - std::cout << desc << std::endl ; - return 1 ; + if (verbose) { + std::cout << "#" << line << std::endl; + std::cout.flush(); } - /* - * open file - */ - std::ifstream ifs( filename.c_str() ); - - if ( ! ifs.good() ) { - std::cerr << "fail to open : " << filename << std::endl ; - return 1; + if (progress && lineNumber % 1000 == 0) { + std::cout.width(12); + boost::chrono::duration const elapsed = + boost::chrono::system_clock::now() - start; + std::cout << std::left << lineNumber << "(" << elapsed << " s)" + << std::endl; } - std::string tri_filename( filename+".convex.wkt" ); - std::ofstream ofs_result( tri_filename.c_str() ) ; + std::vector tokens; + boost::algorithm::split(tokens, line, boost::is_any_of("|")); - if ( ! ofs_result.good() ) { - std::cerr << "fail to write : " << tri_filename << std::endl ; - return 1; - } - - std::string error_filename( filename+".error.wkt" ); - std::ofstream ofs_error( error_filename.c_str() ) ; + std::string const &wkt = tokens.back(); + std::string id; - if ( ! ofs_error.good() ) { - std::cerr << "fail to write : " << error_filename << std::endl ; - return 1; + if (tokens.size() > 1) { + id = tokens.front(); + } else { + std::ostringstream oss; + oss << lineNumber; + id = oss.str(); } - - //boost::timer timer ; - boost::chrono::system_clock::time_point start = boost::chrono::system_clock::now(); - - /* - * process file - */ - int lineNumber = 0 , numFailed = 0 , numSuccess = 0 ; - std::string line ; - - while ( std::getline( ifs, line ) ) { - lineNumber++ ; - - boost::algorithm::trim( line ); - - if ( line.empty() ) { - continue ; - } - - if ( verbose ) { - std::cout << "#" << line << std::endl; - std::cout.flush(); - } - - - if ( progress && lineNumber % 1000 == 0 ) { - std::cout.width( 12 ) ; - boost::chrono::duration elapsed = boost::chrono::system_clock::now() - start; - std::cout << std::left << lineNumber << "(" << elapsed << " s)"<< std::endl ; - } - - - std::vector< std::string > tokens ; - boost::algorithm::split( tokens, line, boost::is_any_of( "|" ) ); - - std::string const& wkt = tokens.back() ; - std::string id ; - - if ( tokens.size() > 1 ) { - id = tokens.front() ; - } - else { - std::ostringstream oss; - oss << lineNumber ; - id = oss.str() ; - } - - //std::cout << "process " << id << std::endl; - - bool failed = true ; - - std::unique_ptr< Geometry > hull, hull3D ; - - try { - std::unique_ptr< Geometry > g; - g = io::readWkt( wkt ) ; - hull = algorithm::convexHull( *g ) ; - hull3D = algorithm::convexHull3D( *g ) ; - failed = false ; - } - catch ( Exception& e ) { - std::cerr << "[Exception]" << id << "|" << e.what() << "|" << wkt << std::endl ; - } - catch ( std::exception& e ) { - std::cerr << "[std::exception]" << id << "|" << e.what() << "|" << wkt << std::endl ; - } - catch ( ... ) { - std::cerr << "[...]" << id << "|" << wkt << std::endl ; - } - - if ( failed ) { - numFailed++ ; - ofs_error << line << std::endl ; - } - else { - numSuccess++ ; - } - - //output triangulated surface - ofs_result << id << "|" << failed << "|" << hull->asText( 5 ) << std::endl; - }//end for each line - - - ofs_error.close(); - ofs_result.close(); - - - boost::chrono::duration elapsed = boost::chrono::system_clock::now() - start; - std::cout << filename << " complete (" << elapsed << " s)---" << std::endl; - std::cout << numFailed << " failed /" << ( numFailed + numSuccess ) << std::endl ; - - if ( numFailed == 0 ) { - //delete empty error file - boost::filesystem::remove( error_filename ); - return EXIT_SUCCESS ; + // std::cout << "process " << id << std::endl; + + bool failed = true; + + std::unique_ptr hull; + std::unique_ptr hull3D; + + try { + std::unique_ptr g; + g = io::readWkt(wkt); + hull = algorithm::convexHull(*g); + hull3D = algorithm::convexHull3D(*g); + failed = false; + } catch (Exception &e) { + std::cerr << "[Exception]" << id << "|" << e.what() << "|" << wkt + << std::endl; + } catch (std::exception &e) { + std::cerr << "[std::exception]" << id << "|" << e.what() << "|" << wkt + << std::endl; + } catch (...) { + std::cerr << "[...]" << id << "|" << wkt << std::endl; } - else { - return EXIT_FAILURE ; + + if (failed) { + numFailed++; + ofs_error << line << std::endl; + } else { + numSuccess++; } -} + // output triangulated surface + ofs_result << id << "|" << failed << "|" << hull->asText(5) << std::endl; + } // end for each line + + ofs_error.close(); + ofs_result.close(); + + boost::chrono::duration const elapsed = + boost::chrono::system_clock::now() - start; + std::cout << filename << " complete (" << elapsed << " s)---" << std::endl; + std::cout << numFailed << " failed /" << (numFailed + numSuccess) + << std::endl; + + if (numFailed == 0) { + // delete empty error file + boost::filesystem::remove(error_filename); + return EXIT_SUCCESS; + } + return EXIT_FAILURE; +} diff --git a/test/regress/polygon_triangulator/main.cpp b/test/regress/polygon_triangulator/main.cpp index f741b5d0..d50f0db1 100644 --- a/test/regress/polygon_triangulator/main.cpp +++ b/test/regress/polygon_triangulator/main.cpp @@ -15,254 +15,252 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ -#include #include +#include -#include #include +#include #include -#include -#include -#include -#include -#include -#include -#include #include -#include +#include #include +#include #include #include +#include +#include +#include +#include +#include +#include -#include -#include -#include #include #include #include +#include +#include +#include #include #include -using namespace SFCGAL ; - - -namespace po = boost::program_options ; - - - - +using namespace SFCGAL; +namespace po = boost::program_options; /* - * Triangulate each polygon in an input file containing lines in the following format : - * "|" ( | ) + * Triangulate each polygon in an input file containing lines in the following + * format : "|" ( | ) */ -int main( int argc, char* argv[] ) +auto +main(int argc, char *argv[]) -> int { - /* - * declare options - */ - po::options_description desc( "polygon triangulator options : " ); - desc.add_options() - ( "help", "produce help message" ) - ( "progress", "display progress" ) - ( "verbose", "verbose mode" ) - ( "force2d","force 2d polygon" ) - ( "line", po::value< int >(), "line to test" ) - ( "filename", po::value< std::string >(), "input filename (id|wkt_[multi]polygon on each line)" ) - ; - - po::variables_map vm; - po::store( po::parse_command_line( argc, argv, desc ), vm ); - po::notify( vm ); - - if ( vm.count( "help" ) ) { - std::cout << desc << std::endl ; - return 0; + /* + * declare options + */ + po::options_description desc("polygon triangulator options : "); + desc.add_options()("help", "produce help message")( + "progress", "display progress")("verbose", "verbose mode")( + "force2d", "force 2d polygon")("line", po::value(), "line to test")( + "filename", po::value(), + "input filename (id|wkt_[multi]polygon on each line)"); + + po::variables_map vm; + po::store(po::parse_command_line(argc, argv, desc), vm); + po::notify(vm); + + if (vm.count("help") != 0U) { + std::cout << desc << std::endl; + return 0; + } + + bool const verbose = vm.count("verbose") != 0; + bool const progress = vm.count("progress") != 0; + bool const force2d = vm.count("force2d") != 0; + + std::string filename; + + if (vm.count("filename") != 0U) { + filename = vm["filename"].as(); + } else { + std::cerr << "missing input file" << std::endl; + std::cout << desc << std::endl; + return 1; + } + + int oneLine = -1; + + if (vm.count("line") != 0U) { + oneLine = vm["line"].as(); + } + + /* + * open file + */ + std::ifstream ifs(filename.c_str()); + + if (!ifs.good()) { + std::cerr << "fail to open : " << filename << std::endl; + return 1; + } + + const std::string tri_filename(filename + ".tri.wkt"); + + std::ofstream tri_ofs(tri_filename.c_str()); + + if (!tri_ofs.good()) { + std::cerr << "fail to write : " << tri_filename << std::endl; + return 1; + } + + const std::string error_filename(filename + ".error.wkt"); + + std::ofstream ofs_error(error_filename.c_str()); + + if (!ofs_error.good()) { + std::cerr << "fail to write : " << error_filename << std::endl; + return 1; + } + + // boost::timer timer ; + boost::chrono::system_clock::time_point const start = + boost::chrono::system_clock::now(); + + std::vector invalidGeom; + std::vector inapropriateGeom; + /* + * process file + */ + int lineNumber = 0; + int numFailed = 0; + int numSuccess = 0; + std::string line; + + while (std::getline(ifs, line)) { + lineNumber++; + + if (-1 != oneLine && oneLine != lineNumber) { + continue; } - bool verbose = vm.count( "verbose" ) != 0 ; - bool progress = vm.count( "progress" ) != 0 ; - bool force2d = vm.count( "force2d" ) != 0 ; - - std::string filename ; + boost::algorithm::trim(line); - if ( vm.count( "filename" ) ) { - filename = vm["filename"].as< std::string >() ; + if (line.empty()) { + continue; } - else { - std::cerr << "missing input file" << std::endl; - std::cout << desc << std::endl ; - return 1 ; - } - - int oneLine = -1; - if ( vm.count( "line" ) ) { - oneLine = vm["line"].as< int >(); + if (verbose) { + std::cout << "#" << line << std::endl; + std::cout.flush(); } - /* - * open file - */ - std::ifstream ifs( filename.c_str() ); - - if ( ! ifs.good() ) { - std::cerr << "fail to open : " << filename << std::endl ; - return 1; + if (progress && lineNumber % 1000 == 0) { + std::cout.width(12); + boost::chrono::duration const elapsed = + boost::chrono::system_clock::now() - start; + std::cout << std::left << lineNumber << "(" << elapsed << " s)" + << std::endl; } - const std::string tri_filename( filename+".tri.wkt" ); + std::vector tokens; + boost::algorithm::split(tokens, line, boost::is_any_of("|")); - std::ofstream tri_ofs( tri_filename.c_str() ) ; + std::string const &wkt = tokens.back(); + std::string id; - if ( ! tri_ofs.good() ) { - std::cerr << "fail to write : " << tri_filename << std::endl ; - return 1; + if (tokens.size() > 1) { + id = tokens.front(); + } else { + std::ostringstream oss; + oss << lineNumber; + id = oss.str(); } - const std::string error_filename( filename+".error.wkt" ); - - std::ofstream ofs_error( error_filename.c_str() ) ; - - if ( ! ofs_error.good() ) { - std::cerr << "fail to write : " << error_filename << std::endl ; - return 1; + // std::cout << "process " << id << std::endl; + + bool failed = true; + TriangulatedSurface triangulatedSurface; + + try { + std::unique_ptr g(io::readWkt(wkt)); + + // io::vtk( *g, (boost::format("/tmp/polygon_%s.vtk") % id ).str() ); + + if (force2d) { + algorithm::force2D(*g); + } + + triangulate::triangulatePolygon3D(*g, triangulatedSurface); + + // check area + double const areaPolygons = algorithm::area3D(*g); + double const areaTriangles = algorithm::area3D(triangulatedSurface); + + double const ratio = fabs(areaPolygons - areaTriangles) / + std::max(areaPolygons, areaTriangles); + + if (ratio > 0.1) { + std::cerr << filename << ":" << lineNumber << " error:" << id << "|" + << "area(polygon) != area(tin) ( " << areaPolygons + << " !=" << areaTriangles << ")" + << "|" << g->asText() << "|" << triangulatedSurface.asText() + << std::endl; + } + + numSuccess++; + failed = false; + } catch (InappropriateGeometryException &e) { + inapropriateGeom.push_back(id); + numFailed++; + } catch (GeometryInvalidityException &e) { + invalidGeom.push_back(id); + numFailed++; + } catch (std::exception &e) { + BOOST_ASSERT_MSG(false, + (boost::format("%s:%d: unhandled std::exception: %s") % + filename % lineNumber % e.what()) + .str() + .c_str()); + } catch (...) { + BOOST_ASSERT_MSG(false, (boost::format("%s:%d: unknown exception") % + filename % lineNumber) + .str() + .c_str()); } + // output triangulated surface + tri_ofs << id << "|" << failed << "|" << triangulatedSurface.asText(5) + << std::endl; + } // end for each line - //boost::timer timer ; - boost::chrono::system_clock::time_point start = boost::chrono::system_clock::now(); - - std::vector< std::string > invalidGeom; - std::vector< std::string > inapropriateGeom; - /* - * process file - */ - int lineNumber = 0 , numFailed = 0 , numSuccess = 0 ; - std::string line ; - - while ( std::getline( ifs, line ) ) { - lineNumber++ ; - - if ( -1 != oneLine && oneLine != lineNumber ) { - continue; - } - - - boost::algorithm::trim( line ); - - if ( line.empty() ) { - continue ; - } - - if ( verbose ) { - std::cout << "#" << line << std::endl; - std::cout.flush(); - } - - - if ( progress && lineNumber % 1000 == 0 ) { - std::cout.width( 12 ) ; - boost::chrono::duration elapsed = boost::chrono::system_clock::now() - start; - std::cout << std::left << lineNumber << "(" << elapsed << " s)"<< std::endl ; - } - - - std::vector< std::string > tokens ; - boost::algorithm::split( tokens, line, boost::is_any_of( "|" ) ); - - std::string const& wkt = tokens.back() ; - std::string id ; - - if ( tokens.size() > 1 ) { - id = tokens.front() ; - } - else { - std::ostringstream oss; - oss << lineNumber ; - id = oss.str() ; - } - - //std::cout << "process " << id << std::endl; - - bool failed = true; - TriangulatedSurface triangulatedSurface ; + ofs_error.close(); + tri_ofs.close(); - try { - std::unique_ptr< Geometry > g( io::readWkt( wkt ) ); + boost::chrono::duration const elapsed = + boost::chrono::system_clock::now() - start; - //io::vtk( *g, (boost::format("/tmp/polygon_%s.vtk") % id ).str() ); + for (auto &i : invalidGeom) { + std::cout << " " << i << " is invalid\n"; + } - if ( force2d ) { - algorithm::force2D( *g ) ; - } + for (auto &i : inapropriateGeom) { + std::cout << " " << i << " is inapropriate for triangulation\n"; + } - triangulate::triangulatePolygon3D( *g, triangulatedSurface ) ; + std::cout << filename << " complete (" << elapsed << " s)---" << std::endl; + std::cout << numFailed << " failed /" << (numFailed + numSuccess) + << std::endl; - //check area - double areaPolygons = algorithm::area3D( *g ) ; - double areaTriangles = algorithm::area3D( triangulatedSurface ); - - double ratio = fabs( areaPolygons - areaTriangles ) / std::max( areaPolygons, areaTriangles ); - - if ( ratio > 0.1 ) { - std::cerr << filename << ":" << lineNumber << " error:" << id << "|" << "area(polygon) != area(tin) ( " << areaPolygons << " !=" << areaTriangles << ")" << "|" << g->asText() << "|" << triangulatedSurface.asText() << std::endl ; - } - - numSuccess++ ; - failed = false; - } - catch ( InappropriateGeometryException& e ) { - inapropriateGeom.push_back( id ); - numFailed++ ; - } - catch ( GeometryInvalidityException& e ) { - invalidGeom.push_back( id ); - numFailed++ ; - } - catch ( std::exception& e ) { - BOOST_ASSERT_MSG( false, ( boost::format( "%s:%d: unhandled std::exception: %s" ) % filename % lineNumber % e.what() ).str().c_str() ); - } - catch ( ... ) { - BOOST_ASSERT_MSG( false, ( boost::format( "%s:%d: unknown exception" ) % filename % lineNumber ).str().c_str() ); - } - - //output triangulated surface - tri_ofs << id << "|" << failed << "|" << triangulatedSurface.asText( 5 ) << std::endl; - }//end for each line - - - ofs_error.close(); - tri_ofs.close(); - - - boost::chrono::duration elapsed = boost::chrono::system_clock::now() - start; - - for ( size_t i=0; i!=invalidGeom.size(); ++i ) { - std::cout << " " << invalidGeom[i] << " is invalid\n"; - } - - for ( size_t i=0; i!=inapropriateGeom.size(); ++i ) { - std::cout << " " << inapropriateGeom[i] << " is inapropriate for triangulation\n"; - } - - std::cout << filename << " complete (" << elapsed << " s)---" << std::endl; - std::cout << numFailed << " failed /" << ( numFailed + numSuccess ) << std::endl ; - - if ( numFailed == 0 ) { - //delete empty error file - boost::filesystem::remove( error_filename ); - return EXIT_SUCCESS ; - } - else { - return EXIT_FAILURE ; - } + if (numFailed == 0) { + // delete empty error file + boost::filesystem::remove(error_filename); + return EXIT_SUCCESS; + } + return EXIT_FAILURE; } - diff --git a/test/regress/standalone/SFCGAL/AreaTest.cpp b/test/regress/standalone/SFCGAL/AreaTest.cpp index a5ca8696..7bff602c 100644 --- a/test/regress/standalone/SFCGAL/AreaTest.cpp +++ b/test/regress/standalone/SFCGAL/AreaTest.cpp @@ -15,102 +15,92 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include #include "../../../test_config.h" -#include #include +#include -#include -#include -#include -#include -#include -#include -#include #include -#include +#include #include +#include #include #include +#include +#include +#include +#include +#include +#include #include #include #include #include -using namespace boost::unit_test ; -using namespace SFCGAL ; - +using namespace boost::unit_test; +using namespace SFCGAL; class RotateCoordinate : public Transform { public: - - void transform( Point& p ) override { - BOOST_ASSERT( ! p.isEmpty() ); - p = Point( - p.is3D() ? p.z() : 0.0, - p.x(), - p.y() - ); - } - + void + transform(Point &p) override + { + BOOST_ASSERT(!p.isEmpty()); + p = Point(p.is3D() ? p.z() : 0.0, p.x(), p.y()); + } }; - -BOOST_AUTO_TEST_SUITE( SFCGAL_AreaTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_AreaTest) /** * Triangulate polygon and make some checks * @todo Check inPolygon.area3D() == outPolygon.area3D(); */ -BOOST_AUTO_TEST_CASE( testComputeArea ) +BOOST_AUTO_TEST_CASE(testComputeArea) { - std::string filename( SFCGAL_TEST_DIRECTORY ); - filename += "/data/AreaTest.txt" ; + std::string filename(SFCGAL_TEST_DIRECTORY); + filename += "/data/AreaTest.txt"; - std::ifstream ifs( filename.c_str() ); - BOOST_REQUIRE( ifs.good() ) ; + std::ifstream ifs(filename.c_str()); + BOOST_REQUIRE(ifs.good()); - std::string line; + std::string line; - while ( std::getline( ifs, line ) ) { - if ( line[0] == '#' || line.empty() ) { - continue ; - } + while (std::getline(ifs, line)) { + if (line[0] == '#' || line.empty()) { + continue; + } - std::istringstream iss( line ); + std::istringstream iss(line); - std::string id ; - iss >> id ; + std::string id; + iss >> id; - double expectedArea = NAN ; - iss >> expectedArea ; + double expectedArea = NAN; + iss >> expectedArea; - std::string inputWkt ; - std::getline( iss, inputWkt ) ; + std::string inputWkt; + std::getline(iss, inputWkt); - std::unique_ptr< Geometry > g( io::readWkt( inputWkt ) ); - double area = algorithm::area3D( *g ) ; - BOOST_TEST_MESSAGE( boost::format( "area( '%1%' ) = %2%" ) % inputWkt % area ); + std::unique_ptr g(io::readWkt(inputWkt)); + double area = algorithm::area3D(*g); + BOOST_TEST_MESSAGE(boost::format("area( '%1%' ) = %2%") % inputWkt % area); - RotateCoordinate rotateCoordinate ; - g->accept( rotateCoordinate ); - double areaRotate = algorithm::area3D( *g ) ; + RotateCoordinate rotateCoordinate; + g->accept(rotateCoordinate); + double const areaRotate = algorithm::area3D(*g); - //check area == areaRotate - BOOST_CHECK_CLOSE( area, areaRotate, 0.5 ); - //check area == expectedArea - BOOST_CHECK_CLOSE( area, expectedArea, 0.5 ); - } + // check area == areaRotate + BOOST_CHECK_CLOSE(area, areaRotate, 0.5); + // check area == expectedArea + BOOST_CHECK_CLOSE(area, expectedArea, 0.5); + } } - BOOST_AUTO_TEST_SUITE_END() - - - - diff --git a/test/regress/standalone/SFCGAL/ConstraintDelaunayTriangulationTest.cpp b/test/regress/standalone/SFCGAL/ConstraintDelaunayTriangulationTest.cpp index 8ef5a0dd..037f16ee 100644 --- a/test/regress/standalone/SFCGAL/ConstraintDelaunayTriangulationTest.cpp +++ b/test/regress/standalone/SFCGAL/ConstraintDelaunayTriangulationTest.cpp @@ -15,7 +15,8 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include @@ -35,53 +36,49 @@ #include #include - #include "../../../test_config.h" #include -using namespace boost::unit_test ; +using namespace boost::unit_test; -using namespace SFCGAL ; -using namespace SFCGAL::triangulate ; +using namespace SFCGAL; +using namespace SFCGAL::triangulate; -BOOST_AUTO_TEST_SUITE( SFCGAL_ConstraintDelaunayTriangulationTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_ConstraintDelaunayTriangulationTest) -BOOST_AUTO_TEST_CASE( testTriangulateRGC ) +BOOST_AUTO_TEST_CASE(testTriangulateRGC) { - ConstraintDelaunayTriangulation triangulation ; + ConstraintDelaunayTriangulation triangulation; - /* - * read points from file - */ - std::string filename( SFCGAL_TEST_DIRECTORY ); - filename += "/data/rgc-france-ign.xyz" ; - std::ifstream ifs( filename.c_str() ); - BOOST_REQUIRE( ifs.good() ) ; + /* + * read points from file + */ + std::string filename(SFCGAL_TEST_DIRECTORY); + filename += "/data/rgc-france-ign.xyz"; + std::ifstream ifs(filename.c_str()); + BOOST_REQUIRE(ifs.good()); - double x = NAN,y = NAN,z = NAN ; + double x = NAN; + double y = NAN; + double z = NAN; - while ( ifs >> x >> y >> z ) { - triangulation.addVertex( Coordinate( x,y,z ) ); - } + while (ifs >> x >> y >> z) { + triangulation.addVertex(Coordinate(x, y, z)); + } - ifs.close(); + ifs.close(); - //std::string wkt = triangulation.getTriangulatedSurface()->asText(5.0) ; - //std::cerr << "INSERT INTO draw (geometry) VALUES ( '" << "MULTIPOLYGON" << wkt.substr(3) << "'::geometry );" << std::endl; + // std::string wkt = triangulation.getTriangulatedSurface()->asText(5.0) ; + // std::cerr << "INSERT INTO draw (geometry) VALUES ( '" << "MULTIPOLYGON" << + // wkt.substr(3) << "'::geometry );" << std::endl; - BOOST_CHECK_EQUAL( triangulation.numVertices(), 36566U ); - BOOST_CHECK_EQUAL( triangulation.numTriangles(), 73114U ); + BOOST_CHECK_EQUAL(triangulation.numVertices(), 36566U); + BOOST_CHECK_EQUAL(triangulation.numTriangles(), 73114U); - std::unique_ptr< TriangulatedSurface > triangulatedSurface = triangulation.getTriangulatedSurface() ; - BOOST_CHECK_EQUAL( triangulatedSurface->numTriangles(), 73114U ); - BOOST_CHECK_CLOSE( algorithm::area( *triangulatedSurface ), 818056610000.0, 0.1 ); + std::unique_ptr triangulatedSurface = + triangulation.getTriangulatedSurface(); + BOOST_CHECK_EQUAL(triangulatedSurface->numTriangles(), 73114U); + BOOST_CHECK_CLOSE(algorithm::area(*triangulatedSurface), 818056610000.0, 0.1); } - - - BOOST_AUTO_TEST_SUITE_END() - - - - diff --git a/test/regress/standalone/SFCGAL/DistanceTest.cpp b/test/regress/standalone/SFCGAL/DistanceTest.cpp index 6bec7cd6..40c161eb 100644 --- a/test/regress/standalone/SFCGAL/DistanceTest.cpp +++ b/test/regress/standalone/SFCGAL/DistanceTest.cpp @@ -15,124 +15,117 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include #include "../../../test_config.h" -#include #include +#include -#include -#include -#include -#include -#include -#include -#include #include -#include +#include #include +#include #include #include +#include +#include +#include +#include +#include +#include #include -//#include +// #include #include #include -using namespace boost::unit_test ; -using namespace SFCGAL ; +using namespace boost::unit_test; +using namespace SFCGAL; - -BOOST_AUTO_TEST_SUITE( SFCGAL_DistanceTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_DistanceTest) /** * Compute the area for given geometries */ -BOOST_AUTO_TEST_CASE( testFileDistanceTest ) +BOOST_AUTO_TEST_CASE(testFileDistanceTest) { - logger().setLogLevel( Logger::Debug ); + logger().setLogLevel(Logger::Debug); - std::string filename( SFCGAL_TEST_DIRECTORY ); - filename += "/data/DistanceTest.txt" ; + std::string filename(SFCGAL_TEST_DIRECTORY); + filename += "/data/DistanceTest.txt"; - std::ifstream ifs( filename.c_str() ); - BOOST_REQUIRE( ifs.good() ) ; + std::ifstream ifs(filename.c_str()); + BOOST_REQUIRE(ifs.good()); - int argc = framework::master_test_suite().argc; - char** argv = framework::master_test_suite().argv; + int const argc = framework::master_test_suite().argc; + char **argv = framework::master_test_suite().argv; - // look for options - int test_one_line = -1; + // look for options + int test_one_line = -1; - for ( int i = 0; i < argc; ++i ) { - std::string argi( argv[i] ); + for (int i = 0; i < argc; ++i) { + std::string const argi(argv[i]); - if ( argi == "--line" ) { - // only test one line - if ( argc > i+1 ) { - sscanf( argv[i+1], "%d", &test_one_line ); - ++i; - continue; - } - } + if (argi == "--line") { + // only test one line + if (argc > i + 1) { + sscanf(argv[i + 1], "%d", &test_one_line); + ++i; + continue; + } } + } - std::string line; - int lineNo = 0; - - while ( std::getline( ifs, line ) ) { - ++lineNo; + std::string line; + int lineNo = 0; - if ( line[0] == '#' || line.empty() ) { - continue ; - } + while (std::getline(ifs, line)) { + ++lineNo; - if ( -1 != test_one_line && lineNo != test_one_line ) { - continue; - } + if (line[0] == '#' || line.empty()) { + continue; + } - BOOST_TEST_MESSAGE( ( boost::format( "%s:%d" ) % filename % lineNo ).str() ); + if (-1 != test_one_line && lineNo != test_one_line) { + continue; + } - std::istringstream iss( line ); + BOOST_TEST_MESSAGE((boost::format("%s:%d") % filename % lineNo).str()); - std::string distanceDimension ; - std::string wktGA, wktGB ; - double expectedDistance = NAN ; + std::istringstream iss(line); - std::getline( iss, distanceDimension, '|' ) ; - std::getline( iss, wktGA, '|' ) ; - std::getline( iss, wktGB, '|' ) ; - iss >> expectedDistance ; + std::string distanceDimension; + std::string wktGA; + std::string wktGB; + double expectedDistance = NAN; - std::unique_ptr< Geometry > gA( io::readWkt( wktGA ) ); - std::unique_ptr< Geometry > gB( io::readWkt( wktGB ) ); + std::getline(iss, distanceDimension, '|'); + std::getline(iss, wktGA, '|'); + std::getline(iss, wktGB, '|'); + iss >> expectedDistance; - //if (43!=lineNo ) continue; - //if (43==lineNo ) - //{ - // io::vtk(gA->as(), "/tmp/gA.vtk"); - // io::vtk(gB->as(), "/tmp/gB.vtk"); - //} + std::unique_ptr gA(io::readWkt(wktGA)); + std::unique_ptr const gB(io::readWkt(wktGB)); + // if (43!=lineNo ) continue; + // if (43==lineNo ) + //{ + // io::vtk(gA->as(), "/tmp/gA.vtk"); + // io::vtk(gB->as(), "/tmp/gB.vtk"); + // } - if ( distanceDimension == "2" ) { - BOOST_CHECK_CLOSE( gA->distance( *gB ), expectedDistance, 1e-13 ); - } - else if ( distanceDimension == "3" ) { - BOOST_CHECK_CLOSE( gA->distance3D( *gB ), expectedDistance, 1e-13 ); - } - else { - BOOST_CHECK( false ); - } + if (distanceDimension == "2") { + BOOST_CHECK_CLOSE(gA->distance(*gB), expectedDistance, 1e-13); + } else if (distanceDimension == "3") { + BOOST_CHECK_CLOSE(gA->distance3D(*gB), expectedDistance, 1e-13); + } else { + BOOST_CHECK(false); } + } } - BOOST_AUTO_TEST_SUITE_END() - - - - diff --git a/test/regress/standalone/SFCGAL/IntersectionTest.cpp b/test/regress/standalone/SFCGAL/IntersectionTest.cpp index 58eae29d..ed9d81b9 100644 --- a/test/regress/standalone/SFCGAL/IntersectionTest.cpp +++ b/test/regress/standalone/SFCGAL/IntersectionTest.cpp @@ -15,50 +15,49 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ -#include -#include #include +#include +#include #include "../../../test_config.h" #include -using namespace boost::unit_test ; -using namespace SFCGAL ; +using namespace boost::unit_test; +using namespace SFCGAL; -BOOST_AUTO_TEST_SUITE( SFCGAL_IntersectionTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_IntersectionTest) // // https://trac.osgeo.org/postgis/ticket/4157 -BOOST_AUTO_TEST_CASE( test_postgis_4157 ) +BOOST_AUTO_TEST_CASE(test_postgis_4157) { - std::unique_ptr< Geometry > g1( io::readWkt( "POLYGON Z ((" - "122395.299 489126.697 8.61546664325712," - "122389.298 489128.73 8.55588025324629," - "122391.489 489135.198 8.5526708028059," - "122397.49 489133.165 8.61225719281685," - "122395.299 489126.697 8.61546664325712))" )); - std::unique_ptr< Geometry > g2( io::readWkt( "POLYHEDRALSURFACE Z (((" - "122390.998245685 489133.068537491 0," - "122391.003145022 489133.066423547 0," - "122391.003145022 489133.066423547 10," - "122390.998245685 489133.068537491 10," - "122390.998245685 489133.068537491 0" - ")),((" - "122391.003145022 489133.066423547 0," - "122383.269575402 489114.842869866 0," - "122383.269575402 489114.842869866 10," - "122391.003145022 489133.066423547 10," - "122391.003145022 489133.066423547 0" - ")))" ) ); - - algorithm::intersection3D( *g1, *g2 ); + std::unique_ptr const g1( + io::readWkt("POLYGON Z ((" + "122395.299 489126.697 8.61546664325712," + "122389.298 489128.73 8.55588025324629," + "122391.489 489135.198 8.5526708028059," + "122397.49 489133.165 8.61225719281685," + "122395.299 489126.697 8.61546664325712))")); + std::unique_ptr const g2( + io::readWkt("POLYHEDRALSURFACE Z (((" + "122390.998245685 489133.068537491 0," + "122391.003145022 489133.066423547 0," + "122391.003145022 489133.066423547 10," + "122390.998245685 489133.068537491 10," + "122390.998245685 489133.068537491 0" + ")),((" + "122391.003145022 489133.066423547 0," + "122383.269575402 489114.842869866 0," + "122383.269575402 489114.842869866 10," + "122391.003145022 489133.066423547 10," + "122391.003145022 489133.066423547 0" + ")))")); + + algorithm::intersection3D(*g1, *g2); } BOOST_AUTO_TEST_SUITE_END() - - - - diff --git a/test/regress/standalone/SFCGAL/IntersectsTest.cpp b/test/regress/standalone/SFCGAL/IntersectsTest.cpp index edb075ec..6b67ed71 100644 --- a/test/regress/standalone/SFCGAL/IntersectsTest.cpp +++ b/test/regress/standalone/SFCGAL/IntersectsTest.cpp @@ -15,34 +15,35 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include -#include -#include -#include -#include -#include -#include -#include #include -#include +#include #include +#include #include #include -#include +#include +#include +#include +#include +#include +#include #include +#include #include "../../../test_config.h" -#include #include +#include -using namespace boost::unit_test ; -using namespace SFCGAL ; +using namespace boost::unit_test; +using namespace SFCGAL; -BOOST_AUTO_TEST_SUITE( SFCGAL_IntersectsTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_IntersectsTest) // // Load an obj @@ -50,7 +51,7 @@ BOOST_AUTO_TEST_SUITE( SFCGAL_IntersectsTest ) // Test intersection with some other objects // FIXME removed wavefront obj loader, transform to wkt -//BOOST_AUTO_TEST_CASE( testIntersectsTeapot ) +// BOOST_AUTO_TEST_CASE( testIntersectsTeapot ) //{ // std::string filename( SFCGAL_TEST_DIRECTORY ); // filename += "/regress/data/teapot.obj" ; @@ -71,56 +72,59 @@ BOOST_AUTO_TEST_SUITE( SFCGAL_IntersectsTest ) // surf.addPolygon( Polygon(ext_ring) ); // } // -// Triangle tri1( Point(3.0, 1.8, 0.0), Point(-2.99, 1.8, -0.081), Point(-2.99, 1.8, 0.081) ); -// Triangle tri2( Point(3.0, 1.8, 5.0), Point(-2.99, 1.8, 5.081), Point(-2.99, 1.8, 5.081) ); +// Triangle tri1( Point(3.0, 1.8, 0.0), Point(-2.99, 1.8, -0.081), +// Point(-2.99, 1.8, 0.081) ); Triangle tri2( Point(3.0, 1.8, 5.0), +// Point(-2.99, 1.8, 5.081), Point(-2.99, 1.8, 5.081) ); // // bool intersects1 = algorithm::intersects3D( tri1, surf ); // bool intersects2 = algorithm::intersects3D( tri2, surf ); -// BOOST_TEST_MESSAGE( boost::format("triangle1 intersects the teapot: %1%") % (intersects1 ? "YES" : "NO") ); -// BOOST_CHECK_EQUAL( intersects1, true ); -// BOOST_TEST_MESSAGE( boost::format("triangle2 intersects the teapot: %1%") % (intersects2 ? "YES" : "NO") ); -// BOOST_CHECK_EQUAL( intersects2, false ); +// BOOST_TEST_MESSAGE( boost::format("triangle1 intersects the teapot: %1%") +// % (intersects1 ? "YES" : "NO") ); BOOST_CHECK_EQUAL( intersects1, true ); +// BOOST_TEST_MESSAGE( boost::format("triangle2 intersects the teapot: %1%") +// % (intersects2 ? "YES" : "NO") ); BOOST_CHECK_EQUAL( intersects2, false ); //} - // // Test limit case -BOOST_AUTO_TEST_CASE( testLimitsIntersects ) +BOOST_AUTO_TEST_CASE(testLimitsIntersects) { - std::string filename( SFCGAL_TEST_DIRECTORY ); - filename += "/data/countries.wkt" ; + std::string filename(SFCGAL_TEST_DIRECTORY); + filename += "/data/countries.wkt"; - std::ifstream ifs( filename.c_str() ); - BOOST_REQUIRE( ifs.good() ) ; + std::ifstream ifs(filename.c_str()); + BOOST_REQUIRE(ifs.good()); - std::string wkt1, wkt2; - std::getline( ifs, wkt1 ); - std::getline( ifs, wkt2 ); + std::string wkt1; + std::string wkt2; + std::getline(ifs, wkt1); + std::getline(ifs, wkt2); - std::unique_ptr< Geometry > g1( io::readWkt( wkt1 ) ); - std::unique_ptr< Geometry > g2( io::readWkt( wkt2 ) ); + std::unique_ptr const g1(io::readWkt(wkt1)); + std::unique_ptr const g2(io::readWkt(wkt2)); - // check that a call to intersects() does not throw - bool throws = false; - algorithm::intersects( *g1, *g2 ); - BOOST_CHECK_EQUAL( throws, false ); + // check that a call to intersects() does not throw + bool const throws = false; + algorithm::intersects(*g1, *g2); + BOOST_CHECK_EQUAL(throws, false); } BOOST_AUTO_TEST_SUITE_END() - // https://gitlab.com/Oslandia/SFCGAL/-/issues/253 -BOOST_AUTO_TEST_CASE( issue_gitlab_253 ) +BOOST_AUTO_TEST_CASE(issue_gitlab_253) { - std::unique_ptr< Geometry > g1( io::readWkt( "POLYHEDRALSURFACE Z (((2 0.5 0.5, 0 0 1, 0 0 0, 2 0.5 0.5)), ((2 0.5 0.5, 0 1 1, 0 0 1, 2 0.5 0.5)), ((2 0.5 0.5, 0 1 0, 0 1 1, 2 0.5 0.5)), ((2 0.5 0.5, 0 0 0, 0 1 0, 2 0.5 0.5)), ((0 0 0, 0 0 1, 0 1 1, 0 1 0, 0 0 0)))" )); - std::unique_ptr< Geometry > g2( io::readWkt( "POINT (0 0.5 0.5)" )); - - // check that a call to intersects() does not throw - bool throws = false; - bool intersects = algorithm::intersects3D( *g1, *g2 ); - BOOST_CHECK_EQUAL( intersects, true ); - intersects = algorithm::intersects3D( *g2, *g1 ); - BOOST_CHECK_EQUAL( intersects, true ); - BOOST_CHECK_EQUAL( throws, false ); + std::unique_ptr const g1( + io::readWkt("POLYHEDRALSURFACE Z (((2 0.5 0.5, 0 0 1, 0 0 0, 2 0.5 " + "0.5)), ((2 0.5 0.5, 0 1 1, 0 0 1, 2 0.5 0.5)), ((2 0.5 0.5, " + "0 1 0, 0 1 1, 2 0.5 0.5)), ((2 0.5 0.5, 0 0 0, 0 1 0, 2 0.5 " + "0.5)), ((0 0 0, 0 0 1, 0 1 1, 0 1 0, 0 0 0)))")); + std::unique_ptr const g2(io::readWkt("POINT (0 0.5 0.5)")); + + // check that a call to intersects() does not throw + bool const throws = false; + bool intersects = algorithm::intersects3D(*g1, *g2); + BOOST_CHECK_EQUAL(intersects, true); + intersects = algorithm::intersects3D(*g2, *g1); + BOOST_CHECK_EQUAL(intersects, true); + BOOST_CHECK_EQUAL(throws, false); } - diff --git a/test/regress/standalone/SFCGAL/StraightSkeletonTest.cpp b/test/regress/standalone/SFCGAL/StraightSkeletonTest.cpp index bb62d359..428faab0 100644 --- a/test/regress/standalone/SFCGAL/StraightSkeletonTest.cpp +++ b/test/regress/standalone/SFCGAL/StraightSkeletonTest.cpp @@ -15,150 +15,198 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include -#include -#include -#include -#include -#include -#include -#include #include -#include +#include #include +#include #include #include -#include -#include +#include +#include +#include +#include +#include +#include #include +#include +#include #include "../../../test_config.h" -#include #include #include +#include #include #include -using namespace boost::unit_test ; +using namespace boost::unit_test; -using namespace SFCGAL ; +using namespace SFCGAL; -BOOST_AUTO_TEST_SUITE( SFCGAL_StraightSkeletonTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_StraightSkeletonTest) namespace { - void runTest(const boost::filesystem::path::string_type& filename) - { - std::ifstream ifs( filename.c_str() ); - BOOST_REQUIRE( ifs.good() ) ; - - std::string line; - std::string lbl_base = boost::filesystem::basename(filename); - - int lineno = 0; - while ( std::getline( ifs, line ) ) { - ++lineno; - if ( line[0] == '#' || line.empty() ) { - continue ; - } - std::stringstream lblstream; - lblstream << lbl_base << ':' << lineno << ": "; - std::string lbl = lblstream.str(); - - std::istringstream iss( line ); - std::string inputWkt ; - std::string outputWkt ; - std::string obtWkt ; - - if ( ! std::getline( iss, inputWkt, '|' ) || - ! std::getline( iss, outputWkt, '|' ) ) - { - std::stringstream ss; - ss << lbl << "missing `|' char in test file"; - BOOST_CHECK_EQUAL("", ss.str()); - continue; - } - - std::unique_ptr< Geometry > g; - try { - g = io::readWkt( inputWkt ); - } catch (const std::exception &e) { - std::stringstream ss; - ss << lbl << e.what(); - BOOST_CHECK_EQUAL("", ss.str()); - continue; - } - std::unique_ptr< MultiLineString > result; - try { - result = algorithm::straightSkeleton( *g ) ; - obtWkt = result->asText( 6 ); - } catch (const std::exception& e) { - obtWkt = std::string(e.what()); - } - std::string obt = lbl + obtWkt; - std::string exp = lbl + outputWkt; - if ( (CGAL_VERSION_MAJOR == 5) && (CGAL_VERSION_MINOR >= 2)) { - BOOST_CHECK_EQUAL( exp, obt ); - } - } +void +runTest(const boost::filesystem::path::string_type &filename) +{ + std::ifstream ifs(filename.c_str()); + BOOST_REQUIRE(ifs.good()); + + std::string line; + std::string const lbl_base = boost::filesystem::basename(filename); + + int lineno = 0; + while (std::getline(ifs, line)) { + ++lineno; + if (line[0] == '#' || line.empty()) { + continue; + } + std::stringstream lblstream; + lblstream << lbl_base << ':' << lineno << ": "; + std::string const lbl = lblstream.str(); + + std::istringstream iss(line); + std::string inputWkt; + std::string outputWkt; + std::string obtWkt; + + if (!std::getline(iss, inputWkt, '|') || + !std::getline(iss, outputWkt, '|')) { + std::stringstream ss; + ss << lbl << "missing `|' char in test file"; + BOOST_CHECK_EQUAL("", ss.str()); + continue; } + + std::unique_ptr g; + try { + g = io::readWkt(inputWkt); + } catch (const std::exception &e) { + std::stringstream ss; + ss << lbl << e.what(); + BOOST_CHECK_EQUAL("", ss.str()); + continue; + } + std::unique_ptr result; + try { + result = algorithm::straightSkeleton(*g); + obtWkt = result->asText(6); + } catch (const std::exception &e) { + obtWkt = std::string(e.what()); + } + std::string const obt = lbl + obtWkt; + std::string const exp = lbl + outputWkt; + if ((CGAL_VERSION_MAJOR == 5) && (CGAL_VERSION_MINOR >= 2)) { + BOOST_CHECK_EQUAL(exp, obt); + } + } } +} // namespace -BOOST_AUTO_TEST_CASE( testStraightSkeleton_issue153 ) +BOOST_AUTO_TEST_CASE(testStraightSkeleton_issue153) { - std::string wkt = "POLYGON((256 760,518 760,518 630,674 630,674 239,673 239,127 239,127 240,126 240,126 513,127 513,127 514,126 514,126 630,255 630,256 630,256 760),(128 629,128 423,270 423,270 422,271 422,271 240,672 240,672 629,128 629),(258 759,258 631,516 631,516 759,258 759),(128 421,128 240,269 240,269 421,128 421))"; - std::string skWkt = "MULTILINESTRING((256.0 760.0,257.0 759.0),(256.0 630.0,256.5 629.5),(255.0 630.0,255.0 629.5),(126.0 630.0,127.0 629.0),(126.0 514.0,127.0 515.0),(127.0 514.0,127.5 514.5),(127.0 513.0,127.5 512.5),(126.0 513.0,127.0 512.0),(126.0 240.0,127.0 241.0),(127.0 240.0,127.5 240.5),(127.0 239.0,127.5 239.5),(673.0 239.0,673.0 240.0),(674.0 239.0,673.0 240.0),(674.0 630.0,673.0 629.0),(518.0 630.0,517.5 629.5),(518.0 760.0,517.0 759.0),(128.0 629.0,127.5 629.5),(672.0 629.0,672.5 629.5),(672.0 240.0,672.5 239.5),(271.0 240.0,270.5 239.5),(271.0 422.0,270.0 421.0),(270.0 422.0,269.5 421.5),(270.0 423.0,269.0 422.0),(128.0 423.0,127.0 422.0),(258.0 759.0,257.5 759.5),(516.0 759.0,516.5 759.5),(516.0 631.0,517.0 630.0),(258.0 631.0,257.0 630.0),(128.0 421.0,127.0 422.0),(269.0 421.0,269.5 421.5),(269.0 240.0,269.5 239.5),(128.0 240.0,127.5 239.5),(256.5 629.5,257.0 630.0),(256.5 629.5,255.0 629.5),(127.5 514.5,127.0 515.0),(127.5 514.5,127.5 512.5),(127.5 512.5,127.0 512.0),(269.5 239.5,270.0 240.0),(269.5 239.5,127.5 239.5),(127.5 239.5,127.5 240.5),(255.0 629.5,127.5 629.5),(127.5 240.5,127.0 241.0),(127.5 629.5,127.0 629.0),(517.5 629.5,672.5 629.5),(517.5 629.5,517.0 630.0),(672.5 629.5,673.0 629.0),(672.5 239.5,673.0 240.0),(672.5 239.5,270.5 239.5),(270.5 239.5,270.0 240.0),(269.5 421.5,269.0 422.0),(269.5 421.5,270.0 421.0),(257.5 759.5,257.0 759.0),(257.5 759.5,516.5 759.5),(516.5 759.5,517.0 759.0),(127.0 512.0,127.0 422.0),(127.0 241.0,127.0 422.0),(269.0 422.0,127.0 422.0),(270.0 421.0,270.0 240.0),(673.0 240.0,673.0 629.0),(127.0 515.0,127.0 629.0),(257.0 759.0,257.0 630.0),(257.0 630.0,517.0 630.0),(517.0 759.0,517.0 630.0))"; - - std::unique_ptr g; - std::unique_ptr expected; - std::unique_ptr result; - - g = io::readWkt(wkt); + std::string const wkt = + "POLYGON((256 760,518 760,518 630,674 630,674 239,673 239,127 239,127 " + "240,126 240,126 513,127 513,127 514,126 514,126 630,255 630,256 " + "630,256 760),(128 629,128 423,270 423,270 422,271 422,271 240,672 " + "240,672 629,128 629),(258 759,258 631,516 631,516 759,258 759),(128 " + "421,128 240,269 240,269 421,128 421))"; + std::string const skWkt = + "MULTILINESTRING((256.0 760.0,257.0 759.0),(256.0 630.0,256.5 " + "629.5),(255.0 630.0,255.0 629.5),(126.0 630.0,127.0 629.0),(126.0 " + "514.0,127.0 515.0),(127.0 514.0,127.5 514.5),(127.0 513.0,127.5 " + "512.5),(126.0 513.0,127.0 512.0),(126.0 240.0,127.0 241.0),(127.0 " + "240.0,127.5 240.5),(127.0 239.0,127.5 239.5),(673.0 239.0,673.0 " + "240.0),(674.0 239.0,673.0 240.0),(674.0 630.0,673.0 629.0),(518.0 " + "630.0,517.5 629.5),(518.0 760.0,517.0 759.0),(128.0 629.0,127.5 " + "629.5),(672.0 629.0,672.5 629.5),(672.0 240.0,672.5 239.5),(271.0 " + "240.0,270.5 239.5),(271.0 422.0,270.0 421.0),(270.0 422.0,269.5 " + "421.5),(270.0 423.0,269.0 422.0),(128.0 423.0,127.0 422.0),(258.0 " + "759.0,257.5 759.5),(516.0 759.0,516.5 759.5),(516.0 631.0,517.0 " + "630.0),(258.0 631.0,257.0 630.0),(128.0 421.0,127.0 422.0),(269.0 " + "421.0,269.5 421.5),(269.0 240.0,269.5 239.5),(128.0 240.0,127.5 " + "239.5),(256.5 629.5,257.0 630.0),(256.5 629.5,255.0 629.5),(127.5 " + "514.5,127.0 515.0),(127.5 514.5,127.5 512.5),(127.5 512.5,127.0 " + "512.0),(269.5 239.5,270.0 240.0),(269.5 239.5,127.5 239.5),(127.5 " + "239.5,127.5 240.5),(255.0 629.5,127.5 629.5),(127.5 240.5,127.0 " + "241.0),(127.5 629.5,127.0 629.0),(517.5 629.5,672.5 629.5),(517.5 " + "629.5,517.0 630.0),(672.5 629.5,673.0 629.0),(672.5 239.5,673.0 " + "240.0),(672.5 239.5,270.5 239.5),(270.5 239.5,270.0 240.0),(269.5 " + "421.5,269.0 422.0),(269.5 421.5,270.0 421.0),(257.5 759.5,257.0 " + "759.0),(257.5 759.5,516.5 759.5),(516.5 759.5,517.0 759.0),(127.0 " + "512.0,127.0 422.0),(127.0 241.0,127.0 422.0),(269.0 422.0,127.0 " + "422.0),(270.0 421.0,270.0 240.0),(673.0 240.0,673.0 629.0),(127.0 " + "515.0,127.0 629.0),(257.0 759.0,257.0 630.0),(257.0 630.0,517.0 " + "630.0),(517.0 759.0,517.0 630.0))"; + + std::unique_ptr g; + std::unique_ptr expected; + std::unique_ptr result; + + g = io::readWkt(wkt); expected = io::readWkt(skWkt); - result = algorithm::straightSkeleton(*g); - BOOST_CHECK( algorithm::covers(*result, *expected) ); + result = algorithm::straightSkeleton(*g); + BOOST_CHECK(algorithm::covers(*result, *expected)); } -BOOST_AUTO_TEST_CASE( testStraightSkeleton_issue133 ) +BOOST_AUTO_TEST_CASE(testStraightSkeleton_issue133) { - std::string wkt = "POLYGON ((4.6496243000000002 43.5206941000000000, 4.6525242999999996 43.5138711000000029, 4.6538323000000004 43.5135961000000009, 4.6575601000000004 43.5140630000000002, 4.6610893000000004 43.5289111000000020, 4.6611813000000000 43.5289641000000032, 4.6613262999999998 43.5290541000000033, 4.6616742999999996 43.5292700999999980, 4.6662613000000004 43.5319630999999987, 4.6694462999999997 43.5364300999999969, 4.6773002999999997 43.5426701000000023, 4.6773223000000002 43.5500510999999975, 4.6770063000000004 43.5516341000000011, 4.6727913000000001 43.5583450999999968, 4.6499202999999998 43.5215560999999980, 4.6496243000000002 43.5206941000000000))"; - std::string skWkt = "MULTILINESTRING((4.6 43.5,4.7 43.5),(4.7 43.5,4.7 43.5),(4.7 43.5,4.7 43.5),(4.7 43.5,4.7 43.5),(4.7 43.5,4.7 43.5),(4.7 43.5,4.7 43.5),(4.7 43.5,4.7 43.5),(4.7 43.5,4.7 43.5),(4.7 43.5,4.7 43.5),(4.7 43.5,4.7 43.5),(4.7 43.5,4.7 43.5),(4.7 43.6,4.7 43.5),(4.7 43.6,4.7 43.5),(4.7 43.6,4.7 43.5),(4.6 43.5,4.7 43.5),(4.7 43.5,4.7 43.5),(4.7 43.5,4.7 43.5),(4.7 43.5,4.7 43.5),(4.7 43.5,4.7 43.5),(4.7 43.5,4.7 43.5),(4.7 43.5,4.7 43.5),(4.7 43.5,4.7 43.5),(4.7 43.5,4.7 43.5),(4.7 43.5,4.7 43.5),(4.7 43.5,4.7 43.5),(4.7 43.5,4.7 43.5),(4.7 43.5,4.7 43.5))"; + std::string const wkt = + "POLYGON ((4.6496243000000002 43.5206941000000000, 4.6525242999999996 " + "43.5138711000000029, 4.6538323000000004 43.5135961000000009, " + "4.6575601000000004 43.5140630000000002, 4.6610893000000004 " + "43.5289111000000020, 4.6611813000000000 43.5289641000000032, " + "4.6613262999999998 43.5290541000000033, 4.6616742999999996 " + "43.5292700999999980, 4.6662613000000004 43.5319630999999987, " + "4.6694462999999997 43.5364300999999969, 4.6773002999999997 " + "43.5426701000000023, 4.6773223000000002 43.5500510999999975, " + "4.6770063000000004 43.5516341000000011, 4.6727913000000001 " + "43.5583450999999968, 4.6499202999999998 43.5215560999999980, " + "4.6496243000000002 43.5206941000000000))"; + std::string const skWkt = + "MULTILINESTRING((4.6 43.5,4.7 43.5),(4.7 43.5,4.7 43.5),(4.7 43.5,4.7 " + "43.5),(4.7 43.5,4.7 43.5),(4.7 43.5,4.7 43.5),(4.7 43.5,4.7 43.5),(4.7 " + "43.5,4.7 43.5),(4.7 43.5,4.7 43.5),(4.7 43.5,4.7 43.5),(4.7 43.5,4.7 " + "43.5),(4.7 43.5,4.7 43.5),(4.7 43.6,4.7 43.5),(4.7 43.6,4.7 43.5),(4.7 " + "43.6,4.7 43.5),(4.6 43.5,4.7 43.5),(4.7 43.5,4.7 43.5),(4.7 43.5,4.7 " + "43.5),(4.7 43.5,4.7 43.5),(4.7 43.5,4.7 43.5),(4.7 43.5,4.7 43.5),(4.7 " + "43.5,4.7 43.5),(4.7 43.5,4.7 43.5),(4.7 43.5,4.7 43.5),(4.7 43.5,4.7 " + "43.5),(4.7 43.5,4.7 43.5),(4.7 43.5,4.7 43.5),(4.7 43.5,4.7 43.5))"; std::unique_ptr g; std::unique_ptr expected; std::unique_ptr result; std::unique_ptr result_wkt1; - g = io::readWkt(wkt); - expected = io::readWkt(skWkt); - result = algorithm::straightSkeleton(*g); + g = io::readWkt(wkt); + expected = io::readWkt(skWkt); + result = algorithm::straightSkeleton(*g); result_wkt1 = io::readWkt(result->asText(1)); - BOOST_CHECK( algorithm::covers(*result_wkt1, *expected) ); + BOOST_CHECK(algorithm::covers(*result_wkt1, *expected)); } -BOOST_AUTO_TEST_CASE( testStraightSkeletonTestIssue ) +BOOST_AUTO_TEST_CASE(testStraightSkeletonTestIssue) { - using namespace boost; - using namespace boost::filesystem; - - std::string testdir( SFCGAL_TEST_DIRECTORY ); - path dirname = testdir + "/data/StraightSkeletonTest" ; - if ( is_directory(dirname) ) - { - directory_iterator it = directory_iterator(dirname); - while ( it != directory_iterator() ) - { - path f = *it; - runTest(f.c_str()); - ++it; - } + using namespace boost; + using namespace boost::filesystem; + + std::string const testdir(SFCGAL_TEST_DIRECTORY); + path const dirname = testdir + "/data/StraightSkeletonTest"; + if (is_directory(dirname)) { + directory_iterator it = directory_iterator(dirname); + while (it != directory_iterator()) { + path const f = *it; + runTest(f.c_str()); + ++it; } + } } - BOOST_AUTO_TEST_SUITE_END() diff --git a/test/regress/standalone/SFCGAL/TriangulatePolygonTest.cpp b/test/regress/standalone/SFCGAL/TriangulatePolygonTest.cpp index d24702aa..d712bfcf 100644 --- a/test/regress/standalone/SFCGAL/TriangulatePolygonTest.cpp +++ b/test/regress/standalone/SFCGAL/TriangulatePolygonTest.cpp @@ -15,113 +15,114 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include "../../../test_config.h" -#include #include +#include -#include -#include -#include -#include -#include -#include -#include #include -#include +#include #include +#include #include #include -#include +#include +#include +#include +#include +#include +#include #include +#include -#include #include +#include #include -using namespace boost::unit_test ; -using namespace SFCGAL ; +using namespace boost::unit_test; +using namespace SFCGAL; -BOOST_AUTO_TEST_SUITE( SFCGAL_TriangulatePolygonTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_TriangulatePolygonTest) /** * Triangulate polygon and make some checks * @todo Check inPolygon.area3D() == outPolygon.area3D(); */ -BOOST_AUTO_TEST_CASE( testTriangulatePolygon ) +BOOST_AUTO_TEST_CASE(testTriangulatePolygon) { - //logger().setLogLevel( Logger::Debug ); + // logger().setLogLevel( Logger::Debug ); - std::string filename( SFCGAL_TEST_DIRECTORY ); - filename += "/data/TriangulatePolygonTest.txt" ; + std::string filename(SFCGAL_TEST_DIRECTORY); + filename += "/data/TriangulatePolygonTest.txt"; - std::ifstream ifs( filename.c_str() ); - BOOST_REQUIRE( ifs.good() ) ; + std::ifstream ifs(filename.c_str()); + BOOST_REQUIRE(ifs.good()); - int numLine = 0 ; - std::string line; + int numLine = 0; + std::string line; - while ( std::getline( ifs, line ) ) { - numLine++ ; + while (std::getline(ifs, line)) { + numLine++; - if ( line[0] == '#' || line.empty() ) { - continue ; - } - - BOOST_TEST_MESSAGE( boost::format( "[line#%s]%s" ) % numLine % line ); + if (line[0] == '#' || line.empty()) { + continue; + } - std::istringstream iss( line ); - bool shouldThrowException = 0 ; - iss >> shouldThrowException ; + BOOST_TEST_MESSAGE(boost::format("[line#%s]%s") % numLine % line); - std::string inputWkt ; - std::getline( iss, inputWkt ) ; + std::istringstream iss(line); + bool shouldThrowException = 0; + iss >> shouldThrowException; - /* - * parse wkt - */ - std::unique_ptr< Geometry > g( io::readWkt( inputWkt ) ); + std::string inputWkt; + std::getline(iss, inputWkt); - /* - * check polygon - */ - BOOST_CHECK( g->is< Polygon >() || g->is< MultiPolygon >() ); + /* + * parse wkt + */ + std::unique_ptr g(io::readWkt(inputWkt)); - /* - * triangulate polygon - */ - TriangulatedSurface triangulatedSurface ; + /* + * check polygon + */ + BOOST_CHECK(g->is() || g->is()); - if ( shouldThrowException ) { - BOOST_CHECK_THROW( triangulate::triangulatePolygon3D( *g, triangulatedSurface ), Exception ); - continue ; - } + /* + * triangulate polygon + */ + TriangulatedSurface triangulatedSurface; - BOOST_CHECK_NO_THROW( triangulate::triangulatePolygon3D( *g, triangulatedSurface ) ) ; + if (shouldThrowException) { + BOOST_CHECK_THROW( + triangulate::triangulatePolygon3D(*g, triangulatedSurface), + Exception); + continue; + } - BOOST_TEST_MESSAGE( boost::format( "#%1% triangle(s)" ) % triangulatedSurface.numGeometries() ); + BOOST_CHECK_NO_THROW( + triangulate::triangulatePolygon3D(*g, triangulatedSurface)); - /* - * make some checks - */ - if ( ! g->isEmpty() ) { - BOOST_CHECK( ! triangulatedSurface.isEmpty() ); - } + BOOST_TEST_MESSAGE(boost::format("#%1% triangle(s)") % + triangulatedSurface.numGeometries()); - if ( g->is3D() ) { - BOOST_CHECK( triangulatedSurface.is3D() ); - } + /* + * make some checks + */ + if (!g->isEmpty()) { + BOOST_CHECK(!triangulatedSurface.isEmpty()); + } - //check area - BOOST_CHECK_CLOSE( algorithm::area3D( *g ), algorithm::area3D( triangulatedSurface ), 0.5 ); + if (g->is3D()) { + BOOST_CHECK(triangulatedSurface.is3D()); } -} + // check area + BOOST_CHECK_CLOSE(algorithm::area3D(*g), + algorithm::area3D(triangulatedSurface), 0.5); + } +} BOOST_AUTO_TEST_SUITE_END() - - - - diff --git a/test/regress/standalone/SFCGAL/WaveFrontObjTest.cpp b/test/regress/standalone/SFCGAL/WaveFrontObjTest.cpp index fc2d156a..e5e1d9b3 100644 --- a/test/regress/standalone/SFCGAL/WaveFrontObjTest.cpp +++ b/test/regress/standalone/SFCGAL/WaveFrontObjTest.cpp @@ -15,34 +15,35 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include #include -#include -#include -#include -#include -#include -#include -#include #include -#include +#include #include +#include #include #include -//#include +#include +#include +#include +#include +#include +#include +// #include #include "../../../test_config.h" -using namespace boost::unit_test ; -using namespace SFCGAL ; +using namespace boost::unit_test; +using namespace SFCGAL; -BOOST_AUTO_TEST_SUITE( SFCGAL_io_WaveFrontObjTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_io_WaveFrontObjTest) // FIXME removed wavefront obj loader, transform to wkt -//BOOST_AUTO_TEST_CASE( testTeaPot ) +// BOOST_AUTO_TEST_CASE( testTeaPot ) //{ // std::string filename( SFCGAL_TEST_DIRECTORY ); // filename += "/regress/data/teapot.obj" ; @@ -63,9 +64,4 @@ BOOST_AUTO_TEST_SUITE( SFCGAL_io_WaveFrontObjTest ) // } //} - BOOST_AUTO_TEST_SUITE_END() - - - - diff --git a/test/regress/standalone/SFCGAL/WktTest.cpp b/test/regress/standalone/SFCGAL/WktTest.cpp index 866621ec..75630cbd 100644 --- a/test/regress/standalone/SFCGAL/WktTest.cpp +++ b/test/regress/standalone/SFCGAL/WktTest.cpp @@ -15,60 +15,56 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include -#include -#include -#include -#include -#include -#include -#include #include -#include +#include #include +#include #include #include +#include +#include +#include +#include +#include +#include #include #include "../../../test_config.h" #include -using namespace boost::unit_test ; +using namespace boost::unit_test; -using namespace SFCGAL ; +using namespace SFCGAL; -BOOST_AUTO_TEST_SUITE( SFCGAL_WktTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_WktTest) -BOOST_AUTO_TEST_CASE( testReadWriter ) +BOOST_AUTO_TEST_CASE(testReadWriter) { - std::string filename( SFCGAL_TEST_DIRECTORY ); - filename += "/data/WktTest.txt" ; - - std::ifstream ifs( filename.c_str() ); - BOOST_REQUIRE( ifs.good() ) ; + std::string filename(SFCGAL_TEST_DIRECTORY); + filename += "/data/WktTest.txt"; - std::string inputWkt; + std::ifstream ifs(filename.c_str()); + BOOST_REQUIRE(ifs.good()); - while ( std::getline( ifs, inputWkt ) ) { - if ( inputWkt[0] == '#' || inputWkt.empty() ) { - continue ; - } + std::string inputWkt; - /* - * parse wkt and check symmetry - */ - std::unique_ptr< Geometry > g( io::readWkt( inputWkt ) ); - std::string outputWkt = g->asText( 1 ); - BOOST_CHECK_EQUAL( inputWkt, outputWkt ); + while (std::getline(ifs, inputWkt)) { + if (inputWkt[0] == '#' || inputWkt.empty()) { + continue; } -} + /* + * parse wkt and check symmetry + */ + std::unique_ptr g(io::readWkt(inputWkt)); + std::string const outputWkt = g->asText(1); + BOOST_CHECK_EQUAL(inputWkt, outputWkt); + } +} BOOST_AUTO_TEST_SUITE_END() - - - - diff --git a/test/regress/standalone/TestModule.cpp b/test/regress/standalone/TestModule.cpp index 25e3fe13..8d161d02 100644 --- a/test/regress/standalone/TestModule.cpp +++ b/test/regress/standalone/TestModule.cpp @@ -15,15 +15,10 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #define BOOST_TEST_MODULE RegressTestSFCGAL #include -using namespace boost::unit_test ; - - - - - - +using namespace boost::unit_test; diff --git a/test/unit/SFCGAL/CoordinateTest.cpp b/test/unit/SFCGAL/CoordinateTest.cpp index b10a3aee..cd34d161 100644 --- a/test/unit/SFCGAL/CoordinateTest.cpp +++ b/test/unit/SFCGAL/CoordinateTest.cpp @@ -31,7 +31,7 @@ BOOST_AUTO_TEST_SUITE(SFCGAL_CoordinateTest) /// Coordinate() ; BOOST_AUTO_TEST_CASE(testDefaultConstructor) { - Coordinate g; + Coordinate const g; BOOST_CHECK(g.isEmpty()); BOOST_CHECK_THROW(g.x(), Exception); BOOST_CHECK_THROW(g.y(), Exception); @@ -41,7 +41,7 @@ BOOST_AUTO_TEST_CASE(testDefaultConstructor) /// Coordinate( const Kernel::FT & x, const Kernel::FT & y ) ; BOOST_AUTO_TEST_CASE(testXYConstructor) { - Coordinate g(3, 4); + Coordinate const g(3, 4); BOOST_CHECK(!g.isEmpty()); BOOST_CHECK(!g.is3D()); BOOST_CHECK_EQUAL(g.x(), 3); @@ -52,7 +52,7 @@ BOOST_AUTO_TEST_CASE(testXYConstructor) /// ) ; BOOST_AUTO_TEST_CASE(testXYZConstructor) { - Coordinate g(3, 4, 5); + Coordinate const g(3, 4, 5); BOOST_CHECK(!g.isEmpty()); BOOST_CHECK(g.is3D()); BOOST_CHECK_EQUAL(g.x(), 3); @@ -63,7 +63,7 @@ BOOST_AUTO_TEST_CASE(testXYZConstructor) /// Coordinate( const double & x, const double & y ) ; BOOST_AUTO_TEST_CASE(testXYConstructorDouble) { - Coordinate g(3.0, 4.0); + Coordinate const g(3.0, 4.0); BOOST_CHECK(!g.isEmpty()); BOOST_CHECK(!g.is3D()); BOOST_CHECK_EQUAL(g.x(), 3); @@ -72,7 +72,7 @@ BOOST_AUTO_TEST_CASE(testXYConstructorDouble) /// Coordinate( const double & x, const double & y, const double& z ) ; BOOST_AUTO_TEST_CASE(testXYZConstructorDouble) { - Coordinate g(3.0, 4.0, 5.0); + Coordinate const g(3.0, 4.0, 5.0); BOOST_CHECK(!g.isEmpty()); BOOST_CHECK(g.is3D()); BOOST_CHECK_EQUAL(g.x(), 3); @@ -91,14 +91,14 @@ BOOST_AUTO_TEST_CASE(testXYZConstructorDouble) /// Coordinate( const Coordinate & other ) ; BOOST_AUTO_TEST_CASE(testCopyConstructorEmpty) { - Coordinate g; - Coordinate copy(g); + Coordinate const g; + const Coordinate ©(g); BOOST_CHECK(copy.isEmpty()); } BOOST_AUTO_TEST_CASE(testCopyConstructorXY) { - Coordinate g(3, 4); - Coordinate copy(g); + Coordinate const g(3, 4); + const Coordinate ©(g); BOOST_CHECK_EQUAL(copy.x(), 3); BOOST_CHECK_EQUAL(copy.y(), 4); } @@ -108,17 +108,17 @@ BOOST_AUTO_TEST_CASE(testCopyConstructorXY) /// int coordinateDimension() const ; BOOST_AUTO_TEST_CASE(testCoordinateDimensionEmpty) { - Coordinate g; + Coordinate const g; BOOST_CHECK_EQUAL(g.coordinateDimension(), 0); } BOOST_AUTO_TEST_CASE(testCoordinateDimensionXY) { - Coordinate g(3, 4); + Coordinate const g(3, 4); BOOST_CHECK_EQUAL(g.coordinateDimension(), 2); } BOOST_AUTO_TEST_CASE(testCoordinateDimensionXYZ) { - Coordinate g(3, 4, 5); + Coordinate const g(3, 4, 5); BOOST_CHECK_EQUAL(g.coordinateDimension(), 3); } @@ -153,8 +153,8 @@ BOOST_AUTO_TEST_CASE(testRoundOneDecimal) /// bool operator < ( const Coordinate & other ) const ; BOOST_AUTO_TEST_CASE(testLessEmpty) { - Coordinate gA; - Coordinate gB; + Coordinate const gA; + Coordinate const gB; BOOST_CHECK_THROW((gA < gB), Exception); } BOOST_AUTO_TEST_CASE(testLessXY_XY) diff --git a/test/unit/SFCGAL/EnvelopeTest.cpp b/test/unit/SFCGAL/EnvelopeTest.cpp index 54b57850..a7c486be 100644 --- a/test/unit/SFCGAL/EnvelopeTest.cpp +++ b/test/unit/SFCGAL/EnvelopeTest.cpp @@ -15,7 +15,8 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include @@ -24,110 +25,108 @@ #include #include -using namespace boost::unit_test ; -using namespace SFCGAL ; +using namespace boost::unit_test; +using namespace SFCGAL; -BOOST_AUTO_TEST_SUITE( SFCGAL_EnvelopeTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_EnvelopeTest) -//Envelope() ; -BOOST_AUTO_TEST_CASE( defaultConstructor ) +// Envelope() ; +BOOST_AUTO_TEST_CASE(defaultConstructor) { - Envelope box ; - BOOST_CHECK( box.boundsN( 0 ).isEmpty() ); - BOOST_CHECK( box.boundsN( 1 ).isEmpty() ); - BOOST_CHECK( box.boundsN( 2 ).isEmpty() ); + Envelope box; + BOOST_CHECK(box.boundsN(0).isEmpty()); + BOOST_CHECK(box.boundsN(1).isEmpty()); + BOOST_CHECK(box.boundsN(2).isEmpty()); } -//Envelope( const Coordinate & p ) ; -BOOST_AUTO_TEST_CASE( constructorWithCoordinateXY ) +// Envelope( const Coordinate & p ) ; +BOOST_AUTO_TEST_CASE(constructorWithCoordinateXY) { - Envelope box( Coordinate( 1.0,2.0 ) ); - BOOST_CHECK( box.boundsN( 0 ) == detail::Interval( 1.0 ) ); - BOOST_CHECK( box.boundsN( 1 ) == detail::Interval( 2.0 ) ); - BOOST_CHECK( box.boundsN( 2 ).isEmpty() ); + Envelope box(Coordinate(1.0, 2.0)); + BOOST_CHECK(box.boundsN(0) == detail::Interval(1.0)); + BOOST_CHECK(box.boundsN(1) == detail::Interval(2.0)); + BOOST_CHECK(box.boundsN(2).isEmpty()); } -//Envelope( const Coordinate & p1, const Coordinate & p2 ) ; -BOOST_AUTO_TEST_CASE( constructorWithTwoCoordinateXY ) +// Envelope( const Coordinate & p1, const Coordinate & p2 ) ; +BOOST_AUTO_TEST_CASE(constructorWithTwoCoordinateXY) { - Envelope box( Coordinate( 3.0,5.0 ), Coordinate( 1.0,2.0 ) ); - BOOST_CHECK( box.boundsN( 0 ) == detail::Interval( 1.0,3.0 ) ); - BOOST_CHECK( box.boundsN( 1 ) == detail::Interval( 2.0,5.0 ) ); - BOOST_CHECK( box.boundsN( 2 ).isEmpty() ); + Envelope box(Coordinate(3.0, 5.0), Coordinate(1.0, 2.0)); + BOOST_CHECK(box.boundsN(0) == detail::Interval(1.0, 3.0)); + BOOST_CHECK(box.boundsN(1) == detail::Interval(2.0, 5.0)); + BOOST_CHECK(box.boundsN(2).isEmpty()); } -//Envelope( const Envelope& other ) ; -//Envelope& operator = ( const Envelope& other ) ; +// Envelope( const Envelope& other ) ; +// Envelope& operator = ( const Envelope& other ) ; //~Envelope() ; -//bool isEmpty() const ; -BOOST_AUTO_TEST_CASE( testIsEmpty ) +// bool isEmpty() const ; +BOOST_AUTO_TEST_CASE(testIsEmpty) { - Envelope box ; - BOOST_CHECK( box.isEmpty() ); + Envelope const box; + BOOST_CHECK(box.isEmpty()); } -BOOST_AUTO_TEST_CASE( testIsNotEmpty ) +BOOST_AUTO_TEST_CASE(testIsNotEmpty) { - Envelope box( Coordinate( 0.0,0.0 ) ) ; - BOOST_CHECK( ! box.isEmpty() ); + Envelope const box(Coordinate(0.0, 0.0)); + BOOST_CHECK(!box.isEmpty()); } -//bool is3D() const ; -BOOST_AUTO_TEST_CASE( testIs3D ) +// bool is3D() const ; +BOOST_AUTO_TEST_CASE(testIs3D) { - Envelope box( Coordinate( 0.0,0.0,0.0 ) ) ; - BOOST_CHECK( box.is3D() ); + Envelope const box(Coordinate(0.0, 0.0, 0.0)); + BOOST_CHECK(box.is3D()); } -BOOST_AUTO_TEST_CASE( testNotIs3D ) +BOOST_AUTO_TEST_CASE(testNotIs3D) { - Envelope box( Coordinate( 0.0,0.0 ) ) ; - BOOST_CHECK( ! box.is3D() ); + Envelope const box(Coordinate(0.0, 0.0)); + BOOST_CHECK(!box.is3D()); } -//void expandToInclude( const Coordinate & coordinate ) ; +// void expandToInclude( const Coordinate & coordinate ) ; -BOOST_AUTO_TEST_CASE( testExpandToInclude ) +BOOST_AUTO_TEST_CASE(testExpandToInclude) { - Envelope box ; - BOOST_CHECK( box.isEmpty() ); + Envelope box; + BOOST_CHECK(box.isEmpty()); - box.expandToInclude( Coordinate( 0.0,0.0 ) ) ; - BOOST_CHECK( ! box.isEmpty() ); - BOOST_CHECK( ! box.is3D() ); + box.expandToInclude(Coordinate(0.0, 0.0)); + BOOST_CHECK(!box.isEmpty()); + BOOST_CHECK(!box.is3D()); - BOOST_CHECK( box.boundsN( 0 ) == detail::Interval( 0.0 ) ); - BOOST_CHECK( box.boundsN( 1 ) == detail::Interval( 0.0 ) ); + BOOST_CHECK(box.boundsN(0) == detail::Interval(0.0)); + BOOST_CHECK(box.boundsN(1) == detail::Interval(0.0)); - box.expandToInclude( Coordinate( 0.0,0.0,0.0 ) ) ; - BOOST_CHECK( ! box.isEmpty() ); - BOOST_CHECK( box.is3D() ); + box.expandToInclude(Coordinate(0.0, 0.0, 0.0)); + BOOST_CHECK(!box.isEmpty()); + BOOST_CHECK(box.is3D()); - BOOST_CHECK( box.boundsN( 0 ) == detail::Interval( 0.0 ) ); - BOOST_CHECK( box.boundsN( 1 ) == detail::Interval( 0.0 ) ); - BOOST_CHECK( box.boundsN( 2 ) == detail::Interval( 0.0 ) ); + BOOST_CHECK(box.boundsN(0) == detail::Interval(0.0)); + BOOST_CHECK(box.boundsN(1) == detail::Interval(0.0)); + BOOST_CHECK(box.boundsN(2) == detail::Interval(0.0)); - box.expandToInclude( Coordinate( 1.0,2.0 ) ) ; - BOOST_CHECK( box.boundsN( 0 ) == detail::Interval( 0.0,1.0 ) ); - BOOST_CHECK( box.boundsN( 1 ) == detail::Interval( 0.0,2.0 ) ); - BOOST_CHECK( box.boundsN( 2 ) == detail::Interval( 0.0 ) ); + box.expandToInclude(Coordinate(1.0, 2.0)); + BOOST_CHECK(box.boundsN(0) == detail::Interval(0.0, 1.0)); + BOOST_CHECK(box.boundsN(1) == detail::Interval(0.0, 2.0)); + BOOST_CHECK(box.boundsN(2) == detail::Interval(0.0)); } - -//std::unique_ptr< LineString > toRing() const ; -BOOST_AUTO_TEST_CASE( testToRing ) +// std::unique_ptr< LineString > toRing() const ; +BOOST_AUTO_TEST_CASE(testToRing) { - Envelope box( 0.0,1.0,2.0,3.0 ); - BOOST_CHECK_EQUAL( box.toRing()->asText( 0 ), "LINESTRING(0 2,1 2,1 3,0 3,0 2)" ); + Envelope const box(0.0, 1.0, 2.0, 3.0); + BOOST_CHECK_EQUAL(box.toRing()->asText(0), "LINESTRING(0 2,1 2,1 3,0 3,0 2)"); } -//std::unique_ptr< Polygon > toPolygon() const ; -BOOST_AUTO_TEST_CASE( testToPolygon ) +// std::unique_ptr< Polygon > toPolygon() const ; +BOOST_AUTO_TEST_CASE(testToPolygon) { - Envelope box( 0.0,1.0,2.0,3.0,4.0,5.0 ); - BOOST_CHECK_EQUAL( box.toSolid()->asText( 0 ), "SOLID Z((((0 2 4,0 3 4,1 3 4,1 2 4,0 2 4)),((0 2 5,1 2 5,1 3 5,0 3 5,0 2 5)),((0 2 4,1 2 4,1 2 5,0 2 5,0 2 4)),((1 3 4,0 3 4,0 3 5,1 3 5,1 3 4)),((1 2 4,1 3 4,1 3 5,1 2 5,1 2 4)),((0 2 4,0 2 5,0 3 5,0 3 4,0 2 4))))" ); + Envelope const box(0.0, 1.0, 2.0, 3.0, 4.0, 5.0); + BOOST_CHECK_EQUAL(box.toSolid()->asText(0), + "SOLID Z((((0 2 4,0 3 4,1 3 4,1 2 4,0 2 4)),((0 2 5,1 2 " + "5,1 3 5,0 3 5,0 2 5)),((0 2 4,1 2 4,1 2 5,0 2 5,0 2 " + "4)),((1 3 4,0 3 4,0 3 5,1 3 5,1 3 4)),((1 2 4,1 3 4,1 3 " + "5,1 2 5,1 2 4)),((0 2 4,0 2 5,0 3 5,0 3 4,0 2 4))))"); } - BOOST_AUTO_TEST_SUITE_END() - - - - diff --git a/test/unit/SFCGAL/GeometryCollectionTest.cpp b/test/unit/SFCGAL/GeometryCollectionTest.cpp index 642b8767..6ab81e60 100644 --- a/test/unit/SFCGAL/GeometryCollectionTest.cpp +++ b/test/unit/SFCGAL/GeometryCollectionTest.cpp @@ -15,149 +15,148 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include #include -#include -#include -#include -#include -#include -#include -#include #include -#include +#include #include +#include #include #include +#include +#include +#include +#include +#include +#include -using namespace boost::unit_test ; -using namespace SFCGAL ; +using namespace boost::unit_test; +using namespace SFCGAL; -BOOST_AUTO_TEST_SUITE( SFCGAL_GeometryCollectionTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_GeometryCollectionTest) -//GeometryCollection() ; -BOOST_AUTO_TEST_CASE( defaultConstructor ) +// GeometryCollection() ; +BOOST_AUTO_TEST_CASE(defaultConstructor) { - GeometryCollection g ; - BOOST_CHECK( g.isEmpty() ); + GeometryCollection const g; + BOOST_CHECK(g.isEmpty()); } -//GeometryCollection( GeometryCollection const& other ) ; -//GeometryCollection& operator = ( const GeometryCollection & other ) ; -//virtual ~GeometryCollection() ; +// GeometryCollection( GeometryCollection const& other ) ; +// GeometryCollection& operator = ( const GeometryCollection & other ) ; +// virtual ~GeometryCollection() ; -//virtual size_t numGeometries() const ; -//virtual const Geometry & geometryN( size_t const& n ) const ; -//virtual Geometry & geometryN( size_t const& n ) ; -//void addGeometry( Geometry * geometry ) ; -//void addGeometry( Geometry const& geometry ) ; -BOOST_AUTO_TEST_CASE( testAccessors ) +// virtual size_t numGeometries() const ; +// virtual const Geometry & geometryN( size_t const& n ) const ; +// virtual Geometry & geometryN( size_t const& n ) ; +// void addGeometry( Geometry * geometry ) ; +// void addGeometry( Geometry const& geometry ) ; +BOOST_AUTO_TEST_CASE(testAccessors) { - GeometryCollection g ; - - g.addGeometry( new Point( 2.0,3.0 ) ) ; - BOOST_CHECK_EQUAL( g.numGeometries(), 1U ); - g.addGeometry( new LineString( Point( 0.0,0.0 ),Point( 1.0,1.0 ) ) ) ; - BOOST_CHECK_EQUAL( g.numGeometries(), 2U ); - g.addGeometry( new Triangle( Point( 0.0,0.0 ),Point( 1.0,0.0 ),Point( 1.0,1.0 ) ) ) ; - BOOST_CHECK_EQUAL( g.numGeometries(), 3U ); - - BOOST_CHECK_EQUAL( g.geometryN( 0 ).asText( 0 ), "POINT(2 3)" ) ; - BOOST_CHECK_EQUAL( g.geometryN( 1 ).asText( 0 ), "LINESTRING(0 0,1 1)" ) ; - BOOST_CHECK_EQUAL( g.geometryN( 2 ).asText( 0 ), "TRIANGLE((0 0,1 0,1 1,0 0))" ) ; + GeometryCollection g; + + g.addGeometry(new Point(2.0, 3.0)); + BOOST_CHECK_EQUAL(g.numGeometries(), 1U); + g.addGeometry(new LineString(Point(0.0, 0.0), Point(1.0, 1.0))); + BOOST_CHECK_EQUAL(g.numGeometries(), 2U); + g.addGeometry( + new Triangle(Point(0.0, 0.0), Point(1.0, 0.0), Point(1.0, 1.0))); + BOOST_CHECK_EQUAL(g.numGeometries(), 3U); + + BOOST_CHECK_EQUAL(g.geometryN(0).asText(0), "POINT(2 3)"); + BOOST_CHECK_EQUAL(g.geometryN(1).asText(0), "LINESTRING(0 0,1 1)"); + BOOST_CHECK_EQUAL(g.geometryN(2).asText(0), "TRIANGLE((0 0,1 0,1 1,0 0))"); } - //-- iterators -//inline iterator begin() -//inline const_iterator begin() const -//inline iterator end() -//inline const_iterator end() const -BOOST_AUTO_TEST_CASE( testIterators ) +// inline iterator begin() +// inline const_iterator begin() const +// inline iterator end() +// inline const_iterator end() const +BOOST_AUTO_TEST_CASE(testIterators) { - GeometryCollection g ; - g.addGeometry( Point( 0.0,0.0 ) ); - g.addGeometry( Point( 1.0,1.0 ) ); + GeometryCollection g; + g.addGeometry(Point(0.0, 0.0)); + g.addGeometry(Point(1.0, 1.0)); - GeometryCollection::const_iterator it = g.begin() ; + GeometryCollection::const_iterator it = g.begin(); - BOOST_CHECK_EQUAL( it->asText( 0 ), "POINT(0 0)" ); - ++it ; - BOOST_CHECK_EQUAL( it->asText( 0 ), "POINT(1 1)" ); - ++it ; - BOOST_CHECK( it == g.end() ); + BOOST_CHECK_EQUAL(it->asText(0), "POINT(0 0)"); + ++it; + BOOST_CHECK_EQUAL(it->asText(0), "POINT(1 1)"); + ++it; + BOOST_CHECK(it == g.end()); } - //-- Geometry -//virtual Geometry * Geometry::clone() const = 0 ; -//virtual Geometry* Geometry::boundary() const ; -//Envelope Geometry::envelope() const ; +// virtual Geometry * Geometry::clone() const = 0 ; +// virtual Geometry* Geometry::boundary() const ; +// Envelope Geometry::envelope() const ; -//std::string Geometry::asText( const int & numDecimals = -1 ) const ; -BOOST_AUTO_TEST_CASE( asTextEmpty ) +// std::string Geometry::asText( const int & numDecimals = -1 ) const ; +BOOST_AUTO_TEST_CASE(asTextEmpty) { - GeometryCollection g; - BOOST_CHECK_EQUAL( g.asText( 1 ), "GEOMETRYCOLLECTION EMPTY" ); + GeometryCollection const g; + BOOST_CHECK_EQUAL(g.asText(1), "GEOMETRYCOLLECTION EMPTY"); } -BOOST_AUTO_TEST_CASE( asText2d ) +BOOST_AUTO_TEST_CASE(asText2d) { - GeometryCollection g; - g.addGeometry( Point( 2.0,3.0 ) ); - g.addGeometry( Triangle( Point( 0.0,0.0 ), Point( 1.0,0.0 ), Point( 1.0,1.0 ) ) ); - BOOST_CHECK_EQUAL( g.asText( 1 ), "GEOMETRYCOLLECTION(POINT(2.0 3.0),TRIANGLE((0.0 0.0,1.0 0.0,1.0 1.0,0.0 0.0)))" ); + GeometryCollection g; + g.addGeometry(Point(2.0, 3.0)); + g.addGeometry(Triangle(Point(0.0, 0.0), Point(1.0, 0.0), Point(1.0, 1.0))); + BOOST_CHECK_EQUAL(g.asText(1), + "GEOMETRYCOLLECTION(POINT(2.0 3.0),TRIANGLE((0.0 0.0,1.0 " + "0.0,1.0 1.0,0.0 0.0)))"); } -BOOST_AUTO_TEST_CASE( asText3d ) +BOOST_AUTO_TEST_CASE(asText3d) { - GeometryCollection g; - g.addGeometry( Point( 2.0,3.0,5.0 ) ); - g.addGeometry( Triangle( Point( 0.0,0.0,6.0 ), Point( 1.0,0.0,6.0 ), Point( 1.0,1.0,6.0 ) ) ); - BOOST_CHECK_EQUAL( g.asText( 1 ), "GEOMETRYCOLLECTION Z(POINT Z(2.0 3.0 5.0),TRIANGLE Z((0.0 0.0 6.0,1.0 0.0 6.0,1.0 1.0 6.0,0.0 0.0 6.0)))" ); + GeometryCollection g; + g.addGeometry(Point(2.0, 3.0, 5.0)); + g.addGeometry(Triangle(Point(0.0, 0.0, 6.0), Point(1.0, 0.0, 6.0), + Point(1.0, 1.0, 6.0))); + BOOST_CHECK_EQUAL(g.asText(1), + "GEOMETRYCOLLECTION Z(POINT Z(2.0 3.0 5.0),TRIANGLE Z((0.0 " + "0.0 6.0,1.0 0.0 6.0,1.0 1.0 6.0,0.0 0.0 6.0)))"); } -//virtual std::string Geometry::geometryType() const = 0 ; -BOOST_AUTO_TEST_CASE( testGeometryType ) +// virtual std::string Geometry::geometryType() const = 0 ; +BOOST_AUTO_TEST_CASE(testGeometryType) { - GeometryCollection g; - BOOST_CHECK_EQUAL( g.geometryType(), "GeometryCollection" ); + GeometryCollection const g; + BOOST_CHECK_EQUAL(g.geometryType(), "GeometryCollection"); } -//virtual GeometryType Geometry::geometryTypeId() const = 0 ; -BOOST_AUTO_TEST_CASE( testGeometryTypeId ) +// virtual GeometryType Geometry::geometryTypeId() const = 0 ; +BOOST_AUTO_TEST_CASE(testGeometryTypeId) { - GeometryCollection g; - BOOST_CHECK_EQUAL( g.geometryTypeId(), TYPE_GEOMETRYCOLLECTION ); + GeometryCollection const g; + BOOST_CHECK_EQUAL(g.geometryTypeId(), TYPE_GEOMETRYCOLLECTION); } -//virtual int Geometry::dimension() const = 0 ; -//virtual int Geometry::coordinateDimension() const = 0 ; -//virtual bool Geometry::isEmpty() const = 0 ; -//virtual bool Geometry::is3D() const = 0 ; -//virtual bool Geometry::isMeasured() const = 0 ; -//virtual bool Geometry::isSimple() const = 0 ; +// virtual int Geometry::dimension() const = 0 ; +// virtual int Geometry::coordinateDimension() const = 0 ; +// virtual bool Geometry::isEmpty() const = 0 ; +// virtual bool Geometry::is3D() const = 0 ; +// virtual bool Geometry::isMeasured() const = 0 ; +// virtual bool Geometry::isSimple() const = 0 ; -//template < typename Derived > inline bool Geometry::is() const -BOOST_AUTO_TEST_CASE( testIsGeometryCollection ) +// template < typename Derived > inline bool Geometry::is() const +BOOST_AUTO_TEST_CASE(testIsGeometryCollection) { - BOOST_CHECK( GeometryCollection().is< GeometryCollection >() ); - BOOST_CHECK( MultiPoint().is< GeometryCollection >() ); - BOOST_CHECK( MultiLineString().is< GeometryCollection >() ); - BOOST_CHECK( MultiPolygon().is< GeometryCollection >() ); - BOOST_CHECK( MultiSolid().is< GeometryCollection >() ); + BOOST_CHECK(GeometryCollection().is()); + BOOST_CHECK(MultiPoint().is()); + BOOST_CHECK(MultiLineString().is()); + BOOST_CHECK(MultiPolygon().is()); + BOOST_CHECK(MultiSolid().is()); } -//template < typename Derived > inline const Derived & Geometry::as() const -//template < typename Derived > inline Derived & Geometry::as() - - +// template < typename Derived > inline const Derived & Geometry::as() const +// template < typename Derived > inline Derived & Geometry::as() BOOST_AUTO_TEST_SUITE_END() - - - - diff --git a/test/unit/SFCGAL/GeometryTest.cpp b/test/unit/SFCGAL/GeometryTest.cpp index ca0e0bf7..319fd294 100644 --- a/test/unit/SFCGAL/GeometryTest.cpp +++ b/test/unit/SFCGAL/GeometryTest.cpp @@ -15,73 +15,67 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include -#include -#include -#include -#include -#include -#include -#include #include -#include +#include #include +#include #include #include +#include +#include +#include +#include +#include +#include -using namespace boost::unit_test ; -using namespace SFCGAL ; +using namespace boost::unit_test; +using namespace SFCGAL; -BOOST_AUTO_TEST_SUITE( SFCGAL_GeometryTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_GeometryTest) -//virtual ~Geometry(); +// virtual ~Geometry(); // MAY BE TESTED IN SUBCLASSES -//virtual Geometry * Geometry::clone() const = 0 ; -//virtual Geometry* Geometry::boundary() const ; -//Envelope Geometry::envelope() const ; -//std::string Geometry::asText( const int & numDecimals = -1 ) const ; -//virtual std::string Geometry::geometryType() const = 0 ; -//virtual GeometryType Geometry::geometryTypeId() const = 0 ; -//virtual int Geometry::dimension() const = 0 ; -//virtual int Geometry::coordinateDimension() const = 0 ; -//virtual bool Geometry::isEmpty() const = 0 ; -//virtual bool Geometry::is3D() const = 0 ; -//virtual bool Geometry::isMeasured() const = 0 ; -//virtual bool Geometry::isSimple() const = 0 ; -//template < typename Derived > inline bool Geometry::is() const -//template < typename Derived > inline const Derived & Geometry::as() const -//template < typename Derived > inline Derived & Geometry::as() - - - -//TODO -//void round( const long & scale = 1 ) ; - -//TODO -//virtual size_t numGeometries() const ; -//virtual const Geometry & geometryN( size_t const& n ) const ; -//virtual Geometry & geometryN( size_t const& n ) ; +// virtual Geometry * Geometry::clone() const = 0 ; +// virtual Geometry* Geometry::boundary() const ; +// Envelope Geometry::envelope() const ; +// std::string Geometry::asText( const int & numDecimals = -1 ) const ; +// virtual std::string Geometry::geometryType() const = 0 ; +// virtual GeometryType Geometry::geometryTypeId() const = 0 ; +// virtual int Geometry::dimension() const = 0 ; +// virtual int Geometry::coordinateDimension() const = 0 ; +// virtual bool Geometry::isEmpty() const = 0 ; +// virtual bool Geometry::is3D() const = 0 ; +// virtual bool Geometry::isMeasured() const = 0 ; +// virtual bool Geometry::isSimple() const = 0 ; +// template < typename Derived > inline bool Geometry::is() const +// template < typename Derived > inline const Derived & Geometry::as() const +// template < typename Derived > inline Derived & Geometry::as() + +// TODO +// void round( const long & scale = 1 ) ; + +// TODO +// virtual size_t numGeometries() const ; +// virtual const Geometry & geometryN( size_t const& n ) const ; +// virtual Geometry & geometryN( size_t const& n ) ; //-- tested in distance -//double distance( const Geometry & other ) const ; -//double distance3D( const Geometry & other ) const ; - +// double distance( const Geometry & other ) const ; +// double distance3D( const Geometry & other ) const ; //-- tested in geometry visitor test -//virtual void accept( GeometryVisitor & visitor ) = 0 ; -//virtual void accept( ConstGeometryVisitor & visitor ) const = 0 ; - -//TODO -//template void serialize( Archive& ar, const unsigned int version ) +// virtual void accept( GeometryVisitor & visitor ) = 0 ; +// virtual void accept( ConstGeometryVisitor & visitor ) const = 0 ; +// TODO +// template void serialize( Archive& ar, const unsigned int +// version ) BOOST_AUTO_TEST_SUITE_END() - - - - diff --git a/test/unit/SFCGAL/GeometryVisitorTest.cpp b/test/unit/SFCGAL/GeometryVisitorTest.cpp index 5c87449c..b7466a1c 100644 --- a/test/unit/SFCGAL/GeometryVisitorTest.cpp +++ b/test/unit/SFCGAL/GeometryVisitorTest.cpp @@ -15,153 +15,174 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include -#include -#include -#include -#include -#include -#include -#include #include -#include +#include #include +#include #include #include +#include +#include +#include +#include +#include +#include #include #include - -using namespace SFCGAL ; +using namespace SFCGAL; // always after CGAL -using namespace boost::unit_test ; +using namespace boost::unit_test; /** * get type from Geometry */ class DemoVisitorGetType : public ConstGeometryVisitor { public: - - void visit( const Point& ) override { - type = "Point"; - } - void visit( const LineString& ) override { - type = "LineString"; - } - void visit( const Polygon& ) override { - type = "Polygon"; - } - void visit( const Triangle& ) override { - type = "Triangle"; - } - void visit( const Solid& ) override { - type = "Solid"; - } - void visit( const MultiPoint& ) override { - type = "MultiPoint"; - } - void visit( const MultiLineString& ) override { - type = "MultiLineString"; - } - void visit( const MultiPolygon& ) override { - type = "MultiPolygon"; - } - void visit( const MultiSolid& ) override { - type = "MultiSolid"; - } - - void visit( const GeometryCollection& ) override { - type = "GeometryCollection"; - } - - void visit( const PolyhedralSurface& ) override { - type = "PolyhedralSurface"; - } - - void visit( const TriangulatedSurface& ) override { - type = "TriangulatedSurface"; - } - -public: - std::string type ; + void + visit(const Point & /*g*/) override + { + type = "Point"; + } + void + visit(const LineString & /*g*/) override + { + type = "LineString"; + } + void + visit(const Polygon & /*g*/) override + { + type = "Polygon"; + } + void + visit(const Triangle & /*g*/) override + { + type = "Triangle"; + } + void + visit(const Solid & /*g*/) override + { + type = "Solid"; + } + void + visit(const MultiPoint & /*g*/) override + { + type = "MultiPoint"; + } + void + visit(const MultiLineString & /*g*/) override + { + type = "MultiLineString"; + } + void + visit(const MultiPolygon & /*g*/) override + { + type = "MultiPolygon"; + } + void + visit(const MultiSolid & /*g*/) override + { + type = "MultiSolid"; + } + + void + visit(const GeometryCollection & /*g*/) override + { + type = "GeometryCollection"; + } + + void + visit(const PolyhedralSurface & /*g*/) override + { + type = "PolyhedralSurface"; + } + + void + visit(const TriangulatedSurface & /*g*/) override + { + type = "TriangulatedSurface"; + } + + std::string type; }; - -template < typename T > -std::string getTypeWithVisitor() +template +auto +getTypeWithVisitor() -> std::string { - std::unique_ptr< Geometry > geometry( new T() ); - DemoVisitorGetType visitor; - geometry->accept( visitor ); - return visitor.type ; + std::unique_ptr geometry(new T()); + DemoVisitorGetType visitor; + geometry->accept(visitor); + return visitor.type; } - - /* * base checks (mainly for compilation issues) */ -BOOST_AUTO_TEST_SUITE( SFCGAL_GeometryVisitorTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_GeometryVisitorTest) -BOOST_AUTO_TEST_CASE( testVisitPoint ) +BOOST_AUTO_TEST_CASE(testVisitPoint) { - BOOST_CHECK_EQUAL( getTypeWithVisitor< Point >(), "Point" ); + BOOST_CHECK_EQUAL(getTypeWithVisitor(), "Point"); } -BOOST_AUTO_TEST_CASE( testVisitLineString ) +BOOST_AUTO_TEST_CASE(testVisitLineString) { - BOOST_CHECK_EQUAL( getTypeWithVisitor< LineString >(), "LineString" ); + BOOST_CHECK_EQUAL(getTypeWithVisitor(), "LineString"); } -BOOST_AUTO_TEST_CASE( testVisitPolygon ) +BOOST_AUTO_TEST_CASE(testVisitPolygon) { - BOOST_CHECK_EQUAL( getTypeWithVisitor< Polygon >(), "Polygon" ); + BOOST_CHECK_EQUAL(getTypeWithVisitor(), "Polygon"); } -BOOST_AUTO_TEST_CASE( testVisitTriangle ) +BOOST_AUTO_TEST_CASE(testVisitTriangle) { - BOOST_CHECK_EQUAL( getTypeWithVisitor< Triangle >(), "Triangle" ); + BOOST_CHECK_EQUAL(getTypeWithVisitor(), "Triangle"); } -BOOST_AUTO_TEST_CASE( testVisitMultiPoint ) +BOOST_AUTO_TEST_CASE(testVisitMultiPoint) { - BOOST_CHECK_EQUAL( getTypeWithVisitor< MultiPoint >(), "MultiPoint" ); + BOOST_CHECK_EQUAL(getTypeWithVisitor(), "MultiPoint"); } -BOOST_AUTO_TEST_CASE( testVisitMultiLineString ) +BOOST_AUTO_TEST_CASE(testVisitMultiLineString) { - BOOST_CHECK_EQUAL( getTypeWithVisitor< MultiLineString >(), "MultiLineString" ); + BOOST_CHECK_EQUAL(getTypeWithVisitor(), "MultiLineString"); } -BOOST_AUTO_TEST_CASE( testVisitMultiPolygon ) +BOOST_AUTO_TEST_CASE(testVisitMultiPolygon) { - BOOST_CHECK_EQUAL( getTypeWithVisitor< MultiPolygon >(), "MultiPolygon" ); + BOOST_CHECK_EQUAL(getTypeWithVisitor(), "MultiPolygon"); } -BOOST_AUTO_TEST_CASE( testVisitMultiSolid ) +BOOST_AUTO_TEST_CASE(testVisitMultiSolid) { - BOOST_CHECK_EQUAL( getTypeWithVisitor< MultiSolid >(), "MultiSolid" ); + BOOST_CHECK_EQUAL(getTypeWithVisitor(), "MultiSolid"); } -BOOST_AUTO_TEST_CASE( testVisitGeometryCollection ) +BOOST_AUTO_TEST_CASE(testVisitGeometryCollection) { - BOOST_CHECK_EQUAL( getTypeWithVisitor< GeometryCollection >(), "GeometryCollection" ); + BOOST_CHECK_EQUAL(getTypeWithVisitor(), + "GeometryCollection"); } -BOOST_AUTO_TEST_CASE( testVisitTriangulatedSurface ) +BOOST_AUTO_TEST_CASE(testVisitTriangulatedSurface) { - BOOST_CHECK_EQUAL( getTypeWithVisitor< TriangulatedSurface >(), "TriangulatedSurface" ); + BOOST_CHECK_EQUAL(getTypeWithVisitor(), + "TriangulatedSurface"); } -BOOST_AUTO_TEST_CASE( testVisitPolyhedralSurface ) +BOOST_AUTO_TEST_CASE(testVisitPolyhedralSurface) { - BOOST_CHECK_EQUAL( getTypeWithVisitor< PolyhedralSurface >(), "PolyhedralSurface" ); + BOOST_CHECK_EQUAL(getTypeWithVisitor(), + "PolyhedralSurface"); } -BOOST_AUTO_TEST_CASE( testVisitSolid ) +BOOST_AUTO_TEST_CASE(testVisitSolid) { - BOOST_CHECK_EQUAL( getTypeWithVisitor< Solid >(), "Solid" ); + BOOST_CHECK_EQUAL(getTypeWithVisitor(), "Solid"); } - BOOST_AUTO_TEST_SUITE_END() - diff --git a/test/unit/SFCGAL/KernelTest.cpp b/test/unit/SFCGAL/KernelTest.cpp index 01deeaa2..05905fe3 100644 --- a/test/unit/SFCGAL/KernelTest.cpp +++ b/test/unit/SFCGAL/KernelTest.cpp @@ -15,95 +15,88 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include #include -#include #include +#include #include -using namespace SFCGAL ; +using namespace SFCGAL; -typedef Kernel::Vector_2 Vector_2 ; -typedef Kernel::Vector_3 Vector_3 ; -typedef Kernel::Point_2 Point_2 ; -typedef Kernel::Point_3 Point_3 ; -typedef Kernel::Segment_2 Segment_2 ; -typedef Kernel::Segment_3 Segment_3 ; +using Vector_2 = Kernel::Vector_2; +using Vector_3 = Kernel::Vector_3; +using Point_2 = Kernel::Point_2; +using Point_3 = Kernel::Point_3; +using Segment_2 = Kernel::Segment_2; +using Segment_3 = Kernel::Segment_3; // always after CGAL -using namespace boost::unit_test ; - -BOOST_AUTO_TEST_SUITE( SFCGAL_KernelTest ) +using namespace boost::unit_test; +BOOST_AUTO_TEST_SUITE(SFCGAL_KernelTest) /** * 1 - 1/3 - 1/3 - 1/3 = 0 */ -BOOST_AUTO_TEST_CASE( testRobustArithmetric ) +BOOST_AUTO_TEST_CASE(testRobustArithmetric) { - Kernel::FT v = 1 ; - v -= Kernel::FT( 1 ) / Kernel::FT( 3 ) ; - v -= Kernel::FT( 1 ) / Kernel::FT( 3 ) ; - v -= Kernel::FT( 1 ) / Kernel::FT( 3 ) ; - BOOST_CHECK_EQUAL( v,0 ); + Kernel::FT v = 1; + v -= Kernel::FT(1) / Kernel::FT(3); + v -= Kernel::FT(1) / Kernel::FT(3); + v -= Kernel::FT(1) / Kernel::FT(3); + BOOST_CHECK_EQUAL(v, 0); } /** * Serialize/Deserialize 1/3 * @todo check with hugo's code */ -BOOST_AUTO_TEST_CASE( testSerializeDeserialize ) +BOOST_AUTO_TEST_CASE(testSerializeDeserialize) { - Kernel::FT a = 1 ; - a /= 3 ; + Kernel::FT a = 1; + a /= 3; - std::stringstream ss ; - ss << CGAL::exact( a ) ; + std::stringstream ss; + ss << CGAL::exact(a); - Kernel::FT b; - ss >> b; - BOOST_CHECK_EQUAL( a, b ) ; + Kernel::FT b; + ss >> b; + BOOST_CHECK_EQUAL(a, b); } - - /** * 3 lines intersecting on POINT(1/3 1) */ -BOOST_AUTO_TEST_CASE( testIntersectsRobutness ) +BOOST_AUTO_TEST_CASE(testIntersectsRobutness) { - LineString ab( Point( 0.0,0.0 ), Point( 1.0,3.0 ) ); - LineString cd( Point( 0.0,1.0 ) , Point( 1.0,1.0 ) ); - LineString ef( Point( -1.0,3.0 ), Point( 1.0,0.0 ) ); - - //ab, cd - CGAL::Object abIcd_ = CGAL::intersection( - Segment_2( ab.startPoint().toPoint_2(), ab.endPoint().toPoint_2() ), - Segment_2( cd.startPoint().toPoint_2(), cd.endPoint().toPoint_2() ) - ); - const Point_2* abIcd = CGAL::object_cast( &abIcd_ ) ; - BOOST_REQUIRE( abIcd != NULL ); - - //would break robustness if construction history is lost - Point intersectionA( *abIcd ); - - CGAL::Object abIef_ = CGAL::intersection( - intersectionA.toPoint_2(), - Segment_2( ef.startPoint().toPoint_2(), ef.endPoint().toPoint_2() ) - ); - const Point_2* abIef = CGAL::object_cast( &abIef_ ) ; - BOOST_REQUIRE( abIef != NULL ); - - Point intersectionB( *abIef ); - - BOOST_CHECK_EQUAL( intersectionA.toPoint_2(), intersectionB.toPoint_2() ); -} + LineString ab(Point(0.0, 0.0), Point(1.0, 3.0)); + LineString cd(Point(0.0, 1.0), Point(1.0, 1.0)); + LineString ef(Point(-1.0, 3.0), Point(1.0, 0.0)); + // ab, cd + CGAL::Object const abIcd_ = CGAL::intersection( + Segment_2(ab.startPoint().toPoint_2(), ab.endPoint().toPoint_2()), + Segment_2(cd.startPoint().toPoint_2(), cd.endPoint().toPoint_2())); + const auto *abIcd = CGAL::object_cast(&abIcd_); + BOOST_REQUIRE(abIcd != NULL); + // would break robustness if construction history is lost + Point const intersectionA(*abIcd); -BOOST_AUTO_TEST_SUITE_END() + CGAL::Object const abIef_ = CGAL::intersection( + intersectionA.toPoint_2(), + Segment_2(ef.startPoint().toPoint_2(), ef.endPoint().toPoint_2())); + const auto *abIef = CGAL::object_cast(&abIef_); + BOOST_REQUIRE(abIef != NULL); + + Point const intersectionB(*abIef); + BOOST_CHECK_EQUAL(intersectionA.toPoint_2(), intersectionB.toPoint_2()); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/unit/SFCGAL/LineStringTest.cpp b/test/unit/SFCGAL/LineStringTest.cpp index b495bbc1..0dd8beb0 100644 --- a/test/unit/SFCGAL/LineStringTest.cpp +++ b/test/unit/SFCGAL/LineStringTest.cpp @@ -15,390 +15,376 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include #include -#include #include -#include #include +#include +#include -using namespace SFCGAL ; -using namespace boost::unit_test ; +using namespace SFCGAL; +using namespace boost::unit_test; -BOOST_AUTO_TEST_SUITE( SFCGAL_LineStringTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_LineStringTest) -///LineString() ; -BOOST_AUTO_TEST_CASE( defaultConstructor ) +/// LineString() ; +BOOST_AUTO_TEST_CASE(defaultConstructor) { - LineString g; - BOOST_CHECK( g.isEmpty() ); - BOOST_CHECK( ! g.is3D() ); - BOOST_CHECK( ! g.isMeasured() ); - BOOST_CHECK_EQUAL( g.numPoints(), 0U ); + LineString const g; + BOOST_CHECK(g.isEmpty()); + BOOST_CHECK(!g.is3D()); + BOOST_CHECK(!g.isMeasured()); + BOOST_CHECK_EQUAL(g.numPoints(), 0U); } -///LineString( const std::vector< Point > & points ) ; -BOOST_AUTO_TEST_CASE( constructorFromVector ) +/// LineString( const std::vector< Point > & points ) ; +BOOST_AUTO_TEST_CASE(constructorFromVector) { - std::vector< Point > points ; - points.push_back( Point( 1.0,1.0 ) ); - points.push_back( Point( 2.0,2.0 ) ); + std::vector points; + points.emplace_back(1.0, 1.0); + points.emplace_back(2.0, 2.0); - LineString g( points ); - BOOST_REQUIRE_EQUAL( g.numPoints(), 2U ); - BOOST_CHECK_EQUAL( g.pointN( 0 ).x(), 1.0 ); - BOOST_CHECK_EQUAL( g.pointN( 0 ).y(), 1.0 ); - BOOST_CHECK_EQUAL( g.pointN( 1 ).x(), 2.0 ); - BOOST_CHECK_EQUAL( g.pointN( 1 ).y(), 2.0 ); + LineString g(points); + BOOST_REQUIRE_EQUAL(g.numPoints(), 2U); + BOOST_CHECK_EQUAL(g.pointN(0).x(), 1.0); + BOOST_CHECK_EQUAL(g.pointN(0).y(), 1.0); + BOOST_CHECK_EQUAL(g.pointN(1).x(), 2.0); + BOOST_CHECK_EQUAL(g.pointN(1).y(), 2.0); } -///LineString( const Point & startPoint, const Point & endPoint ) ; +/// LineString( const Point & startPoint, const Point & endPoint ) ; -BOOST_AUTO_TEST_CASE( twoPointsConstructor ) +BOOST_AUTO_TEST_CASE(twoPointsConstructor) { - LineString g( Point( 0.0,0.0 ), Point( 2.0,3.0 ) ); - BOOST_CHECK( ! g.isEmpty() ); - BOOST_CHECK( ! g.is3D() ); - BOOST_CHECK_EQUAL( g.asText( 1 ), "LINESTRING(0.0 0.0,2.0 3.0)" ); + LineString const g(Point(0.0, 0.0), Point(2.0, 3.0)); + BOOST_CHECK(!g.isEmpty()); + BOOST_CHECK(!g.is3D()); + BOOST_CHECK_EQUAL(g.asText(1), "LINESTRING(0.0 0.0,2.0 3.0)"); } -///LineString( LineString const& other ) ; -///LineString& operator = ( const LineString & other ) ; +/// LineString( LineString const& other ) ; +/// LineString& operator = ( const LineString & other ) ; ///~LineString() ; - -///void clear() ; -BOOST_AUTO_TEST_CASE( testClear ) +/// void clear() ; +BOOST_AUTO_TEST_CASE(testClear) { - LineString g( Point( 0.0,0.0 ), Point( 1.0,1.0 ) ); - g.clear(); - BOOST_CHECK( g.isEmpty() ); + LineString g(Point(0.0, 0.0), Point(1.0, 1.0)); + g.clear(); + BOOST_CHECK(g.isEmpty()); } -///void reverse() ; -BOOST_AUTO_TEST_CASE( testReverse_empty ) +/// void reverse() ; +BOOST_AUTO_TEST_CASE(testReverse_empty) { - LineString g ; - g.reverse(); - BOOST_CHECK( g.isEmpty() ); + LineString g; + g.reverse(); + BOOST_CHECK(g.isEmpty()); } -BOOST_AUTO_TEST_CASE( testReverse_twoPoints ) +BOOST_AUTO_TEST_CASE(testReverse_twoPoints) { - LineString g( Point( 0.0,0.0 ), Point( 1.0,1.0 ) ); - g.reverse(); - BOOST_CHECK_EQUAL( g.pointN( 0 ).x(), 1.0 ); - BOOST_CHECK_EQUAL( g.pointN( 0 ).y(), 1.0 ); - BOOST_CHECK_EQUAL( g.pointN( 1 ).x(), 0.0 ); - BOOST_CHECK_EQUAL( g.pointN( 1 ).y(), 0.0 ); + LineString g(Point(0.0, 0.0), Point(1.0, 1.0)); + g.reverse(); + BOOST_CHECK_EQUAL(g.pointN(0).x(), 1.0); + BOOST_CHECK_EQUAL(g.pointN(0).y(), 1.0); + BOOST_CHECK_EQUAL(g.pointN(1).x(), 0.0); + BOOST_CHECK_EQUAL(g.pointN(1).y(), 0.0); } -///inline size_t numPoints() const { return _points.size(); } +/// inline size_t numPoints() const { return _points.size(); } -///size_t numSegments() const ; -BOOST_AUTO_TEST_CASE( testNumSegments_empty ) +/// size_t numSegments() const ; +BOOST_AUTO_TEST_CASE(testNumSegments_empty) { - LineString g ; - BOOST_CHECK_EQUAL( g.numSegments(), 0U ); + LineString const g; + BOOST_CHECK_EQUAL(g.numSegments(), 0U); } -BOOST_AUTO_TEST_CASE( testNumSegments_onlyOnePoint ) +BOOST_AUTO_TEST_CASE(testNumSegments_onlyOnePoint) { - LineString g ; - g.addPoint( Point( 0.0,0.0 ) ); - BOOST_CHECK_EQUAL( g.numSegments(), 0U ); + LineString g; + g.addPoint(Point(0.0, 0.0)); + BOOST_CHECK_EQUAL(g.numSegments(), 0U); } -BOOST_AUTO_TEST_CASE( testNumSegments_twoPoints ) +BOOST_AUTO_TEST_CASE(testNumSegments_twoPoints) { - LineString g( Point( 0.0,0.0 ), Point( 1.0,1.0 ) ); - BOOST_CHECK_EQUAL( g.numSegments(), 1U ); + LineString const g(Point(0.0, 0.0), Point(1.0, 1.0)); + BOOST_CHECK_EQUAL(g.numSegments(), 1U); } -///inline const Point & pointN( size_t const& n ) const -///inline Point & pointN( size_t const& n ) -///inline const Point & startPoint() const { return _points.front(); } -///inline Point & startPoint() { return _points.front(); } -///inline const Point & endPoint() const { return _points.back(); } -///inline Point & endPoint() { return _points.back(); } -///inline void addPoint( const Point & p ) -///inline void addPoint( Point* p ) +/// inline const Point & pointN( size_t const& n ) const +/// inline Point & pointN( size_t const& n ) +/// inline const Point & startPoint() const { return _points.front(); } +/// inline Point & startPoint() { return _points.front(); } +/// inline const Point & endPoint() const { return _points.back(); } +/// inline Point & endPoint() { return _points.back(); } +/// inline void addPoint( const Point & p ) +/// inline void addPoint( Point* p ) -///bool isClosed() const ; -BOOST_AUTO_TEST_CASE( testIsClosed_empty ) +/// bool isClosed() const ; +BOOST_AUTO_TEST_CASE(testIsClosed_empty) { - LineString g; - BOOST_CHECK( ! g.isClosed() ); + LineString const g; + BOOST_CHECK(!g.isClosed()); } -BOOST_AUTO_TEST_CASE( testIsClosed_noClosed ) +BOOST_AUTO_TEST_CASE(testIsClosed_noClosed) { - LineString g; - g.addPoint( Point( 0.0,0.0 ) ); - g.addPoint( Point( 1.0,0.0 ) ); - g.addPoint( Point( 1.0,1.0 ) ); - BOOST_CHECK( ! g.isClosed() ); + LineString g; + g.addPoint(Point(0.0, 0.0)); + g.addPoint(Point(1.0, 0.0)); + g.addPoint(Point(1.0, 1.0)); + BOOST_CHECK(!g.isClosed()); } -BOOST_AUTO_TEST_CASE( testIsClosed_triangle ) +BOOST_AUTO_TEST_CASE(testIsClosed_triangle) { - LineString g; - g.addPoint( Point( 0.0,0.0 ) ); - g.addPoint( Point( 1.0,0.0 ) ); - g.addPoint( Point( 1.0,1.0 ) ); - g.addPoint( Point( 0.0,0.0 ) ); - BOOST_CHECK( g.isClosed() ); + LineString g; + g.addPoint(Point(0.0, 0.0)); + g.addPoint(Point(1.0, 0.0)); + g.addPoint(Point(1.0, 1.0)); + g.addPoint(Point(0.0, 0.0)); + BOOST_CHECK(g.isClosed()); } -///inline iterator begin() -///inline const_iterator begin() const -///inline iterator end() -///inline const_iterator end() const -BOOST_AUTO_TEST_CASE( simpleIteratorTest ) +/// inline iterator begin() +/// inline const_iterator begin() const +/// inline iterator end() +/// inline const_iterator end() const +BOOST_AUTO_TEST_CASE(simpleIteratorTest) { - LineString g; - g.addPoint( Point( 0.0, 0.0 ) ); - g.addPoint( Point( 1.0, 1.0 ) ); - g.addPoint( Point( 2.0, 2.0 ) ); + LineString g; + g.addPoint(Point(0.0, 0.0)); + g.addPoint(Point(1.0, 1.0)); + g.addPoint(Point(2.0, 2.0)); - LineString::const_iterator it = g.begin() ; - LineString::const_iterator end = g.end() ; - BOOST_CHECK_EQUAL( it->asText( 3 ), "POINT(0.000 0.000)" ); - ++it ; - BOOST_CHECK( it != end ); - BOOST_CHECK_EQUAL( it->asText( 3 ), "POINT(1.000 1.000)" ); - ++it ; - BOOST_CHECK( it != end ); - BOOST_CHECK_EQUAL( it->asText( 3 ), "POINT(2.000 2.000)" ); - ++it ; - BOOST_CHECK( it == end ); + LineString::const_iterator it = g.begin(); + LineString::const_iterator const end = g.end(); + BOOST_CHECK_EQUAL(it->asText(3), "POINT(0.000 0.000)"); + ++it; + BOOST_CHECK(it != end); + BOOST_CHECK_EQUAL(it->asText(3), "POINT(1.000 1.000)"); + ++it; + BOOST_CHECK(it != end); + BOOST_CHECK_EQUAL(it->asText(3), "POINT(2.000 2.000)"); + ++it; + BOOST_CHECK(it == end); } - -BOOST_AUTO_TEST_CASE( iteratorTests ) +BOOST_AUTO_TEST_CASE(iteratorTests) { - std::vector points; - points.push_back( Point( 2.0, 3.0, 1.0 ) ); - points.push_back( Point( 4.0, 5.0, 1.0 ) ); - points.push_back( Point( 6.0, 7.0, 1.0 ) ); - points.push_back( Point( 8.0, 9.0, 1.0 ) ); - LineString g( points ); + std::vector points; + points.emplace_back(2.0, 3.0, 1.0); + points.emplace_back(4.0, 5.0, 1.0); + points.emplace_back(6.0, 7.0, 1.0); + points.emplace_back(8.0, 9.0, 1.0); + LineString g(points); - LineString::Point_2_const_iterator pi, pi_end; - int i = 0; + LineString::Point_2_const_iterator pi; + LineString::Point_2_const_iterator pi_end; + int i = 0; - for ( boost::tie( pi, pi_end ) = g.points_2(); pi != pi_end; pi++, i++ ) { - BOOST_CHECK_EQUAL( *pi, g.pointN( i ).toPoint_2() ); - } + for (boost::tie(pi, pi_end) = g.points_2(); pi != pi_end; pi++, i++) { + BOOST_CHECK_EQUAL(*pi, g.pointN(i).toPoint_2()); + } - LineString::Point_3_const_iterator ppi, ppi_end; - i = 0; + LineString::Point_3_const_iterator ppi; + LineString::Point_3_const_iterator ppi_end; + i = 0; - for ( boost::tie( ppi, ppi_end ) = g.points_3(); ppi != ppi_end; ppi++, i++ ) { - BOOST_CHECK_EQUAL( *ppi, g.pointN( i ).toPoint_3() ); - } + for (boost::tie(ppi, ppi_end) = g.points_3(); ppi != ppi_end; ppi++, i++) { + BOOST_CHECK_EQUAL(*ppi, g.pointN(i).toPoint_3()); + } } +/// void reserve( const size_t & n ) ; -///void reserve( const size_t & n ) ; - -///CGAL::Polygon_2< Kernel > toPolygon_2() const; -BOOST_AUTO_TEST_CASE( testToPolygon_2_Empty ) +/// CGAL::Polygon_2< Kernel > toPolygon_2() const; +BOOST_AUTO_TEST_CASE(testToPolygon_2_Empty) { - LineString g ; - CGAL::Polygon_2< Kernel > polygon = g.toPolygon_2(); - BOOST_CHECK( polygon.is_empty() ); + LineString const g; + CGAL::Polygon_2 const polygon = g.toPolygon_2(); + BOOST_CHECK(polygon.is_empty()); } -BOOST_AUTO_TEST_CASE( testToPolygon_2_checkOrientation ) +BOOST_AUTO_TEST_CASE(testToPolygon_2_checkOrientation) { - LineString g ; - g.addPoint( Point( 0.0,0.0 ) ); - g.addPoint( Point( 1.0,1.0 ) ); - g.addPoint( Point( 1.0,0.0 ) ); - g.addPoint( g.startPoint() ); - - //keep orientation - { - CGAL::Polygon_2< Kernel > polygon = g.toPolygon_2( false ); - BOOST_CHECK( ! polygon.is_empty() ); - BOOST_CHECK( polygon.is_clockwise_oriented() ); - } - //fix orientation - { - CGAL::Polygon_2< Kernel > polygon = g.toPolygon_2( true ); - BOOST_CHECK( ! polygon.is_empty() ); - BOOST_CHECK( polygon.is_counterclockwise_oriented() ); - } + LineString g; + g.addPoint(Point(0.0, 0.0)); + g.addPoint(Point(1.0, 1.0)); + g.addPoint(Point(1.0, 0.0)); + g.addPoint(g.startPoint()); + + // keep orientation + { + CGAL::Polygon_2 const polygon = g.toPolygon_2(false); + BOOST_CHECK(!polygon.is_empty()); + BOOST_CHECK(polygon.is_clockwise_oriented()); + } + // fix orientation + { + CGAL::Polygon_2 const polygon = g.toPolygon_2(true); + BOOST_CHECK(!polygon.is_empty()); + BOOST_CHECK(polygon.is_counterclockwise_oriented()); + } } - //-- Geometry tests - -//virtual Geometry * Geometry::clone() const = 0 ; -BOOST_AUTO_TEST_CASE( testClone ) +// virtual Geometry * Geometry::clone() const = 0 ; +BOOST_AUTO_TEST_CASE(testClone) { - LineString g ; - g.addPoint( Point( 0.0,0.0 ) ); - g.addPoint( Point( 1.0,1.0 ) ); - std::unique_ptr< Geometry > copy( g.clone() ); - BOOST_REQUIRE( copy->is< LineString >() ); - BOOST_CHECK_EQUAL( copy->as< LineString >().numPoints(), 2U ); + LineString g; + g.addPoint(Point(0.0, 0.0)); + g.addPoint(Point(1.0, 1.0)); + std::unique_ptr copy(g.clone()); + BOOST_REQUIRE(copy->is()); + BOOST_CHECK_EQUAL(copy->as().numPoints(), 2U); } -//virtual Geometry* Geometry::boundary() const ; -BOOST_AUTO_TEST_CASE( testBoundary_empty ) +// virtual Geometry* Geometry::boundary() const ; +BOOST_AUTO_TEST_CASE(testBoundary_empty) { - LineString g ; - std::unique_ptr< Geometry > boundary( g.boundary() ); - BOOST_CHECK( boundary->isEmpty() ); - BOOST_CHECK( boundary->is< GeometryCollection >() ); + LineString const g; + std::unique_ptr boundary(g.boundary()); + BOOST_CHECK(boundary->isEmpty()); + BOOST_CHECK(boundary->is()); } -BOOST_AUTO_TEST_CASE( testBoundary_3points ) +BOOST_AUTO_TEST_CASE(testBoundary_3points) { - LineString g ; - g.addPoint( Point( 0.0,0.0 ) ); - g.addPoint( Point( 1.0,1.0 ) ); - g.addPoint( Point( 2.0,2.0 ) ); + LineString g; + g.addPoint(Point(0.0, 0.0)); + g.addPoint(Point(1.0, 1.0)); + g.addPoint(Point(2.0, 2.0)); - std::unique_ptr< Geometry > boundary( g.boundary() ); - BOOST_CHECK( ! boundary->isEmpty() ); - BOOST_REQUIRE( boundary->is< MultiPoint >() ); - BOOST_CHECK_EQUAL( boundary->numGeometries(), 2U ); + std::unique_ptr boundary(g.boundary()); + BOOST_CHECK(!boundary->isEmpty()); + BOOST_REQUIRE(boundary->is()); + BOOST_CHECK_EQUAL(boundary->numGeometries(), 2U); } -BOOST_AUTO_TEST_CASE( testBoundary_closed ) +BOOST_AUTO_TEST_CASE(testBoundary_closed) { - LineString g ; - g.addPoint( Point( 0.0,0.0 ) ); - g.addPoint( Point( 1.0,1.0 ) ); - g.addPoint( Point( 2.0,2.0 ) ); - g.addPoint( g.startPoint() ); + LineString g; + g.addPoint(Point(0.0, 0.0)); + g.addPoint(Point(1.0, 1.0)); + g.addPoint(Point(2.0, 2.0)); + g.addPoint(g.startPoint()); - std::unique_ptr< Geometry > boundary( g.boundary() ); - BOOST_CHECK( boundary->isEmpty() ); - BOOST_CHECK( boundary->is< GeometryCollection >() ); + std::unique_ptr boundary(g.boundary()); + BOOST_CHECK(boundary->isEmpty()); + BOOST_CHECK(boundary->is()); } - -//Envelope Geometry::envelope() const ; -BOOST_AUTO_TEST_CASE( testEnvelope_empty ) +// Envelope Geometry::envelope() const ; +BOOST_AUTO_TEST_CASE(testEnvelope_empty) { - BOOST_CHECK( LineString().envelope().isEmpty() ); + BOOST_CHECK(LineString().envelope().isEmpty()); } -BOOST_AUTO_TEST_CASE( testEnvelope_2D ) +BOOST_AUTO_TEST_CASE(testEnvelope_2D) { - LineString g ; - g.addPoint( Point( 1.0,5.0 ) ); - g.addPoint( Point( 2.0,7.0 ) ); - g.addPoint( Point( 3.0,9.0 ) ); + LineString g; + g.addPoint(Point(1.0, 5.0)); + g.addPoint(Point(2.0, 7.0)); + g.addPoint(Point(3.0, 9.0)); - Envelope box = g.envelope() ; - BOOST_CHECK( ! box.isEmpty() ); - BOOST_CHECK( ! box.is3D() ); + Envelope const box = g.envelope(); + BOOST_CHECK(!box.isEmpty()); + BOOST_CHECK(!box.is3D()); - BOOST_CHECK_EQUAL( box.xMin(), 1.0 ); - BOOST_CHECK_EQUAL( box.xMax(), 3.0 ); - BOOST_CHECK_EQUAL( box.yMin(), 5.0 ); - BOOST_CHECK_EQUAL( box.yMax(), 9.0 ); + BOOST_CHECK_EQUAL(box.xMin(), 1.0); + BOOST_CHECK_EQUAL(box.xMax(), 3.0); + BOOST_CHECK_EQUAL(box.yMin(), 5.0); + BOOST_CHECK_EQUAL(box.yMax(), 9.0); } -BOOST_AUTO_TEST_CASE( testEnvelope_3D ) +BOOST_AUTO_TEST_CASE(testEnvelope_3D) { - LineString g ; - g.addPoint( Point( 1.0,5.0,11.0 ) ); - g.addPoint( Point( 2.0,7.0,15.0 ) ); - g.addPoint( Point( 3.0,9.0,17.0 ) ); + LineString g; + g.addPoint(Point(1.0, 5.0, 11.0)); + g.addPoint(Point(2.0, 7.0, 15.0)); + g.addPoint(Point(3.0, 9.0, 17.0)); - Envelope box = g.envelope() ; - BOOST_CHECK( ! box.isEmpty() ); - BOOST_CHECK( box.is3D() ); + Envelope const box = g.envelope(); + BOOST_CHECK(!box.isEmpty()); + BOOST_CHECK(box.is3D()); - BOOST_CHECK_EQUAL( box.xMin(), 1.0 ); - BOOST_CHECK_EQUAL( box.xMax(), 3.0 ); - BOOST_CHECK_EQUAL( box.yMin(), 5.0 ); - BOOST_CHECK_EQUAL( box.yMax(), 9.0 ); - BOOST_CHECK_EQUAL( box.zMin(), 11.0 ); - BOOST_CHECK_EQUAL( box.zMax(), 17.0 ); + BOOST_CHECK_EQUAL(box.xMin(), 1.0); + BOOST_CHECK_EQUAL(box.xMax(), 3.0); + BOOST_CHECK_EQUAL(box.yMin(), 5.0); + BOOST_CHECK_EQUAL(box.yMax(), 9.0); + BOOST_CHECK_EQUAL(box.zMin(), 11.0); + BOOST_CHECK_EQUAL(box.zMax(), 17.0); } -//std::string Geometry::asText( const int & numDecimals = -1 ) const ; -BOOST_AUTO_TEST_CASE( asTextEmpty ) +// std::string Geometry::asText( const int & numDecimals = -1 ) const ; +BOOST_AUTO_TEST_CASE(asTextEmpty) { - LineString g; - BOOST_CHECK_EQUAL( g.asText( 1 ), "LINESTRING EMPTY" ); + LineString const g; + BOOST_CHECK_EQUAL(g.asText(1), "LINESTRING EMPTY"); } -BOOST_AUTO_TEST_CASE( asText2d ) +BOOST_AUTO_TEST_CASE(asText2d) { - LineString g( - Point( 2.0,3.0 ), - Point( 4.0,5.0 ) - ); - BOOST_CHECK_EQUAL( g.asText( 3 ), "LINESTRING(2.000 3.000,4.000 5.000)" ); + LineString const g(Point(2.0, 3.0), Point(4.0, 5.0)); + BOOST_CHECK_EQUAL(g.asText(3), "LINESTRING(2.000 3.000,4.000 5.000)"); } -BOOST_AUTO_TEST_CASE( asText3d ) +BOOST_AUTO_TEST_CASE(asText3d) { - LineString g( - Point( 2.0,3.0,7.0 ), - Point( 4.0,5.0,8.0 ) - ); - BOOST_CHECK_EQUAL( g.asText( 3 ), "LINESTRING Z(2.000 3.000 7.000,4.000 5.000 8.000)" ); + LineString const g(Point(2.0, 3.0, 7.0), Point(4.0, 5.0, 8.0)); + BOOST_CHECK_EQUAL(g.asText(3), + "LINESTRING Z(2.000 3.000 7.000,4.000 5.000 8.000)"); } -//virtual std::string Geometry::geometryType() const = 0 ; -BOOST_AUTO_TEST_CASE( testGeometryType ) +// virtual std::string Geometry::geometryType() const = 0 ; +BOOST_AUTO_TEST_CASE(testGeometryType) { - LineString g; - BOOST_CHECK_EQUAL( g.geometryType(), "LineString" ); + LineString const g; + BOOST_CHECK_EQUAL(g.geometryType(), "LineString"); } -//virtual GeometryType Geometry::geometryTypeId() const = 0 ; -BOOST_AUTO_TEST_CASE( testGeometryTypeId ) +// virtual GeometryType Geometry::geometryTypeId() const = 0 ; +BOOST_AUTO_TEST_CASE(testGeometryTypeId) { - LineString g; - BOOST_CHECK_EQUAL( g.geometryTypeId(), TYPE_LINESTRING ); + LineString const g; + BOOST_CHECK_EQUAL(g.geometryTypeId(), TYPE_LINESTRING); } -//virtual int Geometry::dimension() const = 0 ; -//virtual int Geometry::coordinateDimension() const = 0 ; +// virtual int Geometry::dimension() const = 0 ; +// virtual int Geometry::coordinateDimension() const = 0 ; -//virtual bool Geometry::isEmpty() const = 0 ; -BOOST_AUTO_TEST_CASE( testIsEmpty_true ) +// virtual bool Geometry::isEmpty() const = 0 ; +BOOST_AUTO_TEST_CASE(testIsEmpty_true) { - LineString g; - BOOST_CHECK( g.isEmpty() ); + LineString const g; + BOOST_CHECK(g.isEmpty()); } -BOOST_AUTO_TEST_CASE( testIsEmpty_false ) +BOOST_AUTO_TEST_CASE(testIsEmpty_false) { - LineString g( Point( 0.0,0.0 ), Point( 1.0,1.0 ) ); - BOOST_CHECK( ! g.isEmpty() ); + LineString const g(Point(0.0, 0.0), Point(1.0, 1.0)); + BOOST_CHECK(!g.isEmpty()); } -//virtual bool Geometry::is3D() const = 0 ; -BOOST_AUTO_TEST_CASE( testIs3D_false ) +// virtual bool Geometry::is3D() const = 0 ; +BOOST_AUTO_TEST_CASE(testIs3D_false) { - LineString g( Point( 0.0,0.0 ), Point( 1.0,1.0 ) ); - BOOST_CHECK( ! g.is3D() ); + LineString const g(Point(0.0, 0.0), Point(1.0, 1.0)); + BOOST_CHECK(!g.is3D()); } -BOOST_AUTO_TEST_CASE( testIs3D_true ) +BOOST_AUTO_TEST_CASE(testIs3D_true) { - LineString g( Point( 0.0,0.0,0.0 ), Point( 1.0,1.0,1.0 ) ); - BOOST_CHECK( g.is3D() ); + LineString const g(Point(0.0, 0.0, 0.0), Point(1.0, 1.0, 1.0)); + BOOST_CHECK(g.is3D()); } -//virtual bool Geometry::isMeasured() const = 0 ; -//virtual bool Geometry::isSimple() const = 0 ; +// virtual bool Geometry::isMeasured() const = 0 ; +// virtual bool Geometry::isSimple() const = 0 ; -//template < typename Derived > inline bool Geometry::is() const -BOOST_AUTO_TEST_CASE( isLineString ) +// template < typename Derived > inline bool Geometry::is() const +BOOST_AUTO_TEST_CASE(isLineString) { - LineString g; - BOOST_CHECK( g.is< LineString >() ); + LineString const g; + BOOST_CHECK(g.is()); } -//template < typename Derived > inline const Derived & Geometry::as() const -//template < typename Derived > inline Derived & Geometry::as() - - +// template < typename Derived > inline const Derived & Geometry::as() const +// template < typename Derived > inline Derived & Geometry::as() BOOST_AUTO_TEST_SUITE_END() - - - - diff --git a/test/unit/SFCGAL/MultiLineStringTest.cpp b/test/unit/SFCGAL/MultiLineStringTest.cpp index 4c33d6a9..83eb812c 100644 --- a/test/unit/SFCGAL/MultiLineStringTest.cpp +++ b/test/unit/SFCGAL/MultiLineStringTest.cpp @@ -15,7 +15,8 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include @@ -24,66 +25,62 @@ #include #include -using namespace boost::unit_test ; -using namespace SFCGAL ; +using namespace boost::unit_test; +using namespace SFCGAL; -BOOST_AUTO_TEST_SUITE( SFCGAL_MultiLineStringTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_MultiLineStringTest) -BOOST_AUTO_TEST_CASE( defaultConstructor ) +BOOST_AUTO_TEST_CASE(defaultConstructor) { - MultiLineString g; - BOOST_CHECK( g.isEmpty() ) ; - BOOST_CHECK( ! g.is3D() ); - BOOST_CHECK_EQUAL( g.numGeometries(), 0U ); + MultiLineString const g; + BOOST_CHECK(g.isEmpty()); + BOOST_CHECK(!g.is3D()); + BOOST_CHECK_EQUAL(g.numGeometries(), 0U); } - //-- addAllowedGeometry -BOOST_AUTO_TEST_CASE( addLineString ) +BOOST_AUTO_TEST_CASE(addLineString) { - MultiLineString g; - g.addGeometry( new LineString() ); - BOOST_CHECK_EQUAL( g.numGeometries(), 1U ); + MultiLineString g; + g.addGeometry(new LineString()); + BOOST_CHECK_EQUAL(g.numGeometries(), 1U); } //-- addForbidenGeometry -BOOST_AUTO_TEST_CASE( addLineStringThrow ) +BOOST_AUTO_TEST_CASE(addLineStringThrow) { - MultiLineString g; - BOOST_CHECK_THROW( g.addGeometry( Point() ), std::exception ); + MultiLineString g; + BOOST_CHECK_THROW(g.addGeometry(Point()), std::exception); } //-- asText -BOOST_AUTO_TEST_CASE( asTextEmpty ) +BOOST_AUTO_TEST_CASE(asTextEmpty) { - MultiLineString g; - BOOST_CHECK_EQUAL( g.asText( 1 ), "MULTILINESTRING EMPTY" ); + MultiLineString const g; + BOOST_CHECK_EQUAL(g.asText(1), "MULTILINESTRING EMPTY"); } -BOOST_AUTO_TEST_CASE( asText2d ) +BOOST_AUTO_TEST_CASE(asText2d) { - MultiLineString g; - g.addGeometry( LineString( Point( 0.0,0.0 ), Point( 1.0,1.0 ) ) ); - g.addGeometry( LineString( Point( 1.0,1.0 ), Point( 2.0,2.0 ) ) ); - BOOST_CHECK_EQUAL( g.asText( 1 ), "MULTILINESTRING((0.0 0.0,1.0 1.0),(1.0 1.0,2.0 2.0))" ); + MultiLineString g; + g.addGeometry(LineString(Point(0.0, 0.0), Point(1.0, 1.0))); + g.addGeometry(LineString(Point(1.0, 1.0), Point(2.0, 2.0))); + BOOST_CHECK_EQUAL(g.asText(1), + "MULTILINESTRING((0.0 0.0,1.0 1.0),(1.0 1.0,2.0 2.0))"); } //-- is< T > -BOOST_AUTO_TEST_CASE( isGeometryCollection ) +BOOST_AUTO_TEST_CASE(isGeometryCollection) { - MultiLineString g; - BOOST_CHECK( g.is< GeometryCollection >() ); + MultiLineString const g; + BOOST_CHECK(g.is()); } -BOOST_AUTO_TEST_CASE( isMultiLineString ) +BOOST_AUTO_TEST_CASE(isMultiLineString) { - MultiLineString g; - BOOST_CHECK( g.is< MultiLineString >() ); + MultiLineString const g; + BOOST_CHECK(g.is()); } BOOST_AUTO_TEST_SUITE_END() - - - - diff --git a/test/unit/SFCGAL/MultiPointTest.cpp b/test/unit/SFCGAL/MultiPointTest.cpp index b79a47ab..dc082498 100644 --- a/test/unit/SFCGAL/MultiPointTest.cpp +++ b/test/unit/SFCGAL/MultiPointTest.cpp @@ -15,7 +15,8 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include @@ -24,71 +25,67 @@ #include #include -using namespace boost::unit_test ; -using namespace SFCGAL ; +using namespace boost::unit_test; +using namespace SFCGAL; -BOOST_AUTO_TEST_SUITE( SFCGAL_MultiPointTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_MultiPointTest) -BOOST_AUTO_TEST_CASE( defaultConstructor ) +BOOST_AUTO_TEST_CASE(defaultConstructor) { - MultiPoint g; - BOOST_CHECK( g.isEmpty() ) ; - BOOST_CHECK( ! g.is3D() ); - BOOST_CHECK_EQUAL( g.numGeometries(), 0U ); + MultiPoint const g; + BOOST_CHECK(g.isEmpty()); + BOOST_CHECK(!g.is3D()); + BOOST_CHECK_EQUAL(g.numGeometries(), 0U); } -BOOST_AUTO_TEST_CASE( testGeometryTypeId ) +BOOST_AUTO_TEST_CASE(testGeometryTypeId) { - MultiPoint g; - BOOST_CHECK_EQUAL( g.geometryTypeId(), TYPE_MULTIPOINT ); + MultiPoint const g; + BOOST_CHECK_EQUAL(g.geometryTypeId(), TYPE_MULTIPOINT); } //-- addAllowedGeometry -BOOST_AUTO_TEST_CASE( addPoint ) +BOOST_AUTO_TEST_CASE(addPoint) { - MultiPoint g; - g.addGeometry( new Point( 2.0, 3.0 ) ); - BOOST_CHECK_EQUAL( g.numGeometries(), 1U ); + MultiPoint g; + g.addGeometry(new Point(2.0, 3.0)); + BOOST_CHECK_EQUAL(g.numGeometries(), 1U); } //-- addForbidenGeometry -BOOST_AUTO_TEST_CASE( addLineStringThrow ) +BOOST_AUTO_TEST_CASE(addLineStringThrow) { - MultiPoint g; - BOOST_CHECK_THROW( g.addGeometry( LineString() ), std::exception ); + MultiPoint g; + BOOST_CHECK_THROW(g.addGeometry(LineString()), std::exception); } //-- asText -BOOST_AUTO_TEST_CASE( asTextEmpty ) +BOOST_AUTO_TEST_CASE(asTextEmpty) { - MultiPoint g; - BOOST_CHECK_EQUAL( g.asText( 1 ), "MULTIPOINT EMPTY" ); + MultiPoint const g; + BOOST_CHECK_EQUAL(g.asText(1), "MULTIPOINT EMPTY"); } -BOOST_AUTO_TEST_CASE( asText2d ) +BOOST_AUTO_TEST_CASE(asText2d) { - MultiPoint g; - g.addGeometry( Point( 2.0,3.0 ) ); - g.addGeometry( Point( 3.0,4.0 ) ); - BOOST_CHECK_EQUAL( g.asText( 3 ), "MULTIPOINT((2.000 3.000),(3.000 4.000))" ); + MultiPoint g; + g.addGeometry(Point(2.0, 3.0)); + g.addGeometry(Point(3.0, 4.0)); + BOOST_CHECK_EQUAL(g.asText(3), "MULTIPOINT((2.000 3.000),(3.000 4.000))"); } //-- is< T > -BOOST_AUTO_TEST_CASE( isGeometryCollection ) +BOOST_AUTO_TEST_CASE(isGeometryCollection) { - MultiPoint g; - BOOST_CHECK( g.is< GeometryCollection >() ); + MultiPoint const g; + BOOST_CHECK(g.is()); } -BOOST_AUTO_TEST_CASE( isMultiPoint ) +BOOST_AUTO_TEST_CASE(isMultiPoint) { - MultiPoint g; - BOOST_CHECK( g.is< MultiPoint >() ); + MultiPoint const g; + BOOST_CHECK(g.is()); } BOOST_AUTO_TEST_SUITE_END() - - - - diff --git a/test/unit/SFCGAL/MultiPolygonTest.cpp b/test/unit/SFCGAL/MultiPolygonTest.cpp index 8ac80134..92aadf3d 100644 --- a/test/unit/SFCGAL/MultiPolygonTest.cpp +++ b/test/unit/SFCGAL/MultiPolygonTest.cpp @@ -15,7 +15,8 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include @@ -23,73 +24,72 @@ #include #include -#include #include +#include -using namespace boost::unit_test ; -using namespace SFCGAL ; +using namespace boost::unit_test; +using namespace SFCGAL; -BOOST_AUTO_TEST_SUITE( SFCGAL_MultiPolygonTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_MultiPolygonTest) -BOOST_AUTO_TEST_CASE( defaultConstructor ) +BOOST_AUTO_TEST_CASE(defaultConstructor) { - MultiPolygon g; - BOOST_CHECK( g.isEmpty() ) ; - BOOST_CHECK( ! g.is3D() ); - BOOST_CHECK_EQUAL( g.numGeometries(), 0U ); + MultiPolygon const g; + BOOST_CHECK(g.isEmpty()); + BOOST_CHECK(!g.is3D()); + BOOST_CHECK_EQUAL(g.numGeometries(), 0U); } -BOOST_AUTO_TEST_CASE( testGeometryTypeId ) +BOOST_AUTO_TEST_CASE(testGeometryTypeId) { - MultiPolygon g; - BOOST_CHECK_EQUAL( g.geometryTypeId(), TYPE_MULTIPOLYGON ); + MultiPolygon const g; + BOOST_CHECK_EQUAL(g.geometryTypeId(), TYPE_MULTIPOLYGON); } //-- addAllowedGeometry -BOOST_AUTO_TEST_CASE( addPolygon ) +BOOST_AUTO_TEST_CASE(addPolygon) { - MultiPolygon g; - g.addGeometry( new Polygon() ); - BOOST_CHECK_EQUAL( g.numGeometries(), 1U ); + MultiPolygon g; + g.addGeometry(new Polygon()); + BOOST_CHECK_EQUAL(g.numGeometries(), 1U); } //-- addForbidenGeometry -BOOST_AUTO_TEST_CASE( addLineStringThrow ) +BOOST_AUTO_TEST_CASE(addLineStringThrow) { - MultiPolygon g; - BOOST_CHECK_THROW( g.addGeometry( LineString() ), std::exception ); + MultiPolygon g; + BOOST_CHECK_THROW(g.addGeometry(LineString()), std::exception); } //-- asText -BOOST_AUTO_TEST_CASE( asTextEmpty ) +BOOST_AUTO_TEST_CASE(asTextEmpty) { - MultiPolygon g; - BOOST_CHECK_EQUAL( g.asText( 1 ), "MULTIPOLYGON EMPTY" ); + MultiPolygon const g; + BOOST_CHECK_EQUAL(g.asText(1), "MULTIPOLYGON EMPTY"); } -BOOST_AUTO_TEST_CASE( asText2d ) +BOOST_AUTO_TEST_CASE(asText2d) { - MultiPolygon g; - g.addGeometry( Envelope( 0.0,1.0,0.0,1.0 ).toPolygon().release() ); - g.addGeometry( Envelope( 2.0,3.0,4.0,5.0 ).toPolygon().release() ); - BOOST_CHECK_EQUAL( g.asText( 3 ), "MULTIPOLYGON(((0.000 0.000,1.000 0.000,1.000 1.000,0.000 1.000,0.000 0.000)),((2.000 4.000,3.000 4.000,3.000 5.000,2.000 5.000,2.000 4.000)))" ); + MultiPolygon g; + g.addGeometry(Envelope(0.0, 1.0, 0.0, 1.0).toPolygon().release()); + g.addGeometry(Envelope(2.0, 3.0, 4.0, 5.0).toPolygon().release()); + BOOST_CHECK_EQUAL(g.asText(3), + "MULTIPOLYGON(((0.000 0.000,1.000 0.000,1.000 1.000,0.000 " + "1.000,0.000 0.000)),((2.000 4.000,3.000 4.000,3.000 " + "5.000,2.000 5.000,2.000 4.000)))"); } //-- is< T > -BOOST_AUTO_TEST_CASE( isGeometryCollection ) +BOOST_AUTO_TEST_CASE(isGeometryCollection) { - MultiPolygon g; - BOOST_CHECK( g.is< GeometryCollection >() ); + MultiPolygon const g; + BOOST_CHECK(g.is()); } -BOOST_AUTO_TEST_CASE( isMultiPolygon ) +BOOST_AUTO_TEST_CASE(isMultiPolygon) { - MultiPolygon g; - BOOST_CHECK( g.is< MultiPolygon >() ); + MultiPolygon const g; + BOOST_CHECK(g.is()); } BOOST_AUTO_TEST_SUITE_END() - - - - diff --git a/test/unit/SFCGAL/MultiSolidTest.cpp b/test/unit/SFCGAL/MultiSolidTest.cpp index 294a7e5d..b068ada3 100644 --- a/test/unit/SFCGAL/MultiSolidTest.cpp +++ b/test/unit/SFCGAL/MultiSolidTest.cpp @@ -15,7 +15,8 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include @@ -23,73 +24,77 @@ #include #include -#include #include +#include -using namespace boost::unit_test ; -using namespace SFCGAL ; +using namespace boost::unit_test; +using namespace SFCGAL; -BOOST_AUTO_TEST_SUITE( SFCGAL_MultiSolidTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_MultiSolidTest) -BOOST_AUTO_TEST_CASE( defaultConstructor ) +BOOST_AUTO_TEST_CASE(defaultConstructor) { - MultiSolid g; - BOOST_CHECK( g.isEmpty() ) ; - BOOST_CHECK( ! g.is3D() ); - BOOST_CHECK_EQUAL( g.numGeometries(), 0U ); + MultiSolid const g; + BOOST_CHECK(g.isEmpty()); + BOOST_CHECK(!g.is3D()); + BOOST_CHECK_EQUAL(g.numGeometries(), 0U); } -BOOST_AUTO_TEST_CASE( testGeometryTypeId ) +BOOST_AUTO_TEST_CASE(testGeometryTypeId) { - MultiSolid g; - BOOST_CHECK_EQUAL( g.geometryTypeId(), TYPE_MULTISOLID ); + MultiSolid const g; + BOOST_CHECK_EQUAL(g.geometryTypeId(), TYPE_MULTISOLID); } //-- addAllowedGeometry -BOOST_AUTO_TEST_CASE( addSolid ) +BOOST_AUTO_TEST_CASE(addSolid) { - MultiSolid g; - g.addGeometry( new Solid() ); - BOOST_CHECK_EQUAL( g.numGeometries(), 1U ); + MultiSolid g; + g.addGeometry(new Solid()); + BOOST_CHECK_EQUAL(g.numGeometries(), 1U); } //-- addForbidenGeometry -BOOST_AUTO_TEST_CASE( addLineStringThrow ) +BOOST_AUTO_TEST_CASE(addLineStringThrow) { - MultiSolid g; - BOOST_CHECK_THROW( g.addGeometry( LineString() ), std::exception ); + MultiSolid g; + BOOST_CHECK_THROW(g.addGeometry(LineString()), std::exception); } //-- asText -BOOST_AUTO_TEST_CASE( asTextEmpty ) +BOOST_AUTO_TEST_CASE(asTextEmpty) { - MultiSolid g; - BOOST_CHECK_EQUAL( g.asText( 1 ), "MULTISOLID EMPTY" ); + MultiSolid const g; + BOOST_CHECK_EQUAL(g.asText(1), "MULTISOLID EMPTY"); } -BOOST_AUTO_TEST_CASE( asText2d ) +BOOST_AUTO_TEST_CASE(asText2d) { - MultiSolid g; - g.addGeometry( Envelope( 0.0,1.0,0.0,1.0,0.0,1.0 ).toSolid().release() ); - g.addGeometry( Envelope( 2.0,3.0,4.0,5.0,6.0,7.0 ).toSolid().release() ); - BOOST_CHECK_EQUAL( g.asText( 0 ), "MULTISOLID Z(((((0 0 0,0 1 0,1 1 0,1 0 0,0 0 0)),((0 0 1,1 0 1,1 1 1,0 1 1,0 0 1)),((0 0 0,1 0 0,1 0 1,0 0 1,0 0 0)),((1 1 0,0 1 0,0 1 1,1 1 1,1 1 0)),((1 0 0,1 1 0,1 1 1,1 0 1,1 0 0)),((0 0 0,0 0 1,0 1 1,0 1 0,0 0 0)))),((((2 4 6,2 5 6,3 5 6,3 4 6,2 4 6)),((2 4 7,3 4 7,3 5 7,2 5 7,2 4 7)),((2 4 6,3 4 6,3 4 7,2 4 7,2 4 6)),((3 5 6,2 5 6,2 5 7,3 5 7,3 5 6)),((3 4 6,3 5 6,3 5 7,3 4 7,3 4 6)),((2 4 6,2 4 7,2 5 7,2 5 6,2 4 6)))))" ); + MultiSolid g; + g.addGeometry(Envelope(0.0, 1.0, 0.0, 1.0, 0.0, 1.0).toSolid().release()); + g.addGeometry(Envelope(2.0, 3.0, 4.0, 5.0, 6.0, 7.0).toSolid().release()); + BOOST_CHECK_EQUAL( + g.asText(0), + "MULTISOLID Z(((((0 0 0,0 1 0,1 1 0,1 0 0,0 0 0)),((0 0 1,1 0 1,1 1 1,0 " + "1 1,0 0 1)),((0 0 0,1 0 0,1 0 1,0 0 1,0 0 0)),((1 1 0,0 1 0,0 1 1,1 1 " + "1,1 1 0)),((1 0 0,1 1 0,1 1 1,1 0 1,1 0 0)),((0 0 0,0 0 1,0 1 1,0 1 0,0 " + "0 0)))),((((2 4 6,2 5 6,3 5 6,3 4 6,2 4 6)),((2 4 7,3 4 7,3 5 7,2 5 7,2 " + "4 7)),((2 4 6,3 4 6,3 4 7,2 4 7,2 4 6)),((3 5 6,2 5 6,2 5 7,3 5 7,3 5 " + "6)),((3 4 6,3 5 6,3 5 7,3 4 7,3 4 6)),((2 4 6,2 4 7,2 5 7,2 5 6,2 4 " + "6)))))"); } //-- is< T > -BOOST_AUTO_TEST_CASE( isGeometryCollection ) +BOOST_AUTO_TEST_CASE(isGeometryCollection) { - MultiSolid g; - BOOST_CHECK( g.is< GeometryCollection >() ); + MultiSolid const g; + BOOST_CHECK(g.is()); } -BOOST_AUTO_TEST_CASE( isMultiSolid ) +BOOST_AUTO_TEST_CASE(isMultiSolid) { - MultiSolid g; - BOOST_CHECK( g.is< MultiSolid >() ); + MultiSolid const g; + BOOST_CHECK(g.is()); } BOOST_AUTO_TEST_SUITE_END() - - - - diff --git a/test/unit/SFCGAL/NumericTest.cpp b/test/unit/SFCGAL/NumericTest.cpp index b36357c9..7d0cb453 100644 --- a/test/unit/SFCGAL/NumericTest.cpp +++ b/test/unit/SFCGAL/NumericTest.cpp @@ -15,7 +15,8 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include @@ -23,37 +24,37 @@ #include -using namespace boost::unit_test ; -using namespace SFCGAL ; +using namespace boost::unit_test; +using namespace SFCGAL; -BOOST_AUTO_TEST_SUITE( SFCGAL_NumericTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_NumericTest) -BOOST_AUTO_TEST_CASE( testFloorRational ) +BOOST_AUTO_TEST_CASE(testFloorRational) { - BOOST_CHECK_EQUAL( SFCGAL::floor( CGAL::Gmpq( 0 ) ), 0 ) ; - BOOST_CHECK_EQUAL( SFCGAL::floor( CGAL::Gmpq( 1,2 ) ), 0 ) ; - BOOST_CHECK_EQUAL( SFCGAL::floor( CGAL::Gmpq( 1,3 ) ), 0 ) ; - BOOST_CHECK_EQUAL( SFCGAL::floor( CGAL::Gmpq( 2,3 ) ), 0 ) ; - BOOST_CHECK_EQUAL( SFCGAL::floor( CGAL::Gmpq( 1,1 ) ), 1 ) ; - BOOST_CHECK_EQUAL( SFCGAL::floor( CGAL::Gmpq( 4,3 ) ), 1 ) ; + BOOST_CHECK_EQUAL(SFCGAL::floor(CGAL::Gmpq(0)), 0); + BOOST_CHECK_EQUAL(SFCGAL::floor(CGAL::Gmpq(1, 2)), 0); + BOOST_CHECK_EQUAL(SFCGAL::floor(CGAL::Gmpq(1, 3)), 0); + BOOST_CHECK_EQUAL(SFCGAL::floor(CGAL::Gmpq(2, 3)), 0); + BOOST_CHECK_EQUAL(SFCGAL::floor(CGAL::Gmpq(1, 1)), 1); + BOOST_CHECK_EQUAL(SFCGAL::floor(CGAL::Gmpq(4, 3)), 1); } -BOOST_AUTO_TEST_CASE( testCeilRational ) +BOOST_AUTO_TEST_CASE(testCeilRational) { - BOOST_CHECK_EQUAL( SFCGAL::ceil( CGAL::Gmpq( 0 ) ), 0 ) ; - BOOST_CHECK_EQUAL( SFCGAL::ceil( CGAL::Gmpq( 1,2 ) ), 1 ) ; - BOOST_CHECK_EQUAL( SFCGAL::ceil( CGAL::Gmpq( 1,3 ) ), 1 ) ; - BOOST_CHECK_EQUAL( SFCGAL::ceil( CGAL::Gmpq( 1,1 ) ), 1 ) ; - BOOST_CHECK_EQUAL( SFCGAL::ceil( CGAL::Gmpq( 4,3 ) ), 2 ) ; + BOOST_CHECK_EQUAL(SFCGAL::ceil(CGAL::Gmpq(0)), 0); + BOOST_CHECK_EQUAL(SFCGAL::ceil(CGAL::Gmpq(1, 2)), 1); + BOOST_CHECK_EQUAL(SFCGAL::ceil(CGAL::Gmpq(1, 3)), 1); + BOOST_CHECK_EQUAL(SFCGAL::ceil(CGAL::Gmpq(1, 1)), 1); + BOOST_CHECK_EQUAL(SFCGAL::ceil(CGAL::Gmpq(4, 3)), 2); } -BOOST_AUTO_TEST_CASE( testRoundRational ) +BOOST_AUTO_TEST_CASE(testRoundRational) { - BOOST_CHECK_EQUAL( SFCGAL::round( CGAL::Gmpq( 0 ) ), 0 ) ; - BOOST_CHECK_EQUAL( SFCGAL::round( CGAL::Gmpq( 1,2 ) ), 1 ) ; - BOOST_CHECK_EQUAL( SFCGAL::round( CGAL::Gmpq( 1,3 ) ), 0 ) ; - BOOST_CHECK_EQUAL( SFCGAL::round( CGAL::Gmpq( 1,1 ) ), 1 ) ; - BOOST_CHECK_EQUAL( SFCGAL::round( CGAL::Gmpq( 4,3 ) ), 1 ) ; + BOOST_CHECK_EQUAL(SFCGAL::round(CGAL::Gmpq(0)), 0); + BOOST_CHECK_EQUAL(SFCGAL::round(CGAL::Gmpq(1, 2)), 1); + BOOST_CHECK_EQUAL(SFCGAL::round(CGAL::Gmpq(1, 3)), 0); + BOOST_CHECK_EQUAL(SFCGAL::round(CGAL::Gmpq(1, 1)), 1); + BOOST_CHECK_EQUAL(SFCGAL::round(CGAL::Gmpq(4, 3)), 1); } BOOST_AUTO_TEST_SUITE_END() diff --git a/test/unit/SFCGAL/PointTest.cpp b/test/unit/SFCGAL/PointTest.cpp index 1c2bbbff..9bbbc744 100644 --- a/test/unit/SFCGAL/PointTest.cpp +++ b/test/unit/SFCGAL/PointTest.cpp @@ -15,265 +15,254 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include -#include #include -#include #include +#include +#include #include -using namespace boost::unit_test ; - -using namespace SFCGAL ; +using namespace boost::unit_test; -BOOST_AUTO_TEST_SUITE( SFCGAL_PointTest ) +using namespace SFCGAL; +BOOST_AUTO_TEST_SUITE(SFCGAL_PointTest) -//Point() ; -BOOST_AUTO_TEST_CASE( defaultConstructor ) +// Point() ; +BOOST_AUTO_TEST_CASE(defaultConstructor) { - Point g; - BOOST_CHECK( g.isEmpty() ) ; - BOOST_CHECK( ! g.is3D() ); - BOOST_CHECK( ! g.isMeasured() ); - - // no more access to double - BOOST_CHECK_THROW( g.x(), Exception ); - BOOST_CHECK_THROW( g.y(), Exception ); - BOOST_CHECK_THROW( g.z(), Exception ); - BOOST_CHECK( std::isnan( g.m() ) ); + Point const g; + BOOST_CHECK(g.isEmpty()); + BOOST_CHECK(!g.is3D()); + BOOST_CHECK(!g.isMeasured()); + + // no more access to double + BOOST_CHECK_THROW(g.x(), Exception); + BOOST_CHECK_THROW(g.y(), Exception); + BOOST_CHECK_THROW(g.z(), Exception); + BOOST_CHECK(std::isnan(g.m())); } -//Point( const Coordinate & coordinate ) ; +// Point( const Coordinate & coordinate ) ; -//Point( const Kernel::FT & x, const Kernel::FT & y ) ; -BOOST_AUTO_TEST_CASE( xyConstructor ) +// Point( const Kernel::FT & x, const Kernel::FT & y ) ; +BOOST_AUTO_TEST_CASE(xyConstructor) { - Point g( 2.0,3.0 ); - BOOST_CHECK( ! g.isEmpty() ) ; - BOOST_CHECK( ! g.is3D() ); - BOOST_CHECK_EQUAL( g.x(), 2.0 ); - BOOST_CHECK_EQUAL( g.y(), 3.0 ); - BOOST_CHECK_EQUAL( g.z(), 0 ); + Point const g(2.0, 3.0); + BOOST_CHECK(!g.isEmpty()); + BOOST_CHECK(!g.is3D()); + BOOST_CHECK_EQUAL(g.x(), 2.0); + BOOST_CHECK_EQUAL(g.y(), 3.0); + BOOST_CHECK_EQUAL(g.z(), 0); } -//Point( const Kernel::FT & x, const Kernel::FT & y, const Kernel::FT & z ) ; -//Point( const double & x, const double & y, const double & z = NaN() ) ; -BOOST_AUTO_TEST_CASE( xyzConstructor ) +// Point( const Kernel::FT & x, const Kernel::FT & y, const Kernel::FT & z ) ; +// Point( const double & x, const double & y, const double & z = NaN() ) ; +BOOST_AUTO_TEST_CASE(xyzConstructor) { - Point g( 2.0,3.0,4.0 ); - BOOST_CHECK( ! g.isEmpty() ) ; - BOOST_CHECK( g.is3D() ); - BOOST_CHECK_EQUAL( g.x(), 2.0 ); - BOOST_CHECK_EQUAL( g.y(), 3.0 ); - BOOST_CHECK_EQUAL( g.z(), 4.0 ); + Point const g(2.0, 3.0, 4.0); + BOOST_CHECK(!g.isEmpty()); + BOOST_CHECK(g.is3D()); + BOOST_CHECK_EQUAL(g.x(), 2.0); + BOOST_CHECK_EQUAL(g.y(), 3.0); + BOOST_CHECK_EQUAL(g.z(), 4.0); } -//Point( const Kernel::Point_2 & other ) ; -//Point( const Kernel::Point_3 & other ) ; -//Point( const Point & other ) ; -//Point& operator = ( const Point & other ) ; +// Point( const Kernel::Point_2 & other ) ; +// Point( const Kernel::Point_3 & other ) ; +// Point( const Point & other ) ; +// Point& operator = ( const Point & other ) ; //~Point() ; - //-- tested in Coordinate -//inline Kernel::RT x() const { return _coordinate.x() ; } -//inline Kernel::RT y() const { return _coordinate.y() ; } -//inline Kernel::RT z() const { return _coordinate.z() ; } +// inline Kernel::RT x() const { return _coordinate.x() ; } +// inline Kernel::RT y() const { return _coordinate.y() ; } +// inline Kernel::RT z() const { return _coordinate.z() ; } -//inline double m() const { return _m ; } -//inline void setM( const double & m ) { _m = m ; } -BOOST_AUTO_TEST_CASE( testGetSetM ) +// inline double m() const { return _m ; } +// inline void setM( const double & m ) { _m = m ; } +BOOST_AUTO_TEST_CASE(testGetSetM) { - Point p( 3.0,4.0 ); - BOOST_CHECK( ! p.isMeasured() ); - BOOST_CHECK( std::isnan( p.m() ) ); - p.setM( 5.0 ); - BOOST_CHECK_EQUAL( p.m(), 5.0 ); + Point p(3.0, 4.0); + BOOST_CHECK(!p.isMeasured()); + BOOST_CHECK(std::isnan(p.m())); + p.setM(5.0); + BOOST_CHECK_EQUAL(p.m(), 5.0); } -//bool operator < ( const Point & other ) const ; -//bool operator == ( const Point & other ) const ; -//bool operator != ( const Point & other ) const ; - +// bool operator < ( const Point & other ) const ; +// bool operator == ( const Point & other ) const ; +// bool operator != ( const Point & other ) const ; -//inline Kernel::Vector_2 toVector_2() const -//inline Kernel::Vector_3 toVector_3() const -//inline Kernel::Point_2 toPoint_2() const -//inline Kernel::Point_3 toPoint_3() const -BOOST_AUTO_TEST_CASE( emptyToVector_2 ) +// inline Kernel::Vector_2 toVector_2() const +// inline Kernel::Vector_3 toVector_3() const +// inline Kernel::Point_2 toPoint_2() const +// inline Kernel::Point_3 toPoint_3() const +BOOST_AUTO_TEST_CASE(emptyToVector_2) { - Point g ; - CGAL::Vector_2< Kernel > p = g.toVector_2(); - BOOST_CHECK_EQUAL( CGAL::to_double( p.x() ), 0.0 ); - BOOST_CHECK_EQUAL( CGAL::to_double( p.y() ), 0.0 ); + Point const g; + CGAL::Vector_2 const p = g.toVector_2(); + BOOST_CHECK_EQUAL(CGAL::to_double(p.x()), 0.0); + BOOST_CHECK_EQUAL(CGAL::to_double(p.y()), 0.0); } -BOOST_AUTO_TEST_CASE( xyToVector_2 ) +BOOST_AUTO_TEST_CASE(xyToVector_2) { - Point g( 3.0, 4.0 ); - CGAL::Vector_2< Kernel > p = g.toVector_2(); - BOOST_CHECK_EQUAL( CGAL::to_double( p.x() ), 3.0 ); - BOOST_CHECK_EQUAL( CGAL::to_double( p.y() ), 4.0 ); + Point const g(3.0, 4.0); + CGAL::Vector_2 const p = g.toVector_2(); + BOOST_CHECK_EQUAL(CGAL::to_double(p.x()), 3.0); + BOOST_CHECK_EQUAL(CGAL::to_double(p.y()), 4.0); } -BOOST_AUTO_TEST_CASE( xyToVector_3 ) +BOOST_AUTO_TEST_CASE(xyToVector_3) { - Point g( 3.0, 4.0 ); - CGAL::Vector_3< Kernel > p = g.toVector_3(); + Point const g(3.0, 4.0); + CGAL::Vector_3 const p = g.toVector_3(); - BOOST_CHECK_EQUAL( CGAL::to_double( p.x() ), 3.0 ); - BOOST_CHECK_EQUAL( CGAL::to_double( p.y() ), 4.0 ); - BOOST_CHECK_EQUAL( CGAL::to_double( p.z() ), 0.0 ); + BOOST_CHECK_EQUAL(CGAL::to_double(p.x()), 3.0); + BOOST_CHECK_EQUAL(CGAL::to_double(p.y()), 4.0); + BOOST_CHECK_EQUAL(CGAL::to_double(p.z()), 0.0); } - -//template typename TypeForDimension::Point toPoint_d() const; -//inline Coordinate & coordinate() { return _coordinate; } -//inline const Coordinate & coordinate() const { return _coordinate; } - +// template typename TypeForDimension::Point toPoint_d() const; +// inline Coordinate & coordinate() { return _coordinate; } +// inline const Coordinate & coordinate() const { return _coordinate; } //-- SFCGAL::Geometry -//virtual Geometry * Geometry::clone() const = 0 ; -BOOST_AUTO_TEST_CASE( testClone ) +// virtual Geometry * Geometry::clone() const = 0 ; +BOOST_AUTO_TEST_CASE(testClone) { - Point p( 3.0,4.0 ); - std::unique_ptr< Geometry > copy( p.clone() ); - BOOST_REQUIRE( copy->is< Point >() ); - BOOST_CHECK_EQUAL( copy->as< Point >().x(), 3.0 ); - BOOST_CHECK_EQUAL( copy->as< Point >().y(), 4.0 ); + Point const p(3.0, 4.0); + std::unique_ptr copy(p.clone()); + BOOST_REQUIRE(copy->is()); + BOOST_CHECK_EQUAL(copy->as().x(), 3.0); + BOOST_CHECK_EQUAL(copy->as().y(), 4.0); } -//virtual Geometry* Geometry::boundary() const ; -BOOST_AUTO_TEST_CASE( testBoundary ) +// virtual Geometry* Geometry::boundary() const ; +BOOST_AUTO_TEST_CASE(testBoundary) { - Point p( 3.0,4.0 ); - std::unique_ptr< Geometry > boundary( p.boundary() ); - BOOST_CHECK( boundary->isEmpty() ); - BOOST_CHECK( boundary->is< GeometryCollection >() ); + Point const p(3.0, 4.0); + std::unique_ptr boundary(p.boundary()); + BOOST_CHECK(boundary->isEmpty()); + BOOST_CHECK(boundary->is()); } -//Envelope Geometry::envelope() const ; -BOOST_AUTO_TEST_CASE( testEnvelope_empty ) +// Envelope Geometry::envelope() const ; +BOOST_AUTO_TEST_CASE(testEnvelope_empty) { - BOOST_CHECK( Point().envelope().isEmpty() ); + BOOST_CHECK(Point().envelope().isEmpty()); } -BOOST_AUTO_TEST_CASE( testEnvelope_2D ) +BOOST_AUTO_TEST_CASE(testEnvelope_2D) { - Point g( 3.0,4.0 ); - Envelope box = g.envelope() ; - BOOST_CHECK( ! box.isEmpty() ); - BOOST_CHECK( ! box.is3D() ); - - BOOST_CHECK_EQUAL( box.xMin(), 3.0 ); - BOOST_CHECK_EQUAL( box.xMax(), 3.0 ); - BOOST_CHECK_EQUAL( box.yMin(), 4.0 ); - BOOST_CHECK_EQUAL( box.yMax(), 4.0 ); + Point const g(3.0, 4.0); + Envelope const box = g.envelope(); + BOOST_CHECK(!box.isEmpty()); + BOOST_CHECK(!box.is3D()); + + BOOST_CHECK_EQUAL(box.xMin(), 3.0); + BOOST_CHECK_EQUAL(box.xMax(), 3.0); + BOOST_CHECK_EQUAL(box.yMin(), 4.0); + BOOST_CHECK_EQUAL(box.yMax(), 4.0); } -BOOST_AUTO_TEST_CASE( testEnvelope_3D ) +BOOST_AUTO_TEST_CASE(testEnvelope_3D) { - Point g( 3.0,4.0,5.0 ); - Envelope box = g.envelope() ; - BOOST_CHECK( ! box.isEmpty() ); - BOOST_CHECK( box.is3D() ); - - BOOST_CHECK_EQUAL( box.xMin(), 3.0 ); - BOOST_CHECK_EQUAL( box.xMax(), 3.0 ); - BOOST_CHECK_EQUAL( box.yMin(), 4.0 ); - BOOST_CHECK_EQUAL( box.yMax(), 4.0 ); - BOOST_CHECK_EQUAL( box.zMin(), 5.0 ); - BOOST_CHECK_EQUAL( box.zMax(), 5.0 ); + Point const g(3.0, 4.0, 5.0); + Envelope const box = g.envelope(); + BOOST_CHECK(!box.isEmpty()); + BOOST_CHECK(box.is3D()); + + BOOST_CHECK_EQUAL(box.xMin(), 3.0); + BOOST_CHECK_EQUAL(box.xMax(), 3.0); + BOOST_CHECK_EQUAL(box.yMin(), 4.0); + BOOST_CHECK_EQUAL(box.yMax(), 4.0); + BOOST_CHECK_EQUAL(box.zMin(), 5.0); + BOOST_CHECK_EQUAL(box.zMax(), 5.0); } - -//std::string Geometry::asText( const int & numDecimals = -1 ) const ; -BOOST_AUTO_TEST_CASE( asTextEmpty ) +// std::string Geometry::asText( const int & numDecimals = -1 ) const ; +BOOST_AUTO_TEST_CASE(asTextEmpty) { - Point g; - BOOST_CHECK_EQUAL( g.asText( 1 ), "POINT EMPTY" ); + Point const g; + BOOST_CHECK_EQUAL(g.asText(1), "POINT EMPTY"); } -BOOST_AUTO_TEST_CASE( asText2d ) +BOOST_AUTO_TEST_CASE(asText2d) { - Point g( 2.0,3.0 ); - BOOST_CHECK_EQUAL( g.asText( 3 ), "POINT(2.000 3.000)" ); + Point const g(2.0, 3.0); + BOOST_CHECK_EQUAL(g.asText(3), "POINT(2.000 3.000)"); } -BOOST_AUTO_TEST_CASE( asText3d ) +BOOST_AUTO_TEST_CASE(asText3d) { - Point g( 2.0,3.0,4.0 ); - BOOST_CHECK_EQUAL( g.asText( 3 ), "POINT Z(2.000 3.000 4.000)" ); + Point const g(2.0, 3.0, 4.0); + BOOST_CHECK_EQUAL(g.asText(3), "POINT Z(2.000 3.000 4.000)"); } -//virtual std::string Geometry::geometryType() const = 0 ; -BOOST_AUTO_TEST_CASE( testGeometryType ) +// virtual std::string Geometry::geometryType() const = 0 ; +BOOST_AUTO_TEST_CASE(testGeometryType) { - Point g; - BOOST_CHECK_EQUAL( g.geometryType(), "Point" ); + Point const g; + BOOST_CHECK_EQUAL(g.geometryType(), "Point"); } -//virtual GeometryType Geometry::geometryTypeId() const = 0 ; -BOOST_AUTO_TEST_CASE( testGeometryTypeId ) +// virtual GeometryType Geometry::geometryTypeId() const = 0 ; +BOOST_AUTO_TEST_CASE(testGeometryTypeId) { - Point g; - BOOST_CHECK_EQUAL( g.geometryTypeId(), TYPE_POINT ); + Point const g; + BOOST_CHECK_EQUAL(g.geometryTypeId(), TYPE_POINT); } -//virtual int Geometry::dimension() const = 0 ; -BOOST_AUTO_TEST_CASE( testDimension ) +// virtual int Geometry::dimension() const = 0 ; +BOOST_AUTO_TEST_CASE(testDimension) { - Point g; - BOOST_CHECK_EQUAL( g.dimension(), 0 ); + Point const g; + BOOST_CHECK_EQUAL(g.dimension(), 0); } -//virtual int Geometry::coordinateDimension() const = 0 ; -BOOST_AUTO_TEST_CASE( testCoordinateDimension ) +// virtual int Geometry::coordinateDimension() const = 0 ; +BOOST_AUTO_TEST_CASE(testCoordinateDimension) { - BOOST_CHECK_EQUAL( Point().coordinateDimension(), 0 ); - BOOST_CHECK_EQUAL( Point( 2.0,3.0 ).coordinateDimension(), 2 ); - BOOST_CHECK_EQUAL( Point( 2.0,3.0,4.0 ).coordinateDimension(), 3 ); + BOOST_CHECK_EQUAL(Point().coordinateDimension(), 0); + BOOST_CHECK_EQUAL(Point(2.0, 3.0).coordinateDimension(), 2); + BOOST_CHECK_EQUAL(Point(2.0, 3.0, 4.0).coordinateDimension(), 3); } -//virtual bool Geometry::isEmpty() const = 0 ; -BOOST_AUTO_TEST_CASE( testIsEmpty ) +// virtual bool Geometry::isEmpty() const = 0 ; +BOOST_AUTO_TEST_CASE(testIsEmpty) { - BOOST_CHECK( Point().isEmpty() ); - BOOST_CHECK( ! Point( 2.0,3.0 ).isEmpty() ); + BOOST_CHECK(Point().isEmpty()); + BOOST_CHECK(!Point(2.0, 3.0).isEmpty()); } -//virtual bool Geometry::is3D() const = 0 ; -BOOST_AUTO_TEST_CASE( testIs3D ) +// virtual bool Geometry::is3D() const = 0 ; +BOOST_AUTO_TEST_CASE(testIs3D) { - BOOST_CHECK( ! Point().is3D() ); - BOOST_CHECK( ! Point( 2.0,3.0 ).is3D() ); - BOOST_CHECK( Point( 2.0,3.0,4.0 ).is3D() ); + BOOST_CHECK(!Point().is3D()); + BOOST_CHECK(!Point(2.0, 3.0).is3D()); + BOOST_CHECK(Point(2.0, 3.0, 4.0).is3D()); } -//virtual bool Geometry::isMeasured() const = 0 ; -BOOST_AUTO_TEST_CASE( testIsMeasured ) +// virtual bool Geometry::isMeasured() const = 0 ; +BOOST_AUTO_TEST_CASE(testIsMeasured) { - BOOST_CHECK( ! Point().isMeasured() ); - BOOST_CHECK( ! Point( 2.0,3.0 ).isMeasured() ); - BOOST_CHECK( ! Point( 2.0,3.0,4.0 ).isMeasured() ); - BOOST_CHECK( Point( 2.0,3.0,4.0,5.0 ).isMeasured() ); + BOOST_CHECK(!Point().isMeasured()); + BOOST_CHECK(!Point(2.0, 3.0).isMeasured()); + BOOST_CHECK(!Point(2.0, 3.0, 4.0).isMeasured()); + BOOST_CHECK(Point(2.0, 3.0, 4.0, 5.0).isMeasured()); } -//TODO -//virtual bool Geometry::isSimple() const = 0 ; +// TODO +// virtual bool Geometry::isSimple() const = 0 ; -//template < typename Derived > inline bool Geometry::is() const -BOOST_AUTO_TEST_CASE( isPoint ) +// template < typename Derived > inline bool Geometry::is() const +BOOST_AUTO_TEST_CASE(isPoint) { - Point g; - BOOST_CHECK( g.is< Point >() ); + Point const g; + BOOST_CHECK(g.is()); } -//template < typename Derived > inline const Derived & Geometry::as() const -//template < typename Derived > inline Derived & Geometry::as() -BOOST_AUTO_TEST_CASE( asPoint ) +// template < typename Derived > inline const Derived & Geometry::as() const +// template < typename Derived > inline Derived & Geometry::as() +BOOST_AUTO_TEST_CASE(asPoint) { - std::unique_ptr< Geometry > g( new Point() ); - BOOST_CHECK( g->as< Point >().isEmpty() ); + std::unique_ptr g(new Point()); + BOOST_CHECK(g->as().isEmpty()); } - - BOOST_AUTO_TEST_SUITE_END() - - - - diff --git a/test/unit/SFCGAL/PolygonTest.cpp b/test/unit/SFCGAL/PolygonTest.cpp index b15ec97d..6c4aa207 100644 --- a/test/unit/SFCGAL/PolygonTest.cpp +++ b/test/unit/SFCGAL/PolygonTest.cpp @@ -15,242 +15,222 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include -#include -#include #include #include +#include +#include #include -using namespace boost::unit_test ; -using namespace SFCGAL ; +using namespace boost::unit_test; +using namespace SFCGAL; -BOOST_AUTO_TEST_SUITE( SFCGAL_PolygonTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_PolygonTest) -//Polygon() ; -BOOST_AUTO_TEST_CASE( defaultConstructor ) +// Polygon() ; +BOOST_AUTO_TEST_CASE(defaultConstructor) { - Polygon g; - BOOST_CHECK( g.isEmpty() ); - BOOST_CHECK( ! g.is3D() ); - BOOST_CHECK_EQUAL( g.numInteriorRings(), 0U ); + Polygon const g; + BOOST_CHECK(g.isEmpty()); + BOOST_CHECK(!g.is3D()); + BOOST_CHECK_EQUAL(g.numInteriorRings(), 0U); } -//Polygon( const std::vector< LineString > & rings ) ; -//Polygon( const LineString & exteriorRing ) ; -BOOST_AUTO_TEST_CASE( exteriorRingConstructor ) +// Polygon( const std::vector< LineString > & rings ) ; +// Polygon( const LineString & exteriorRing ) ; +BOOST_AUTO_TEST_CASE(exteriorRingConstructor) { - LineString exteriorRing ; - exteriorRing.addPoint( Point( 0.0,0.0 ) ); - exteriorRing.addPoint( Point( 1.0,0.0 ) ); - exteriorRing.addPoint( Point( 1.0,1.0 ) ); - exteriorRing.addPoint( Point( 0.0,1.0 ) ); - exteriorRing.addPoint( Point( 0.0,0.0 ) ); + LineString exteriorRing; + exteriorRing.addPoint(Point(0.0, 0.0)); + exteriorRing.addPoint(Point(1.0, 0.0)); + exteriorRing.addPoint(Point(1.0, 1.0)); + exteriorRing.addPoint(Point(0.0, 1.0)); + exteriorRing.addPoint(Point(0.0, 0.0)); - Polygon g( exteriorRing ); - BOOST_CHECK( ! g.isEmpty() ); - BOOST_CHECK( ! g.is3D() ); - BOOST_CHECK_EQUAL( g.numInteriorRings(), 0U ); - BOOST_CHECK_EQUAL( g.exteriorRing().numPoints(), 5U ); + Polygon g(exteriorRing); + BOOST_CHECK(!g.isEmpty()); + BOOST_CHECK(!g.is3D()); + BOOST_CHECK_EQUAL(g.numInteriorRings(), 0U); + BOOST_CHECK_EQUAL(g.exteriorRing().numPoints(), 5U); } -BOOST_AUTO_TEST_CASE( exteriorRingConstructor3D ) +BOOST_AUTO_TEST_CASE(exteriorRingConstructor3D) { - Polygon g; - g.exteriorRing().addPoint( Point( 0.0,0.0,2.0 ) ); - g.exteriorRing().addPoint( Point( 1.0,0.0,2.0 ) ); - g.exteriorRing().addPoint( Point( 1.0,1.0,2.0 ) ); - g.exteriorRing().addPoint( Point( 0.0,1.0,2.0 ) ); - g.exteriorRing().addPoint( Point( 0.0,0.0,2.0 ) ); + Polygon g; + g.exteriorRing().addPoint(Point(0.0, 0.0, 2.0)); + g.exteriorRing().addPoint(Point(1.0, 0.0, 2.0)); + g.exteriorRing().addPoint(Point(1.0, 1.0, 2.0)); + g.exteriorRing().addPoint(Point(0.0, 1.0, 2.0)); + g.exteriorRing().addPoint(Point(0.0, 0.0, 2.0)); - BOOST_CHECK( ! g.isEmpty() ); - BOOST_CHECK( g.is3D() ); - BOOST_CHECK_EQUAL( g.numInteriorRings(), 0U ); + BOOST_CHECK(!g.isEmpty()); + BOOST_CHECK(g.is3D()); + BOOST_CHECK_EQUAL(g.numInteriorRings(), 0U); } - -//Polygon( LineString * exteriorRing ) ; -//Polygon( const Triangle & triangle ) ; -BOOST_AUTO_TEST_CASE( testConstructorTriangle ) +// Polygon( LineString * exteriorRing ) ; +// Polygon( const Triangle & triangle ) ; +BOOST_AUTO_TEST_CASE(testConstructorTriangle) { - Polygon g( - Triangle( - Point( 0.0,0.0 ), - Point( 0.0,1.0 ), - Point( 1.0,1.0 ) - ) - ); - BOOST_CHECK_EQUAL( g.numRings(), 1U ); - BOOST_CHECK_EQUAL( g.exteriorRing().numPoints(), 4U ); + Polygon g(Triangle(Point(0.0, 0.0), Point(0.0, 1.0), Point(1.0, 1.0))); + BOOST_CHECK_EQUAL(g.numRings(), 1U); + BOOST_CHECK_EQUAL(g.exteriorRing().numPoints(), 4U); } -//Polygon( Polygon const& other ) ; +// Polygon( Polygon const& other ) ; -//Polygon( const CGAL::Polygon_2< Kernel >& other ); -//Polygon( const CGAL::Polygon_with_holes_2< Kernel >& poly ); +// Polygon( const CGAL::Polygon_2< Kernel >& other ); +// Polygon( const CGAL::Polygon_with_holes_2< Kernel >& poly ); -//Polygon& operator = ( const Polygon & other ) ; +// Polygon& operator = ( const Polygon & other ) ; //~Polygon() ; - -//bool isCounterClockWiseOriented() const; - -//void reverse() ; -BOOST_AUTO_TEST_CASE( testReverse ) -{ - Polygon g( - Triangle( - Point( 0.0,0.0 ), - Point( 1.0,0.0 ), - Point( 1.0,1.0 ) - ) - ); - BOOST_CHECK( g.isCounterClockWiseOriented() ); - g.reverse(); - BOOST_CHECK( ! g.isCounterClockWiseOriented() ); -} -//TODO same with holes - -//inline const LineString & exteriorRing() const -//inline LineString & exteriorRing() -//inline void setExteriorRing( const LineString& ring ) -//inline void setExteriorRing( LineString* ring ) -//inline bool hasInteriorRings() const -//inline size_t numInteriorRings() const -//inline const LineString & interiorRingN( const size_t & n ) const -//inline LineString & interiorRingN( const size_t & n ) -//inline size_t numRings() const -//inline const LineString & ringN( const size_t & n ) const -//inline LineString & ringN( const size_t & n ) -//inline void addInteriorRing( const LineString & ls ) -//inline void addInteriorRing( LineString* ls ) -//inline void addRing( const LineString & ls ) -//inline void addRing( LineString* ls ) -//inline iterator begin() { return _rings.begin() ; } -//inline const_iterator begin() const { return _rings.begin() ; } -//inline iterator end() { return _rings.end() ; } -//inline const_iterator end() const { return _rings.end() ; } - - - -//CGAL::Polygon_2 toPolygon_2( bool fixOrientation = true ) const; -//CGAL::Polygon_with_holes_2 toPolygon_with_holes_2( bool fixOrientation = true ) const; - - +// bool isCounterClockWiseOriented() const; + +// void reverse() ; +BOOST_AUTO_TEST_CASE(testReverse) +{ + Polygon g(Triangle(Point(0.0, 0.0), Point(1.0, 0.0), Point(1.0, 1.0))); + BOOST_CHECK(g.isCounterClockWiseOriented()); + g.reverse(); + BOOST_CHECK(!g.isCounterClockWiseOriented()); +} +// TODO same with holes + +// inline const LineString & exteriorRing() const +// inline LineString & exteriorRing() +// inline void setExteriorRing( const LineString& ring ) +// inline void setExteriorRing( LineString* ring ) +// inline bool hasInteriorRings() const +// inline size_t numInteriorRings() const +// inline const LineString & interiorRingN( const size_t & n ) const +// inline LineString & interiorRingN( const size_t & n ) +// inline size_t numRings() const +// inline const LineString & ringN( const size_t & n ) const +// inline LineString & ringN( const size_t & n ) +// inline void addInteriorRing( const LineString & ls ) +// inline void addInteriorRing( LineString* ls ) +// inline void addRing( const LineString & ls ) +// inline void addRing( LineString* ls ) +// inline iterator begin() { return _rings.begin() ; } +// inline const_iterator begin() const { return _rings.begin() ; } +// inline iterator end() { return _rings.end() ; } +// inline const_iterator end() const { return _rings.end() ; } + +// CGAL::Polygon_2 toPolygon_2( bool fixOrientation = true ) const; +// CGAL::Polygon_with_holes_2 toPolygon_with_holes_2( bool +// fixOrientation = true ) const; //-- Geometry -//virtual Geometry * Geometry::clone() const = 0 ; -BOOST_AUTO_TEST_CASE( testClone ) +// virtual Geometry * Geometry::clone() const = 0 ; +BOOST_AUTO_TEST_CASE(testClone) { - LineString exteriorRing ; - exteriorRing.addPoint( Point( 0.0,0.0 ) ); - exteriorRing.addPoint( Point( 1.0,0.0 ) ); - exteriorRing.addPoint( Point( 1.0,1.0 ) ); - exteriorRing.addPoint( Point( 0.0,1.0 ) ); - exteriorRing.addPoint( Point( 0.0,0.0 ) ); + LineString exteriorRing; + exteriorRing.addPoint(Point(0.0, 0.0)); + exteriorRing.addPoint(Point(1.0, 0.0)); + exteriorRing.addPoint(Point(1.0, 1.0)); + exteriorRing.addPoint(Point(0.0, 1.0)); + exteriorRing.addPoint(Point(0.0, 0.0)); - Polygon g( exteriorRing ); - std::unique_ptr< Polygon > copy( g.clone() ); + Polygon const g(exteriorRing); + std::unique_ptr copy(g.clone()); - BOOST_CHECK( ! copy->isEmpty() ); - BOOST_CHECK( ! copy->is3D() ); - BOOST_CHECK_EQUAL( copy->numInteriorRings(), 0U ); - BOOST_CHECK_EQUAL( copy->exteriorRing().numPoints(), 5U ); + BOOST_CHECK(!copy->isEmpty()); + BOOST_CHECK(!copy->is3D()); + BOOST_CHECK_EQUAL(copy->numInteriorRings(), 0U); + BOOST_CHECK_EQUAL(copy->exteriorRing().numPoints(), 5U); } -//virtual Geometry* Geometry::boundary() const ; -BOOST_AUTO_TEST_CASE( testBoundaryEmpty ) +// virtual Geometry* Geometry::boundary() const ; +BOOST_AUTO_TEST_CASE(testBoundaryEmpty) { - std::unique_ptr< Geometry > boundary( Polygon().boundary() ); - BOOST_CHECK( boundary->isEmpty() ); - BOOST_CHECK( boundary->is< GeometryCollection >() ); + std::unique_ptr boundary(Polygon().boundary()); + BOOST_CHECK(boundary->isEmpty()); + BOOST_CHECK(boundary->is()); } -BOOST_AUTO_TEST_CASE( testBoundaryWithoutHoles ) +BOOST_AUTO_TEST_CASE(testBoundaryWithoutHoles) { - std::string wkt( "POLYGON((0 0,0 1,1 1,0 0))" ) ; - std::unique_ptr< Geometry > boundary( io::readWkt( wkt )->boundary() ); - BOOST_CHECK( ! boundary->isEmpty() ); - BOOST_CHECK_EQUAL( boundary->asText( 0 ), "LINESTRING(0 0,0 1,1 1,0 0)" ); + std::string const wkt("POLYGON((0 0,0 1,1 1,0 0))"); + std::unique_ptr boundary(io::readWkt(wkt)->boundary()); + BOOST_CHECK(!boundary->isEmpty()); + BOOST_CHECK_EQUAL(boundary->asText(0), "LINESTRING(0 0,0 1,1 1,0 0)"); } -BOOST_AUTO_TEST_CASE( testBoundaryWithHoles ) +BOOST_AUTO_TEST_CASE(testBoundaryWithHoles) { - std::string wkt( "POLYGON((0 0,0 5,5 5,0 5,0 0),(1 1,2 1,2 2,1 1))" ) ; - std::unique_ptr< Geometry > boundary( io::readWkt( wkt )->boundary() ); - BOOST_CHECK( ! boundary->isEmpty() ); - BOOST_CHECK_EQUAL( boundary->asText( 0 ), "MULTILINESTRING((0 0,0 5,5 5,0 5,0 0),(1 1,2 1,2 2,1 1))" ); + std::string const wkt("POLYGON((0 0,0 5,5 5,0 5,0 0),(1 1,2 1,2 2,1 1))"); + std::unique_ptr boundary(io::readWkt(wkt)->boundary()); + BOOST_CHECK(!boundary->isEmpty()); + BOOST_CHECK_EQUAL(boundary->asText(0), + "MULTILINESTRING((0 0,0 5,5 5,0 5,0 0),(1 1,2 1,2 2,1 1))"); } -//Envelope Geometry::envelope() const ; +// Envelope Geometry::envelope() const ; -//std::string Geometry::asText( const int & numDecimals = -1 ) const ; -BOOST_AUTO_TEST_CASE( asTextEmpty ) +// std::string Geometry::asText( const int & numDecimals = -1 ) const ; +BOOST_AUTO_TEST_CASE(asTextEmpty) { - Polygon g; - BOOST_CHECK_EQUAL( g.asText( 1 ), "POLYGON EMPTY" ); + Polygon const g; + BOOST_CHECK_EQUAL(g.asText(1), "POLYGON EMPTY"); } -BOOST_AUTO_TEST_CASE( asText2d ) +BOOST_AUTO_TEST_CASE(asText2d) { - Polygon g; - g.exteriorRing().addPoint( Point( 0.0,0.0 ) ); - g.exteriorRing().addPoint( Point( 1.0,0.0 ) ); - g.exteriorRing().addPoint( Point( 1.0,1.0 ) ); - g.exteriorRing().addPoint( Point( 0.0,1.0 ) ); - g.exteriorRing().addPoint( Point( 0.0,0.0 ) ); + Polygon g; + g.exteriorRing().addPoint(Point(0.0, 0.0)); + g.exteriorRing().addPoint(Point(1.0, 0.0)); + g.exteriorRing().addPoint(Point(1.0, 1.0)); + g.exteriorRing().addPoint(Point(0.0, 1.0)); + g.exteriorRing().addPoint(Point(0.0, 0.0)); - BOOST_CHECK_EQUAL( g.asText( 1 ), "POLYGON((0.0 0.0,1.0 0.0,1.0 1.0,0.0 1.0,0.0 0.0))" ); + BOOST_CHECK_EQUAL(g.asText(1), + "POLYGON((0.0 0.0,1.0 0.0,1.0 1.0,0.0 1.0,0.0 0.0))"); } -BOOST_AUTO_TEST_CASE( asText3d ) +BOOST_AUTO_TEST_CASE(asText3d) { - Polygon g; - g.exteriorRing().addPoint( Point( 0.0,0.0,2.0 ) ); - g.exteriorRing().addPoint( Point( 1.0,0.0,2.0 ) ); - g.exteriorRing().addPoint( Point( 1.0,1.0,2.0 ) ); - g.exteriorRing().addPoint( Point( 0.0,1.0,2.0 ) ); - g.exteriorRing().addPoint( Point( 0.0,0.0,2.0 ) ); + Polygon g; + g.exteriorRing().addPoint(Point(0.0, 0.0, 2.0)); + g.exteriorRing().addPoint(Point(1.0, 0.0, 2.0)); + g.exteriorRing().addPoint(Point(1.0, 1.0, 2.0)); + g.exteriorRing().addPoint(Point(0.0, 1.0, 2.0)); + g.exteriorRing().addPoint(Point(0.0, 0.0, 2.0)); - BOOST_CHECK_EQUAL( g.asText( 1 ), "POLYGON Z((0.0 0.0 2.0,1.0 0.0 2.0,1.0 1.0 2.0,0.0 1.0 2.0,0.0 0.0 2.0))" ); + BOOST_CHECK_EQUAL(g.asText(1), "POLYGON Z((0.0 0.0 2.0,1.0 0.0 2.0,1.0 1.0 " + "2.0,0.0 1.0 2.0,0.0 0.0 2.0))"); } -//virtual std::string Geometry::geometryType() const = 0 ; -BOOST_AUTO_TEST_CASE( testGeometryType ) +// virtual std::string Geometry::geometryType() const = 0 ; +BOOST_AUTO_TEST_CASE(testGeometryType) { - Polygon g; - BOOST_CHECK_EQUAL( g.geometryType(), "Polygon" ); + Polygon const g; + BOOST_CHECK_EQUAL(g.geometryType(), "Polygon"); } -//virtual GeometryType Geometry::geometryTypeId() const = 0 ; -BOOST_AUTO_TEST_CASE( testGeometryTypeId ) +// virtual GeometryType Geometry::geometryTypeId() const = 0 ; +BOOST_AUTO_TEST_CASE(testGeometryTypeId) { - Polygon g; - BOOST_CHECK_EQUAL( g.geometryTypeId(), TYPE_POLYGON ); + Polygon const g; + BOOST_CHECK_EQUAL(g.geometryTypeId(), TYPE_POLYGON); } -//virtual int Geometry::dimension() const = 0 ; -BOOST_AUTO_TEST_CASE( testDimension ) +// virtual int Geometry::dimension() const = 0 ; +BOOST_AUTO_TEST_CASE(testDimension) { - Polygon g; - BOOST_CHECK_EQUAL( g.dimension(), 2 ); + Polygon const g; + BOOST_CHECK_EQUAL(g.dimension(), 2); } -//virtual int Geometry::coordinateDimension() const = 0 ; -//virtual bool Geometry::isEmpty() const = 0 ; -//virtual bool Geometry::is3D() const = 0 ; -//virtual bool Geometry::isMeasured() const = 0 ; -//virtual bool Geometry::isSimple() const = 0 ; +// virtual int Geometry::coordinateDimension() const = 0 ; +// virtual bool Geometry::isEmpty() const = 0 ; +// virtual bool Geometry::is3D() const = 0 ; +// virtual bool Geometry::isMeasured() const = 0 ; +// virtual bool Geometry::isSimple() const = 0 ; -//template < typename Derived > inline bool Geometry::is() const -BOOST_AUTO_TEST_CASE( isPolygon ) +// template < typename Derived > inline bool Geometry::is() const +BOOST_AUTO_TEST_CASE(isPolygon) { - Polygon g; - BOOST_CHECK( g.is< Polygon >() ); + Polygon const g; + BOOST_CHECK(g.is()); } -//template < typename Derived > inline const Derived & Geometry::as() const -//template < typename Derived > inline Derived & Geometry::as() - - - +// template < typename Derived > inline const Derived & Geometry::as() const +// template < typename Derived > inline Derived & Geometry::as() BOOST_AUTO_TEST_SUITE_END() - - - - diff --git a/test/unit/SFCGAL/SolidTest.cpp b/test/unit/SFCGAL/SolidTest.cpp index e07ee348..902472ab 100644 --- a/test/unit/SFCGAL/SolidTest.cpp +++ b/test/unit/SFCGAL/SolidTest.cpp @@ -15,7 +15,8 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include @@ -24,87 +25,85 @@ #include #include -using namespace boost::unit_test ; +using namespace boost::unit_test; -using namespace SFCGAL ; +using namespace SFCGAL; -BOOST_AUTO_TEST_SUITE( SFCGAL_SolidTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_SolidTest) -//Solid() ; -//Solid( const PolyhedralSurface & exteriorShell ) ; -//Solid( PolyhedralSurface * exteriorShell ) ; -//Solid( const std::vector< PolyhedralSurface > & shells ) ; -//Solid( Solid const& other ) ; -//Solid& operator = ( const Solid & other ) ; +// Solid() ; +// Solid( const PolyhedralSurface & exteriorShell ) ; +// Solid( PolyhedralSurface * exteriorShell ) ; +// Solid( const std::vector< PolyhedralSurface > & shells ) ; +// Solid( Solid const& other ) ; +// Solid& operator = ( const Solid & other ) ; //~Solid() ; -//inline const PolyhedralSurface & exteriorShell() const { return _shells[0] ; } -//inline PolyhedralSurface & exteriorShell() { return _shells[0] ; } -//inline size_t numInteriorShells() const { return _shells.size() - 1 ; } -//inline const PolyhedralSurface & interiorShellN( size_t const& n ) const { return _shells[n+1]; } -//inline PolyhedralSurface & interiorShellN( size_t const& n ) { return _shells[n+1]; } -//inline void addInteriorShell( const PolyhedralSurface & shell ) -//inline void addInteriorShell( PolyhedralSurface * shell ) -//inline size_t numShells() const { -//inline const PolyhedralSurface & shellN( const size_t & n ) const { -//inline PolyhedralSurface & shellN( const size_t & n ) { +// inline const PolyhedralSurface & exteriorShell() const { return _shells[0] +// ; } inline PolyhedralSurface & exteriorShell() { return _shells[0] ; +// } inline size_t numInteriorShells() const { return +// _shells.size() - 1 ; } inline const PolyhedralSurface & interiorShellN( +// size_t const& n ) const { return _shells[n+1]; } inline PolyhedralSurface & +// interiorShellN( size_t const& n ) { return _shells[n+1]; } inline void +// addInteriorShell( const PolyhedralSurface & shell ) inline void +// addInteriorShell( PolyhedralSurface * shell ) inline size_t numShells() +// const { inline const PolyhedralSurface & shellN( const size_t & n ) const { +// inline PolyhedralSurface & shellN( const size_t & n ) { //-- iterators -//inline iterator begin() { return _shells.begin() ; } -//inline const_iterator begin() const { return _shells.begin() ; } -//inline iterator end() { return _shells.end() ; } -//inline const_iterator end() const { return _shells.end() ; } - +// inline iterator begin() { return _shells.begin() ; } +// inline const_iterator begin() const { return _shells.begin() ; } +// inline iterator end() { return _shells.end() ; } +// inline const_iterator end() const { return _shells.end() ; } //-- helpers -//virtual Geometry * Geometry::clone() const = 0 ; -//virtual Geometry* Geometry::boundary() const ; -//Envelope Geometry::envelope() const ; -//std::string Geometry::asText( const int & numDecimals = -1 ) const ; -//virtual std::string Geometry::geometryType() const = 0 ; -//virtual GeometryType Geometry::geometryTypeId() const = 0 ; -//virtual int Geometry::dimension() const = 0 ; -//virtual int Geometry::coordinateDimension() const = 0 ; -//virtual bool Geometry::isEmpty() const = 0 ; -//virtual bool Geometry::is3D() const = 0 ; -//virtual bool Geometry::isMeasured() const = 0 ; -//virtual bool Geometry::isSimple() const = 0 ; -//template < typename Derived > inline bool Geometry::is() const -//template < typename Derived > inline const Derived & Geometry::as() const -//template < typename Derived > inline Derived & Geometry::as() - - +// virtual Geometry * Geometry::clone() const = 0 ; +// virtual Geometry* Geometry::boundary() const ; +// Envelope Geometry::envelope() const ; +// std::string Geometry::asText( const int & numDecimals = -1 ) const ; +// virtual std::string Geometry::geometryType() const = 0 ; +// virtual GeometryType Geometry::geometryTypeId() const = 0 ; +// virtual int Geometry::dimension() const = 0 ; +// virtual int Geometry::coordinateDimension() const = 0 ; +// virtual bool Geometry::isEmpty() const = 0 ; +// virtual bool Geometry::is3D() const = 0 ; +// virtual bool Geometry::isMeasured() const = 0 ; +// virtual bool Geometry::isSimple() const = 0 ; +// template < typename Derived > inline bool Geometry::is() const +// template < typename Derived > inline const Derived & Geometry::as() const +// template < typename Derived > inline Derived & Geometry::as() //-- other tests -BOOST_AUTO_TEST_CASE( solidReadTest ) +BOOST_AUTO_TEST_CASE(solidReadTest) { - // the unit cube where half of a cube has been substracted - std::string gstr = "SOLID(" - // exterior shell - "(" - "((0 0 0,0 1 0,1 1 0,1 0 0,0 0 0))," // front face - "((1 0 0,1 1 0,1 1 1,1 0 1,1 0 0))," // right face - "((0 1 0,0 1 1,1 1 1,1 1 0,0 1 0))," // top face - "((0 0 1,0 1 1,0 1 0,0 0 0,0 0 1))," // left face - "((1 0 1,1 1 1,0 1 1,0 0 1,1 0 1))," // back face - "((1 0 0,1 0 1,0 0 1,0 0 0,1 0 0))" // bottom face - ")," - // interior shell, a.k.a. a hole - "(" - "((0 0 0,0 0.5 0,0.5 0.5 0,0.5 0 0,0 0 0))," // front face - "((0.5 0 0,0.5 0.5 0,0.5 0.5 0.5,0.5 0 0.5,0.5 0 0))," // right face - "((0 0.5 0,0 0.5 0.5,0.5 0.5 0.5,0.5 0.5 0,0 0.5 0))," // top face - "((0 0 0.5,0 0.5 0.5,0 0.5 0,0 0 0,0 0 0.5))," // left face - "((0.5 0 0.5,0.5 0.5 0.5,0 0.5 0.5,0 0 0.5,0.5 0 0.5))," // back face - "((0.5 0 0,0.5 0 0.5,0 0 0.5,0 0 0,0.5 0 0))" // bottom face - ")" - ")"; - - std::unique_ptr g( io::readWkt( gstr ) ); - BOOST_CHECK_EQUAL( g->as< Solid >().numShells(),2U ); + // the unit cube where half of a cube has been substracted + std::string const gstr = + "SOLID(" + // exterior shell + "(" + "((0 0 0,0 1 0,1 1 0,1 0 0,0 0 0))," // front face + "((1 0 0,1 1 0,1 1 1,1 0 1,1 0 0))," // right face + "((0 1 0,0 1 1,1 1 1,1 1 0,0 1 0))," // top face + "((0 0 1,0 1 1,0 1 0,0 0 0,0 0 1))," // left face + "((1 0 1,1 1 1,0 1 1,0 0 1,1 0 1))," // back face + "((1 0 0,1 0 1,0 0 1,0 0 0,1 0 0))" // bottom face + ")," + // interior shell, a.k.a. a hole + "(" + "((0 0 0,0 0.5 0,0.5 0.5 0,0.5 0 0,0 0 0))," // front face + "((0.5 0 0,0.5 0.5 0,0.5 0.5 0.5,0.5 0 0.5,0.5 0 0))," // right face + "((0 0.5 0,0 0.5 0.5,0.5 0.5 0.5,0.5 0.5 0,0 0.5 0))," // top face + "((0 0 0.5,0 0.5 0.5,0 0.5 0,0 0 0,0 0 0.5))," // left face + "((0.5 0 0.5,0.5 0.5 0.5,0 0.5 0.5,0 0 0.5,0.5 0 0.5))," // back face + "((0.5 0 0,0.5 0 0.5,0 0 0.5,0 0 0,0.5 0 0))" // bottom face + ")" + ")"; + + std::unique_ptr g(io::readWkt(gstr)); + BOOST_CHECK_EQUAL(g->as().numShells(), 2U); } BOOST_AUTO_TEST_SUITE_END() diff --git a/test/unit/SFCGAL/TriangleTest.cpp b/test/unit/SFCGAL/TriangleTest.cpp index f62b0220..a34ddfa2 100644 --- a/test/unit/SFCGAL/TriangleTest.cpp +++ b/test/unit/SFCGAL/TriangleTest.cpp @@ -15,233 +15,219 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include -#include #include #include +#include #include -using namespace boost::unit_test ; +using namespace boost::unit_test; -using namespace SFCGAL ; +using namespace SFCGAL; -BOOST_AUTO_TEST_SUITE( SFCGAL_TriangleTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_TriangleTest) -//Triangle(); -BOOST_AUTO_TEST_CASE( testDefaultConstructor ) +// Triangle(); +BOOST_AUTO_TEST_CASE(testDefaultConstructor) { - Triangle g ; - BOOST_CHECK( g.isEmpty() ); + Triangle const g; + BOOST_CHECK(g.isEmpty()); } -//Triangle( const Kernel::Triangle_2 & triangle ) ; -BOOST_AUTO_TEST_CASE( testConstructorTriangle_2 ) +// Triangle( const Kernel::Triangle_2 & triangle ) ; +BOOST_AUTO_TEST_CASE(testConstructorTriangle_2) { - Kernel::Point_2 a( 0.0,0.0 ); - Kernel::Point_2 b( 1.0,0.0 ); - Kernel::Point_2 c( 1.0,1.0 ); + Kernel::Point_2 const a(0.0, 0.0); + Kernel::Point_2 const b(1.0, 0.0); + Kernel::Point_2 const c(1.0, 1.0); - Triangle g( Kernel::Triangle_2( a,b,c ) ) ; - BOOST_CHECK( ! g.isEmpty() ); - BOOST_CHECK( ! g.is3D() ) ; + Triangle g(Kernel::Triangle_2(a, b, c)); + BOOST_CHECK(!g.isEmpty()); + BOOST_CHECK(!g.is3D()); - BOOST_CHECK_EQUAL( g.vertex( 0 ).toPoint_2(), a ); - BOOST_CHECK_EQUAL( g.vertex( 1 ).toPoint_2(), b ); - BOOST_CHECK_EQUAL( g.vertex( 2 ).toPoint_2(), c ); + BOOST_CHECK_EQUAL(g.vertex(0).toPoint_2(), a); + BOOST_CHECK_EQUAL(g.vertex(1).toPoint_2(), b); + BOOST_CHECK_EQUAL(g.vertex(2).toPoint_2(), c); } -//Triangle( const Kernel::Triangle_3 & triangle ) ; -BOOST_AUTO_TEST_CASE( testConstructorTriangle_3 ) +// Triangle( const Kernel::Triangle_3 & triangle ) ; +BOOST_AUTO_TEST_CASE(testConstructorTriangle_3) { - Kernel::Point_3 a( 0.0,0.0,1.0 ); - Kernel::Point_3 b( 1.0,0.0,2.0 ); - Kernel::Point_3 c( 1.0,1.0,3.0 ); + Kernel::Point_3 const a(0.0, 0.0, 1.0); + Kernel::Point_3 const b(1.0, 0.0, 2.0); + Kernel::Point_3 const c(1.0, 1.0, 3.0); - Triangle g( Kernel::Triangle_3( a,b,c ) ) ; - BOOST_CHECK( ! g.isEmpty() ); - BOOST_CHECK( g.is3D() ) ; + Triangle g(Kernel::Triangle_3(a, b, c)); + BOOST_CHECK(!g.isEmpty()); + BOOST_CHECK(g.is3D()); - BOOST_CHECK_EQUAL( g.vertex( 0 ).toPoint_3(), a ); - BOOST_CHECK_EQUAL( g.vertex( 1 ).toPoint_3(), b ); - BOOST_CHECK_EQUAL( g.vertex( 2 ).toPoint_3(), c ); + BOOST_CHECK_EQUAL(g.vertex(0).toPoint_3(), a); + BOOST_CHECK_EQUAL(g.vertex(1).toPoint_3(), b); + BOOST_CHECK_EQUAL(g.vertex(2).toPoint_3(), c); } -//Triangle( const Point & p, const Point & q, const Point & r ); -//Triangle( const Triangle & other ); -//Triangle& operator = ( const Triangle & other ); +// Triangle( const Point & p, const Point & q, const Point & r ); +// Triangle( const Triangle & other ); +// Triangle& operator = ( const Triangle & other ); //~Triangle(); -//void reverse() ; -BOOST_AUTO_TEST_CASE( testReverse ) +// void reverse() ; +BOOST_AUTO_TEST_CASE(testReverse) { - Kernel::Point_3 a( 0.0,0.0,1.0 ); - Kernel::Point_3 b( 1.0,0.0,2.0 ); - Kernel::Point_3 c( 1.0,1.0,3.0 ); + Kernel::Point_3 const a(0.0, 0.0, 1.0); + Kernel::Point_3 const b(1.0, 0.0, 2.0); + Kernel::Point_3 const c(1.0, 1.0, 3.0); - Triangle g( Kernel::Triangle_3( a,b,c ) ) ; - g.reverse(); + Triangle g(Kernel::Triangle_3(a, b, c)); + g.reverse(); - BOOST_CHECK_EQUAL( g.vertex( 0 ).toPoint_3(), a ); - BOOST_CHECK_EQUAL( g.vertex( 1 ).toPoint_3(), c ); - BOOST_CHECK_EQUAL( g.vertex( 2 ).toPoint_3(), b ); + BOOST_CHECK_EQUAL(g.vertex(0).toPoint_3(), a); + BOOST_CHECK_EQUAL(g.vertex(1).toPoint_3(), c); + BOOST_CHECK_EQUAL(g.vertex(2).toPoint_3(), b); } -//Polygon toPolygon() const ; - -//inline const Point & vertex( const int & i ) const -//inline Point & vertex( const int & i ) -//inline Kernel::Triangle_2 toTriangle_2() const -//inline Kernel::Triangle_3 toTriangle_3() const +// Polygon toPolygon() const ; -//template < int D > inline typename TypeForDimension::Triangle toTriangle_d() const +// inline const Point & vertex( const int & i ) const +// inline Point & vertex( const int & i ) +// inline Kernel::Triangle_2 toTriangle_2() const +// inline Kernel::Triangle_3 toTriangle_3() const +// template < int D > inline typename TypeForDimension::Triangle +// toTriangle_d() const //-- Geometry tests -//virtual Geometry * Geometry::clone() const = 0 ; -BOOST_AUTO_TEST_CASE( testClone ) +// virtual Geometry * Geometry::clone() const = 0 ; +BOOST_AUTO_TEST_CASE(testClone) { - Kernel::Point_3 a( 0.0,0.0,1.0 ); - Kernel::Point_3 b( 1.0,0.0,2.0 ); - Kernel::Point_3 c( 1.0,1.0,3.0 ); + Kernel::Point_3 const a(0.0, 0.0, 1.0); + Kernel::Point_3 const b(1.0, 0.0, 2.0); + Kernel::Point_3 const c(1.0, 1.0, 3.0); - Triangle g( Kernel::Triangle_3( a,b,c ) ) ; + Triangle const g(Kernel::Triangle_3(a, b, c)); - std::unique_ptr< Geometry > copy( g.clone() ); - BOOST_REQUIRE( copy->is< Triangle >() ); - BOOST_CHECK_EQUAL( copy->asText( 0 ), "TRIANGLE Z((0 0 1,1 0 2,1 1 3,0 0 1))" ); + std::unique_ptr copy(g.clone()); + BOOST_REQUIRE(copy->is()); + BOOST_CHECK_EQUAL(copy->asText(0), "TRIANGLE Z((0 0 1,1 0 2,1 1 3,0 0 1))"); } -//virtual Geometry* Geometry::boundary() const ; -BOOST_AUTO_TEST_CASE( testBoundary ) +// virtual Geometry* Geometry::boundary() const ; +BOOST_AUTO_TEST_CASE(testBoundary) { - Kernel::Point_2 a( 0.0,0.0 ); - Kernel::Point_2 b( 1.0,0.0 ); - Kernel::Point_2 c( 1.0,1.0 ); + Kernel::Point_2 const a(0.0, 0.0); + Kernel::Point_2 const b(1.0, 0.0); + Kernel::Point_2 const c(1.0, 1.0); - Triangle g( Kernel::Triangle_2( a,b,c ) ) ; + Triangle const g(Kernel::Triangle_2(a, b, c)); - std::unique_ptr< Geometry > boundary( g.boundary() ); - BOOST_CHECK_EQUAL( boundary->asText( 0 ), "LINESTRING(0 0,1 0,1 1,0 0)" ); + std::unique_ptr boundary(g.boundary()); + BOOST_CHECK_EQUAL(boundary->asText(0), "LINESTRING(0 0,1 0,1 1,0 0)"); } -//Envelope Geometry::envelope() const ; -BOOST_AUTO_TEST_CASE( testEnvelope_empty ) +// Envelope Geometry::envelope() const ; +BOOST_AUTO_TEST_CASE(testEnvelope_empty) { - Triangle g ; + Triangle const g; - Envelope bbox = g.envelope() ; - BOOST_CHECK( bbox.isEmpty() ); + Envelope const bbox = g.envelope(); + BOOST_CHECK(bbox.isEmpty()); } -BOOST_AUTO_TEST_CASE( testEnvelope_2d ) +BOOST_AUTO_TEST_CASE(testEnvelope_2d) { - Kernel::Point_2 a( 0.0,-1.0 ); - Kernel::Point_2 b( 0.5,0.2 ); - Kernel::Point_2 c( 1.0,1.5 ); + Kernel::Point_2 const a(0.0, -1.0); + Kernel::Point_2 const b(0.5, 0.2); + Kernel::Point_2 const c(1.0, 1.5); - Triangle g( Kernel::Triangle_2( a,b,c ) ) ; + Triangle const g(Kernel::Triangle_2(a, b, c)); - Envelope bbox = g.envelope() ; - BOOST_CHECK( ! bbox.isEmpty() ); - BOOST_CHECK( ! bbox.is3D() ); + Envelope const bbox = g.envelope(); + BOOST_CHECK(!bbox.isEmpty()); + BOOST_CHECK(!bbox.is3D()); - BOOST_CHECK_EQUAL( bbox.xMin(), 0.0 ); - BOOST_CHECK_EQUAL( bbox.xMax(), 1.0 ); - BOOST_CHECK_EQUAL( bbox.yMin(), -1.0 ); - BOOST_CHECK_EQUAL( bbox.yMax(), 1.5 ); + BOOST_CHECK_EQUAL(bbox.xMin(), 0.0); + BOOST_CHECK_EQUAL(bbox.xMax(), 1.0); + BOOST_CHECK_EQUAL(bbox.yMin(), -1.0); + BOOST_CHECK_EQUAL(bbox.yMax(), 1.5); } -BOOST_AUTO_TEST_CASE( testEnvelope_3d ) +BOOST_AUTO_TEST_CASE(testEnvelope_3d) { - Kernel::Point_3 a( 0.0,-1.0,2.0 ); - Kernel::Point_3 b( 0.5,0.2,4.0 ); - Kernel::Point_3 c( 1.0,1.5,8.0 ); + Kernel::Point_3 const a(0.0, -1.0, 2.0); + Kernel::Point_3 const b(0.5, 0.2, 4.0); + Kernel::Point_3 const c(1.0, 1.5, 8.0); - Triangle g( Kernel::Triangle_3( a,b,c ) ) ; + Triangle const g(Kernel::Triangle_3(a, b, c)); - Envelope bbox = g.envelope() ; - BOOST_CHECK( ! bbox.isEmpty() ); - BOOST_CHECK( bbox.is3D() ); - BOOST_CHECK_EQUAL( bbox.xMin(), 0.0 ); - BOOST_CHECK_EQUAL( bbox.xMax(), 1.0 ); - BOOST_CHECK_EQUAL( bbox.yMin(), -1.0 ); - BOOST_CHECK_EQUAL( bbox.yMax(), 1.5 ); - BOOST_CHECK_EQUAL( bbox.zMin(), 2.0 ); - BOOST_CHECK_EQUAL( bbox.zMax(), 8.0 ); + Envelope const bbox = g.envelope(); + BOOST_CHECK(!bbox.isEmpty()); + BOOST_CHECK(bbox.is3D()); + BOOST_CHECK_EQUAL(bbox.xMin(), 0.0); + BOOST_CHECK_EQUAL(bbox.xMax(), 1.0); + BOOST_CHECK_EQUAL(bbox.yMin(), -1.0); + BOOST_CHECK_EQUAL(bbox.yMax(), 1.5); + BOOST_CHECK_EQUAL(bbox.zMin(), 2.0); + BOOST_CHECK_EQUAL(bbox.zMax(), 8.0); } -//std::string Geometry::asText( const int & numDecimals = -1 ) const ; -BOOST_AUTO_TEST_CASE( asTextEmpty ) +// std::string Geometry::asText( const int & numDecimals = -1 ) const ; +BOOST_AUTO_TEST_CASE(asTextEmpty) { - Triangle g; - BOOST_CHECK_EQUAL( g.asText( 1 ), "TRIANGLE EMPTY" ); + Triangle const g; + BOOST_CHECK_EQUAL(g.asText(1), "TRIANGLE EMPTY"); } -BOOST_AUTO_TEST_CASE( asText2d ) +BOOST_AUTO_TEST_CASE(asText2d) { - Triangle g( - Point( 0.0,0.0 ), - Point( 1.0,0.0 ), - Point( 1.0,1.0 ) - ); - BOOST_CHECK_EQUAL( g.asText( 1 ), "TRIANGLE((0.0 0.0,1.0 0.0,1.0 1.0,0.0 0.0))" ); + Triangle const g(Point(0.0, 0.0), Point(1.0, 0.0), Point(1.0, 1.0)); + BOOST_CHECK_EQUAL(g.asText(1), "TRIANGLE((0.0 0.0,1.0 0.0,1.0 1.0,0.0 0.0))"); } -BOOST_AUTO_TEST_CASE( asText3d ) +BOOST_AUTO_TEST_CASE(asText3d) { - Triangle g( - Point( 0.0,0.0,2.0 ), - Point( 1.0,0.0,3.0 ), - Point( 1.0,1.0,4.0 ) - ); - BOOST_CHECK_EQUAL( g.asText( 1 ), "TRIANGLE Z((0.0 0.0 2.0,1.0 0.0 3.0,1.0 1.0 4.0,0.0 0.0 2.0))" ); + Triangle const g(Point(0.0, 0.0, 2.0), Point(1.0, 0.0, 3.0), + Point(1.0, 1.0, 4.0)); + BOOST_CHECK_EQUAL( + g.asText(1), + "TRIANGLE Z((0.0 0.0 2.0,1.0 0.0 3.0,1.0 1.0 4.0,0.0 0.0 2.0))"); } - -//virtual std::string Geometry::geometryType() const = 0 ; -BOOST_AUTO_TEST_CASE( testGeometryType ) +// virtual std::string Geometry::geometryType() const = 0 ; +BOOST_AUTO_TEST_CASE(testGeometryType) { - BOOST_CHECK_EQUAL( Triangle().geometryType(), "Triangle" ); + BOOST_CHECK_EQUAL(Triangle().geometryType(), "Triangle"); } -//virtual GeometryType Geometry::geometryTypeId() const = 0 ; -BOOST_AUTO_TEST_CASE( testGeometryTypeId ) +// virtual GeometryType Geometry::geometryTypeId() const = 0 ; +BOOST_AUTO_TEST_CASE(testGeometryTypeId) { - BOOST_CHECK_EQUAL( Triangle().geometryTypeId(), TYPE_TRIANGLE ); + BOOST_CHECK_EQUAL(Triangle().geometryTypeId(), TYPE_TRIANGLE); } -//virtual int Geometry::dimension() const = 0 ; -//virtual int Geometry::coordinateDimension() const = 0 ; -//virtual bool Geometry::isEmpty() const = 0 ; -BOOST_AUTO_TEST_CASE( testIsEmpty ) +// virtual int Geometry::dimension() const = 0 ; +// virtual int Geometry::coordinateDimension() const = 0 ; +// virtual bool Geometry::isEmpty() const = 0 ; +BOOST_AUTO_TEST_CASE(testIsEmpty) { - BOOST_CHECK( Point().isEmpty() ); - BOOST_CHECK( ! Triangle( - Point( 0.0,0.0,2.0 ), - Point( 1.0,0.0,3.0 ), - Point( 1.0,1.0,4.0 ) - ).isEmpty() ); + BOOST_CHECK(Point().isEmpty()); + BOOST_CHECK(!Triangle(Point(0.0, 0.0, 2.0), Point(1.0, 0.0, 3.0), + Point(1.0, 1.0, 4.0)) + .isEmpty()); } -//virtual bool Geometry::is3D() const = 0 ; -//virtual bool Geometry::isMeasured() const = 0 ; -//virtual bool Geometry::isSimple() const = 0 ; +// virtual bool Geometry::is3D() const = 0 ; +// virtual bool Geometry::isMeasured() const = 0 ; +// virtual bool Geometry::isSimple() const = 0 ; -//template < typename Derived > inline bool Geometry::is() const -BOOST_AUTO_TEST_CASE( isTriangle ) +// template < typename Derived > inline bool Geometry::is() const +BOOST_AUTO_TEST_CASE(isTriangle) { - Triangle g; - BOOST_CHECK( g.is< Triangle >() ); + Triangle const g; + BOOST_CHECK(g.is()); } -//template < typename Derived > inline const Derived & Geometry::as() const -//template < typename Derived > inline Derived & Geometry::as() -BOOST_AUTO_TEST_CASE( asTriangle ) +// template < typename Derived > inline const Derived & Geometry::as() const +// template < typename Derived > inline Derived & Geometry::as() +BOOST_AUTO_TEST_CASE(asTriangle) { - std::unique_ptr< Geometry > g( new Triangle() ); - BOOST_CHECK( g->as< Triangle >().isEmpty() ); + std::unique_ptr g(new Triangle()); + BOOST_CHECK(g->as().isEmpty()); } - - - BOOST_AUTO_TEST_SUITE_END() - - - - diff --git a/test/unit/SFCGAL/TriangulatedSurfaceTest.cpp b/test/unit/SFCGAL/TriangulatedSurfaceTest.cpp index 39440206..80185e43 100644 --- a/test/unit/SFCGAL/TriangulatedSurfaceTest.cpp +++ b/test/unit/SFCGAL/TriangulatedSurfaceTest.cpp @@ -15,207 +15,201 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ -#include #include -#include +#include #include +#include #include -#include #include +#include #include -using namespace boost::unit_test ; +using namespace boost::unit_test; -using namespace SFCGAL ; +using namespace SFCGAL; -BOOST_AUTO_TEST_SUITE( SFCGAL_TriangulatedSurfaceTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_TriangulatedSurfaceTest) -//TriangulatedSurface() ; -BOOST_AUTO_TEST_CASE( defaultConstructor ) +// TriangulatedSurface() ; +BOOST_AUTO_TEST_CASE(defaultConstructor) { - TriangulatedSurface g ; - BOOST_CHECK( g.isEmpty() ) ; - BOOST_CHECK_EQUAL( g.numTriangles(), 0U ) ; + TriangulatedSurface const g; + BOOST_CHECK(g.isEmpty()); + BOOST_CHECK_EQUAL(g.numTriangles(), 0U); } -//TriangulatedSurface( const std::vector< Triangle > & triangle ) ; -BOOST_AUTO_TEST_CASE( constructorWithTriangles ) +// TriangulatedSurface( const std::vector< Triangle > & triangle ) ; +BOOST_AUTO_TEST_CASE(constructorWithTriangles) { - std::vector< Triangle > triangles ; - triangles.push_back( Triangle( Point( 0.0,0.0 ), Point( 1.0,0.0 ), Point( 1.0,1.0 ) ) ) ; - triangles.push_back( Triangle( Point( 0.0,0.0 ), Point( 1.0,1.0 ), Point( 0.0,1.0 ) ) ) ; + std::vector triangles; + triangles.emplace_back(Point(0.0, 0.0), Point(1.0, 0.0), Point(1.0, 1.0)); + triangles.emplace_back(Point(0.0, 0.0), Point(1.0, 1.0), Point(0.0, 1.0)); - TriangulatedSurface g( triangles ) ; - BOOST_CHECK( ! g.isEmpty() ) ; - BOOST_CHECK_EQUAL( g.numTriangles(), 2U ) ; + TriangulatedSurface const g(triangles); + BOOST_CHECK(!g.isEmpty()); + BOOST_CHECK_EQUAL(g.numTriangles(), 2U); } -//TriangulatedSurface( TriangulatedSurface const& other ) ; -//TriangulatedSurface& operator = ( const TriangulatedSurface & other ) ; +// TriangulatedSurface( TriangulatedSurface const& other ) ; +// TriangulatedSurface& operator = ( const TriangulatedSurface & other ) ; //~TriangulatedSurface() ; -//inline size_t numTriangles() const { return _triangles.size(); } -//inline const Triangle & triangleN( size_t const& n ) const { -//inline Triangle & triangleN( size_t const& n ) { -//inline void addTriangle( const Triangle & triangle ) -//inline void addTriangle( Triangle * triangle ) -//void addTriangles( const TriangulatedSurface & other ) ; - - -//virtual size_t numGeometries() const ; -//virtual const Triangle & geometryN( size_t const& n ) const ; -//virtual Triangle & geometryN( size_t const& n ) ; +// inline size_t numTriangles() const { return _triangles.size(); } +// inline const Triangle & triangleN( size_t const& n ) const { +// inline Triangle & triangleN( size_t const& n ) { +// inline void addTriangle( const Triangle & triangle ) +// inline void addTriangle( Triangle * triangle ) +// void addTriangles( const TriangulatedSurface & other ) ; +// virtual size_t numGeometries() const ; +// virtual const Triangle & geometryN( size_t const& n ) const ; +// virtual Triangle & geometryN( size_t const& n ) ; -//void reserve( const size_t & n ) ; +// void reserve( const size_t & n ) ; //-- iterators -//inline iterator begin() { -//inline const_iterator begin() const { -//inline iterator end() { -//inline const_iterator end() const { - - +// inline iterator begin() { +// inline const_iterator begin() const { +// inline iterator end() { +// inline const_iterator end() const { //-- helpers -//template < typename K, typename Polyhedron > std::unique_ptr toPolyhedron_3() const; -// TODO - +// template < typename K, typename Polyhedron > std::unique_ptr +// toPolyhedron_3() const; +// TODO //-- Geometry tests -//virtual Geometry * Geometry::clone() const = 0 ; -BOOST_AUTO_TEST_CASE( testClone ) +// virtual Geometry * Geometry::clone() const = 0 ; +BOOST_AUTO_TEST_CASE(testClone) { - std::vector< Triangle > triangles ; - triangles.push_back( Triangle( Point( 0.0,0.0 ), Point( 1.0,0.0 ), Point( 1.0,1.0 ) ) ) ; - triangles.push_back( Triangle( Point( 0.0,0.0 ), Point( 1.0,1.0 ), Point( 0.0,1.0 ) ) ) ; + std::vector triangles; + triangles.emplace_back(Point(0.0, 0.0), Point(1.0, 0.0), Point(1.0, 1.0)); + triangles.emplace_back(Point(0.0, 0.0), Point(1.0, 1.0), Point(0.0, 1.0)); - TriangulatedSurface g( triangles ) ; + TriangulatedSurface const g(triangles); - std::unique_ptr< Geometry > copy( g.clone() ); - BOOST_REQUIRE( copy->is< TriangulatedSurface >() ); - BOOST_CHECK_EQUAL( copy->as< TriangulatedSurface >().numTriangles(), 2U ); + std::unique_ptr copy(g.clone()); + BOOST_REQUIRE(copy->is()); + BOOST_CHECK_EQUAL(copy->as().numTriangles(), 2U); } -//virtual Geometry* Geometry::boundary() const ; -BOOST_AUTO_TEST_CASE( testBoundary ) +// virtual Geometry* Geometry::boundary() const ; +BOOST_AUTO_TEST_CASE(testBoundary) { - std::vector< Triangle > triangles ; - triangles.push_back( Triangle( Point( 0.0,0.0 ), Point( 1.0,0.0 ), Point( 1.0,1.0 ) ) ) ; - triangles.push_back( Triangle( Point( 0.0,0.0 ), Point( 1.0,1.0 ), Point( 0.0,1.0 ) ) ) ; - - TriangulatedSurface g( triangles ) ; - std::unique_ptr< Geometry > boundary( g.boundary() ); - // TODO add algorithm::lineMerge and update - BOOST_CHECK_EQUAL( boundary->asText( 0 ), "MULTILINESTRING((0 0,1 0),(1 0,1 1),(1 1,0 1),(0 1,0 0))" ); + std::vector triangles; + triangles.emplace_back(Point(0.0, 0.0), Point(1.0, 0.0), Point(1.0, 1.0)); + triangles.emplace_back(Point(0.0, 0.0), Point(1.0, 1.0), Point(0.0, 1.0)); + + TriangulatedSurface const g(triangles); + std::unique_ptr boundary(g.boundary()); + // TODO add algorithm::lineMerge and update + BOOST_CHECK_EQUAL(boundary->asText(0), + "MULTILINESTRING((0 0,1 0),(1 0,1 1),(1 1,0 1),(0 1,0 0))"); } -BOOST_AUTO_TEST_CASE( testBoundaryClosed ) +BOOST_AUTO_TEST_CASE(testBoundaryClosed) { - Point a( 0.0, 0.0, 0.0 ); - Point b( 1.0, 0.0, 0.0 ); - Point c( 0.0, 1.0, 0.0 ); - Point d( 0.0, 0.0, 1.0 ); - - std::vector< Triangle > triangles ; - triangles.push_back( Triangle( a, c, b ) ) ; - triangles.push_back( Triangle( a, b, d ) ) ; - triangles.push_back( Triangle( b, c, d ) ) ; - triangles.push_back( Triangle( c, a, d ) ) ; - - TriangulatedSurface g( triangles ) ; - std::unique_ptr< Geometry > boundary( g.boundary() ); - BOOST_CHECK( boundary->isEmpty() ); + Point const a(0.0, 0.0, 0.0); + Point const b(1.0, 0.0, 0.0); + Point const c(0.0, 1.0, 0.0); + Point const d(0.0, 0.0, 1.0); + + std::vector triangles; + triangles.emplace_back(a, c, b); + triangles.emplace_back(a, b, d); + triangles.emplace_back(b, c, d); + triangles.emplace_back(c, a, d); + + TriangulatedSurface const g(triangles); + std::unique_ptr boundary(g.boundary()); + BOOST_CHECK(boundary->isEmpty()); } - -//Envelope Geometry::envelope() const ; -BOOST_AUTO_TEST_CASE( testEnvelope ) +// Envelope Geometry::envelope() const ; +BOOST_AUTO_TEST_CASE(testEnvelope) { - Point a( 0.0, 0.0, 0.0 ); - Point b( 1.0, 0.0, 0.0 ); - Point c( 0.0, 1.0, 0.0 ); - Point d( 0.0, 0.0, 1.0 ); - - std::vector< Triangle > triangles ; - triangles.push_back( Triangle( a, c, b ) ) ; - triangles.push_back( Triangle( a, b, d ) ) ; - triangles.push_back( Triangle( b, c, d ) ) ; - triangles.push_back( Triangle( c, a, d ) ) ; - - TriangulatedSurface g( triangles ) ; - Envelope bbox = g.envelope() ; - BOOST_CHECK_EQUAL( bbox.xMin(), 0.0 ); - BOOST_CHECK_EQUAL( bbox.xMax(), 1.0 ); - BOOST_CHECK_EQUAL( bbox.yMin(), 0.0 ); - BOOST_CHECK_EQUAL( bbox.yMax(), 1.0 ); - BOOST_CHECK_EQUAL( bbox.zMin(), 0.0 ); - BOOST_CHECK_EQUAL( bbox.zMax(), 1.0 ); + Point const a(0.0, 0.0, 0.0); + Point const b(1.0, 0.0, 0.0); + Point const c(0.0, 1.0, 0.0); + Point const d(0.0, 0.0, 1.0); + + std::vector triangles; + triangles.emplace_back(a, c, b); + triangles.emplace_back(a, b, d); + triangles.emplace_back(b, c, d); + triangles.emplace_back(c, a, d); + + TriangulatedSurface const g(triangles); + Envelope const bbox = g.envelope(); + BOOST_CHECK_EQUAL(bbox.xMin(), 0.0); + BOOST_CHECK_EQUAL(bbox.xMax(), 1.0); + BOOST_CHECK_EQUAL(bbox.yMin(), 0.0); + BOOST_CHECK_EQUAL(bbox.yMax(), 1.0); + BOOST_CHECK_EQUAL(bbox.zMin(), 0.0); + BOOST_CHECK_EQUAL(bbox.zMax(), 1.0); } -//std::string Geometry::asText( const int & numDecimals = -1 ) const ; -//TODO +// std::string Geometry::asText( const int & numDecimals = -1 ) const ; +// TODO -//virtual std::string Geometry::geometryType() const = 0 ; -BOOST_AUTO_TEST_CASE( testGeometryType ) +// virtual std::string Geometry::geometryType() const = 0 ; +BOOST_AUTO_TEST_CASE(testGeometryType) { - TriangulatedSurface g; - BOOST_CHECK_EQUAL( g.geometryType(), "TriangulatedSurface" ); + TriangulatedSurface const g; + BOOST_CHECK_EQUAL(g.geometryType(), "TriangulatedSurface"); } -//virtual GeometryType Geometry::geometryTypeId() const = 0 ; -BOOST_AUTO_TEST_CASE( testGeometryTypeId ) +// virtual GeometryType Geometry::geometryTypeId() const = 0 ; +BOOST_AUTO_TEST_CASE(testGeometryTypeId) { - TriangulatedSurface g; - BOOST_CHECK_EQUAL( g.geometryTypeId(), TYPE_TRIANGULATEDSURFACE ); + TriangulatedSurface const g; + BOOST_CHECK_EQUAL(g.geometryTypeId(), TYPE_TRIANGULATEDSURFACE); } -//virtual int Geometry::dimension() const = 0 ; -BOOST_AUTO_TEST_CASE( testDimension ) +// virtual int Geometry::dimension() const = 0 ; +BOOST_AUTO_TEST_CASE(testDimension) { - TriangulatedSurface g; - BOOST_CHECK_EQUAL( g.dimension(), 2 ); //surface + TriangulatedSurface const g; + BOOST_CHECK_EQUAL(g.dimension(), 2); // surface } -//virtual int Geometry::coordinateDimension() const = 0 ; -//virtual bool Geometry::isEmpty() const = 0 ; -//virtual bool Geometry::is3D() const = 0 ; -//virtual bool Geometry::isMeasured() const = 0 ; -//virtual bool Geometry::isSimple() const = 0 ; -//template < typename Derived > inline bool Geometry::is() const -BOOST_AUTO_TEST_CASE( isTriangulatedSurface ) +// virtual int Geometry::coordinateDimension() const = 0 ; +// virtual bool Geometry::isEmpty() const = 0 ; +// virtual bool Geometry::is3D() const = 0 ; +// virtual bool Geometry::isMeasured() const = 0 ; +// virtual bool Geometry::isSimple() const = 0 ; +// template < typename Derived > inline bool Geometry::is() const +BOOST_AUTO_TEST_CASE(isTriangulatedSurface) { - TriangulatedSurface g; - BOOST_CHECK( g.is< TriangulatedSurface >() ); + TriangulatedSurface const g; + BOOST_CHECK(g.is()); } -//template < typename Derived > inline const Derived & Geometry::as() const -//template < typename Derived > inline Derived & Geometry::as() - - +// template < typename Derived > inline const Derived & Geometry::as() const +// template < typename Derived > inline Derived & Geometry::as() //-- other tests -BOOST_AUTO_TEST_CASE( polyhedronConversionTest ) +BOOST_AUTO_TEST_CASE(polyhedronConversionTest) { - // two unit squares sharing a common edge (1,0)-(1,1) - std::string gstr = "POLYHEDRALSURFACE(((0 0 0,0 1 0,1 1 0,1 0 0,0 0 0))," - "((1 0 0,1 1 0,2 1 0,2 0 0,1 0 0)))"; - // the following surface would generate an exception, since the two polygons have opposite orientations - // "POLYHEDRALSURFACE(((0 0 0,0 1 0,1 1 0,1 0 0,0 0 0)),((2 0 0,2 1 0,1 1 0,1 0 0,2 0 0)))"; - std::unique_ptr g( io::readWkt( gstr ) ); - - TriangulatedSurface tri; - triangulate::triangulatePolygon3D( *g, tri ); - - std::unique_ptr > poly( tri.toPolyhedron_3 >() ); - // we check the two squares share a common edge - BOOST_CHECK_EQUAL( poly->size_of_facets(), 4U ); - BOOST_CHECK_EQUAL( poly->size_of_vertices(), 6U ); + // two unit squares sharing a common edge (1,0)-(1,1) + std::string const gstr = + "POLYHEDRALSURFACE(((0 0 0,0 1 0,1 1 0,1 0 0,0 0 0))," + "((1 0 0,1 1 0,2 1 0,2 0 0,1 0 0)))"; + // the following surface would generate an exception, since the two polygons + // have opposite orientations "POLYHEDRALSURFACE(((0 0 0,0 1 0,1 1 0,1 0 0,0 0 + // 0)),((2 0 0,2 1 0,1 1 0,1 0 0,2 0 0)))"; + std::unique_ptr const g(io::readWkt(gstr)); + + TriangulatedSurface tri; + triangulate::triangulatePolygon3D(*g, tri); + + std::unique_ptr> poly( + tri.toPolyhedron_3>()); + // we check the two squares share a common edge + BOOST_CHECK_EQUAL(poly->size_of_facets(), 4U); + BOOST_CHECK_EQUAL(poly->size_of_vertices(), 6U); } BOOST_AUTO_TEST_SUITE_END() - - - - diff --git a/test/unit/SFCGAL/algorithm/AlphaShapesTest.cpp b/test/unit/SFCGAL/algorithm/AlphaShapesTest.cpp index 6534ca1c..3e979afe 100644 --- a/test/unit/SFCGAL/algorithm/AlphaShapesTest.cpp +++ b/test/unit/SFCGAL/algorithm/AlphaShapesTest.cpp @@ -45,20 +45,22 @@ BOOST_AUTO_TEST_SUITE(SFCGAL_algorithm_AlphaShapesTest) // algorithm::alphaShapes -BOOST_AUTO_TEST_CASE(testAlphaShapes2D_ComputeAlpha) { +BOOST_AUTO_TEST_CASE(testAlphaShapes2D_ComputeAlpha) +{ std::vector points; - points.push_back(Point(0.0, 0.0)); - points.push_back(Point(1.0, 0.0)); - points.push_back(Point(1.0, 1.0)); - points.push_back(Point(0.0, 1.0)); - - LineString lineString(points); - size_t nb_comp = 3; - std::unique_ptr alphaShapes( + points.emplace_back(0.0, 0.0); + points.emplace_back(1.0, 0.0); + points.emplace_back(1.0, 1.0); + points.emplace_back(0.0, 1.0); + + LineString const lineString(points); + size_t const nb_comp = 3; + std::unique_ptr const alphaShapes( algorithm::optimal_alpha_shapes(lineString, false, nb_comp)); } -BOOST_AUTO_TEST_CASE(testAlphaShapes2D_Empty) { +BOOST_AUTO_TEST_CASE(testAlphaShapes2D_Empty) +{ GeometryCollection collect; collect.addGeometry(Polygon()); collect.addGeometry(Polygon()); @@ -66,7 +68,8 @@ BOOST_AUTO_TEST_CASE(testAlphaShapes2D_Empty) { BOOST_CHECK(alphaShapes->isEmpty()); } -BOOST_AUTO_TEST_CASE(testAlphaShapes2D_ColinearProduceEmpty) { +BOOST_AUTO_TEST_CASE(testAlphaShapes2D_ColinearProduceEmpty) +{ LineString lineString; lineString.addPoint(Point(0.0, 0.0)); lineString.addPoint(Point(1.0, 1.0)); @@ -76,37 +79,40 @@ BOOST_AUTO_TEST_CASE(testAlphaShapes2D_ColinearProduceEmpty) { BOOST_CHECK(alphaShapes->isEmpty()); } -BOOST_AUTO_TEST_CASE(testAlphaShapes2D_Triangle) { +BOOST_AUTO_TEST_CASE(testAlphaShapes2D_Triangle) +{ std::vector points; - points.push_back(Point(0.0, 0.0)); - points.push_back(Point(0.5, 0.5)); - points.push_back(Point(1.0, 0.0)); - points.push_back(Point(0.0, 1.0)); + points.emplace_back(0.0, 0.0); + points.emplace_back(0.5, 0.5); + points.emplace_back(1.0, 0.0); + points.emplace_back(0.0, 1.0); - LineString lineString(points); + LineString const lineString(points); std::unique_ptr alphaShapes(algorithm::alphaShapes(lineString)); BOOST_CHECK(alphaShapes->is()); - std::string expectedWkt = + std::string const expectedWkt = "POLYGON((0.0 0.0,0.0 1.0,0.5 0.5,1.0 0.0,0.0 0.0))"; BOOST_CHECK_EQUAL(alphaShapes->asText(1), expectedWkt); } -BOOST_AUTO_TEST_CASE(testAlphaShapes2D_Polygon) { +BOOST_AUTO_TEST_CASE(testAlphaShapes2D_Polygon) +{ std::vector points; - points.push_back(Point(0.0, 0.0)); - points.push_back(Point(1.0, 0.0)); - points.push_back(Point(1.0, 1.0)); - points.push_back(Point(0.0, 1.0)); + points.emplace_back(0.0, 0.0); + points.emplace_back(1.0, 0.0); + points.emplace_back(1.0, 1.0); + points.emplace_back(0.0, 1.0); - LineString lineString(points); + LineString const lineString(points); std::unique_ptr alphaShapes(algorithm::alphaShapes(lineString)); BOOST_CHECK(alphaShapes->is()); - std::string expectedWkt = + std::string const expectedWkt = "POLYGON((0.0 0.0,0.0 1.0,1.0 1.0,1.0 0.0,0.0 0.0))"; BOOST_CHECK_EQUAL(alphaShapes->asText(1), expectedWkt); } -BOOST_AUTO_TEST_CASE(testAlphaShapes2D_MultiPoint) { +BOOST_AUTO_TEST_CASE(testAlphaShapes2D_MultiPoint) +{ std::string inputData(SFCGAL_TEST_DIRECTORY); inputData += "/data/AlphaShapesWkt.txt"; std::ifstream ifs(inputData.c_str()); diff --git a/test/unit/SFCGAL/algorithm/ApproximateMedialAxis.cpp b/test/unit/SFCGAL/algorithm/ApproximateMedialAxis.cpp index 5d6be3eb..d0e4acf6 100644 --- a/test/unit/SFCGAL/algorithm/ApproximateMedialAxis.cpp +++ b/test/unit/SFCGAL/algorithm/ApproximateMedialAxis.cpp @@ -15,127 +15,163 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include +#include #include -#include #include -#include -#include -#include -#include -#include -#include -#include #include +#include #include #include -#include -#include +#include +#include +#include +#include +#include +#include #include +#include +#include #include -using namespace boost::unit_test ; -using namespace SFCGAL ; - -BOOST_AUTO_TEST_SUITE( SFCGAL_algorithm_ApproximateMedialAxisTest ) +using namespace boost::unit_test; +using namespace SFCGAL; +BOOST_AUTO_TEST_SUITE(SFCGAL_algorithm_ApproximateMedialAxisTest) -BOOST_AUTO_TEST_CASE( testTriangle45 ) +BOOST_AUTO_TEST_CASE(testTriangle45) { - std::unique_ptr< Geometry > g( io::readWkt( "TRIANGLE((1 1,2 1,2 2,1 1))" ) ); - - std::string expectedWKT( "MULTILINESTRING((1.0 1.0,1.7 1.3),(2.0 2.0,1.7 1.3))"); - { - std::unique_ptr< MultiLineString > result( algorithm::approximateMedialAxis( *g ) ) ; - BOOST_CHECK_EQUAL( result->asText( 1 ), expectedWKT ); - } + std::unique_ptr const g(io::readWkt("TRIANGLE((1 1,2 1,2 2,1 1))")); + + std::string const expectedWKT( + "MULTILINESTRING((1.0 1.0,1.7 1.3),(2.0 2.0,1.7 1.3))"); + { + std::unique_ptr result( + algorithm::approximateMedialAxis(*g)); + BOOST_CHECK_EQUAL(result->asText(1), expectedWKT); + } } -BOOST_AUTO_TEST_CASE( testTriangle60 ) +BOOST_AUTO_TEST_CASE(testTriangle60) { - std::unique_ptr< Geometry > g( io::readWkt( "TRIANGLE((1 1,3 1,2 3,1 1))" ) ); - - std::string expectedWKT( "MULTILINESTRING EMPTY" ); - { - std::unique_ptr< MultiLineString > result( algorithm::approximateMedialAxis( *g ) ) ; - BOOST_CHECK_EQUAL( result->numGeometries(), 0U ); - BOOST_CHECK_EQUAL( result->asText( 1 ), expectedWKT ); - } + std::unique_ptr const g(io::readWkt("TRIANGLE((1 1,3 1,2 3,1 1))")); + + std::string const expectedWKT("MULTILINESTRING EMPTY"); + { + std::unique_ptr result( + algorithm::approximateMedialAxis(*g)); + BOOST_CHECK_EQUAL(result->numGeometries(), 0U); + BOOST_CHECK_EQUAL(result->asText(1), expectedWKT); + } } -BOOST_AUTO_TEST_CASE( testPolygon ) +BOOST_AUTO_TEST_CASE(testPolygon) { - std::unique_ptr< Geometry > g( io::readWkt( "POLYGON((0 0,20 0,20 10,0 10,0 0))" ) ); - - std::string expectedWKT( "MULTILINESTRING((5 5,15 5))" ); - { - std::unique_ptr< MultiLineString > result( algorithm::approximateMedialAxis( *g ) ) ; - BOOST_CHECK_EQUAL( result->numGeometries(), 1U ); - BOOST_CHECK_EQUAL( result->asText( 0 ), expectedWKT ); - } + std::unique_ptr const g( + io::readWkt("POLYGON((0 0,20 0,20 10,0 10,0 0))")); + + std::string const expectedWKT("MULTILINESTRING((5 5,15 5))"); + { + std::unique_ptr result( + algorithm::approximateMedialAxis(*g)); + BOOST_CHECK_EQUAL(result->numGeometries(), 1U); + BOOST_CHECK_EQUAL(result->asText(0), expectedWKT); + } } -BOOST_AUTO_TEST_CASE( testPolygonWithHole ) +BOOST_AUTO_TEST_CASE(testPolygonWithHole) { - std::unique_ptr< Geometry > g( io::readWkt( "POLYGON( (0 0,10 0,10 10,0 10,0 0)" - ", (4 4,4 6,6 6,6 4,4 4)" - ")" - ) - ); - - std::unique_ptr< MultiLineString > result( algorithm::approximateMedialAxis( *g ) ) ; - BOOST_CHECK_EQUAL( result->numGeometries(), 4 ); - - std::unique_ptr< Geometry > expected( io::readWkt( "MULTILINESTRING( (2 2,8 2)" - ", (2 2,2 8)" - ", (8 2,8 8)" - ", (2 8,8 8)" - ")" - ) - ); - - BOOST_CHECK( algorithm::covers( *result, *expected ) ); + std::unique_ptr const g( + io::readWkt("POLYGON( (0 0,10 0,10 10,0 10,0 0)" + ", (4 4,4 6,6 6,6 4,4 4)" + ")")); + + std::unique_ptr result(algorithm::approximateMedialAxis(*g)); + BOOST_CHECK_EQUAL(result->numGeometries(), 4); + + std::unique_ptr const expected( + io::readWkt("MULTILINESTRING( (2 2,8 2)" + ", (2 2,2 8)" + ", (8 2,8 8)" + ", (2 8,8 8)" + ")")); + + BOOST_CHECK(algorithm::covers(*result, *expected)); } -BOOST_AUTO_TEST_CASE( testPolygonWithTouchingHoles ) +BOOST_AUTO_TEST_CASE(testPolygonWithTouchingHoles) { - std::unique_ptr< Geometry > g( io::readWkt( "POLYGON((-1.0 -1.0,1.0 -1.0,1.0 1.0,-1.0 1.0,-1.0 -1.0),(-0.5 -0.5,-0.5 0.5,-0.1 0.5,0.1 -0.5,-0.5 -0.5),(0.1 -0.5,0.1 0.5,0.5 0.5,0.5 -0.5,0.1 -0.5))" ) ); - - // just for valgrind - BOOST_CHECK_THROW( std::unique_ptr< MultiLineString > result( algorithm::approximateMedialAxis( *g ) ), NotImplementedException ) ; - + std::unique_ptr const g( + io::readWkt("POLYGON((-1.0 -1.0,1.0 -1.0,1.0 1.0,-1.0 1.0,-1.0 " + "-1.0),(-0.5 -0.5,-0.5 0.5,-0.1 0.5,0.1 -0.5,-0.5 -0.5),(0.1 " + "-0.5,0.1 0.5,0.5 0.5,0.5 -0.5,0.1 -0.5))")); + + // just for valgrind + BOOST_CHECK_THROW(std::unique_ptr result( + algorithm::approximateMedialAxis(*g)), + NotImplementedException); } -BOOST_AUTO_TEST_CASE( testMultiPolygon ) +BOOST_AUTO_TEST_CASE(testMultiPolygon) { - std::unique_ptr< Geometry > g( io::readWkt( "MULTIPOLYGON(((3.000000 0.000000,2.875000 0.484123,2.750000 0.661438,2.625000 0.780625,2.500000 0.866025,2.375000 0.927025,2.250000 0.968246,2.125000 0.992157,2.000000 1.000000,1.875000 1.484123,1.750000 1.661438,1.625000 1.780625,1.500000 1.866025,1.375000 1.927025,1.250000 1.968246,1.125000 1.992157,1.000000 2.000000,0.750000 2.661438,0.500000 2.866025,0.250000 2.968246,0.000000 3.000000,-0.250000 2.968246,-0.500000 2.866025,-0.750000 2.661438,-1.000000 2.000000,-1.125000 1.992157,-1.250000 1.968246,-1.375000 1.927025,-1.500000 1.866025,-1.625000 1.780625,-1.750000 1.661438,-1.875000 1.484123,-2.000000 1.000000,-2.125000 0.992157,-2.250000 0.968246,-2.375000 0.927025,-2.500000 0.866025,-2.625000 0.780625,-2.750000 0.661438,-2.875000 0.484123,-3.000000 0.000000,-2.875000 -0.484123,-2.750000 -0.661438,-2.625000 -0.780625,-2.500000 -0.866025,-2.375000 -0.927025,-2.250000 -0.968246,-2.125000 -0.992157,-2.000000 -1.000000,-1.875000 -1.484123,-1.750000 -1.661438,-1.625000 -1.780625,-1.500000 -1.866025,-1.375000 -1.927025,-1.250000 -1.968246,-1.125000 -1.992157,-1.000000 -2.000000,-0.750000 -2.661438,-0.500000 -2.866025,-0.250000 -2.968246,0.000000 -3.000000,0.250000 -2.968246,0.500000 -2.866025,0.750000 -2.661438,1.000000 -2.000000,1.125000 -1.992157,1.250000 -1.968246,1.375000 -1.927025,1.500000 -1.866025,1.625000 -1.780625,1.750000 -1.661438,1.875000 -1.484123,2.000000 -1.000000,2.125000 -0.992157,2.250000 -0.968246,2.375000 -0.927025,2.500000 -0.866025,2.625000 -0.780625,2.750000 -0.661438,2.875000 -0.484123,3.000000 0.000000),(0.000000 1.000000,0.125000 0.515877,0.250000 0.338562,0.375000 0.219375,0.500000 0.133975,0.625000 0.072975,0.750000 0.031754,0.875000 0.007843,1.000000 0.000000,0.875000 -0.007843,0.750000 -0.031754,0.625000 -0.072975,0.500000 -0.133975,0.375000 -0.219375,0.250000 -0.338562,0.125000 -0.515877,0.000000 -1.000000,-0.125000 -0.515877,-0.250000 -0.338562,-0.375000 -0.219375,-0.500000 -0.133975,-0.625000 -0.072975,-0.750000 -0.031754,-0.875000 -0.007843,-1.000000 0.000000,-0.875000 0.007843,-0.750000 0.031754,-0.625000 0.072975,-0.500000 0.133975,-0.375000 0.219375,-0.250000 0.338562,-0.125000 0.515877,0.000000 1.000000)))" ) ); - std::unique_ptr< MultiLineString > result( algorithm::approximateMedialAxis( *g ) ) ; - BOOST_CHECK_EQUAL( result->numGeometries(), 108U ); + std::unique_ptr const g(io::readWkt( + "MULTIPOLYGON(((3.000000 0.000000,2.875000 0.484123,2.750000 " + "0.661438,2.625000 0.780625,2.500000 0.866025,2.375000 0.927025,2.250000 " + "0.968246,2.125000 0.992157,2.000000 1.000000,1.875000 1.484123,1.750000 " + "1.661438,1.625000 1.780625,1.500000 1.866025,1.375000 1.927025,1.250000 " + "1.968246,1.125000 1.992157,1.000000 2.000000,0.750000 2.661438,0.500000 " + "2.866025,0.250000 2.968246,0.000000 3.000000,-0.250000 " + "2.968246,-0.500000 2.866025,-0.750000 2.661438,-1.000000 " + "2.000000,-1.125000 1.992157,-1.250000 1.968246,-1.375000 " + "1.927025,-1.500000 1.866025,-1.625000 1.780625,-1.750000 " + "1.661438,-1.875000 1.484123,-2.000000 1.000000,-2.125000 " + "0.992157,-2.250000 0.968246,-2.375000 0.927025,-2.500000 " + "0.866025,-2.625000 0.780625,-2.750000 0.661438,-2.875000 " + "0.484123,-3.000000 0.000000,-2.875000 -0.484123,-2.750000 " + "-0.661438,-2.625000 -0.780625,-2.500000 -0.866025,-2.375000 " + "-0.927025,-2.250000 -0.968246,-2.125000 -0.992157,-2.000000 " + "-1.000000,-1.875000 -1.484123,-1.750000 -1.661438,-1.625000 " + "-1.780625,-1.500000 -1.866025,-1.375000 -1.927025,-1.250000 " + "-1.968246,-1.125000 -1.992157,-1.000000 -2.000000,-0.750000 " + "-2.661438,-0.500000 -2.866025,-0.250000 -2.968246,0.000000 " + "-3.000000,0.250000 -2.968246,0.500000 -2.866025,0.750000 " + "-2.661438,1.000000 -2.000000,1.125000 -1.992157,1.250000 " + "-1.968246,1.375000 -1.927025,1.500000 -1.866025,1.625000 " + "-1.780625,1.750000 -1.661438,1.875000 -1.484123,2.000000 " + "-1.000000,2.125000 -0.992157,2.250000 -0.968246,2.375000 " + "-0.927025,2.500000 -0.866025,2.625000 -0.780625,2.750000 " + "-0.661438,2.875000 -0.484123,3.000000 0.000000),(0.000000 " + "1.000000,0.125000 0.515877,0.250000 0.338562,0.375000 0.219375,0.500000 " + "0.133975,0.625000 0.072975,0.750000 0.031754,0.875000 0.007843,1.000000 " + "0.000000,0.875000 -0.007843,0.750000 -0.031754,0.625000 " + "-0.072975,0.500000 -0.133975,0.375000 -0.219375,0.250000 " + "-0.338562,0.125000 -0.515877,0.000000 -1.000000,-0.125000 " + "-0.515877,-0.250000 -0.338562,-0.375000 -0.219375,-0.500000 " + "-0.133975,-0.625000 -0.072975,-0.750000 -0.031754,-0.875000 " + "-0.007843,-1.000000 0.000000,-0.875000 0.007843,-0.750000 " + "0.031754,-0.625000 0.072975,-0.500000 0.133975,-0.375000 " + "0.219375,-0.250000 0.338562,-0.125000 0.515877,0.000000 1.000000)))")); + std::unique_ptr result(algorithm::approximateMedialAxis(*g)); + BOOST_CHECK_EQUAL(result->numGeometries(), 108U); } - -BOOST_AUTO_TEST_CASE( testInvalidTypes ) +BOOST_AUTO_TEST_CASE(testInvalidTypes) { - std::vector< std::string > wkt; - wkt.push_back( "POINT(1 2)" ); - wkt.push_back( "LINESTRING(0 0,1 1)" ); - - for ( std::vector< std::string >::const_iterator it=wkt.begin(), - itE=wkt.end(); - it != itE; ++it ) - { - std::unique_ptr< Geometry > g( io::readWkt( *it ) ); - std::unique_ptr< MultiLineString > result( - algorithm::approximateMedialAxis( *g ) - ); - BOOST_CHECK_EQUAL( result->numGeometries(), 0U ); - } + std::vector wkt; + wkt.emplace_back("POINT(1 2)"); + wkt.emplace_back("LINESTRING(0 0,1 1)"); + + for (auto &it : wkt) { + std::unique_ptr const g(io::readWkt(it)); + std::unique_ptr result( + algorithm::approximateMedialAxis(*g)); + BOOST_CHECK_EQUAL(result->numGeometries(), 0U); + } } - BOOST_AUTO_TEST_SUITE_END() - diff --git a/test/unit/SFCGAL/algorithm/AreaTest.cpp b/test/unit/SFCGAL/algorithm/AreaTest.cpp index fb33156e..f651e810 100644 --- a/test/unit/SFCGAL/algorithm/AreaTest.cpp +++ b/test/unit/SFCGAL/algorithm/AreaTest.cpp @@ -15,183 +15,182 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include +#include #include -#include #include -#include -#include -#include -#include -#include -#include -#include #include +#include #include #include -#include +#include +#include +#include +#include +#include +#include #include +#include #include -using namespace boost::unit_test ; -using namespace SFCGAL ; +using namespace boost::unit_test; +using namespace SFCGAL; -BOOST_AUTO_TEST_SUITE( SFCGAL_algorithm_AreaTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_algorithm_AreaTest) - -BOOST_AUTO_TEST_CASE( testEmpty2D3D ) +BOOST_AUTO_TEST_CASE(testEmpty2D3D) { - tools::Registry& registry = tools::Registry::instance() ; - std::vector< std::string > typeNames = tools::Registry::instance().getGeometryTypes(); - - for ( size_t i = 0; i < typeNames.size(); i++ ) { - BOOST_TEST_MESSAGE( typeNames[i] ) ; - - std::unique_ptr< Geometry > g( registry.newGeometryByTypeName( typeNames[i] ) ) ; - BOOST_REQUIRE( g.get() != NULL ) ; - BOOST_CHECK_EQUAL( algorithm::area( *g ), 0.0 ); - BOOST_CHECK_EQUAL( algorithm::area3D( *g ), 0.0 ); - } + tools::Registry const ®istry = tools::Registry::instance(); + std::vector const typeNames = + tools::Registry::instance().getGeometryTypes(); + + for (const auto &typeName : typeNames) { + BOOST_TEST_MESSAGE(typeName); + + std::unique_ptr const g(registry.newGeometryByTypeName(typeName)); + BOOST_REQUIRE(g.get() != NULL); + BOOST_CHECK_EQUAL(algorithm::area(*g), 0.0); + BOOST_CHECK_EQUAL(algorithm::area3D(*g), 0.0); + } } - - -BOOST_AUTO_TEST_CASE( testSignedArea2D_lineString ) +BOOST_AUTO_TEST_CASE(testSignedArea2D_lineString) { - LineString lineString ; - lineString.addPoint( Point( 0.0,0.0 ) ); - lineString.addPoint( Point( 1.0,0.0 ) ); - lineString.addPoint( Point( 1.0,1.0 ) ); - lineString.addPoint( Point( 0.0,1.0 ) ); - lineString.addPoint( lineString.startPoint() ); - - BOOST_CHECK_EQUAL( algorithm::signedArea( lineString ), 1.0 ); - lineString.reverse() ; - BOOST_CHECK_EQUAL( algorithm::signedArea( lineString ), -1.0 ); + LineString lineString; + lineString.addPoint(Point(0.0, 0.0)); + lineString.addPoint(Point(1.0, 0.0)); + lineString.addPoint(Point(1.0, 1.0)); + lineString.addPoint(Point(0.0, 1.0)); + lineString.addPoint(lineString.startPoint()); + + BOOST_CHECK_EQUAL(algorithm::signedArea(lineString), 1.0); + lineString.reverse(); + BOOST_CHECK_EQUAL(algorithm::signedArea(lineString), -1.0); } -BOOST_AUTO_TEST_CASE( testSignedArea2D_triangle ) +BOOST_AUTO_TEST_CASE(testSignedArea2D_triangle) { - Triangle triangle( - Point( 0.0,0.0 ), - Point( 1.0,0.0 ), - Point( 1.0,1.0 ) - ) ; - - BOOST_CHECK_EQUAL( algorithm::signedArea( triangle ), 0.5 ); - triangle.reverse() ; - BOOST_CHECK_EQUAL( algorithm::signedArea( triangle ), -0.5 ); -} - - + Triangle triangle(Point(0.0, 0.0), Point(1.0, 0.0), Point(1.0, 1.0)); + BOOST_CHECK_EQUAL(algorithm::signedArea(triangle), 0.5); + triangle.reverse(); + BOOST_CHECK_EQUAL(algorithm::signedArea(triangle), -0.5); +} // must return 0.0 -BOOST_AUTO_TEST_CASE( testPoint2D3D ) +BOOST_AUTO_TEST_CASE(testPoint2D3D) { - BOOST_CHECK_EQUAL( algorithm::area( Point( 3.0,4.0 ) ), 0.0 ); - BOOST_CHECK_EQUAL( algorithm::area3D( Point( 3.0,4.0,5.0 ) ), 0.0 ); + BOOST_CHECK_EQUAL(algorithm::area(Point(3.0, 4.0)), 0.0); + BOOST_CHECK_EQUAL(algorithm::area3D(Point(3.0, 4.0, 5.0)), 0.0); } // must return 0.0 -BOOST_AUTO_TEST_CASE( testLineString2D3D ) +BOOST_AUTO_TEST_CASE(testLineString2D3D) { - BOOST_CHECK_EQUAL( algorithm::area( LineString( Point( 0.0,0.0 ),Point( 1.0,1.0 ) ) ), 0.0 ); - BOOST_CHECK_EQUAL( algorithm::area3D( LineString( Point( 0.0,0.0,0.0 ),Point( 1.0,1.0,1.0 ) ) ), 0.0 ); + BOOST_CHECK_EQUAL( + algorithm::area(LineString(Point(0.0, 0.0), Point(1.0, 1.0))), 0.0); + BOOST_CHECK_EQUAL( + algorithm::area3D(LineString(Point(0.0, 0.0, 0.0), Point(1.0, 1.0, 1.0))), + 0.0); } // must return 0.0 -BOOST_AUTO_TEST_CASE( testArea2D_PolygonWithHoleWithBadOrientation ) +BOOST_AUTO_TEST_CASE(testArea2D_PolygonWithHoleWithBadOrientation) { - Polygon polygon ; - - // exterior ring - { - LineString ring ; - ring.addPoint( Point( 0.0,0.0 ) ); - ring.addPoint( Point( 5.0,0.0 ) ); - ring.addPoint( Point( 5.0,5.0 ) ); - ring.addPoint( Point( 0.0,5.0 ) ); - ring.addPoint( ring.startPoint() ); - - polygon.setExteriorRing( ring ); - } - - // hole 1 - { - LineString ring ; - ring.addPoint( Point( 1.0,1.0 ) ); - ring.addPoint( Point( 2.0,1.0 ) ); - ring.addPoint( Point( 2.0,2.0 ) ); - ring.addPoint( Point( 1.0,2.0 ) ); - ring.addPoint( ring.startPoint() ); - - polygon.addRing( ring ); - } - - // hole 2 - { - LineString ring ; - ring.addPoint( Point( 3.0,3.0 ) ); - ring.addPoint( Point( 4.0,3.0 ) ); - ring.addPoint( Point( 4.0,4.0 ) ); - ring.addPoint( Point( 3.0,4.0 ) ); - ring.addPoint( ring.startPoint() ); - - polygon.addRing( ring ); - } - - // 5x5 - 1 - 1 = 23 - BOOST_CHECK_EQUAL( algorithm::area3D( polygon ), 23.0 ); + Polygon polygon; + + // exterior ring + { + LineString ring; + ring.addPoint(Point(0.0, 0.0)); + ring.addPoint(Point(5.0, 0.0)); + ring.addPoint(Point(5.0, 5.0)); + ring.addPoint(Point(0.0, 5.0)); + ring.addPoint(ring.startPoint()); + + polygon.setExteriorRing(ring); + } + + // hole 1 + { + LineString ring; + ring.addPoint(Point(1.0, 1.0)); + ring.addPoint(Point(2.0, 1.0)); + ring.addPoint(Point(2.0, 2.0)); + ring.addPoint(Point(1.0, 2.0)); + ring.addPoint(ring.startPoint()); + + polygon.addRing(ring); + } + + // hole 2 + { + LineString ring; + ring.addPoint(Point(3.0, 3.0)); + ring.addPoint(Point(4.0, 3.0)); + ring.addPoint(Point(4.0, 4.0)); + ring.addPoint(Point(3.0, 4.0)); + ring.addPoint(ring.startPoint()); + + polygon.addRing(ring); + } + + // 5x5 - 1 - 1 = 23 + BOOST_CHECK_EQUAL(algorithm::area3D(polygon), 23.0); } - - -BOOST_AUTO_TEST_CASE( testArea3D_Triangle1 ) +BOOST_AUTO_TEST_CASE(testArea3D_Triangle1) { - Triangle triangle( Point( 0.0,0.0,0.0 ), Point( 0.0,0.0,1.0 ), Point( 0.0,1.0, 0.0 ) ); - BOOST_CHECK_EQUAL( algorithm::area3D( triangle ), 0.5 ); + Triangle const triangle(Point(0.0, 0.0, 0.0), Point(0.0, 0.0, 1.0), + Point(0.0, 1.0, 0.0)); + BOOST_CHECK_EQUAL(algorithm::area3D(triangle), 0.5); } -BOOST_AUTO_TEST_CASE( testArea3D_Triangle2 ) +BOOST_AUTO_TEST_CASE(testArea3D_Triangle2) { - Triangle triangle( Point( 0.0,0.0,0.0 ), Point( 0.0,0.0,4.0 ), Point( 0.0,4.0, 0.0 ) ); - BOOST_CHECK_EQUAL( algorithm::area3D( triangle ), 8.0 ); + Triangle const triangle(Point(0.0, 0.0, 0.0), Point(0.0, 0.0, 4.0), + Point(0.0, 4.0, 0.0)); + BOOST_CHECK_EQUAL(algorithm::area3D(triangle), 8.0); } -BOOST_AUTO_TEST_CASE( testArea2D_Triangle ) +BOOST_AUTO_TEST_CASE(testArea2D_Triangle) { - Triangle triangle1( Point( 0.0,0.0 ), Point( 4.0,0.0 ), Point( 4.0,4.0 ) ); - // the same, inverted - Triangle triangle2( Point( 0.0,0.0 ), Point( 0.0,4.0 ), Point( 4.0,4.0 ) ); - BOOST_CHECK_EQUAL( algorithm::area( triangle1 ), 8.0 ); - BOOST_CHECK_EQUAL( algorithm::area( triangle2 ), 8.0 ); + Triangle const triangle1(Point(0.0, 0.0), Point(4.0, 0.0), Point(4.0, 4.0)); + // the same, inverted + Triangle const triangle2(Point(0.0, 0.0), Point(0.0, 4.0), Point(4.0, 4.0)); + BOOST_CHECK_EQUAL(algorithm::area(triangle1), 8.0); + BOOST_CHECK_EQUAL(algorithm::area(triangle2), 8.0); } -BOOST_AUTO_TEST_CASE( testArea3D_Square1x1 ) +BOOST_AUTO_TEST_CASE(testArea3D_Square1x1) { - std::unique_ptr< Geometry > g( io::readWkt( "POLYGON((0.0 0.0 0.0,0.0 0.0 1.0,0.0 1.0 1.0,0.0 1.0 0.0,0.0 0.0 0.0))" ) ); - BOOST_CHECK_EQUAL( g->asText( 1 ), "POLYGON Z((0.0 0.0 0.0,0.0 0.0 1.0,0.0 1.0 1.0,0.0 1.0 0.0,0.0 0.0 0.0))" ); - BOOST_CHECK_CLOSE( algorithm::area3D( *g ), 1.0, 1e-10 ); + std::unique_ptr g( + io::readWkt("POLYGON((0.0 0.0 0.0,0.0 0.0 1.0,0.0 1.0 1.0,0.0 1.0 " + "0.0,0.0 0.0 0.0))")); + BOOST_CHECK_EQUAL(g->asText(1), "POLYGON Z((0.0 0.0 0.0,0.0 0.0 1.0,0.0 1.0 " + "1.0,0.0 1.0 0.0,0.0 0.0 0.0))"); + BOOST_CHECK_CLOSE(algorithm::area3D(*g), 1.0, 1e-10); } -BOOST_AUTO_TEST_CASE( testArea3D_Square4X4 ) +BOOST_AUTO_TEST_CASE(testArea3D_Square4X4) { - std::string wkt( "POLYGON((0.0 0.0 0.0,0.0 0.0 4.0,0.0 4.0 4.0,0.0 4.0 0.0,0.0 0.0 0.0))" ); - std::unique_ptr< Geometry > g( io::readWkt( wkt ) ); - BOOST_CHECK_CLOSE( algorithm::area3D( *g ), 16.0, 1e-10 ); + std::string const wkt( + "POLYGON((0.0 0.0 0.0,0.0 0.0 4.0,0.0 4.0 4.0,0.0 4.0 0.0,0.0 0.0 0.0))"); + std::unique_ptr const g(io::readWkt(wkt)); + BOOST_CHECK_CLOSE(algorithm::area3D(*g), 16.0, 1e-10); } -BOOST_AUTO_TEST_CASE( testArea3D_Square4X4WithHole ) +BOOST_AUTO_TEST_CASE(testArea3D_Square4X4WithHole) { - std::string wkt( "POLYGON((0.0 0.0 0.0,0.0 0.0 4.0,0.0 4.0 4.0,0.0 4.0 0.0,0.0 0.0 0.0),(0.0 2.0 2.0,0.0 3.0 2.0,0.0 3.0 3.0,0.0 2.0 3.0,0.0 2.0 2.0))" ); - std::unique_ptr< Geometry > g( io::readWkt( wkt ) ); - BOOST_CHECK_CLOSE( algorithm::area3D( *g ), 15.0, 1e-10 ); + std::string const wkt( + "POLYGON((0.0 0.0 0.0,0.0 0.0 4.0,0.0 4.0 4.0,0.0 4.0 0.0,0.0 0.0 " + "0.0),(0.0 2.0 2.0,0.0 3.0 2.0,0.0 3.0 3.0,0.0 2.0 3.0,0.0 2.0 2.0))"); + std::unique_ptr const g(io::readWkt(wkt)); + BOOST_CHECK_CLOSE(algorithm::area3D(*g), 15.0, 1e-10); } - BOOST_AUTO_TEST_SUITE_END() - diff --git a/test/unit/SFCGAL/algorithm/BoundaryTest.cpp b/test/unit/SFCGAL/algorithm/BoundaryTest.cpp index a04c3ab3..5ac38c80 100644 --- a/test/unit/SFCGAL/algorithm/BoundaryTest.cpp +++ b/test/unit/SFCGAL/algorithm/BoundaryTest.cpp @@ -15,159 +15,157 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include -#include -#include -#include -#include -#include -#include -#include #include -#include +#include #include +#include #include #include +#include +#include +#include +#include +#include +#include #include -using namespace boost::unit_test ; -using namespace SFCGAL ; +using namespace boost::unit_test; +using namespace SFCGAL; -BOOST_AUTO_TEST_SUITE( SFCGAL_algorithm_BoundaryTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_algorithm_BoundaryTest) //-- Point -BOOST_AUTO_TEST_CASE( emptyPoint ) +BOOST_AUTO_TEST_CASE(emptyPoint) { - Point g; - std::unique_ptr< Geometry > boundary( g.boundary() ); + Point const g; + std::unique_ptr boundary(g.boundary()); - BOOST_CHECK( boundary->is< GeometryCollection >() ); - BOOST_CHECK( boundary->isEmpty() ); + BOOST_CHECK(boundary->is()); + BOOST_CHECK(boundary->isEmpty()); } -BOOST_AUTO_TEST_CASE( pointXY ) +BOOST_AUTO_TEST_CASE(pointXY) { - Point g( 2.0,3.0 ); - std::unique_ptr< Geometry > boundary( g.boundary() ); + Point const g(2.0, 3.0); + std::unique_ptr boundary(g.boundary()); - BOOST_CHECK( boundary->is< GeometryCollection >() ); - BOOST_CHECK( boundary->isEmpty() ); + BOOST_CHECK(boundary->is()); + BOOST_CHECK(boundary->isEmpty()); } //-- LineString -BOOST_AUTO_TEST_CASE( emptyLineString ) +BOOST_AUTO_TEST_CASE(emptyLineString) { - LineString g; - std::unique_ptr< Geometry > boundary( g.boundary() ); + LineString const g; + std::unique_ptr boundary(g.boundary()); - BOOST_CHECK( boundary->is< GeometryCollection >() ); - BOOST_CHECK( boundary->isEmpty() ); + BOOST_CHECK(boundary->is()); + BOOST_CHECK(boundary->isEmpty()); } -BOOST_AUTO_TEST_CASE( lineStringSegment ) +BOOST_AUTO_TEST_CASE(lineStringSegment) { - BOOST_TEST_MESSAGE( "check that a LineSegment has a MultiPoint boundary composed of 2 points" ); + BOOST_TEST_MESSAGE("check that a LineSegment has a MultiPoint boundary " + "composed of 2 points"); - LineString g; - g.addPoint( Point( 0.0,0.0 ) ); - g.addPoint( Point( 1.0,1.0 ) ); - std::unique_ptr< Geometry > boundary( g.boundary() ); + LineString g; + g.addPoint(Point(0.0, 0.0)); + g.addPoint(Point(1.0, 1.0)); + std::unique_ptr boundary(g.boundary()); - BOOST_CHECK( boundary->is< MultiPoint >() ); - BOOST_CHECK_EQUAL( boundary->as< MultiPoint >().numGeometries(), 2U ); + BOOST_CHECK(boundary->is()); + BOOST_CHECK_EQUAL(boundary->as().numGeometries(), 2U); } -BOOST_AUTO_TEST_CASE( lineStringWithThreePoints ) +BOOST_AUTO_TEST_CASE(lineStringWithThreePoints) { - BOOST_TEST_MESSAGE( "check that a LineString with 3 points has a MultiPoint boundary composed of 2 points" ); + BOOST_TEST_MESSAGE("check that a LineString with 3 points has a MultiPoint " + "boundary composed of 2 points"); - LineString g; - g.addPoint( Point( 0.0,0.0 ) ); - g.addPoint( Point( 1.0,1.0 ) ); - g.addPoint( Point( 2.0,2.0 ) ); - std::unique_ptr< Geometry > boundary( g.boundary() ); + LineString g; + g.addPoint(Point(0.0, 0.0)); + g.addPoint(Point(1.0, 1.0)); + g.addPoint(Point(2.0, 2.0)); + std::unique_ptr boundary(g.boundary()); - BOOST_CHECK( boundary->is< MultiPoint >() ); - BOOST_CHECK_EQUAL( boundary->as< MultiPoint >().numGeometries(), 2U ); + BOOST_CHECK(boundary->is()); + BOOST_CHECK_EQUAL(boundary->as().numGeometries(), 2U); } -BOOST_AUTO_TEST_CASE( lineStringClosed ) +BOOST_AUTO_TEST_CASE(lineStringClosed) { - BOOST_TEST_MESSAGE( "check that a closed LineString has empty boundary" ); + BOOST_TEST_MESSAGE("check that a closed LineString has empty boundary"); - LineString g; - g.addPoint( Point( 0.0,0.0 ) ); - g.addPoint( Point( 1.0,1.0 ) ); - g.addPoint( Point( 2.0,2.0 ) ); - g.addPoint( Point( 0.0,0.0 ) ); + LineString g; + g.addPoint(Point(0.0, 0.0)); + g.addPoint(Point(1.0, 1.0)); + g.addPoint(Point(2.0, 2.0)); + g.addPoint(Point(0.0, 0.0)); - std::unique_ptr< Geometry > boundary( g.boundary() ); + std::unique_ptr boundary(g.boundary()); - BOOST_CHECK( boundary->isEmpty() ); - BOOST_CHECK( boundary->is< GeometryCollection >() ); + BOOST_CHECK(boundary->isEmpty()); + BOOST_CHECK(boundary->is()); } //-- MultiLineString -BOOST_AUTO_TEST_CASE( multiLineStringSimple ) +BOOST_AUTO_TEST_CASE(multiLineStringSimple) { - BOOST_TEST_MESSAGE( "check common point between two LineStrings" ); + BOOST_TEST_MESSAGE("check common point between two LineStrings"); - MultiLineString g ; - g.addGeometry( LineString( Point( 0.0,0.0 ), Point( 1.0,1.0 ) ) ); - g.addGeometry( LineString( Point( 0.0,0.0 ), Point( 1.0,2.0 ) ) ); + MultiLineString g; + g.addGeometry(LineString(Point(0.0, 0.0), Point(1.0, 1.0))); + g.addGeometry(LineString(Point(0.0, 0.0), Point(1.0, 2.0))); - g.addGeometry( LineString( Point( 1.0,1.0 ), Point( 1.0,2.0 ) ) ); + g.addGeometry(LineString(Point(1.0, 1.0), Point(1.0, 2.0))); - std::unique_ptr< Geometry > boundary( g.boundary() ); + std::unique_ptr boundary(g.boundary()); - BOOST_CHECK( boundary->isEmpty() ); - BOOST_CHECK( boundary->is< GeometryCollection >() ); + BOOST_CHECK(boundary->isEmpty()); + BOOST_CHECK(boundary->is()); } - - //-- MultiPolygon -//TODO TDD +// TODO TDD -BOOST_AUTO_TEST_CASE( multiPolygonSimple ) +BOOST_AUTO_TEST_CASE(multiPolygonSimple) { - BOOST_TEST_MESSAGE( "check common point between two LineStrings" ); - - MultiPolygon g ; - { - LineString ring; - ring.addPoint( Point( 0.0, 0.0 ) ); - ring.addPoint( Point( 1.0, 0.0 ) ); - ring.addPoint( Point( 1.0, 1.0 ) ); - ring.addPoint( Point( 0.0, 1.0 ) ); - ring.addPoint( Point( 0.0, 0.0 ) ); - - g.addGeometry( Polygon( ring ) ); - } - { - LineString ring; - ring.addPoint( Point( 1.0, 0.0 ) ); - ring.addPoint( Point( 2.0, 0.0 ) ); - ring.addPoint( Point( 2.0, 1.0 ) ); - ring.addPoint( Point( 1.0, 1.0 ) ); - ring.addPoint( Point( 1.0, 0.0 ) ); - - g.addGeometry( Polygon( ring ) ); - } - - std::unique_ptr< Geometry > boundary( g.boundary() ); - - BOOST_CHECK( ! boundary->isEmpty() ); - BOOST_CHECK( boundary->is< MultiLineString >() ); + BOOST_TEST_MESSAGE("check common point between two LineStrings"); + + MultiPolygon g; + { + LineString ring; + ring.addPoint(Point(0.0, 0.0)); + ring.addPoint(Point(1.0, 0.0)); + ring.addPoint(Point(1.0, 1.0)); + ring.addPoint(Point(0.0, 1.0)); + ring.addPoint(Point(0.0, 0.0)); + + g.addGeometry(Polygon(ring)); + } + { + LineString ring; + ring.addPoint(Point(1.0, 0.0)); + ring.addPoint(Point(2.0, 0.0)); + ring.addPoint(Point(2.0, 1.0)); + ring.addPoint(Point(1.0, 1.0)); + ring.addPoint(Point(1.0, 0.0)); + + g.addGeometry(Polygon(ring)); + } + + std::unique_ptr boundary(g.boundary()); + + BOOST_CHECK(!boundary->isEmpty()); + BOOST_CHECK(boundary->is()); } - - BOOST_AUTO_TEST_SUITE_END() - diff --git a/test/unit/SFCGAL/algorithm/ConnectedTest.cpp b/test/unit/SFCGAL/algorithm/ConnectedTest.cpp index d4ca94cb..c9b2b1b3 100644 --- a/test/unit/SFCGAL/algorithm/ConnectedTest.cpp +++ b/test/unit/SFCGAL/algorithm/ConnectedTest.cpp @@ -15,74 +15,74 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include -#include -#include -#include -#include -#include -#include -#include #include -#include +#include #include +#include #include #include -#include +#include +#include +#include +#include +#include +#include #include +#include -using namespace boost::unit_test ; -using namespace SFCGAL ; -using namespace SFCGAL::algorithm ; +using namespace boost::unit_test; +using namespace SFCGAL; +using namespace SFCGAL::algorithm; -BOOST_AUTO_TEST_SUITE( SFCGAL_algorithm_Connected ) +BOOST_AUTO_TEST_SUITE(SFCGAL_algorithm_Connected) -BOOST_AUTO_TEST_CASE( allFine ) +BOOST_AUTO_TEST_CASE(allFine) { - std::unique_ptr< Geometry > geom ( io::readWkt( - "POLYHEDRALSURFACE(((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)),\ + std::unique_ptr geom( + io::readWkt("POLYHEDRALSURFACE(((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)),\ ((0 0 0, 0 0 1, 0 1 1, 0 1 0, 0 0 0)),\ ((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)),\ ((1 1 1, 0 1 1, 0 0 1, 1 0 1, 1 1 1)),\ ((1 1 1, 1 0 1, 1 0 0, 1 1 0, 1 1 1)),\ - ((1 1 1, 1 1 0, 0 1 0, 0 1 1, 1 1 1)))" ) ); + ((1 1 1, 1 1 0, 0 1 0, 0 1 1, 1 1 1)))")); - SurfaceGraph graph( geom->as< PolyhedralSurface >() ); - BOOST_CHECK_MESSAGE( isConnected( graph ) , "not connected" ); - BOOST_CHECK_MESSAGE( isClosed( graph ) , "not closed" ); + SurfaceGraph const graph(geom->as()); + BOOST_CHECK_MESSAGE(isConnected(graph), "not connected"); + BOOST_CHECK_MESSAGE(isClosed(graph), "not closed"); } -BOOST_AUTO_TEST_CASE( notConnected ) +BOOST_AUTO_TEST_CASE(notConnected) { - std::unique_ptr< Geometry > geom ( io::readWkt( - "POLYHEDRALSURFACE(((0 0 -1, 0 1 -1, 1 1 -1, 1 0 -1, 0 0 -1)),\ + std::unique_ptr geom(io::readWkt( + "POLYHEDRALSURFACE(((0 0 -1, 0 1 -1, 1 1 -1, 1 0 -1, 0 0 -1)),\ ((0 0 0, 0 0 1, 0 1 1, 0 1 0, 0 0 0)),\ ((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)),\ ((1 1 1, 0 1 1, 0 0 1, 1 0 1, 1 1 1)),\ ((1 1 1, 1 0 1, 1 0 0, 1 1 0, 1 1 1)),\ - ((1 1 1, 1 1 0, 0 1 0, 0 1 1, 1 1 1)))" ) ); + ((1 1 1, 1 1 0, 0 1 0, 0 1 1, 1 1 1)))")); - SurfaceGraph graph( geom->as< PolyhedralSurface >() ); - BOOST_CHECK_MESSAGE( !isConnected( graph ) , "connected" ); - BOOST_CHECK_MESSAGE( !isClosed( graph ) , "closed" ); + SurfaceGraph const graph(geom->as()); + BOOST_CHECK_MESSAGE(!isConnected(graph), "connected"); + BOOST_CHECK_MESSAGE(!isClosed(graph), "closed"); } -BOOST_AUTO_TEST_CASE( notClosed ) +BOOST_AUTO_TEST_CASE(notClosed) { - std::unique_ptr< Geometry > geom ( io::readWkt( - "POLYHEDRALSURFACE(((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)),\ + std::unique_ptr geom( + io::readWkt("POLYHEDRALSURFACE(((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)),\ ((0 0 0, 0 0 1, 0 1 1, 0 1 0, 0 0 0)),\ ((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)),\ ((1 1 1, 0 1 1, 0 0 1, 1 0 1, 1 1 1)),\ - ((1 1 1, 1 0 1, 1 0 0, 1 1 0, 1 1 1)))" ) ); - - SurfaceGraph graph( geom->as< PolyhedralSurface >() ); - BOOST_CHECK_MESSAGE( isConnected( graph ) , "not connected" ); - BOOST_CHECK_MESSAGE( !isClosed( graph ) , "closed" ); + ((1 1 1, 1 0 1, 1 0 0, 1 1 0, 1 1 1)))")); + SurfaceGraph const graph(geom->as()); + BOOST_CHECK_MESSAGE(isConnected(graph), "not connected"); + BOOST_CHECK_MESSAGE(!isClosed(graph), "closed"); } BOOST_AUTO_TEST_SUITE_END() diff --git a/test/unit/SFCGAL/algorithm/ConsistentOrientationBuilderTest.cpp b/test/unit/SFCGAL/algorithm/ConsistentOrientationBuilderTest.cpp index 9c13a7a0..87d0648e 100644 --- a/test/unit/SFCGAL/algorithm/ConsistentOrientationBuilderTest.cpp +++ b/test/unit/SFCGAL/algorithm/ConsistentOrientationBuilderTest.cpp @@ -15,91 +15,61 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include +#include #include -#include #include -#include -#include -#include -#include -#include -#include -#include #include +#include #include #include -#include +#include +#include +#include +#include +#include +#include #include #include +#include +using namespace SFCGAL; +using namespace boost::unit_test; -using namespace SFCGAL ; -using namespace boost::unit_test ; - -BOOST_AUTO_TEST_SUITE( SFCGAL_algorithm_ConsistentOrientationBuilderTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_algorithm_ConsistentOrientationBuilderTest) -BOOST_AUTO_TEST_CASE( testOppositeTriangle ) +BOOST_AUTO_TEST_CASE(testOppositeTriangle) { - algorithm::ConsistentOrientationBuilder builder ; - builder.addTriangle( - Triangle( - Point( 0.0, 0.0, 0.0 ), - Point( 1.0, 0.0, 0.0 ), - Point( 0.0, 1.0, 0.0 ) - ) - ); - builder.addTriangle( - Triangle( - Point( 0.0, 0.0, 0.0 ), - Point( -1.0, 0.0, 0.0 ), - Point( 0.0, 1.0, 0.0 ) - ) - ); - TriangulatedSurface triangulatedSurface = builder.buildTriangulatedSurface(); - BOOST_CHECK_EQUAL( triangulatedSurface.numGeometries(), 2U ); - BOOST_CHECK( algorithm::hasConsistentOrientation3D( triangulatedSurface ) ); + algorithm::ConsistentOrientationBuilder builder; + builder.addTriangle(Triangle(Point(0.0, 0.0, 0.0), Point(1.0, 0.0, 0.0), + Point(0.0, 1.0, 0.0))); + builder.addTriangle(Triangle(Point(0.0, 0.0, 0.0), Point(-1.0, 0.0, 0.0), + Point(0.0, 1.0, 0.0))); + TriangulatedSurface const triangulatedSurface = + builder.buildTriangulatedSurface(); + BOOST_CHECK_EQUAL(triangulatedSurface.numGeometries(), 2U); + BOOST_CHECK(algorithm::hasConsistentOrientation3D(triangulatedSurface)); } -BOOST_AUTO_TEST_CASE( testFourTriangle ) +BOOST_AUTO_TEST_CASE(testFourTriangle) { - algorithm::ConsistentOrientationBuilder builder ; - builder.addTriangle( - Triangle( - Point( 0.0, 0.0, 0.0 ), - Point( 1.0, 0.0, 0.0 ), - Point( 0.0, 1.0, 0.0 ) - ) - ); - builder.addTriangle( - Triangle( - Point( 0.0, 0.0, 0.0 ), - Point( -1.0, 0.0, 0.0 ), - Point( 0.0, 1.0, 0.0 ) - ) - ); - builder.addTriangle( - Triangle( - Point( 0.0, 0.0, 0.0 ), - Point( 1.0, 0.0, 0.0 ), - Point( 0.0,-1.0, 0.0 ) - ) - ); - builder.addTriangle( - Triangle( - Point( 0.0, 0.0, 0.0 ), - Point( -1.0, 0.0, 0.0 ), - Point( 0.0,-1.0, 0.0 ) - ) - ); - TriangulatedSurface triangulatedSurface = builder.buildTriangulatedSurface(); - BOOST_CHECK_EQUAL( triangulatedSurface.numGeometries(), 4U ); - BOOST_CHECK( algorithm::hasConsistentOrientation3D( triangulatedSurface ) ); + algorithm::ConsistentOrientationBuilder builder; + builder.addTriangle(Triangle(Point(0.0, 0.0, 0.0), Point(1.0, 0.0, 0.0), + Point(0.0, 1.0, 0.0))); + builder.addTriangle(Triangle(Point(0.0, 0.0, 0.0), Point(-1.0, 0.0, 0.0), + Point(0.0, 1.0, 0.0))); + builder.addTriangle(Triangle(Point(0.0, 0.0, 0.0), Point(1.0, 0.0, 0.0), + Point(0.0, -1.0, 0.0))); + builder.addTriangle(Triangle(Point(0.0, 0.0, 0.0), Point(-1.0, 0.0, 0.0), + Point(0.0, -1.0, 0.0))); + TriangulatedSurface const triangulatedSurface = + builder.buildTriangulatedSurface(); + BOOST_CHECK_EQUAL(triangulatedSurface.numGeometries(), 4U); + BOOST_CHECK(algorithm::hasConsistentOrientation3D(triangulatedSurface)); } - BOOST_AUTO_TEST_SUITE_END() - diff --git a/test/unit/SFCGAL/algorithm/ConvexHullTest.cpp b/test/unit/SFCGAL/algorithm/ConvexHullTest.cpp index cc5239e5..44c8f0e7 100644 --- a/test/unit/SFCGAL/algorithm/ConvexHullTest.cpp +++ b/test/unit/SFCGAL/algorithm/ConvexHullTest.cpp @@ -15,163 +15,149 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include -#include -#include -#include -#include -#include -#include -#include #include -#include +#include #include +#include #include #include -#include +#include +#include +#include +#include +#include +#include #include +#include -using namespace SFCGAL ; +using namespace SFCGAL; // always after CGAL -using namespace boost::unit_test ; +using namespace boost::unit_test; -BOOST_AUTO_TEST_SUITE( SFCGAL_algorithm_ConvexHullTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_algorithm_ConvexHullTest) // algorithm::convexHull -BOOST_AUTO_TEST_CASE( testConvexHull2D_Empty ) +BOOST_AUTO_TEST_CASE(testConvexHull2D_Empty) { - GeometryCollection collect; - collect.addGeometry( Polygon() ); - collect.addGeometry( Polygon() ); - std::unique_ptr< Geometry > hull( algorithm::convexHull( collect ) ); - BOOST_CHECK( hull->isEmpty() ); + GeometryCollection collect; + collect.addGeometry(Polygon()); + collect.addGeometry(Polygon()); + std::unique_ptr hull(algorithm::convexHull(collect)); + BOOST_CHECK(hull->isEmpty()); } - -BOOST_AUTO_TEST_CASE( testConvexHull2D_ColinearProduceLineString ) +BOOST_AUTO_TEST_CASE(testConvexHull2D_ColinearProduceLineString) { - LineString lineString ; - lineString.addPoint( Point( 0.0,0.0 ) ); - lineString.addPoint( Point( 1.0,1.0 ) ); - lineString.addPoint( Point( 2.0,2.0 ) ); - - std::unique_ptr< Geometry > hull( algorithm::convexHull( lineString ) ); - BOOST_REQUIRE( hull->is< LineString >() ); - BOOST_CHECK_EQUAL( hull->as< LineString >().numPoints(), 2U ); - - std::string hullWKT = hull->asText( 1 ) ; - BOOST_CHECK( - ( hullWKT == "LINESTRING(0.0 0.0,2.0 2.0)" ) - || ( hullWKT == "LINESTRING(2.0 2.0,0.0 0.0)" ) - ); + LineString lineString; + lineString.addPoint(Point(0.0, 0.0)); + lineString.addPoint(Point(1.0, 1.0)); + lineString.addPoint(Point(2.0, 2.0)); + + std::unique_ptr hull(algorithm::convexHull(lineString)); + BOOST_REQUIRE(hull->is()); + BOOST_CHECK_EQUAL(hull->as().numPoints(), 2U); + + std::string const hullWKT = hull->asText(1); + BOOST_CHECK((hullWKT == "LINESTRING(0.0 0.0,2.0 2.0)") || + (hullWKT == "LINESTRING(2.0 2.0,0.0 0.0)")); } -BOOST_AUTO_TEST_CASE( testConvexHull2D_Triangle ) +BOOST_AUTO_TEST_CASE(testConvexHull2D_Triangle) { - std::vector< Point > points ; - points.push_back( Point( 0.0,0.0 ) ); - points.push_back( Point( 0.5,0.5 ) ); - points.push_back( Point( 1.0,0.0 ) ); - points.push_back( Point( 0.0,1.0 ) ); - - LineString lineString( points ) ; - std::unique_ptr< Geometry > hull( algorithm::convexHull( lineString ) ); - BOOST_CHECK( hull->is() ); + std::vector points; + points.emplace_back(0.0, 0.0); + points.emplace_back(0.5, 0.5); + points.emplace_back(1.0, 0.0); + points.emplace_back(0.0, 1.0); + + LineString const lineString(points); + std::unique_ptr hull(algorithm::convexHull(lineString)); + BOOST_CHECK(hull->is()); } -BOOST_AUTO_TEST_CASE( testConvexHull2D_Polygon ) +BOOST_AUTO_TEST_CASE(testConvexHull2D_Polygon) { - std::vector< Point > points ; - points.push_back( Point( 0.0,0.0 ) ); - points.push_back( Point( 1.0,0.0 ) ); - points.push_back( Point( 1.0,1.0 ) ); - points.push_back( Point( 0.0,1.0 ) ); - - LineString lineString( points ) ; - std::unique_ptr< Geometry > hull( algorithm::convexHull( lineString ) ); - BOOST_CHECK( hull->is() ); + std::vector points; + points.emplace_back(0.0, 0.0); + points.emplace_back(1.0, 0.0); + points.emplace_back(1.0, 1.0); + points.emplace_back(0.0, 1.0); + + LineString const lineString(points); + std::unique_ptr hull(algorithm::convexHull(lineString)); + BOOST_CHECK(hull->is()); } - - // algorithm::convexHull3D -BOOST_AUTO_TEST_CASE( testConvexHull3D_Empty ) +BOOST_AUTO_TEST_CASE(testConvexHull3D_Empty) { - GeometryCollection collect; - collect.addGeometry( Polygon() ); - collect.addGeometry( Polygon() ); - std::unique_ptr< Geometry > hull( algorithm::convexHull3D( collect ) ); - BOOST_CHECK( hull->isEmpty() ); + GeometryCollection collect; + collect.addGeometry(Polygon()); + collect.addGeometry(Polygon()); + std::unique_ptr hull(algorithm::convexHull3D(collect)); + BOOST_CHECK(hull->isEmpty()); } - -BOOST_AUTO_TEST_CASE( testConvexHull3D_Point ) +BOOST_AUTO_TEST_CASE(testConvexHull3D_Point) { - Point p( 1.0,2.0,3.0 ); - std::unique_ptr< Geometry > hull( algorithm::convexHull3D( p ) ); - BOOST_CHECK( hull->is< Point >() ); - BOOST_CHECK_EQUAL( hull->as< Point >().x(), 1.0 ) ; - BOOST_CHECK_EQUAL( hull->as< Point >().y(), 2.0 ) ; - BOOST_CHECK_EQUAL( hull->as< Point >().z(), 3.0 ) ; + Point const p(1.0, 2.0, 3.0); + std::unique_ptr hull(algorithm::convexHull3D(p)); + BOOST_CHECK(hull->is()); + BOOST_CHECK_EQUAL(hull->as().x(), 1.0); + BOOST_CHECK_EQUAL(hull->as().y(), 2.0); + BOOST_CHECK_EQUAL(hull->as().z(), 3.0); } /* * @todo Test if points are collinear */ -BOOST_AUTO_TEST_CASE( testConvexHull3D_LineStringCollinear ) +BOOST_AUTO_TEST_CASE(testConvexHull3D_LineStringCollinear) { - std::vector< Point > points ; - points.push_back( Point( 0.0,0.0,0.0 ) ); - points.push_back( Point( 1.0,1.0,1.0 ) ); - points.push_back( Point( 2.0,2.0,2.0 ) ); - points.push_back( Point( 3.0,3.0,3.0 ) ); - - LineString lineString( points ) ; - std::unique_ptr< Geometry > hull( algorithm::convexHull3D( lineString ) ); - BOOST_CHECK( hull->is< LineString >() ); + std::vector points; + points.emplace_back(0.0, 0.0, 0.0); + points.emplace_back(1.0, 1.0, 1.0); + points.emplace_back(2.0, 2.0, 2.0); + points.emplace_back(3.0, 3.0, 3.0); + + LineString const lineString(points); + std::unique_ptr hull(algorithm::convexHull3D(lineString)); + BOOST_CHECK(hull->is()); } -BOOST_AUTO_TEST_CASE( testConvexHull3D_LineStringCoplanar ) +BOOST_AUTO_TEST_CASE(testConvexHull3D_LineStringCoplanar) { - std::vector< Point > points ; - points.push_back( Point( 0.0,0.0,1.0 ) ); - points.push_back( Point( 1.0,0.0,1.0 ) ); - points.push_back( Point( 1.0,1.0,1.0 ) ); - points.push_back( Point( 0.0,1.0,1.0 ) ); - - LineString lineString( points ) ; - std::unique_ptr< Geometry > hull( algorithm::convexHull3D( lineString ) ); - BOOST_CHECK( hull->is< PolyhedralSurface >() ); - BOOST_CHECK_EQUAL( hull->as< PolyhedralSurface >().numPolygons(), 2U ); + std::vector points; + points.emplace_back(0.0, 0.0, 1.0); + points.emplace_back(1.0, 0.0, 1.0); + points.emplace_back(1.0, 1.0, 1.0); + points.emplace_back(0.0, 1.0, 1.0); + + LineString const lineString(points); + std::unique_ptr hull(algorithm::convexHull3D(lineString)); + BOOST_CHECK(hull->is()); + BOOST_CHECK_EQUAL(hull->as().numPolygons(), 2U); } - - - -BOOST_AUTO_TEST_CASE( testConvexHull3D_Tetrahedron ) +BOOST_AUTO_TEST_CASE(testConvexHull3D_Tetrahedron) { - std::vector< Point > points ; - points.push_back( Point( 0.0,0.0,0.0 ) ); - points.push_back( Point( 1.0,0.0,0.0 ) ); - points.push_back( Point( 0.0,1.0,0.0 ) ); - points.push_back( Point( 0.0,0.0,1.0 ) ); - - LineString lineString( points ) ; - std::unique_ptr< Geometry > hull( algorithm::convexHull3D( lineString ) ); - BOOST_CHECK( hull->is< PolyhedralSurface >() ); - BOOST_CHECK_EQUAL( hull->as< PolyhedralSurface >().numPolygons(), 4U ); - + std::vector points; + points.emplace_back(0.0, 0.0, 0.0); + points.emplace_back(1.0, 0.0, 0.0); + points.emplace_back(0.0, 1.0, 0.0); + points.emplace_back(0.0, 0.0, 1.0); + + LineString const lineString(points); + std::unique_ptr hull(algorithm::convexHull3D(lineString)); + BOOST_CHECK(hull->is()); + BOOST_CHECK_EQUAL(hull->as().numPolygons(), 4U); } - - - - BOOST_AUTO_TEST_SUITE_END() - diff --git a/test/unit/SFCGAL/algorithm/CoversPointsTest.cpp b/test/unit/SFCGAL/algorithm/CoversPointsTest.cpp index 6814f45e..083c960c 100644 --- a/test/unit/SFCGAL/algorithm/CoversPointsTest.cpp +++ b/test/unit/SFCGAL/algorithm/CoversPointsTest.cpp @@ -15,68 +15,73 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include #include +#include #include -#include #include -#include -#include -#include -#include -#include -#include -#include #include +#include #include #include -#include +#include +#include +#include +#include +#include +#include #include +#include -using namespace SFCGAL ; -using namespace SFCGAL::detail ; -using namespace boost::unit_test ; +using namespace SFCGAL; +using namespace SFCGAL::detail; +using namespace boost::unit_test; -BOOST_AUTO_TEST_SUITE( SFCGAL_algorithm_CoversPointsTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_algorithm_CoversPointsTest) -BOOST_AUTO_TEST_CASE( testPointPointCoversPoints ) +BOOST_AUTO_TEST_CASE(testPointPointCoversPoints) { - Point pta( 0.0, 1.0, 0.0 ); - Point ptb( 0.0, 1.0, 0.0 ); - Point ptc( 0.0, 0.0, 0.0 ); - BOOST_CHECK_EQUAL( algorithm::coversPoints( pta, ptb ), true ); - BOOST_CHECK_EQUAL( algorithm::coversPoints( pta, ptc ), false ); - BOOST_CHECK_EQUAL( algorithm::coversPoints3D( pta, ptb ), true ); - BOOST_CHECK_EQUAL( algorithm::coversPoints3D( pta, ptc ), false ); + Point const pta(0.0, 1.0, 0.0); + Point const ptb(0.0, 1.0, 0.0); + Point const ptc(0.0, 0.0, 0.0); + BOOST_CHECK_EQUAL(algorithm::coversPoints(pta, ptb), true); + BOOST_CHECK_EQUAL(algorithm::coversPoints(pta, ptc), false); + BOOST_CHECK_EQUAL(algorithm::coversPoints3D(pta, ptb), true); + BOOST_CHECK_EQUAL(algorithm::coversPoints3D(pta, ptc), false); } -BOOST_AUTO_TEST_CASE( testPolygonPolygonCoversPoints ) +BOOST_AUTO_TEST_CASE(testPolygonPolygonCoversPoints) { - { - std::unique_ptr p1 = io::readWkt( "POLYGON((-1.0 -1.0,1.0 -1.0,1.0 1.0,-1.0 1.0,-1.0 -1.0))" ); - std::unique_ptr p2 = io::readWkt( "POLYGON((-0.5 -0.5,-0.5 0.5,0.5 0.5,0.5 -0.5,-0.5 -0.5))" ); + { + std::unique_ptr const p1 = + io::readWkt("POLYGON((-1.0 -1.0,1.0 -1.0,1.0 1.0,-1.0 1.0,-1.0 -1.0))"); + std::unique_ptr const p2 = + io::readWkt("POLYGON((-0.5 -0.5,-0.5 0.5,0.5 0.5,0.5 -0.5,-0.5 -0.5))"); - BOOST_CHECK_EQUAL( algorithm::coversPoints( *p1, *p2 ), true ); - BOOST_CHECK_EQUAL( algorithm::coversPoints3D( *p1, *p2 ), true ); - } + BOOST_CHECK_EQUAL(algorithm::coversPoints(*p1, *p2), true); + BOOST_CHECK_EQUAL(algorithm::coversPoints3D(*p1, *p2), true); + } - { - // a square with a substracted triangle => concave shape - std::unique_ptr p1 = io::readWkt( "POLYGON((0.4 0,0 0,0 1,1 1,1 0,0.6 0,0.5 0.4,0.4 0))" ); - // a smaller square - std::unique_ptr p2 = io::readWkt( "POLYGON((0.2 0.2,0.8 0.2,0.8 0.8,0.2 0.8,0.2 0.2))" ); + { + // a square with a substracted triangle => concave shape + std::unique_ptr const p1 = + io::readWkt("POLYGON((0.4 0,0 0,0 1,1 1,1 0,0.6 0,0.5 0.4,0.4 0))"); + // a smaller square + std::unique_ptr const p2 = + io::readWkt("POLYGON((0.2 0.2,0.8 0.2,0.8 0.8,0.2 0.8,0.2 0.2))"); - // ST_covers would answer false - BOOST_CHECK_EQUAL( algorithm::coversPoints( *p1, *p2 ), true ); - BOOST_CHECK_EQUAL( algorithm::coversPoints3D( *p1, *p2 ), true ); - } + // ST_covers would answer false + BOOST_CHECK_EQUAL(algorithm::coversPoints(*p1, *p2), true); + BOOST_CHECK_EQUAL(algorithm::coversPoints3D(*p1, *p2), true); + } } -BOOST_AUTO_TEST_CASE( testCollectionCoversPoints ) +BOOST_AUTO_TEST_CASE(testCollectionCoversPoints) { #if 0 { @@ -96,4 +101,3 @@ BOOST_AUTO_TEST_CASE( testCollectionCoversPoints ) } BOOST_AUTO_TEST_SUITE_END() - diff --git a/test/unit/SFCGAL/algorithm/CoversTest.cpp b/test/unit/SFCGAL/algorithm/CoversTest.cpp index 279e682a..4b14387b 100644 --- a/test/unit/SFCGAL/algorithm/CoversTest.cpp +++ b/test/unit/SFCGAL/algorithm/CoversTest.cpp @@ -15,115 +15,119 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include #include #include +#include #include -#include #include -#include -#include -#include -#include -#include -#include -#include #include +#include #include #include -#include +#include +#include +#include +#include +#include +#include #include +#include #include "../../../test_config.h" -using namespace SFCGAL ; -using namespace boost::unit_test ; +using namespace SFCGAL; +using namespace boost::unit_test; -BOOST_AUTO_TEST_SUITE( SFCGAL_algorithm_CoversTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_algorithm_CoversTest) /** * Perform tests in test/data/CoversTest.txt */ -BOOST_AUTO_TEST_CASE( testFileCoversTest ) +BOOST_AUTO_TEST_CASE(testFileCoversTest) { - int argc = framework::master_test_suite().argc; - char** argv = framework::master_test_suite().argv; - - // look for options - int test_one_line = -1; - - for ( int i = 0; i < argc; ++i ) { - std::string argi( argv[i] ); - - if ( argi == "--line" ) { - // only test one line - if ( argc >= i+1 ) { - sscanf( argv[i+1], "%d", &test_one_line ); - ++i; - continue; - } - } + int const argc = framework::master_test_suite().argc; + char **argv = framework::master_test_suite().argv; + + // look for options + int test_one_line = -1; + + for (int i = 0; i < argc; ++i) { + std::string const argi(argv[i]); + + if (argi == "--line") { + // only test one line + if (argc >= i + 1) { + sscanf(argv[i + 1], "%d", &test_one_line); + ++i; + continue; + } } + } - std::string filename( SFCGAL_TEST_DIRECTORY ); - filename += "/data/CoversTest.txt" ; - - std::ifstream ifs( filename.c_str() ); - BOOST_REQUIRE( ifs.good() ) ; - - int numLine = 0 ; - std::string line; - - while ( std::getline( ifs, line ) ) { - numLine++; + std::string filename(SFCGAL_TEST_DIRECTORY); + filename += "/data/CoversTest.txt"; - if ( test_one_line != -1 && test_one_line != numLine ) { - continue; - } + std::ifstream ifs(filename.c_str()); + BOOST_REQUIRE(ifs.good()); - if ( line[0] == '#' || line.empty() ) { - continue ; - } + int numLine = 0; + std::string line; - BOOST_TEST_MESSAGE( boost::format( "line#%s:%s" ) % numLine % line ); + while (std::getline(ifs, line)) { + numLine++; - std::istringstream iss( line ); - - std::string distanceDimension ; - std::string wktGA, wktGB ; - std::string trueOrFalse ; - - std::getline( iss, distanceDimension, '|' ) ; - std::getline( iss, wktGA, '|' ) ; - std::getline( iss, wktGB, '|' ) ; - std::getline( iss, trueOrFalse, '|' ) ; - - bool expected = ( trueOrFalse == "true" ) ? true : false ; + if (test_one_line != -1 && test_one_line != numLine) { + continue; + } - std::unique_ptr< Geometry > gA( io::readWkt( wktGA ) ); - std::unique_ptr< Geometry > gB( io::readWkt( wktGB ) ); + if (line[0] == '#' || line.empty()) { + continue; + } - try { - if ( distanceDimension == "2" ) { - BOOST_CHECK_MESSAGE( algorithm::covers( *gA,*gB ) == expected, numLine << ": covers(" << gA->asText() << ", " << gB->asText() << ") should be " << ( expected ? "TRUE" : "FALSE" ) ); - } - else if ( distanceDimension == "3" ) { - bool got = algorithm::covers3D( *gA,*gB ); - BOOST_CHECK_MESSAGE( got == expected, numLine << ": covers3D(" << gA->asText() << ", " << gB->asText() << ") should be " << ( expected ? "TRUE" : "FALSE" ) ); - } - else { - BOOST_CHECK( false ); - } - } - catch ( std::exception& e ) { - BOOST_CHECK_MESSAGE( false, numLine << ": " << e.what() ); - } + BOOST_TEST_MESSAGE(boost::format("line#%s:%s") % numLine % line); + + std::istringstream iss(line); + + std::string distanceDimension; + std::string wktGA; + std::string wktGB; + std::string trueOrFalse; + + std::getline(iss, distanceDimension, '|'); + std::getline(iss, wktGA, '|'); + std::getline(iss, wktGB, '|'); + std::getline(iss, trueOrFalse, '|'); + + bool const expected = trueOrFalse == "true"; + + std::unique_ptr gA(io::readWkt(wktGA)); + std::unique_ptr gB(io::readWkt(wktGB)); + + try { + if (distanceDimension == "2") { + BOOST_CHECK_MESSAGE(algorithm::covers(*gA, *gB) == expected, + numLine << ": covers(" << gA->asText() << ", " + << gB->asText() << ") should be " + << (expected ? "TRUE" : "FALSE")); + } else if (distanceDimension == "3") { + bool const got = algorithm::covers3D(*gA, *gB); + BOOST_CHECK_MESSAGE(got == expected, + numLine << ": covers3D(" << gA->asText() << ", " + << gB->asText() << ") should be " + << (expected ? "TRUE" : "FALSE")); + } else { + BOOST_CHECK(false); + } + } catch (std::exception &e) { + BOOST_CHECK_MESSAGE(false, numLine << ": " << e.what()); } + } } BOOST_AUTO_TEST_SUITE_END() - diff --git a/test/unit/SFCGAL/algorithm/DifferenceTest.cpp b/test/unit/SFCGAL/algorithm/DifferenceTest.cpp index b7b88966..40e0d294 100644 --- a/test/unit/SFCGAL/algorithm/DifferenceTest.cpp +++ b/test/unit/SFCGAL/algorithm/DifferenceTest.cpp @@ -15,363 +15,416 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include -#include +#include +#include #include +#include #include -#include -#include #include -#include #include +#include #include using namespace SFCGAL; -using namespace boost::unit_test ; +using namespace boost::unit_test; -BOOST_AUTO_TEST_SUITE( SFCGAL_algorithm_DifferenceTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_algorithm_DifferenceTest) -BOOST_AUTO_TEST_CASE( testDifferenceXPoint ) +BOOST_AUTO_TEST_CASE(testDifferenceXPoint) { - // The same point - BOOST_CHECK( algorithm::difference( Point( 0,0 ), Point( 0,0 ) )->isEmpty() ); - // A different point - BOOST_CHECK( *algorithm::difference( Point( 1,0 ), Point( 0,0 ) ) == Point( 1,0 ) ); - // A different point (reversed) - BOOST_CHECK( *algorithm::difference( Point( 0,0 ), Point( 1,0 ) ) == Point( 0,0 ) ); - - // check difference(X, point) == X - std::vector typeNames; - - for ( size_t i = 0; i < typeNames.size(); ++i ) { - std::unique_ptr newGeo( tools::Registry::instance().newGeometryByTypeName( typeNames[i] ) ); - std::unique_ptr diffGeo = algorithm::difference( *newGeo, Point( 0, 0 ) ); - BOOST_CHECK( *newGeo == *diffGeo ); - } + // The same point + BOOST_CHECK(algorithm::difference(Point(0, 0), Point(0, 0))->isEmpty()); + // A different point + BOOST_CHECK(*algorithm::difference(Point(1, 0), Point(0, 0)) == Point(1, 0)); + // A different point (reversed) + BOOST_CHECK(*algorithm::difference(Point(0, 0), Point(1, 0)) == Point(0, 0)); + + // check difference(X, point) == X + std::vector const typeNames; + + for (const auto &typeName : typeNames) { + std::unique_ptr const newGeo( + tools::Registry::instance().newGeometryByTypeName(typeName)); + std::unique_ptr const diffGeo = + algorithm::difference(*newGeo, Point(0, 0)); + BOOST_CHECK(*newGeo == *diffGeo); + } } -BOOST_AUTO_TEST_CASE( testDifferenceXLineString ) +BOOST_AUTO_TEST_CASE(testDifferenceXLineString) { - // Point x Linestring intersecting - BOOST_CHECK( algorithm::difference( Point( 0,0 ), *io::readWkt( "LINESTRING(0 0,1 1)" ) )->isEmpty() ); - // Point x linestring not intersecting - BOOST_CHECK( *algorithm::difference( Point( 0,0 ), *io::readWkt( "LINESTRING(0 1,1 1)" ) ) == Point( 0, 0 ) ); - - // two linestrings with two segments overlapping - { - std::unique_ptr ls1 = io::readWkt( "LINESTRING(0 0,1 0)" ); - std::unique_ptr ls2 = io::readWkt( "LINESTRING(0.5 0,0.7 0)" ); - std::unique_ptr diff = algorithm::difference( *ls1, *ls2 ); - BOOST_CHECK( *diff == *io::readWkt( "MULTILINESTRING((0 0,0.5 0),(0.7 0,1 0))" ) ); - } - // two linestrings with two opposite segments overlapping - { - std::unique_ptr ls1 = io::readWkt( "LINESTRING(0 0,1 0)" ); - std::unique_ptr ls2 = io::readWkt( "LINESTRING(0.7 0,0.5 0)" ); - std::unique_ptr diff = algorithm::difference( *ls1, *ls2 ); - BOOST_CHECK( *diff == *io::readWkt( "MULTILINESTRING((0 0,0.5 0),(0.7 0,1 0))" ) ); - } - // two linestrings with two segments crossing - { - std::unique_ptr ls1 = io::readWkt( "LINESTRING(-1 0,1 0)" ); - std::unique_ptr ls2 = io::readWkt( "LINESTRING(0 -1,0 1)" ); - std::unique_ptr diff = algorithm::difference( *ls1, *ls2 ); - BOOST_CHECK( *diff == *ls1 ); - } - // two linestrings with two segments partly overlapping - { - std::unique_ptr ls1 = io::readWkt( "LINESTRING(0 0,1 0)" ); - std::unique_ptr ls2 = io::readWkt( "LINESTRING(-1 0,0.7 0)" ); - std::unique_ptr diff = algorithm::difference( *ls1, *ls2 ); - BOOST_CHECK( *diff == *io::readWkt( "LINESTRING(0.7 0,1 0)" ) ); - } - // two linestrings with a segment covering another one - { - std::unique_ptr ls1 = io::readWkt( "LINESTRING(0 0,1 0)" ); - std::unique_ptr ls2 = io::readWkt( "LINESTRING(-1 0,2 0)" ); - std::unique_ptr diff = algorithm::difference( *ls1, *ls2 ); - BOOST_CHECK( diff->isEmpty() ); - } - // two linestrings that do not intersect - { - std::unique_ptr ls1 = io::readWkt( "LINESTRING(0 0,1 0)" ); - std::unique_ptr ls2 = io::readWkt( "LINESTRING(0 1,1 1)" ); - std::unique_ptr diff = algorithm::difference( *ls1, *ls2 ); - BOOST_CHECK( *diff == *ls1 ); - } - // two linestrings with more than one segment - { - std::unique_ptr ls1 = io::readWkt( "LINESTRING(0 0,1 0,1 1)" ); - std::unique_ptr ls2 = io::readWkt( "LINESTRING(0.3 0,1 0,1 0.4)" ); - std::unique_ptr diff = algorithm::difference( *ls1, *ls2 ); - BOOST_CHECK( *diff == *io::readWkt( "MULTILINESTRING((0 0,0.3 0),(1 0.4,1 1))" ) ); - } - - // check difference(X, linestring) == X, with dimension(X) > 1 - // TODO: add generators of random geometries to avoid empty geometries here ? - std::vector typeNames; - - for ( size_t i = 0; i < typeNames.size(); ++i ) { - std::unique_ptr newGeo( tools::Registry::instance().newGeometryByTypeName( typeNames[i] ) ); - - if ( newGeo->dimension() > 1 ) { - std::unique_ptr diffGeo = algorithm::difference( *newGeo, Point( 0, 0 ) ); - BOOST_CHECK( *newGeo == *diffGeo ); - } + // Point x Linestring intersecting + BOOST_CHECK( + algorithm::difference(Point(0, 0), *io::readWkt("LINESTRING(0 0,1 1)")) + ->isEmpty()); + // Point x linestring not intersecting + BOOST_CHECK(*algorithm::difference(Point(0, 0), + *io::readWkt("LINESTRING(0 1,1 1)")) == + Point(0, 0)); + + // two linestrings with two segments overlapping + { + std::unique_ptr const ls1 = io::readWkt("LINESTRING(0 0,1 0)"); + std::unique_ptr const ls2 = + io::readWkt("LINESTRING(0.5 0,0.7 0)"); + std::unique_ptr const diff = algorithm::difference(*ls1, *ls2); + BOOST_CHECK(*diff == + *io::readWkt("MULTILINESTRING((0 0,0.5 0),(0.7 0,1 0))")); + } + // two linestrings with two opposite segments overlapping + { + std::unique_ptr const ls1 = io::readWkt("LINESTRING(0 0,1 0)"); + std::unique_ptr const ls2 = + io::readWkt("LINESTRING(0.7 0,0.5 0)"); + std::unique_ptr const diff = algorithm::difference(*ls1, *ls2); + BOOST_CHECK(*diff == + *io::readWkt("MULTILINESTRING((0 0,0.5 0),(0.7 0,1 0))")); + } + // two linestrings with two segments crossing + { + std::unique_ptr const ls1 = io::readWkt("LINESTRING(-1 0,1 0)"); + std::unique_ptr const ls2 = io::readWkt("LINESTRING(0 -1,0 1)"); + std::unique_ptr const diff = algorithm::difference(*ls1, *ls2); + BOOST_CHECK(*diff == *ls1); + } + // two linestrings with two segments partly overlapping + { + std::unique_ptr const ls1 = io::readWkt("LINESTRING(0 0,1 0)"); + std::unique_ptr const ls2 = io::readWkt("LINESTRING(-1 0,0.7 0)"); + std::unique_ptr const diff = algorithm::difference(*ls1, *ls2); + BOOST_CHECK(*diff == *io::readWkt("LINESTRING(0.7 0,1 0)")); + } + // two linestrings with a segment covering another one + { + std::unique_ptr const ls1 = io::readWkt("LINESTRING(0 0,1 0)"); + std::unique_ptr const ls2 = io::readWkt("LINESTRING(-1 0,2 0)"); + std::unique_ptr diff = algorithm::difference(*ls1, *ls2); + BOOST_CHECK(diff->isEmpty()); + } + // two linestrings that do not intersect + { + std::unique_ptr const ls1 = io::readWkt("LINESTRING(0 0,1 0)"); + std::unique_ptr const ls2 = io::readWkt("LINESTRING(0 1,1 1)"); + std::unique_ptr const diff = algorithm::difference(*ls1, *ls2); + BOOST_CHECK(*diff == *ls1); + } + // two linestrings with more than one segment + { + std::unique_ptr const ls1 = + io::readWkt("LINESTRING(0 0,1 0,1 1)"); + std::unique_ptr const ls2 = + io::readWkt("LINESTRING(0.3 0,1 0,1 0.4)"); + std::unique_ptr const diff = algorithm::difference(*ls1, *ls2); + BOOST_CHECK(*diff == + *io::readWkt("MULTILINESTRING((0 0,0.3 0),(1 0.4,1 1))")); + } + + // check difference(X, linestring) == X, with dimension(X) > 1 + // TODO: add generators of random geometries to avoid empty geometries here ? + std::vector const typeNames; + + for (const auto &typeName : typeNames) { + std::unique_ptr newGeo( + tools::Registry::instance().newGeometryByTypeName(typeName)); + + if (newGeo->dimension() > 1) { + std::unique_ptr const diffGeo = + algorithm::difference(*newGeo, Point(0, 0)); + BOOST_CHECK(*newGeo == *diffGeo); } + } } -BOOST_AUTO_TEST_CASE( testDifferencePolygonPolygon2D ) +BOOST_AUTO_TEST_CASE(testDifferencePolygonPolygon2D) { - // two identical polygons - { - std::unique_ptr ls1 = io::readWkt( "POLYGON((-1 -1,1 -1,1 1,-1 1,-1 -1))" ); - std::unique_ptr ls2 = io::readWkt( "POLYGON((-1 -1,1 -1,1 1,-1 1,-1 -1))" ); - std::unique_ptr diff = algorithm::difference( *ls1, *ls2 ); - BOOST_CHECK( *diff == *io::readWkt( "GEOMETRYCOLLECTION EMPTY" ) ); - } - - // two polygons, one of wich is invalid for CGAL but valid for SFS - { - std::unique_ptr ls1 = io::readWkt( "POLYGON((-1 -1,1 -1,1 1,-1 1,-1 -1))" ); - std::unique_ptr ls2 = io::readWkt( "POLYGON((-1 -1,1 -1,1 1,-1 1,-1 -1),(-0.5 -0.5,-0.5 0.5,0.5 0.5,1 -0.5,-0.5 -0.5))" ); - std::unique_ptr diff = algorithm::difference( *ls1, *ls2 ); - BOOST_CHECK( *diff == *io::readWkt( "POLYGON((-0.5 -0.5,1 -0.5,0.5 0.5,-0.5 0.5,-0.5 -0.5))" ) ); - BOOST_CHECK( algorithm::isValid( *diff ) ); - } - - // two polygons the result has a hole touching the outer boundary - { - std::unique_ptr ls1 = io::readWkt( "POLYGON((-1 -1,1 -1,1 1,-1 1,-1 -1))" ); - std::unique_ptr ls2 = io::readWkt( "POLYGON((-0.5 -0.5,1 -0.5,0.5 0.5,-0.5 0.5,-0.5 -0.5))" ); - std::unique_ptr diff = algorithm::difference( *ls1, *ls2 ); - BOOST_CHECK( algorithm::isValid( *diff ) ); - BOOST_CHECK( *diff == *io::readWkt( "POLYGON((-1 -1,1 -1,1 -0.5,1 1,-1 1,-1 -1),(1 -0.5,-0.5 -0.5,-0.5 0.5,0.5 0.5,1 -0.5))" ) ); - } + // two identical polygons + { + std::unique_ptr const ls1 = + io::readWkt("POLYGON((-1 -1,1 -1,1 1,-1 1,-1 -1))"); + std::unique_ptr const ls2 = + io::readWkt("POLYGON((-1 -1,1 -1,1 1,-1 1,-1 -1))"); + std::unique_ptr const diff = algorithm::difference(*ls1, *ls2); + BOOST_CHECK(*diff == *io::readWkt("GEOMETRYCOLLECTION EMPTY")); + } + + // two polygons, one of wich is invalid for CGAL but valid for SFS + { + std::unique_ptr const ls1 = + io::readWkt("POLYGON((-1 -1,1 -1,1 1,-1 1,-1 -1))"); + std::unique_ptr const ls2 = + io::readWkt("POLYGON((-1 -1,1 -1,1 1,-1 1,-1 -1),(-0.5 -0.5,-0.5 " + "0.5,0.5 0.5,1 -0.5,-0.5 -0.5))"); + std::unique_ptr const diff = algorithm::difference(*ls1, *ls2); + BOOST_CHECK( + *diff == + *io::readWkt("POLYGON((-0.5 -0.5,1 -0.5,0.5 0.5,-0.5 0.5,-0.5 -0.5))")); + BOOST_CHECK(algorithm::isValid(*diff)); + } + + // two polygons the result has a hole touching the outer boundary + { + std::unique_ptr const ls1 = + io::readWkt("POLYGON((-1 -1,1 -1,1 1,-1 1,-1 -1))"); + std::unique_ptr const ls2 = + io::readWkt("POLYGON((-0.5 -0.5,1 -0.5,0.5 0.5,-0.5 0.5,-0.5 -0.5))"); + std::unique_ptr const diff = algorithm::difference(*ls1, *ls2); + BOOST_CHECK(algorithm::isValid(*diff)); + BOOST_CHECK(*diff == + *io::readWkt("POLYGON((-1 -1,1 -1,1 -0.5,1 1,-1 1,-1 -1),(1 " + "-0.5,-0.5 -0.5,-0.5 0.5,0.5 0.5,1 -0.5))")); + } } -BOOST_AUTO_TEST_CASE( testDifferenceVolumeVolume ) +BOOST_AUTO_TEST_CASE(testDifferenceVolumeVolume) { - // two cubes - { - std::unique_ptr ls1 = io::readWkt( - "SOLID((((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)),\ + // two cubes + { + std::unique_ptr const ls1 = + io::readWkt("SOLID((((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)),\ ((0 0 0, 0 0 1, 0 1 1, 0 1 0, 0 0 0)),\ ((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)),\ ((1 1 1, 0 1 1, 0 0 1, 1 0 1, 1 1 1)),\ ((1 1 1, 1 0 1, 1 0 0, 1 1 0, 1 1 1)),\ - ((1 1 1, 1 1 0, 0 1 0, 0 1 1, 1 1 1))))" ); - std::unique_ptr ls2 = io::readWkt( - "SOLID((((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)),\ + ((1 1 1, 1 1 0, 0 1 0, 0 1 1, 1 1 1))))"); + std::unique_ptr const ls2 = + io::readWkt("SOLID((((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)),\ ((0 0 0, 0 0 1, 0 1 1, 0 1 0, 0 0 0)),\ ((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)),\ ((1 1 1, 0 1 1, 0 0 1, 1 0 1, 1 1 1)),\ ((1 1 1, 1 0 1, 1 0 0, 1 1 0, 1 1 1)),\ - ((1 1 1, 1 1 0, 0 1 0, 0 1 1, 1 1 1))))" ); - std::unique_ptr diff = algorithm::difference3D( *ls1, *ls2 ); - BOOST_CHECK( *diff == *io::readWkt( "GEOMETRYCOLLECTION EMPTY" ) ); - } - // two cubes - { - std::unique_ptr ls1 = io::readWkt( - "SOLID((((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)),\ + ((1 1 1, 1 1 0, 0 1 0, 0 1 1, 1 1 1))))"); + std::unique_ptr const diff = algorithm::difference3D(*ls1, *ls2); + BOOST_CHECK(*diff == *io::readWkt("GEOMETRYCOLLECTION EMPTY")); + } + // two cubes + { + std::unique_ptr const ls1 = + io::readWkt("SOLID((((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)),\ ((0 0 0, 0 0 1, 0 1 1, 0 1 0, 0 0 0)),\ ((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)),\ ((1 1 1, 0 1 1, 0 0 1, 1 0 1, 1 1 1)),\ ((1 1 1, 1 0 1, 1 0 0, 1 1 0, 1 1 1)),\ - ((1 1 1, 1 1 0, 0 1 0, 0 1 1, 1 1 1))))" ); - std::unique_ptr ls2 = io::readWkt( - "SOLID((((0 0 0.5, 0 1 0.5, 1 1 0.5, 1 0 0.5, 0 0 0.5)),\ + ((1 1 1, 1 1 0, 0 1 0, 0 1 1, 1 1 1))))"); + std::unique_ptr const ls2 = + io::readWkt("SOLID((((0 0 0.5, 0 1 0.5, 1 1 0.5, 1 0 0.5, 0 0 0.5)),\ ((0 0 0.5, 0 0 1, 0 1 1, 0 1 0.5, 0 0 0.5)),\ ((0 0 0.5, 1 0 0.5, 1 0 1, 0 0 1, 0 0 0.5)),\ ((1 1 1, 0 1 1, 0 0 1, 1 0 1, 1 1 1)),\ ((1 1 1, 1 0 1, 1 0 0.5, 1 1 0.5, 1 1 1)),\ - ((1 1 1, 1 1 0.5, 0 1 0.5, 0 1 1, 1 1 1))))" ); - std::unique_ptr diff = algorithm::difference3D( *ls1, *ls2 ); - BOOST_CHECK( algorithm::volume( *diff ) == Kernel::FT( 0.5 ) ); - } - - + ((1 1 1, 1 1 0.5, 0 1 0.5, 0 1 1, 1 1 1))))"); + std::unique_ptr const diff = algorithm::difference3D(*ls1, *ls2); + BOOST_CHECK(algorithm::volume(*diff) == Kernel::FT(0.5)); + } } -BOOST_AUTO_TEST_CASE( testDifferenceLinePolygon ) +BOOST_AUTO_TEST_CASE(testDifferenceLinePolygon) { - // segment - polygon in 2D - { - std::unique_ptr ls1 = io::readWkt( "LINESTRING(-10 0,10 0)" ); - std::unique_ptr ls2 = io::readWkt( "POLYGON((-1 -1,1 -1,1 1,-1 1,-1 -1),(-0.5 -0.5,-0.5 0.5,0 0,-0.5 -0.5),(0.5 0.5,0.5 -0.5,0 0,0.5 0.5))" ); - std::unique_ptr diff = algorithm::difference( *ls1, *ls2 ); - BOOST_CHECK( *diff == *io::readWkt( "MULTILINESTRING((-10 0,-1 0),(-0.5 0,0 0,0.5 0),(1 0,10 0))" ) ); - } - - // segment - polygon in 2D, with sement lying on hole border - { - std::unique_ptr ls1 = io::readWkt( "LINESTRING(-10 0,10 0)" ); - std::unique_ptr ls2 = io::readWkt( "POLYGON((-1 -1,1 -1,1 1,-1 1,-1 -1),(-0.5 -0.5,-0.5 0.5,0 0,-0.5 -0.5),(0.5 0,0.5 -0.5,0 0,0.5 0))" ); - std::unique_ptr diff = algorithm::difference( *ls1, *ls2 ); - BOOST_CHECK( *diff == *io::readWkt( "MULTILINESTRING((-10 0,-1 0),(-0.5 0,0 0),(1 0,10 0))" ) ); - } - + // segment - polygon in 2D + { + std::unique_ptr const ls1 = io::readWkt("LINESTRING(-10 0,10 0)"); + std::unique_ptr const ls2 = + io::readWkt("POLYGON((-1 -1,1 -1,1 1,-1 1,-1 -1),(-0.5 -0.5,-0.5 0.5,0 " + "0,-0.5 -0.5),(0.5 0.5,0.5 -0.5,0 0,0.5 0.5))"); + std::unique_ptr const diff = algorithm::difference(*ls1, *ls2); + BOOST_CHECK( + *diff == + *io::readWkt( + "MULTILINESTRING((-10 0,-1 0),(-0.5 0,0 0,0.5 0),(1 0,10 0))")); + } + + // segment - polygon in 2D, with sement lying on hole border + { + std::unique_ptr const ls1 = io::readWkt("LINESTRING(-10 0,10 0)"); + std::unique_ptr const ls2 = + io::readWkt("POLYGON((-1 -1,1 -1,1 1,-1 1,-1 -1),(-0.5 -0.5,-0.5 0.5,0 " + "0,-0.5 -0.5),(0.5 0,0.5 -0.5,0 0,0.5 0))"); + std::unique_ptr const diff = algorithm::difference(*ls1, *ls2); + BOOST_CHECK( + *diff == + *io::readWkt("MULTILINESTRING((-10 0,-1 0),(-0.5 0,0 0),(1 0,10 0))")); + } } -BOOST_AUTO_TEST_CASE( testDifferencePoinLine ) +BOOST_AUTO_TEST_CASE(testDifferencePoinLine) { - // point - segment in 3D - { - std::unique_ptr ls1 = io::readWkt( "POINT(0.5 0.5 0.6)" ); - std::unique_ptr ls2 = io::readWkt( "LINESTRING(0 0 0,1 1 1)" ); - std::unique_ptr diff = algorithm::difference3D( *ls1, *ls2 ); - BOOST_CHECK( *diff == *io::readWkt( "POINT(0.5 0.5 0.6)" ) ); - } - { - std::unique_ptr ls1 = io::readWkt( "POINT(0.5 0.5 0.5)" ); - std::unique_ptr ls2 = io::readWkt( "LINESTRING(0 0 0,1 1 1)" ); - std::unique_ptr diff = algorithm::difference3D( *ls1, *ls2 ); - BOOST_CHECK( *diff == *io::readWkt( "GEOMETRYCOLLECTION EMPTY" ) ); - } - + // point - segment in 3D + { + std::unique_ptr const ls1 = io::readWkt("POINT(0.5 0.5 0.6)"); + std::unique_ptr const ls2 = + io::readWkt("LINESTRING(0 0 0,1 1 1)"); + std::unique_ptr const diff = algorithm::difference3D(*ls1, *ls2); + BOOST_CHECK(*diff == *io::readWkt("POINT(0.5 0.5 0.6)")); + } + { + std::unique_ptr const ls1 = io::readWkt("POINT(0.5 0.5 0.5)"); + std::unique_ptr const ls2 = + io::readWkt("LINESTRING(0 0 0,1 1 1)"); + std::unique_ptr const diff = algorithm::difference3D(*ls1, *ls2); + BOOST_CHECK(*diff == *io::readWkt("GEOMETRYCOLLECTION EMPTY")); + } } -BOOST_AUTO_TEST_CASE( testDifferencePoinPolygon2D ) +BOOST_AUTO_TEST_CASE(testDifferencePoinPolygon2D) { - // point - triangle in 3D - { - std::unique_ptr ls1 = io::readWkt( "POINT(0.5 0.5 0.6)" ); - std::unique_ptr ls2 = io::readWkt( "POLYGON((0 0 0,1 1 1,1 0 1,0 0 0))" ); - std::unique_ptr diff = algorithm::difference3D( *ls1, *ls2 ); - BOOST_CHECK( *diff == *io::readWkt( "POINT(0.5 0.5 0.6)" ) ); - } - { - std::unique_ptr ls1 = io::readWkt( "POINT(0.5 0.5 0.5)" ); - std::unique_ptr ls2 = io::readWkt( "POLYGON((0 0 0,1 1 1,1 0 1,0 0 0))" ); - std::unique_ptr diff = algorithm::difference3D( *ls1, *ls2 ); - BOOST_CHECK( *diff == *io::readWkt( "GEOMETRYCOLLECTION EMPTY" ) ); - } + // point - triangle in 3D + { + std::unique_ptr const ls1 = io::readWkt("POINT(0.5 0.5 0.6)"); + std::unique_ptr const ls2 = + io::readWkt("POLYGON((0 0 0,1 1 1,1 0 1,0 0 0))"); + std::unique_ptr const diff = algorithm::difference3D(*ls1, *ls2); + BOOST_CHECK(*diff == *io::readWkt("POINT(0.5 0.5 0.6)")); + } + { + std::unique_ptr const ls1 = io::readWkt("POINT(0.5 0.5 0.5)"); + std::unique_ptr const ls2 = + io::readWkt("POLYGON((0 0 0,1 1 1,1 0 1,0 0 0))"); + std::unique_ptr const diff = algorithm::difference3D(*ls1, *ls2); + BOOST_CHECK(*diff == *io::readWkt("GEOMETRYCOLLECTION EMPTY")); + } } -BOOST_AUTO_TEST_CASE( testDifferencePoinVolume ) +BOOST_AUTO_TEST_CASE(testDifferencePoinVolume) { - // point - volume - { - std::unique_ptr ls1 = io::readWkt( "POINT(0.5 0.5 0.5)" ); - std::unique_ptr ls2 = io::readWkt( - "SOLID((((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)),\ + // point - volume + { + std::unique_ptr const ls1 = io::readWkt("POINT(0.5 0.5 0.5)"); + std::unique_ptr const ls2 = + io::readWkt("SOLID((((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)),\ ((0 0 0, 0 0 1, 0 1 1, 0 1 0, 0 0 0)),\ ((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)),\ ((1 1 1, 0 1 1, 0 0 1, 1 0 1, 1 1 1)),\ ((1 1 1, 1 0 1, 1 0 0, 1 1 0, 1 1 1)),\ - ((1 1 1, 1 1 0, 0 1 0, 0 1 1, 1 1 1))))" ); - std::unique_ptr diff = algorithm::difference3D( *ls1, *ls2 ); - BOOST_CHECK( *diff == *io::readWkt( "GEOMETRYCOLLECTION EMPTY" ) ); - } - { - std::unique_ptr ls1 = io::readWkt( "POINT(1.001 0.5 0.5)" ); - std::unique_ptr ls2 = io::readWkt( - "SOLID((((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)),\ + ((1 1 1, 1 1 0, 0 1 0, 0 1 1, 1 1 1))))"); + std::unique_ptr const diff = algorithm::difference3D(*ls1, *ls2); + BOOST_CHECK(*diff == *io::readWkt("GEOMETRYCOLLECTION EMPTY")); + } + { + std::unique_ptr const ls1 = io::readWkt("POINT(1.001 0.5 0.5)"); + std::unique_ptr const ls2 = + io::readWkt("SOLID((((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)),\ ((0 0 0, 0 0 1, 0 1 1, 0 1 0, 0 0 0)),\ ((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)),\ ((1 1 1, 0 1 1, 0 0 1, 1 0 1, 1 1 1)),\ ((1 1 1, 1 0 1, 1 0 0, 1 1 0, 1 1 1)),\ - ((1 1 1, 1 1 0, 0 1 0, 0 1 1, 1 1 1))))" ); - std::unique_ptr diff = algorithm::difference3D( *ls1, *ls2 ); - BOOST_CHECK( *diff == *io::readWkt( "POINT(1.001 0.5 0.5)" ) ); - } - + ((1 1 1, 1 1 0, 0 1 0, 0 1 1, 1 1 1))))"); + std::unique_ptr const diff = algorithm::difference3D(*ls1, *ls2); + BOOST_CHECK(*diff == *io::readWkt("POINT(1.001 0.5 0.5)")); + } } -BOOST_AUTO_TEST_CASE( testDifferenceTriangleTriangle3D ) +BOOST_AUTO_TEST_CASE(testDifferenceTriangleTriangle3D) { - // triangle - trangle in 3D don't share the same plane - { - std::unique_ptr ls1 = io::readWkt( "TRIANGLE((0 0 0,0 1 1,1 0 0,0 0 0))" ); - std::unique_ptr ls2 = io::readWkt( "TRIANGLE((0 0 0,0 1 1.01,1 0 0,0 0 0))" ); - std::unique_ptr diff = algorithm::difference3D( *ls1, *ls2 ); - BOOST_CHECK( *diff == *io::readWkt( "TRIANGLE((0 0 0,0 1 1,1 0 0,0 0 0))" ) ); - } - // triangle - trangle in 3D don't intersect - { - std::unique_ptr ls1 = io::readWkt( "TRIANGLE((0 0 0,0 1 1,1 0 0,0 0 0))" ); - std::unique_ptr ls2 = io::readWkt( "TRIANGLE((.6 .6 .6,1.6 1.6 1.6,1.6 .6 .6,.6 .6 .6))" ); - std::unique_ptr diff = algorithm::difference3D( *ls1, *ls2 ); - BOOST_CHECK( *diff == *io::readWkt( "TRIANGLE((0 0 0,0 1 1,1 0 0,0 0 0))" ) ); - } - // triangle - triangle in 3D do intersect - { - std::unique_ptr ls1 = io::readWkt( "TRIANGLE((0 0 0,0 1 1,1 0 0,0 0 0))" ); - std::unique_ptr ls2 = io::readWkt( "TRIANGLE((.1 .1 .1,1.6 1.6 1.6,1.6 .6 .6,.1 .1 .1))" ); - std::unique_ptr diff = algorithm::difference3D( *ls1, *ls2 ); - BOOST_CHECK( *diff == *io::readWkt( "TIN(((0 1 1,.5 .5 .5,.1 .1 .1,0 1 1)),((0 0 0,0 1 1,.1 .1 .1,0 0 0)),((.7 .3 .3,1 0 0,.1 .1 .1,.7 .3 .3)),((1 0 0,0 0 0,.1 .1 .1,1 0 0)))" ) ); - } - + // triangle - trangle in 3D don't share the same plane + { + std::unique_ptr const ls1 = + io::readWkt("TRIANGLE((0 0 0,0 1 1,1 0 0,0 0 0))"); + std::unique_ptr const ls2 = + io::readWkt("TRIANGLE((0 0 0,0 1 1.01,1 0 0,0 0 0))"); + std::unique_ptr const diff = algorithm::difference3D(*ls1, *ls2); + BOOST_CHECK(*diff == *io::readWkt("TRIANGLE((0 0 0,0 1 1,1 0 0,0 0 0))")); + } + // triangle - trangle in 3D don't intersect + { + std::unique_ptr const ls1 = + io::readWkt("TRIANGLE((0 0 0,0 1 1,1 0 0,0 0 0))"); + std::unique_ptr const ls2 = + io::readWkt("TRIANGLE((.6 .6 .6,1.6 1.6 1.6,1.6 .6 .6,.6 .6 .6))"); + std::unique_ptr const diff = algorithm::difference3D(*ls1, *ls2); + BOOST_CHECK(*diff == *io::readWkt("TRIANGLE((0 0 0,0 1 1,1 0 0,0 0 0))")); + } + // triangle - triangle in 3D do intersect + { + std::unique_ptr const ls1 = + io::readWkt("TRIANGLE((0 0 0,0 1 1,1 0 0,0 0 0))"); + std::unique_ptr const ls2 = + io::readWkt("TRIANGLE((.1 .1 .1,1.6 1.6 1.6,1.6 .6 .6,.1 .1 .1))"); + std::unique_ptr const diff = algorithm::difference3D(*ls1, *ls2); + BOOST_CHECK(*diff == + *io::readWkt("TIN(((0 1 1,.5 .5 .5,.1 .1 .1,0 1 1)),((0 0 0,0 " + "1 1,.1 .1 .1,0 0 0)),((.7 .3 .3,1 0 0,.1 .1 " + ".1,.7 .3 .3)),((1 0 0,0 0 0,.1 .1 .1,1 0 0)))")); + } } -BOOST_AUTO_TEST_CASE( testDifferenceTriangleVolume ) +BOOST_AUTO_TEST_CASE(testDifferenceTriangleVolume) { - // triangle - volume in 3D - { - std::unique_ptr ls1 = io::readWkt( "TRIANGLE((0 0 .5,10 0 .5,0 10 .5,0 0 .5))" ); - std::unique_ptr ls2 = io::readWkt( - "SOLID((((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)),\ + // triangle - volume in 3D + { + std::unique_ptr const ls1 = + io::readWkt("TRIANGLE((0 0 .5,10 0 .5,0 10 .5,0 0 .5))"); + std::unique_ptr const ls2 = + io::readWkt("SOLID((((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)),\ ((0 0 0, 0 0 1, 0 1 1, 0 1 0, 0 0 0)),\ ((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)),\ ((1 1 1, 0 1 1, 0 0 1, 1 0 1, 1 1 1)),\ ((1 1 1, 1 0 1, 1 0 0, 1 1 0, 1 1 1)),\ - ((1 1 1, 1 1 0, 0 1 0, 0 1 1, 1 1 1))))" ); - std::unique_ptr diff = algorithm::difference3D( *ls1, *ls2 ); - std::unique_ptr ref = io::readWkt( "TIN(((0/1 10/1 1/2,9/20 1/1 1/2,1/2 1/1 1/2,0/1 10/1 1/2)),((0/1 10/1 1/2,1/2 1/1 1/2,18/19 1/1 1/2,0/1 10/1 1/2)),((0/1 10/1 1/2,0/1 1/1 1/2,9/20 1/1 1/2,0/1 10/1 1/2)),((1/1 0/1 1/2,10/1 0/1 1/2,1/1 1/2 1/2,1/1 0/1 1/2)),((1/1 1/1 1/2,0/1 10/1 1/2,18/19 1/1 1/2,1/1 1/1 1/2)),((10/1 0/1 1/2,0/1 10/1 1/2,1/1 1/1 1/2,10/1 0/1 1/2)),((1/1 1/2 1/2,10/1 0/1 1/2,1/1 1/1 1/2,1/1 1/2 1/2)))" ); - BOOST_CHECK( algorithm::covers( *diff, *ref ) && algorithm::covers( *ref, *diff ) ); - } + ((1 1 1, 1 1 0, 0 1 0, 0 1 1, 1 1 1))))"); + std::unique_ptr const diff = algorithm::difference3D(*ls1, *ls2); + std::unique_ptr const ref = io::readWkt( + "TIN(((0/1 10/1 1/2,9/20 1/1 1/2,1/2 1/1 1/2,0/1 10/1 1/2)),((0/1 10/1 " + "1/2,1/2 1/1 1/2,18/19 1/1 1/2,0/1 10/1 1/2)),((0/1 10/1 1/2,0/1 1/1 " + "1/2,9/20 1/1 1/2,0/1 10/1 1/2)),((1/1 0/1 1/2,10/1 0/1 1/2,1/1 1/2 " + "1/2,1/1 0/1 1/2)),((1/1 1/1 1/2,0/1 10/1 1/2,18/19 1/1 1/2,1/1 1/1 " + "1/2)),((10/1 0/1 1/2,0/1 10/1 1/2,1/1 1/1 1/2,10/1 0/1 1/2)),((1/1 " + "1/2 1/2,10/1 0/1 1/2,1/1 1/1 1/2,1/1 1/2 1/2)))"); + BOOST_CHECK(algorithm::covers(*diff, *ref) && + algorithm::covers(*ref, *diff)); + } } -BOOST_AUTO_TEST_CASE( testDifferenceLineVolume ) +BOOST_AUTO_TEST_CASE(testDifferenceLineVolume) { - // segment - volume in 3D - { - std::unique_ptr ls1 = io::readWkt( "LINESTRING(-3 -3 .5,3 3 .5,1 1.1 .5,1 .1 .5,.1 .1 .5)" ); - std::unique_ptr ls2 = io::readWkt( - "SOLID((((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)),\ + // segment - volume in 3D + { + std::unique_ptr const ls1 = + io::readWkt("LINESTRING(-3 -3 .5,3 3 .5,1 1.1 .5,1 .1 .5,.1 .1 .5)"); + std::unique_ptr const ls2 = + io::readWkt("SOLID((((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)),\ ((0 0 0, 0 0 1, 0 1 1, 0 1 0, 0 0 0)),\ ((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)),\ ((1 1 1, 0 1 1, 0 0 1, 1 0 1, 1 1 1)),\ ((1 1 1, 1 0 1, 1 0 0, 1 1 0, 1 1 1)),\ - ((1 1 1, 1 1 0, 0 1 0, 0 1 1, 1 1 1))))" ); - std::unique_ptr diff = algorithm::difference3D( *ls1, *ls2 ); - BOOST_CHECK( *diff == *io::readWkt( "MULTILINESTRING((-3 -3 .5,0 0 .5),(1 1 .5,3 3 .5,1 1.1 .5,1 1 .5))" ) ); - } - + ((1 1 1, 1 1 0, 0 1 0, 0 1 1, 1 1 1))))"); + std::unique_ptr const diff = algorithm::difference3D(*ls1, *ls2); + BOOST_CHECK(*diff == *io::readWkt("MULTILINESTRING((-3 -3 .5,0 0 .5),(1 1 " + ".5,3 3 .5,1 1.1 .5,1 1 .5))")); + } } -BOOST_AUTO_TEST_CASE( testDifferencePolygonVolume ) +BOOST_AUTO_TEST_CASE(testDifferencePolygonVolume) { - // polygon - volume crashing the algo in garden - { - std::unique_ptr ls1 = io::readWkt( "POLYGON((1 -1 -1,1 1 -1,1 1 1,1 -1 1,1 -1 -1))" ); - std::unique_ptr ls2 = io::readWkt( - "SOLID((((0 0 0,0 1 0,1 1 0,1 0 0,0 0 0)),\ + // polygon - volume crashing the algo in garden + { + std::unique_ptr const ls1 = + io::readWkt("POLYGON((1 -1 -1,1 1 -1,1 1 1,1 -1 1,1 -1 -1))"); + std::unique_ptr const ls2 = + io::readWkt("SOLID((((0 0 0,0 1 0,1 1 0,1 0 0,0 0 0)),\ ((0 0 0,0 0 1,0 1 1,0 1 0,0 0 0)),\ ((0 0 0,1 0 0,1 0 1,0 0 1,0 0 0)),\ ((1 1 1,0 1 1,0 0 1,1 0 1,1 1 1)),\ ((1 1 1,1 0 1,1 0 0,1 1 0,1 1 1)),\ - ((1 1 1,1 1 0,0 1 0,0 1 1,1 1 1))))" ); - std::unique_ptr diff = algorithm::difference3D( *ls1, *ls2 ); - } - + ((1 1 1,1 1 0,0 1 0,0 1 1,1 1 1))))"); + std::unique_ptr const diff = algorithm::difference3D(*ls1, *ls2); + } } -BOOST_AUTO_TEST_CASE( testDifference3DDivideByZeroCrash ) +BOOST_AUTO_TEST_CASE(testDifference3DDivideByZeroCrash) { - // Correct behaviour is to throw an exception about the degenerate polygon in g1. - // Incorrect behaviour is a divide by zero error - { - std::unique_ptr g1 = io::readWkt("SOLID((((1 1 0.5,0.5 1 0.5,0.5 1.5 0.5,1 1 0.5)),\ + // Correct behaviour is to throw an exception about the degenerate polygon in + // g1. Incorrect behaviour is a divide by zero error + { + std::unique_ptr const g1 = + io::readWkt("SOLID((((1 1 0.5,0.5 1 0.5,0.5 1.5 0.5,1 1 0.5)),\ ((0.5 1 0.5,1 1 0.5,1 1 -1,0.5 1 0.5)),\ ((0.5 1.5 0.5,0.5 1 0.5,0.5 1 1,0.5 1.5 0.5)),\ ((1 1 0.5,0.5 1.5 0.5,1.5 1.5 0.5,1 1 0.5)),\ @@ -419,7 +472,8 @@ BOOST_AUTO_TEST_CASE( testDifference3DDivideByZeroCrash ) ((1 0.5 0.5,1 0.5 1,1 -1 1,1 0.5 0.5)),\ ((0 0.5 1,1 -1 1,0.5 0.5 1,0 0.5 1)),\ ((1 0.5 1,0.5 0.5 1,1 -1 1,1 0.5 1))))"); - std::unique_ptr g2 = io::readWkt("SOLID((((-0.5 1 1,-0.5 1 -0.5,-1 1 1,-0.5 1 1)),\ + std::unique_ptr const g2 = + io::readWkt("SOLID((((-0.5 1 1,-0.5 1 -0.5,-1 1 1,-0.5 1 1)),\ ((-0.5 1 -0.5,-0.5 1 1,-0.5 1.5 -0.5,-0.5 1 -0.5)),\ ((-1 1 1,-0.5 1 -0.5,-1 1 -1,-1 1 1)),\ ((-0.5 1 1,-1 1 1,-0.5 0.5 1,-0.5 1 1)),\ @@ -468,22 +522,18 @@ BOOST_AUTO_TEST_CASE( testDifference3DDivideByZeroCrash ) ((1.5 -0.5 -0.5,1 -0.5 0.5,1 -0.5 -0,1.5 -0.5 -0.5)),\ ((1 -1 1,1 -0.5 0.5,1 -0.5 1,1 -1 1))))"); - try - { - std::unique_ptr diff = algorithm::difference3D( *g1, *g2, algorithm::NoValidityCheck() ); - } - catch(...) - { - } - - try - { - std::unique_ptr diff = algorithm::difference3D( *g2, *g1, algorithm::NoValidityCheck() ); - } - catch(...) - { - } + try { + std::unique_ptr const diff = + algorithm::difference3D(*g1, *g2, algorithm::NoValidityCheck()); + } catch (...) { + } + + try { + std::unique_ptr const diff = + algorithm::difference3D(*g2, *g1, algorithm::NoValidityCheck()); + } catch (...) { } + } } BOOST_AUTO_TEST_SUITE_END() diff --git a/test/unit/SFCGAL/algorithm/DistanceTest.cpp b/test/unit/SFCGAL/algorithm/DistanceTest.cpp index ab6b0b7a..4ed05809 100644 --- a/test/unit/SFCGAL/algorithm/DistanceTest.cpp +++ b/test/unit/SFCGAL/algorithm/DistanceTest.cpp @@ -15,44 +15,46 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include -#include -#include -#include -#include -#include -#include -#include #include -#include +#include #include +#include #include #include -#include +#include +#include +#include +#include +#include +#include #include +#include -#include #include +#include -using namespace SFCGAL ; +using namespace SFCGAL; // always after CGAL -using namespace boost::unit_test ; +using namespace boost::unit_test; -BOOST_AUTO_TEST_SUITE( SFCGAL_algorithm_DistanceTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_algorithm_DistanceTest) /* * check that distance between empty points is infinity */ -BOOST_AUTO_TEST_CASE( testDistanceBetweenEmptyPointsIsInfinity ) +BOOST_AUTO_TEST_CASE(testDistanceBetweenEmptyPointsIsInfinity) { - BOOST_CHECK_EQUAL( Point().distance( Point() ), std::numeric_limits< double >::infinity() ); + BOOST_CHECK_EQUAL(Point().distance(Point()), + std::numeric_limits::infinity()); } -//TODO enable when implement is complete +// TODO enable when implement is complete #if 0 /* @@ -102,146 +104,160 @@ BOOST_AUTO_TEST_CASE( testDistance3DBetweenEmptyGeometriesIsDefined ) #endif - -BOOST_AUTO_TEST_CASE( testDistancePointPoint ) +BOOST_AUTO_TEST_CASE(testDistancePointPoint) { - BOOST_CHECK_EQUAL( Point( 0.0,0.0 ).distance( Point( 0.0,0.0 ) ), 0.0 ); - BOOST_CHECK_EQUAL( Point( 1.0,1.0 ).distance( Point( 4.0,5.0 ) ), 5.0 ); + BOOST_CHECK_EQUAL(Point(0.0, 0.0).distance(Point(0.0, 0.0)), 0.0); + BOOST_CHECK_EQUAL(Point(1.0, 1.0).distance(Point(4.0, 5.0)), 5.0); } -BOOST_AUTO_TEST_CASE( testDistancePointPoint3D ) +BOOST_AUTO_TEST_CASE(testDistancePointPoint3D) { - BOOST_CHECK_EQUAL( Point( 0.0,0.0,0.0 ).distance3D( Point( 0.0,0.0,0.0 ) ), 0.0 ); - BOOST_CHECK_EQUAL( Point( 1.0,1.0,1.0 ).distance3D( Point( 4.0,1.0,5.0 ) ), 5.0 ); + BOOST_CHECK_EQUAL(Point(0.0, 0.0, 0.0).distance3D(Point(0.0, 0.0, 0.0)), 0.0); + BOOST_CHECK_EQUAL(Point(1.0, 1.0, 1.0).distance3D(Point(4.0, 1.0, 5.0)), 5.0); } - -//testPointLineString -BOOST_AUTO_TEST_CASE( testDistancePointLineString_pointOnLineString ) +// testPointLineString +BOOST_AUTO_TEST_CASE(testDistancePointLineString_pointOnLineString) { - Point point( 1.0,1.0 ); - LineString lineString( - Point( 0.0,0.0 ), - Point( 2.0,2.0 ) - ); - BOOST_CHECK_EQUAL( point.distance( lineString ), 0.0 ); + Point const point(1.0, 1.0); + LineString const lineString(Point(0.0, 0.0), Point(2.0, 2.0)); + BOOST_CHECK_EQUAL(point.distance(lineString), 0.0); } -BOOST_AUTO_TEST_CASE( testDistancePointLineString_pointOnLineString_badLineStringDefinition ) +BOOST_AUTO_TEST_CASE( + testDistancePointLineString_pointOnLineString_badLineStringDefinition) { - Point point( 3.0,4.0 ); - LineString lineString ; - lineString.addPoint( Point( 0.0,0.0 ) ); - BOOST_CHECK_THROW( point.distance( lineString ), GeometryInvalidityException ); + Point const point(3.0, 4.0); + LineString lineString; + lineString.addPoint(Point(0.0, 0.0)); + BOOST_CHECK_THROW(point.distance(lineString), GeometryInvalidityException); } -BOOST_AUTO_TEST_CASE( testDistancePointLineString_pointOnLineString_collapsedSegments ) +BOOST_AUTO_TEST_CASE( + testDistancePointLineString_pointOnLineString_collapsedSegments) { - Point point( 3.0,4.0 ); - LineString lineString ; - lineString.addPoint( Point( 0.0,0.0 ) ); - lineString.addPoint( Point( 0.0,0.0 ) ); - BOOST_CHECK_THROW( point.distance( lineString ), GeometryInvalidityException ); + Point const point(3.0, 4.0); + LineString lineString; + lineString.addPoint(Point(0.0, 0.0)); + lineString.addPoint(Point(0.0, 0.0)); + BOOST_CHECK_THROW(point.distance(lineString), GeometryInvalidityException); } -BOOST_AUTO_TEST_CASE( testDistancePointLineString3D_pointOnLineString_collapsedSegments ) +BOOST_AUTO_TEST_CASE( + testDistancePointLineString3D_pointOnLineString_collapsedSegments) { - Point point( 0.0,3.0,4.0 ); - LineString lineString ; - lineString.addPoint( Point( 0.0,0.0,0.0 ) ); - lineString.addPoint( Point( 0.0,-1.0,-1.0 ) ); - BOOST_CHECK_EQUAL( point.distance3D( lineString ), 5.0 ); + Point const point(0.0, 3.0, 4.0); + LineString lineString; + lineString.addPoint(Point(0.0, 0.0, 0.0)); + lineString.addPoint(Point(0.0, -1.0, -1.0)); + BOOST_CHECK_EQUAL(point.distance3D(lineString), 5.0); } - - -BOOST_AUTO_TEST_CASE( testDistancePointLineString_pointOutOfLineString ) +BOOST_AUTO_TEST_CASE(testDistancePointLineString_pointOutOfLineString) { - Point point( 0.0,1.0 ); - LineString lineString( - Point( 0.0,0.0 ), - Point( 2.0,2.0 ) - ); - BOOST_CHECK_EQUAL( point.distance( lineString ), sqrt( 2.0 )/2.0 ); + Point const point(0.0, 1.0); + LineString const lineString(Point(0.0, 0.0), Point(2.0, 2.0)); + BOOST_CHECK_EQUAL(point.distance(lineString), sqrt(2.0) / 2.0); } -//testPointPolygon -BOOST_AUTO_TEST_CASE( testDistancePointPolygon_pointInPolygon ) +// testPointPolygon +BOOST_AUTO_TEST_CASE(testDistancePointPolygon_pointInPolygon) { - std::unique_ptr< Geometry > gA( io::readWkt( "POINT(0.5 0.5)" ) ); - std::unique_ptr< Geometry > gB( io::readWkt( "POLYGON((0.0 0.0,1.0 0.0,1.0 1.0,0.0 1.0,0.0 0.0))" ) ); - BOOST_CHECK_EQUAL( gA->distance( *gB ), 0.0 ); + std::unique_ptr gA(io::readWkt("POINT(0.5 0.5)")); + std::unique_ptr const gB( + io::readWkt("POLYGON((0.0 0.0,1.0 0.0,1.0 1.0,0.0 1.0,0.0 0.0))")); + BOOST_CHECK_EQUAL(gA->distance(*gB), 0.0); } -BOOST_AUTO_TEST_CASE( testDistancePointPolygon_pointOutOfPolygon ) +BOOST_AUTO_TEST_CASE(testDistancePointPolygon_pointOutOfPolygon) { - std::unique_ptr< Geometry > gA( io::readWkt( "POINT(0.0 1.0)" ) ); - std::unique_ptr< Geometry > gB( io::readWkt( "POLYGON((0.0 0.0,2.0 2.0,2.0 0.0,0.0 0.0))" ) ); - BOOST_CHECK_EQUAL( gA->distance( *gB ), sqrt( 2.0 )/2.0 ); + std::unique_ptr gA(io::readWkt("POINT(0.0 1.0)")); + std::unique_ptr const gB( + io::readWkt("POLYGON((0.0 0.0,2.0 2.0,2.0 0.0,0.0 0.0))")); + BOOST_CHECK_EQUAL(gA->distance(*gB), sqrt(2.0) / 2.0); } // LineString / LineString 2D -BOOST_AUTO_TEST_CASE( testDistanceLineStringLineString_zeroLengthSegments ) +BOOST_AUTO_TEST_CASE(testDistanceLineStringLineString_zeroLengthSegments) { - std::unique_ptr< Geometry > gA( io::readWkt( "LINESTRING(0.0 0.0,-1.0 -1.0)" ) ); - std::unique_ptr< Geometry > gB( io::readWkt( "LINESTRING(3.0 4.0,4.0 5.0)" ) ); - BOOST_CHECK_EQUAL( gA->distance( *gB ), 5.0 ); + std::unique_ptr gA(io::readWkt("LINESTRING(0.0 0.0,-1.0 -1.0)")); + std::unique_ptr const gB( + io::readWkt("LINESTRING(3.0 4.0,4.0 5.0)")); + BOOST_CHECK_EQUAL(gA->distance(*gB), 5.0); } // LineString / LineString 3D -BOOST_AUTO_TEST_CASE( testDistanceLineStringLineString3D_zeroLengthSegments ) +BOOST_AUTO_TEST_CASE(testDistanceLineStringLineString3D_zeroLengthSegments) { - std::unique_ptr< Geometry > gA( io::readWkt( "LINESTRING(0.0 0.0 0.0,-1.0 -1.0 -1.0)" ) ); - std::unique_ptr< Geometry > gB( io::readWkt( "LINESTRING(0.0 3.0 4.0,0.0 4.0 5.0)" ) ); - BOOST_CHECK_EQUAL( gA->distance3D( *gB ), 5.0 ); + std::unique_ptr gA( + io::readWkt("LINESTRING(0.0 0.0 0.0,-1.0 -1.0 -1.0)")); + std::unique_ptr const gB( + io::readWkt("LINESTRING(0.0 3.0 4.0,0.0 4.0 5.0)")); + BOOST_CHECK_EQUAL(gA->distance3D(*gB), 5.0); } // LineString / Triangle -BOOST_AUTO_TEST_CASE( testDistance3DLineStringTriangle_lineStringInTriangle ) +BOOST_AUTO_TEST_CASE(testDistance3DLineStringTriangle_lineStringInTriangle) { - std::unique_ptr< Geometry > gA( io::readWkt( "LINESTRING(-1.0 0.0 1.0,1.0 0.0 1.0)" ) ); - std::unique_ptr< Geometry > gB( io::readWkt( "TRIANGLE((-4.0 0.0 1.0,4.0 0.0 1.0,0.0 4.0 1.0,-4.0 0.0 1.0))" ) ); - BOOST_CHECK_EQUAL( gA->distance3D( *gB ), 0.0 ); + std::unique_ptr gA( + io::readWkt("LINESTRING(-1.0 0.0 1.0,1.0 0.0 1.0)")); + std::unique_ptr const gB(io::readWkt( + "TRIANGLE((-4.0 0.0 1.0,4.0 0.0 1.0,0.0 4.0 1.0,-4.0 0.0 1.0))")); + BOOST_CHECK_EQUAL(gA->distance3D(*gB), 0.0); } -BOOST_AUTO_TEST_CASE( testDistance3DLineStringTriangle_lineStringStartPointIsNearest ) +BOOST_AUTO_TEST_CASE( + testDistance3DLineStringTriangle_lineStringStartPointIsNearest) { - std::unique_ptr< Geometry > gA( io::readWkt( "LINESTRING(-1.0 0.0 2.0,1.0 0.0 3.0)" ) ); - std::unique_ptr< Geometry > gB( io::readWkt( "TRIANGLE((-4.0 0.0 1.0,4.0 0.0 1.0,0.0 4.0 1.0,-4.0 0.0 1.0))" ) ); - BOOST_CHECK_EQUAL( gA->distance3D( *gB ), 1.0 ); + std::unique_ptr gA( + io::readWkt("LINESTRING(-1.0 0.0 2.0,1.0 0.0 3.0)")); + std::unique_ptr const gB(io::readWkt( + "TRIANGLE((-4.0 0.0 1.0,4.0 0.0 1.0,0.0 4.0 1.0,-4.0 0.0 1.0))")); + BOOST_CHECK_EQUAL(gA->distance3D(*gB), 1.0); } // Triangle / Triangle -BOOST_AUTO_TEST_CASE( testDistance3DTriangleTriangle_contained ) +BOOST_AUTO_TEST_CASE(testDistance3DTriangleTriangle_contained) { - std::unique_ptr< Geometry > gA( io::readWkt( "TRIANGLE((-3.0 0.0 1.0,3.0 0.0 1.0,0.0 3.0 1.0,-3.0 0.0 1.0))" ) ); - std::unique_ptr< Geometry > gB( io::readWkt( "TRIANGLE((-4.0 0.0 1.0,4.0 0.0 1.0,0.0 4.0 1.0,-4.0 0.0 1.0))" ) ); - BOOST_CHECK_EQUAL( gA->distance3D( *gB ), 0.0 ); + std::unique_ptr gA(io::readWkt( + "TRIANGLE((-3.0 0.0 1.0,3.0 0.0 1.0,0.0 3.0 1.0,-3.0 0.0 1.0))")); + std::unique_ptr const gB(io::readWkt( + "TRIANGLE((-4.0 0.0 1.0,4.0 0.0 1.0,0.0 4.0 1.0,-4.0 0.0 1.0))")); + BOOST_CHECK_EQUAL(gA->distance3D(*gB), 0.0); } -BOOST_AUTO_TEST_CASE( testDistance3DTriangleTriangle_parallel ) +BOOST_AUTO_TEST_CASE(testDistance3DTriangleTriangle_parallel) { - std::unique_ptr< Geometry > gA( io::readWkt( "TRIANGLE((-3.0 0.0 1.0,3.0 0.0 1.0,0.0 3.0 1.0,-3.0 0.0 1.0))" ) ); - std::unique_ptr< Geometry > gB( io::readWkt( "TRIANGLE((-4.0 0.0 2.0,4.0 0.0 2.0,0.0 4.0 2.0,-4.0 0.0 2.0))" ) ); - BOOST_CHECK_EQUAL( gA->distance3D( *gB ), 1.0 ); + std::unique_ptr gA(io::readWkt( + "TRIANGLE((-3.0 0.0 1.0,3.0 0.0 1.0,0.0 3.0 1.0,-3.0 0.0 1.0))")); + std::unique_ptr const gB(io::readWkt( + "TRIANGLE((-4.0 0.0 2.0,4.0 0.0 2.0,0.0 4.0 2.0,-4.0 0.0 2.0))")); + BOOST_CHECK_EQUAL(gA->distance3D(*gB), 1.0); } // Polygon / Polygon -BOOST_AUTO_TEST_CASE( testDistancePolygonPolygon_disjoint ) +BOOST_AUTO_TEST_CASE(testDistancePolygonPolygon_disjoint) { - std::unique_ptr< Geometry > gA( io::readWkt( "POLYGON((0.0 0.0,1.0 0.0,1.0 1.0,0.0 1.0,0.0 0.0))" ) ); - std::unique_ptr< Geometry > gB( io::readWkt( "POLYGON((2.0 0.0,3.0 0.0,3.0 1.0,2.0 1.0,2.0 0.0))" ) ); - BOOST_CHECK_EQUAL( gA->distance( *gB ), 1.0 ); + std::unique_ptr gA( + io::readWkt("POLYGON((0.0 0.0,1.0 0.0,1.0 1.0,0.0 1.0,0.0 0.0))")); + std::unique_ptr const gB( + io::readWkt("POLYGON((2.0 0.0,3.0 0.0,3.0 1.0,2.0 1.0,2.0 0.0))")); + BOOST_CHECK_EQUAL(gA->distance(*gB), 1.0); } -BOOST_AUTO_TEST_CASE( testDistanceMultiPointMultiPoint_disjoint ) +BOOST_AUTO_TEST_CASE(testDistanceMultiPointMultiPoint_disjoint) { - std::unique_ptr< Geometry > gA( io::readWkt( "MULTIPOINT((0.0 0.0),(1.0 0.0),(1.0 1.0),(0.0 1.0))" ) ); - std::unique_ptr< Geometry > gB( io::readWkt( "MULTIPOINT((8.0 8.0),(4.0 5.0))" ) ); - BOOST_CHECK_EQUAL( gA->distance( *gB ), 5.0 ); + std::unique_ptr gA( + io::readWkt("MULTIPOINT((0.0 0.0),(1.0 0.0),(1.0 1.0),(0.0 1.0))")); + std::unique_ptr const gB( + io::readWkt("MULTIPOINT((8.0 8.0),(4.0 5.0))")); + BOOST_CHECK_EQUAL(gA->distance(*gB), 5.0); } // Polygon / Solid -BOOST_AUTO_TEST_CASE( testDistancePolygonSolid ) +BOOST_AUTO_TEST_CASE(testDistancePolygonSolid) { - std::unique_ptr< Geometry > gA( io::readWkt( "POLYGON((1 -1 -1,1 1 -1,1 1 1,1 -1 1,1 -1 -1))" ) ); - std::unique_ptr< Geometry > gB( io::readWkt( "SOLID((((0 0 0,0 1 0,1 1 0,1 0 0,0 0 0)),((0 0 0,0 0 1,0 1 1,0 1 0,0 0 0)),((0 0 0,1 0 0,1 0 1,0 0 1,0 0 0)),((1 1 1,0 1 1,0 0 1,1 0 1,1 1 1)),((1 1 1,1 0 1,1 0 0,1 1 0,1 1 1)),((1 1 1,1 1 0,0 1 0,0 1 1,1 1 1))))" ) ); - BOOST_CHECK_EQUAL( gA->distance3D( *gB ), 0 ); + std::unique_ptr gA( + io::readWkt("POLYGON((1 -1 -1,1 1 -1,1 1 1,1 -1 1,1 -1 -1))")); + std::unique_ptr const gB( + io::readWkt("SOLID((((0 0 0,0 1 0,1 1 0,1 0 0,0 0 0)),((0 0 0,0 0 1,0 1 " + "1,0 1 0,0 0 0)),((0 0 0,1 0 0,1 0 1,0 0 1,0 0 0)),((1 1 1,0 " + "1 1,0 0 1,1 0 1,1 1 1)),((1 1 1,1 0 1,1 0 0,1 1 0,1 1 " + "1)),((1 1 1,1 1 0,0 1 0,0 1 1,1 1 1))))")); + BOOST_CHECK_EQUAL(gA->distance3D(*gB), 0); } - BOOST_AUTO_TEST_SUITE_END() - diff --git a/test/unit/SFCGAL/algorithm/ExtrudeTest.cpp b/test/unit/SFCGAL/algorithm/ExtrudeTest.cpp index a194f499..6d15f871 100644 --- a/test/unit/SFCGAL/algorithm/ExtrudeTest.cpp +++ b/test/unit/SFCGAL/algorithm/ExtrudeTest.cpp @@ -15,160 +15,159 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include -#include -#include -#include -#include -#include -#include -#include #include -#include +#include #include +#include #include #include -#include +#include +#include +#include +#include +#include +#include #include #include #include -using namespace SFCGAL ; +using namespace SFCGAL; // always after CGAL -using namespace boost::unit_test ; - -BOOST_AUTO_TEST_SUITE( SFCGAL_algorithm_ExtrudeTest ) +using namespace boost::unit_test; +BOOST_AUTO_TEST_SUITE(SFCGAL_algorithm_ExtrudeTest) -BOOST_AUTO_TEST_CASE( testExtrudePoint ) +BOOST_AUTO_TEST_CASE(testExtrudePoint) { - Point g( 0.0,0.0,0.0 ); - std::unique_ptr< Geometry > ext( algorithm::extrude( g, 0.0, 0.0, 1.0 ) ); - BOOST_CHECK( ext->is< LineString >() ); - BOOST_CHECK( ext->as< LineString >().is3D() ); - BOOST_CHECK_EQUAL( ext->asText( 1 ), "LINESTRING Z(0.0 0.0 0.0,0.0 0.0 1.0)" ); + Point const g(0.0, 0.0, 0.0); + std::unique_ptr ext(algorithm::extrude(g, 0.0, 0.0, 1.0)); + BOOST_CHECK(ext->is()); + BOOST_CHECK(ext->as().is3D()); + BOOST_CHECK_EQUAL(ext->asText(1), "LINESTRING Z(0.0 0.0 0.0,0.0 0.0 1.0)"); } - -BOOST_AUTO_TEST_CASE( testExtrudeLineString ) +BOOST_AUTO_TEST_CASE(testExtrudeLineString) { - LineString g( - Point( 0.0,0.0,0.0 ), - Point( 1.0,0.0,0.0 ) - ); - std::unique_ptr< Geometry > ext( algorithm::extrude( g, 0.0, 0.0, 1.0 ) ); - BOOST_CHECK( ext->is< PolyhedralSurface >() ); - BOOST_CHECK( ext->as< PolyhedralSurface >().is3D() ); - BOOST_CHECK_EQUAL( ext->asText( 1 ), "POLYHEDRALSURFACE Z(((0.0 0.0 0.0,1.0 0.0 0.0,1.0 0.0 1.0,0.0 0.0 1.0,0.0 0.0 0.0)))" ); + LineString const g(Point(0.0, 0.0, 0.0), Point(1.0, 0.0, 0.0)); + std::unique_ptr ext(algorithm::extrude(g, 0.0, 0.0, 1.0)); + BOOST_CHECK(ext->is()); + BOOST_CHECK(ext->as().is3D()); + BOOST_CHECK_EQUAL(ext->asText(1), + "POLYHEDRALSURFACE Z(((0.0 0.0 0.0,1.0 0.0 0.0,1.0 0.0 " + "1.0,0.0 0.0 1.0,0.0 0.0 0.0)))"); } - - -BOOST_AUTO_TEST_CASE( testExtrudeSquare ) +BOOST_AUTO_TEST_CASE(testExtrudeSquare) { - std::vector< Point > points; - points.push_back( Point( 0.0,0.0,0.0 ) ); - points.push_back( Point( 1.0,0.0,0.0 ) ); - points.push_back( Point( 1.0,1.0,0.0 ) ); - points.push_back( Point( 0.0,1.0,0.0 ) ); - points.push_back( Point( 0.0,0.0,0.0 ) ); - - LineString exteriorRing( points ) ; - Polygon g( exteriorRing ); - std::unique_ptr< Geometry > ext( algorithm::extrude( g, 0.0, 0.0, 1.0 ) ); - BOOST_CHECK( ext->is< Solid >() ); - BOOST_CHECK_EQUAL( ext->as< Solid >().numShells(), 1U ); - BOOST_CHECK_EQUAL( ext->as< Solid >().exteriorShell().numPolygons(), 6U ); + std::vector points; + points.emplace_back(0.0, 0.0, 0.0); + points.emplace_back(1.0, 0.0, 0.0); + points.emplace_back(1.0, 1.0, 0.0); + points.emplace_back(0.0, 1.0, 0.0); + points.emplace_back(0.0, 0.0, 0.0); + + LineString const exteriorRing(points); + Polygon const g(exteriorRing); + std::unique_ptr ext(algorithm::extrude(g, 0.0, 0.0, 1.0)); + BOOST_CHECK(ext->is()); + BOOST_CHECK_EQUAL(ext->as().numShells(), 1U); + BOOST_CHECK_EQUAL(ext->as().exteriorShell().numPolygons(), 6U); } -BOOST_AUTO_TEST_CASE( testExtrudePolyhedral ) +BOOST_AUTO_TEST_CASE(testExtrudePolyhedral) { - std::unique_ptr g = io::readWkt( "POLYHEDRALSURFACE(((0 0 0,0 1 0,1 1 0,1 0 0,0 0 0)))" ); + std::unique_ptr const g = + io::readWkt("POLYHEDRALSURFACE(((0 0 0,0 1 0,1 1 0,1 0 0,0 0 0)))"); - std::unique_ptr< Geometry > ext = algorithm::extrude( *g, 0.0, 0.0, 1.0 ); - BOOST_CHECK( ext->is< Solid >() ); - BOOST_CHECK_EQUAL( ext->as< Solid >().numShells(), 1U ); + std::unique_ptr ext = algorithm::extrude(*g, 0.0, 0.0, 1.0); + BOOST_CHECK(ext->is()); + BOOST_CHECK_EQUAL(ext->as().numShells(), 1U); } -BOOST_AUTO_TEST_CASE( testExtrudeMultiPolygon ) +BOOST_AUTO_TEST_CASE(testExtrudeMultiPolygon) { - std::vector< Point > points; - points.push_back( Point( 0.0,0.0,0.0 ) ); - points.push_back( Point( 1.0,0.0,0.0 ) ); - points.push_back( Point( 1.0,1.0,0.0 ) ); - points.push_back( Point( 0.0,1.0,0.0 ) ); - points.push_back( Point( 0.0,0.0,0.0 ) ); - - std::vector< Point > points2; - points2.push_back( Point( 2.0,0.0,0.0 ) ); - points2.push_back( Point( 3.0,0.0,0.0 ) ); - points2.push_back( Point( 3.0,1.0,0.0 ) ); - points2.push_back( Point( 2.0,1.0,0.0 ) ); - points2.push_back( Point( 2.0,0.0,0.0 ) ); - - LineString exteriorRing( points ) ; - LineString exteriorRing2( points2 ) ; - Polygon g1( exteriorRing ); - Polygon g2( exteriorRing2 ); - MultiPolygon mp; - mp.addGeometry( g1 ); - mp.addGeometry( g2 ); - - std::unique_ptr< Geometry > ext( algorithm::extrude( mp, 0.0, 0.0, 1.0 ) ); - BOOST_CHECK( ext->is< MultiSolid >() ); - BOOST_CHECK_EQUAL( ext->as().numGeometries(), 2U ); + std::vector points; + points.emplace_back(0.0, 0.0, 0.0); + points.emplace_back(1.0, 0.0, 0.0); + points.emplace_back(1.0, 1.0, 0.0); + points.emplace_back(0.0, 1.0, 0.0); + points.emplace_back(0.0, 0.0, 0.0); + + std::vector points2; + points2.emplace_back(2.0, 0.0, 0.0); + points2.emplace_back(3.0, 0.0, 0.0); + points2.emplace_back(3.0, 1.0, 0.0); + points2.emplace_back(2.0, 1.0, 0.0); + points2.emplace_back(2.0, 0.0, 0.0); + + LineString const exteriorRing(points); + LineString const exteriorRing2(points2); + Polygon const g1(exteriorRing); + Polygon const g2(exteriorRing2); + MultiPolygon mp; + mp.addGeometry(g1); + mp.addGeometry(g2); + + std::unique_ptr ext(algorithm::extrude(mp, 0.0, 0.0, 1.0)); + BOOST_CHECK(ext->is()); + BOOST_CHECK_EQUAL(ext->as().numGeometries(), 2U); } - -BOOST_AUTO_TEST_CASE( testExtrudeSquareWithHole ) +BOOST_AUTO_TEST_CASE(testExtrudeSquareWithHole) { - std::vector< LineString > rings; - { - std::vector< Point > points; - points.push_back( Point( 0.0,0.0,0.0 ) ); - points.push_back( Point( 1.0,0.0,0.0 ) ); - points.push_back( Point( 1.0,1.0,0.0 ) ); - points.push_back( Point( 0.0,1.0,0.0 ) ); - points.push_back( Point( 0.0,0.0,0.0 ) ); - rings.push_back( LineString( points ) ); - } - { - std::vector< Point > points; - points.push_back( Point( 0.2,0.2,0.0 ) ); - points.push_back( Point( 0.8,0.2,0.0 ) ); - points.push_back( Point( 0.8,0.8,0.0 ) ); - points.push_back( Point( 0.2,0.8,0.0 ) ); - points.push_back( Point( 0.2,0.2,0.0 ) ); - - std::reverse( points.begin(), points.end() ); - - rings.push_back( LineString( points ) ); - } - - Polygon g( rings ); - std::unique_ptr< Geometry > ext( algorithm::extrude( g, 0.0, 0.0, 1.0 ) ); - BOOST_CHECK( ext->is< Solid >() ); - BOOST_CHECK_EQUAL( ext->as< Solid >().numShells(), 1U ); - BOOST_CHECK_EQUAL( ext->as< Solid >().exteriorShell().numPolygons(), 10U ); + std::vector rings; + { + std::vector points; + points.emplace_back(0.0, 0.0, 0.0); + points.emplace_back(1.0, 0.0, 0.0); + points.emplace_back(1.0, 1.0, 0.0); + points.emplace_back(0.0, 1.0, 0.0); + points.emplace_back(0.0, 0.0, 0.0); + rings.emplace_back(points); + } + { + std::vector points; + points.emplace_back(0.2, 0.2, 0.0); + points.emplace_back(0.8, 0.2, 0.0); + points.emplace_back(0.8, 0.8, 0.0); + points.emplace_back(0.2, 0.8, 0.0); + points.emplace_back(0.2, 0.2, 0.0); + + std::reverse(points.begin(), points.end()); + + rings.emplace_back(points); + } + + Polygon const g(rings); + std::unique_ptr ext(algorithm::extrude(g, 0.0, 0.0, 1.0)); + BOOST_CHECK(ext->is()); + BOOST_CHECK_EQUAL(ext->as().numShells(), 1U); + BOOST_CHECK_EQUAL(ext->as().exteriorShell().numPolygons(), 10U); } - -//SELECT ST_AsText(ST_Extrude(ST_Extrude(ST_Extrude('POINT(0 0)', 1, 0, 0), 0, 1, 0), 0, 0, 1)); -BOOST_AUTO_TEST_CASE( testChainingExtrude ) +// SELECT ST_AsText(ST_Extrude(ST_Extrude(ST_Extrude('POINT(0 0)', 1, 0, 0), 0, +// 1, 0), 0, 0, 1)); +BOOST_AUTO_TEST_CASE(testChainingExtrude) { - std::unique_ptr< Geometry > g( new Point( 0.0,0.0 ) ); - g = algorithm::extrude( *g, 1.0, 0.0, 0.0 ) ; - BOOST_CHECK_EQUAL( g->asText( 0 ), "LINESTRING Z(0 0 0,1 0 0)" ) ; - g = algorithm::extrude( *g, 0.0, 1.0, 0.0 ) ; - BOOST_CHECK_EQUAL( g->asText( 0 ), "POLYHEDRALSURFACE Z(((0 0 0,1 0 0,1 1 0,0 1 0,0 0 0)))" ) ; - g = algorithm::extrude( *g, 0.0, 0.0, 1.0 ) ; - BOOST_CHECK_EQUAL( g->asText( 0 ), "SOLID Z((((0 1 0,1 1 0,1 0 0,0 1 0)),((0 1 1,1 0 1,1 1 1,0 1 1)),((0 1 0,1 0 0,0 0 0,0 1 0)),((0 1 1,0 0 1,1 0 1,0 1 1)),((1 0 0,1 1 0,1 1 1,1 0 1,1 0 0)),((1 1 0,0 1 0,0 1 1,1 1 1,1 1 0)),((0 1 0,0 0 0,0 0 1,0 1 1,0 1 0)),((0 0 0,1 0 0,1 0 1,0 0 1,0 0 0))))" ) ; + std::unique_ptr g(new Point(0.0, 0.0)); + g = algorithm::extrude(*g, 1.0, 0.0, 0.0); + BOOST_CHECK_EQUAL(g->asText(0), "LINESTRING Z(0 0 0,1 0 0)"); + g = algorithm::extrude(*g, 0.0, 1.0, 0.0); + BOOST_CHECK_EQUAL(g->asText(0), + "POLYHEDRALSURFACE Z(((0 0 0,1 0 0,1 1 0,0 1 0,0 0 0)))"); + g = algorithm::extrude(*g, 0.0, 0.0, 1.0); + BOOST_CHECK_EQUAL( + g->asText(0), + "SOLID Z((((0 1 0,1 1 0,1 0 0,0 1 0)),((0 1 1,1 0 1,1 1 1,0 1 1)),((0 1 " + "0,1 0 0,0 0 0,0 1 0)),((0 1 1,0 0 1,1 0 1,0 1 1)),((1 0 0,1 1 0,1 1 1,1 " + "0 1,1 0 0)),((1 1 0,0 1 0,0 1 1,1 1 1,1 1 0)),((0 1 0,0 0 0,0 0 1,0 1 " + "1,0 1 0)),((0 0 0,1 0 0,1 0 1,0 0 1,0 0 0))))"); } - BOOST_AUTO_TEST_SUITE_END() - diff --git a/test/unit/SFCGAL/algorithm/Force3DTest.cpp b/test/unit/SFCGAL/algorithm/Force3DTest.cpp index 641085c7..06ba74d2 100644 --- a/test/unit/SFCGAL/algorithm/Force3DTest.cpp +++ b/test/unit/SFCGAL/algorithm/Force3DTest.cpp @@ -15,77 +15,75 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include +#include #include -#include #include -#include -#include -#include -#include -#include -#include -#include #include +#include #include #include -#include +#include +#include +#include +#include +#include +#include #include +#include #include -using namespace boost::unit_test ; -using namespace SFCGAL ; +using namespace boost::unit_test; +using namespace SFCGAL; // note that it relies on a visitor -BOOST_AUTO_TEST_SUITE( SFCGAL_algorithm_Force3DTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_algorithm_Force3DTest) -BOOST_AUTO_TEST_CASE( testIgnoreEmpty ) +BOOST_AUTO_TEST_CASE(testIgnoreEmpty) { - tools::Registry& registry = tools::Registry::instance() ; - std::vector< std::string > typeNames = tools::Registry::instance().getGeometryTypes(); - - for ( size_t i = 0; i < typeNames.size(); i++ ) { - BOOST_TEST_MESSAGE( typeNames[i] ) ; - - std::unique_ptr< Geometry > g( registry.newGeometryByTypeName( typeNames[i] ) ) ; - BOOST_REQUIRE( g.get() != NULL ) ; - algorithm::force3D( *g ) ; - BOOST_CHECK( g->isEmpty() ) ; - } + tools::Registry const ®istry = tools::Registry::instance(); + std::vector const typeNames = + tools::Registry::instance().getGeometryTypes(); + + for (const auto &typeName : typeNames) { + BOOST_TEST_MESSAGE(typeName); + + std::unique_ptr g(registry.newGeometryByTypeName(typeName)); + BOOST_REQUIRE(g.get() != NULL); + algorithm::force3D(*g); + BOOST_CHECK(g->isEmpty()); + } } -BOOST_AUTO_TEST_CASE( testPointForceZ ) +BOOST_AUTO_TEST_CASE(testPointForceZ) { - Point p( 3.0,4.0 ); - algorithm::force3D( p ); - BOOST_CHECK_EQUAL( p.asText( 1 ), "POINT Z(3.0 4.0 0.0)" ); + Point p(3.0, 4.0); + algorithm::force3D(p); + BOOST_CHECK_EQUAL(p.asText(1), "POINT Z(3.0 4.0 0.0)"); } -BOOST_AUTO_TEST_CASE( testPointForceZWithValue ) +BOOST_AUTO_TEST_CASE(testPointForceZWithValue) { - Point p( 3.0,4.0 ); - algorithm::force3D( p,-9999.0 ); - BOOST_CHECK_EQUAL( p.asText( 1 ), "POINT Z(3.0 4.0 -9999.0)" ); + Point p(3.0, 4.0); + algorithm::force3D(p, -9999.0); + BOOST_CHECK_EQUAL(p.asText(1), "POINT Z(3.0 4.0 -9999.0)"); } - -BOOST_AUTO_TEST_CASE( test_MixedLineString2D3D ) +BOOST_AUTO_TEST_CASE(test_MixedLineString2D3D) { - LineString lineString ; - lineString.addPoint( Point( 1.0,1.0 ) ); - lineString.addPoint( Point( 2.0,2.0,1.0 ) ); - lineString.addPoint( Point( 3.0,3.0 ) ); - algorithm::force3D( lineString ); - // should keep 1.0 for the second point - BOOST_CHECK_EQUAL( lineString.asText( 1 ), "LINESTRING Z(1.0 1.0 0.0,2.0 2.0 1.0,3.0 3.0 0.0)" ); + LineString lineString; + lineString.addPoint(Point(1.0, 1.0)); + lineString.addPoint(Point(2.0, 2.0, 1.0)); + lineString.addPoint(Point(3.0, 3.0)); + algorithm::force3D(lineString); + // should keep 1.0 for the second point + BOOST_CHECK_EQUAL(lineString.asText(1), + "LINESTRING Z(1.0 1.0 0.0,2.0 2.0 1.0,3.0 3.0 0.0)"); } - - - BOOST_AUTO_TEST_SUITE_END() - diff --git a/test/unit/SFCGAL/algorithm/IntersectionTest.cpp b/test/unit/SFCGAL/algorithm/IntersectionTest.cpp index 4f535787..a7a3df42 100644 --- a/test/unit/SFCGAL/algorithm/IntersectionTest.cpp +++ b/test/unit/SFCGAL/algorithm/IntersectionTest.cpp @@ -15,229 +15,236 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include +#include #include -#include -#include -#include -#include -#include #include -#include -#include -#include -#include -#include -#include -#include #include +#include #include #include +#include +#include +#include +#include +#include +#include +#include +#include #include +#include +#include #include "../../../test_config.h" -#include #include +#include using namespace SFCGAL; -using namespace boost::unit_test ; -//namespace SFCGAL{ -//inline Geometry* new_clone( const Geometry& g ) +using namespace boost::unit_test; +// namespace SFCGAL{ +// inline Geometry* new_clone( const Geometry& g ) //{ -// return g.clone(); -//} -//} +// return g.clone(); +// } +// } -void insertOrReplace( boost::ptr_map& map, std::string key, Geometry* value ) +void +insertOrReplace(boost::ptr_map &map, std::string key, + Geometry *value) { - boost::ptr_map::iterator found = map.find( key ); + boost::ptr_map::iterator const found = map.find(key); - if ( found != map.end() ) { - map.erase( found ); - } + if (found != map.end()) { + map.erase(found); + } - map.insert( key, value ); + map.insert(key, value); } -BOOST_AUTO_TEST_SUITE( SFCGAL_algorithm_IntersectionTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_algorithm_IntersectionTest) -BOOST_AUTO_TEST_CASE( testFileIntersectionTest ) +BOOST_AUTO_TEST_CASE(testFileIntersectionTest) { - int argc = framework::master_test_suite().argc; - char** argv = framework::master_test_suite().argv; - - // look for options - int test_one_line = -1; - bool print_line_number = false; - - for ( int i = 0; i < argc; ++i ) { - std::string argi( argv[i] ); - - if ( argi == "--line" ) { - // only test one line - if ( argc >= i+1 ) { - sscanf( argv[i+1], "%d", &test_one_line ); - ++i; - continue; - } - } - - if ( argi == "--line-number" ) { - print_line_number = true; - } + int const argc = framework::master_test_suite().argc; + char **argv = framework::master_test_suite().argv; + + // look for options + int test_one_line = -1; + bool print_line_number = false; + + for (int i = 0; i < argc; ++i) { + std::string const argi(argv[i]); + + if (argi == "--line") { + // only test one line + if (argc >= i + 1) { + sscanf(argv[i + 1], "%d", &test_one_line); + ++i; + continue; + } + } + + if (argi == "--line-number") { + print_line_number = true; } + } - boost::ptr_map storedGeom; + boost::ptr_map storedGeom; - //logger().setLogLevel( Logger::Debug ); + // logger().setLogLevel( Logger::Debug ); - std::string filename( SFCGAL_TEST_DIRECTORY ); - filename += "/data/IntersectionTest.txt" ; + std::string filename(SFCGAL_TEST_DIRECTORY); + filename += "/data/IntersectionTest.txt"; - std::ifstream ifs( filename.c_str() ); - BOOST_REQUIRE( ifs.good() ) ; + std::ifstream ifs(filename.c_str()); + BOOST_REQUIRE(ifs.good()); - int numLine = 0 ; - std::string line; + int numLine = 0; + std::string line; - while ( std::getline( ifs, line ) ) { - numLine++; + while (std::getline(ifs, line)) { + numLine++; - if ( line[0] == '#' || line.empty() ) { - continue ; - } + if (line[0] == '#' || line.empty()) { + continue; + } + + if (print_line_number) { + std::cout << numLine << std::endl; + } + + if (test_one_line == -1) { + BOOST_TEST_MESSAGE(boost::format("line#%s:%s") % numLine % line); + } - if ( print_line_number ) { - std::cout << numLine << std::endl; - } + std::istringstream iss(line); - if ( test_one_line == -1 ) { - BOOST_TEST_MESSAGE( boost::format( "line#%s:%s" ) % numLine % line ); - } + std::string dimension; + std::string wktGA; + std::string wktGB; + std::string wktOut; - std::istringstream iss( line ); + std::getline(iss, dimension, '|'); - std::string dimension ; - std::string wktGA, wktGB ; - std::string wktOut ; + if (dimension == "S") { + // store the geometry + std::string geomName; + std::getline(iss, geomName, '|'); + std::getline(iss, wktGA, '|'); + insertOrReplace(storedGeom, geomName, io::readWkt(wktGA).release()); + continue; + } - std::getline( iss, dimension, '|' ) ; - - if ( dimension == "S" ) { - // store the geometry - std::string geomName; - std::getline( iss, geomName, '|' ); - std::getline( iss, wktGA, '|' ); - insertOrReplace( storedGeom, geomName, io::readWkt( wktGA ).release() ); - continue; - } - - // we need to read the lines until here to store reference - if ( test_one_line != -1 ) { - if ( numLine != test_one_line ) { - continue; - } - else { - BOOST_TEST_MESSAGE( boost::format( "line#%s:%s" ) % numLine % line ); - } - } - - std::unique_ptr< Geometry > gA; - std::unique_ptr< Geometry > gB; - std::unique_ptr< Geometry > gOut; - - std::getline( iss, wktGA, '|' ) ; - - if ( wktGA[0] == '@' ) { - // stored geometry reference - std::string name = wktGA.substr( 1 ); - const boost::ptr_map::const_iterator found = storedGeom.find( name ); - - if ( found == storedGeom.end() ) { - BOOST_REQUIRE_MESSAGE( false, numLine << ": can't find the geometry named " << name ); - } - - gA.reset( found->second->clone() ); - } - else { - gA = io::readWkt( wktGA ); - } - - insertOrReplace( storedGeom, "A", gA->clone() ); - - std::getline( iss, wktGB, '|' ) ; - - if ( wktGB[0] == '@' ) { - // stored geometry reference - std::string name = wktGB.substr( 1 ); - const boost::ptr_map::const_iterator found = storedGeom.find( name ); - - if ( found == storedGeom.end() ) { - BOOST_REQUIRE_MESSAGE( false, numLine << ": can't find the geometry named " << name ); - } - - gB.reset( found->second->clone() ); - } - else { - gB = io::readWkt( wktGB ); - } - - insertOrReplace( storedGeom, "B", gB->clone() ); - - // exception management - bool expectException = false; - bool expectNotImplemented = false; - - std::getline( iss, wktOut, '|' ) ; - - if ( wktOut[0] == '@' ) { - // stored geometry reference - std::string name = wktOut.substr( 1 ); - const boost::ptr_map::const_iterator found = storedGeom.find( name ); - - if ( found == storedGeom.end() ) { - BOOST_CHECK_MESSAGE( false, numLine << ": can't find the geometry named " << name ); - } - - gOut.reset( found->second->clone() ); - } - // expect an exception - else if ( wktOut[0] == '!' ) { - if ( wktOut == "!NotImplemented" ) { - expectNotImplemented = true; - } - - expectException = true; - } - else { - gOut = io::readWkt( wktOut ); - } - - - try { - if ( dimension == "2" ) { - std::unique_ptr result = algorithm::intersection( *gA,*gB ); - BOOST_CHECK_MESSAGE( *result == *gOut, numLine << ": intersection(" << gA->asText() << ", " << gB->asText() << ") is " << result->asText() << " and should be " << gOut->asText() ); - } - else if ( dimension == "3" ) { - std::unique_ptr result = algorithm::intersection3D( *gA,*gB ); - BOOST_CHECK_MESSAGE( *result == *gOut, numLine << ": intersection3D(" << gA->asText() << ", " << gB->asText() << ") is " << result->asText() << " and should be " << gOut->asText() ); - } - else { - BOOST_CHECK( false ); - } - } - catch ( SFCGAL::NotImplementedException& e ) { - BOOST_CHECK_MESSAGE( expectNotImplemented, numLine << ": " << e.what() ); - } - catch ( std::exception& e ) { - BOOST_CHECK_MESSAGE( expectException, numLine << ": " << e.what() ); - } + // we need to read the lines until here to store reference + if (test_one_line != -1) { + if (numLine != test_one_line) { + continue; + } + BOOST_TEST_MESSAGE(boost::format("line#%s:%s") % numLine % line); } + + std::unique_ptr gA; + std::unique_ptr gB; + std::unique_ptr gOut; + + std::getline(iss, wktGA, '|'); + + if (wktGA[0] == '@') { + // stored geometry reference + std::string const name = wktGA.substr(1); + const boost::ptr_map::const_iterator found = + storedGeom.find(name); + + if (found == storedGeom.end()) { + BOOST_REQUIRE_MESSAGE( + false, numLine << ": can't find the geometry named " << name); + } + + gA.reset(found->second->clone()); + } else { + gA = io::readWkt(wktGA); + } + + insertOrReplace(storedGeom, "A", gA->clone()); + + std::getline(iss, wktGB, '|'); + + if (wktGB[0] == '@') { + // stored geometry reference + std::string const name = wktGB.substr(1); + const boost::ptr_map::const_iterator found = + storedGeom.find(name); + + if (found == storedGeom.end()) { + BOOST_REQUIRE_MESSAGE( + false, numLine << ": can't find the geometry named " << name); + } + + gB.reset(found->second->clone()); + } else { + gB = io::readWkt(wktGB); + } + + insertOrReplace(storedGeom, "B", gB->clone()); + + // exception management + bool expectException = false; + bool expectNotImplemented = false; + + std::getline(iss, wktOut, '|'); + + if (wktOut[0] == '@') { + // stored geometry reference + std::string const name = wktOut.substr(1); + const boost::ptr_map::const_iterator found = + storedGeom.find(name); + + if (found == storedGeom.end()) { + BOOST_CHECK_MESSAGE(false, numLine << ": can't find the geometry named " + << name); + } + + gOut.reset(found->second->clone()); + } + // expect an exception + else if (wktOut[0] == '!') { + if (wktOut == "!NotImplemented") { + expectNotImplemented = true; + } + + expectException = true; + } else { + gOut = io::readWkt(wktOut); + } + + try { + if (dimension == "2") { + std::unique_ptr result = algorithm::intersection(*gA, *gB); + BOOST_CHECK_MESSAGE(*result == *gOut, + numLine << ": intersection(" << gA->asText() << ", " + << gB->asText() << ") is " + << result->asText() << " and should be " + << gOut->asText()); + } else if (dimension == "3") { + std::unique_ptr result = algorithm::intersection3D(*gA, *gB); + BOOST_CHECK_MESSAGE(*result == *gOut, + numLine << ": intersection3D(" << gA->asText() + << ", " << gB->asText() << ") is " + << result->asText() << " and should be " + << gOut->asText()); + } else { + BOOST_CHECK(false); + } + } catch (SFCGAL::NotImplementedException &e) { + BOOST_CHECK_MESSAGE(expectNotImplemented, numLine << ": " << e.what()); + } catch (std::exception &e) { + BOOST_CHECK_MESSAGE(expectException, numLine << ": " << e.what()); + } + } } BOOST_AUTO_TEST_SUITE_END() - diff --git a/test/unit/SFCGAL/algorithm/IntersectsTest.cpp b/test/unit/SFCGAL/algorithm/IntersectsTest.cpp index 8840a416..d9d2af66 100644 --- a/test/unit/SFCGAL/algorithm/IntersectsTest.cpp +++ b/test/unit/SFCGAL/algorithm/IntersectsTest.cpp @@ -15,101 +15,111 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include #include #include +#include #include -#include #include -#include -#include -#include -#include -#include -#include -#include #include +#include #include #include -#include -#include +#include +#include +#include +#include +#include +#include #include +#include #include +#include #include "../../../test_config.h" -using namespace SFCGAL ; -using namespace boost::unit_test ; +using namespace SFCGAL; +using namespace boost::unit_test; -BOOST_AUTO_TEST_SUITE( SFCGAL_algorithm_IntersectsTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_algorithm_IntersectsTest) /** * Perform tests in test/data/IntersectsTest.txt */ -BOOST_AUTO_TEST_CASE( testFileIntersectsTest ) +BOOST_AUTO_TEST_CASE(testFileIntersectsTest) { - //logger().setLogLevel( Logger::Debug ); - - std::string filename( SFCGAL_TEST_DIRECTORY ); - filename += "/data/IntersectsTest.txt" ; - - std::ifstream ifs( filename.c_str() ); - BOOST_REQUIRE( ifs.good() ) ; - - int numLine = 0 ; - std::string line; - - while ( std::getline( ifs, line ) ) { - numLine++; - - if ( line[0] == '#' || line.empty() ) { - continue ; - } - - BOOST_TEST_MESSAGE( boost::format( "line#%s:%s" ) % numLine % line ); - - std::istringstream iss( line ); - - std::string distanceDimension ; - std::string wktGA, wktGB ; - std::string trueOrFalse ; - - std::getline( iss, distanceDimension, '|' ) ; - std::getline( iss, wktGA, '|' ) ; - std::getline( iss, wktGB, '|' ) ; - std::getline( iss, trueOrFalse, '|' ) ; - - bool expected = ( trueOrFalse == "true" ) ? true : false ; - - std::unique_ptr< Geometry > gA( io::readWkt( wktGA ) ); - std::unique_ptr< Geometry > gB( io::readWkt( wktGB ) ); - - try { - if ( distanceDimension == "2" ) { - BOOST_CHECK_MESSAGE( algorithm::intersects( *gA,*gB ) == expected, numLine << ": intersects(" << gA->asText() << ", " << gB->asText() << ") should be " << ( expected ? "TRUE" : "FALSE" ) ); - // test symmetric call - BOOST_CHECK_MESSAGE( algorithm::intersects( *gB,*gA ) == expected, numLine << ": intersects(" << gB->asText() << ", " << gA->asText() << ") should be " << ( expected ? "TRUE" : "FALSE" ) ); - } - else if ( distanceDimension == "3" ) { - bool got = algorithm::intersects3D( *gA,*gB ); - BOOST_CHECK_MESSAGE( got == expected, numLine << ": intersects3D(" << gA->asText() << ", " << gB->asText() << ") should be " << ( expected ? "TRUE" : "FALSE" ) ); - // test symmetric call - got = algorithm::intersects3D( *gB,*gA ); - BOOST_CHECK_MESSAGE( got == expected, numLine << ": intersects3D(" << gB->asText() << ", " << gA->asText() << ") should be " << ( expected ? "TRUE" : "FALSE" ) ); - } - else { - BOOST_CHECK( false ); - } - } - catch ( std::exception& e ) { - BOOST_CHECK_MESSAGE( false, numLine << ": " << e.what() ); - } + // logger().setLogLevel( Logger::Debug ); + + std::string filename(SFCGAL_TEST_DIRECTORY); + filename += "/data/IntersectsTest.txt"; + + std::ifstream ifs(filename.c_str()); + BOOST_REQUIRE(ifs.good()); + + int numLine = 0; + std::string line; + + while (std::getline(ifs, line)) { + numLine++; + + if (line[0] == '#' || line.empty()) { + continue; } + + BOOST_TEST_MESSAGE(boost::format("line#%s:%s") % numLine % line); + + std::istringstream iss(line); + + std::string distanceDimension; + std::string wktGA; + std::string wktGB; + std::string trueOrFalse; + + std::getline(iss, distanceDimension, '|'); + std::getline(iss, wktGA, '|'); + std::getline(iss, wktGB, '|'); + std::getline(iss, trueOrFalse, '|'); + + bool const expected = trueOrFalse == "true"; + + std::unique_ptr gA(io::readWkt(wktGA)); + std::unique_ptr gB(io::readWkt(wktGB)); + + try { + if (distanceDimension == "2") { + BOOST_CHECK_MESSAGE(algorithm::intersects(*gA, *gB) == expected, + numLine << ": intersects(" << gA->asText() << ", " + << gB->asText() << ") should be " + << (expected ? "TRUE" : "FALSE")); + // test symmetric call + BOOST_CHECK_MESSAGE(algorithm::intersects(*gB, *gA) == expected, + numLine << ": intersects(" << gB->asText() << ", " + << gA->asText() << ") should be " + << (expected ? "TRUE" : "FALSE")); + } else if (distanceDimension == "3") { + bool got = algorithm::intersects3D(*gA, *gB); + BOOST_CHECK_MESSAGE(got == expected, + numLine << ": intersects3D(" << gA->asText() << ", " + << gB->asText() << ") should be " + << (expected ? "TRUE" : "FALSE")); + // test symmetric call + got = algorithm::intersects3D(*gB, *gA); + BOOST_CHECK_MESSAGE(got == expected, + numLine << ": intersects3D(" << gB->asText() << ", " + << gA->asText() << ") should be " + << (expected ? "TRUE" : "FALSE")); + } else { + BOOST_CHECK(false); + } + } catch (std::exception &e) { + BOOST_CHECK_MESSAGE(false, numLine << ": " << e.what()); + } + } } BOOST_AUTO_TEST_SUITE_END() - diff --git a/test/unit/SFCGAL/algorithm/IsValidTest.cpp b/test/unit/SFCGAL/algorithm/IsValidTest.cpp index a64cc703..58297dbf 100644 --- a/test/unit/SFCGAL/algorithm/IsValidTest.cpp +++ b/test/unit/SFCGAL/algorithm/IsValidTest.cpp @@ -15,70 +15,76 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include -#include -#include -#include -#include -#include -#include -#include #include -#include +#include #include +#include #include #include -#include +#include +#include +#include +#include +#include +#include #include #include +#include -using namespace boost::unit_test ; -using namespace SFCGAL ; +using namespace boost::unit_test; +using namespace SFCGAL; -BOOST_AUTO_TEST_SUITE( SFCGAL_algorithm_IsValid ) +BOOST_AUTO_TEST_SUITE(SFCGAL_algorithm_IsValid) -BOOST_AUTO_TEST_CASE( geometryIsValid ) +BOOST_AUTO_TEST_CASE(geometryIsValid) { - const std::vector< TestGeometry > testGeometry( createTestGeometries() ); - const std::size_t nbOfTest = testGeometry.size(); - - for ( std::size_t t=0; t g; + const std::vector testGeometry(createTestGeometries()); + const std::size_t nbOfTest = testGeometry.size(); - try { - g = io::readWkt( tg.wkt ); - } - catch ( WktParseException& ) { - BOOST_CHECK_MESSAGE( !tg.isValid, ( boost::format( "%d: parse error on valid geometry %s" ) % t % tg.wkt ) ); - continue; - } + for (std::size_t t = 0; t < nbOfTest; t++) { + const TestGeometry &tg = testGeometry[t]; + // std::cerr << t << ":" << tg.wkt << "\n"; + std::unique_ptr g; - Validity v = algorithm::isValid( *g ); - BOOST_CHECK_MESSAGE( v == tg.isValid, ( boost::format( "%d:%s should be %s (%s)%s%s : %s" ) % t % g->geometryType() % ( tg.isValid?"valid":"invalid" ) % tg.comment % ( v?".":", reason: " ) % v.reason() % tg.wkt ) ); + try { + g = io::readWkt(tg.wkt); + } catch (WktParseException &) { + BOOST_CHECK_MESSAGE( + !tg.isValid, + (boost::format("%d: parse error on valid geometry %s") % t % tg.wkt)); + continue; } + Validity const v = algorithm::isValid(*g); + BOOST_CHECK_MESSAGE(v == tg.isValid, + (boost::format("%d:%s should be %s (%s)%s%s : %s") % t % + g->geometryType() % + (tg.isValid ? "valid" : "invalid") % tg.comment % + (v ? "." : ", reason: ") % v.reason() % tg.wkt)); + } } -BOOST_AUTO_TEST_CASE( geometryWithNan ) +BOOST_AUTO_TEST_CASE(geometryWithNan) { - const double inf = std::numeric_limits::infinity(); - const double quietNaN = std::numeric_limits::quiet_NaN(); - const double sigNaN = std::numeric_limits::signaling_NaN(); + const double inf = std::numeric_limits::infinity(); + const double quietNaN = std::numeric_limits::quiet_NaN(); + const double sigNaN = std::numeric_limits::signaling_NaN(); - BOOST_CHECK_THROW( Coordinate( quietNaN ,1.0,2.0 ), NonFiniteValueException ); - BOOST_CHECK_THROW( Coordinate( inf,1.0,2.0 ), NonFiniteValueException ); - BOOST_CHECK_THROW( Coordinate( sigNaN,1.0,2.0 ), NonFiniteValueException ); + BOOST_CHECK_THROW(Coordinate(quietNaN, 1.0, 2.0), NonFiniteValueException); + BOOST_CHECK_THROW(Coordinate(inf, 1.0, 2.0), NonFiniteValueException); + BOOST_CHECK_THROW(Coordinate(sigNaN, 1.0, 2.0), NonFiniteValueException); } -BOOST_AUTO_TEST_CASE( disconnectedTIN ) +BOOST_AUTO_TEST_CASE(disconnectedTIN) { - std::unique_ptr< Geometry > g( io::readWkt( "TIN(((0 0,1 0,0 1,0 0)),((2 0,3 0,2 1,2 0)))" ) ); - Validity v = algorithm::isValid( *g ); - BOOST_CHECK( !v ); + std::unique_ptr const g( + io::readWkt("TIN(((0 0,1 0,0 1,0 0)),((2 0,3 0,2 1,2 0)))")); + Validity const v = algorithm::isValid(*g); + BOOST_CHECK(!v); } BOOST_AUTO_TEST_SUITE_END() diff --git a/test/unit/SFCGAL/algorithm/LengthTest.cpp b/test/unit/SFCGAL/algorithm/LengthTest.cpp index 0fb2030a..38e2ed90 100644 --- a/test/unit/SFCGAL/algorithm/LengthTest.cpp +++ b/test/unit/SFCGAL/algorithm/LengthTest.cpp @@ -15,89 +15,93 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include +#include #include -#include #include -#include -#include -#include -#include -#include -#include -#include #include +#include #include #include -#include +#include +#include +#include +#include +#include +#include #include +#include +using namespace boost::unit_test; +using namespace SFCGAL; -using namespace boost::unit_test ; -using namespace SFCGAL ; - -BOOST_AUTO_TEST_SUITE( SFCGAL_algorithm_LengthTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_algorithm_LengthTest) -BOOST_AUTO_TEST_CASE( testZeroLength ) +BOOST_AUTO_TEST_CASE(testZeroLength) { - BOOST_CHECK_EQUAL( algorithm::length( *io::readWkt( "POINT(0.0 0.0)" ) ), 0.0 ); - BOOST_CHECK_EQUAL( algorithm::length( *io::readWkt( "LINESTRING EMPTY" ) ), 0.0 ); - BOOST_CHECK_EQUAL( algorithm::length( *io::readWkt( "POLYGON((0 0,0 1,1 1,1 0,0 0))" ) ), 0.0 ); + BOOST_CHECK_EQUAL(algorithm::length(*io::readWkt("POINT(0.0 0.0)")), 0.0); + BOOST_CHECK_EQUAL(algorithm::length(*io::readWkt("LINESTRING EMPTY")), 0.0); + BOOST_CHECK_EQUAL( + algorithm::length(*io::readWkt("POLYGON((0 0,0 1,1 1,1 0,0 0))")), 0.0); } -BOOST_AUTO_TEST_CASE( testZeroLengthVertical ) +BOOST_AUTO_TEST_CASE(testZeroLengthVertical) { - BOOST_CHECK_EQUAL( algorithm::length( *io::readWkt( "LINESTRING(0.0 0.0 0.0,0.0 0.0 1.0)" ) ), 0.0 ); + BOOST_CHECK_EQUAL( + algorithm::length(*io::readWkt("LINESTRING(0.0 0.0 0.0,0.0 0.0 1.0)")), + 0.0); } -BOOST_AUTO_TEST_CASE( testLengthLineString ) +BOOST_AUTO_TEST_CASE(testLengthLineString) { - BOOST_CHECK_EQUAL( algorithm::length( *io::readWkt( "LINESTRING(0.0 0.0,3.0 4.0)" ) ), 5.0 ); - BOOST_CHECK_EQUAL( algorithm::length( *io::readWkt( "LINESTRING(0.0 0.0,0.0 1.0,1.0 1.0)" ) ), 2.0 ); + BOOST_CHECK_EQUAL( + algorithm::length(*io::readWkt("LINESTRING(0.0 0.0,3.0 4.0)")), 5.0); + BOOST_CHECK_EQUAL( + algorithm::length(*io::readWkt("LINESTRING(0.0 0.0,0.0 1.0,1.0 1.0)")), + 2.0); } //-- 3D - -BOOST_AUTO_TEST_CASE( test3DZeroLength ) +BOOST_AUTO_TEST_CASE(test3DZeroLength) { - BOOST_CHECK_EQUAL( algorithm::length3D( *io::readWkt( "POINT(0.0 0.0)" ) ), 0.0 ); - BOOST_CHECK_EQUAL( algorithm::length3D( *io::readWkt( "LINESTRING EMPTY" ) ), 0.0 ); - BOOST_CHECK_EQUAL( algorithm::length3D( *io::readWkt( "POLYGON((0 0,0 1,1 1,1 0,0 0))" ) ), 0.0 ); + BOOST_CHECK_EQUAL(algorithm::length3D(*io::readWkt("POINT(0.0 0.0)")), 0.0); + BOOST_CHECK_EQUAL(algorithm::length3D(*io::readWkt("LINESTRING EMPTY")), 0.0); + BOOST_CHECK_EQUAL( + algorithm::length3D(*io::readWkt("POLYGON((0 0,0 1,1 1,1 0,0 0))")), 0.0); } -BOOST_AUTO_TEST_CASE( test3DLengthVertical ) +BOOST_AUTO_TEST_CASE(test3DLengthVertical) { - BOOST_CHECK_EQUAL( algorithm::length3D( *io::readWkt( "LINESTRING(0.0 0.0 0.0,0.0 0.0 1.0)" ) ), 1.0 ); + BOOST_CHECK_EQUAL( + algorithm::length3D(*io::readWkt("LINESTRING(0.0 0.0 0.0,0.0 0.0 1.0)")), + 1.0); } -BOOST_AUTO_TEST_CASE( test3DLengthLineString ) +BOOST_AUTO_TEST_CASE(test3DLengthLineString) { - BOOST_CHECK_EQUAL( algorithm::length3D( *io::readWkt( "LINESTRING(0.0 0.0 0.0,0.0 1.0 0.0,0.0 1.0 1.0)" ) ), 2.0 ); + BOOST_CHECK_EQUAL(algorithm::length3D(*io::readWkt( + "LINESTRING(0.0 0.0 0.0,0.0 1.0 0.0,0.0 1.0 1.0)")), + 2.0); } - //-- invalid type 2D -BOOST_AUTO_TEST_CASE( testLength_invalidType ) +BOOST_AUTO_TEST_CASE(testLength_invalidType) { - std::vector< std::string > wkts ; - wkts.push_back( "POINT(3.0 4.0)" ); - wkts.push_back( "TRIANGLE((0.0 0.0,1.0 0.0,1.0 1.0,0.0 0.0))" ); - wkts.push_back( "POLYGON((0.0 0.0,1.0 0.0,1.0 1.0,0.0 0.0))" ); - - for ( size_t i = 0; i < wkts.size(); i++ ) { - BOOST_TEST_MESSAGE( wkts[i] ); - BOOST_CHECK_EQUAL( algorithm::length( *io::readWkt( wkts[i] ) ), 0.0 ); - BOOST_CHECK_EQUAL( algorithm::length3D( *io::readWkt( wkts[i] ) ), 0.0 ); - } - + std::vector wkts; + wkts.emplace_back("POINT(3.0 4.0)"); + wkts.emplace_back("TRIANGLE((0.0 0.0,1.0 0.0,1.0 1.0,0.0 0.0))"); + wkts.emplace_back("POLYGON((0.0 0.0,1.0 0.0,1.0 1.0,0.0 0.0))"); + + for (auto &wkt : wkts) { + BOOST_TEST_MESSAGE(wkt); + BOOST_CHECK_EQUAL(algorithm::length(*io::readWkt(wkt)), 0.0); + BOOST_CHECK_EQUAL(algorithm::length3D(*io::readWkt(wkt)), 0.0); + } } //-- invalid type 3D - - - BOOST_AUTO_TEST_SUITE_END() - diff --git a/test/unit/SFCGAL/algorithm/LineSubstringTest.cpp b/test/unit/SFCGAL/algorithm/LineSubstringTest.cpp index 63579383..71188009 100644 --- a/test/unit/SFCGAL/algorithm/LineSubstringTest.cpp +++ b/test/unit/SFCGAL/algorithm/LineSubstringTest.cpp @@ -15,1145 +15,947 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ // Boost #include // SFCGAL +#include #include -#include -#include #include -#include +#include +#include -using namespace boost::unit_test ; -using namespace SFCGAL ; +using namespace boost::unit_test; +using namespace SFCGAL; -namespace +namespace { +void +test(const std::string &wkt, double start_frac, double end_frac, + const std::string &expected_wkt, bool verify_using_covers = true, + bool verify_is_empty = false) { - void test( const std::string& wkt - , double start_frac - , double end_frac - , const std::string& expected_wkt - , bool verify_using_covers = true - , bool verify_is_empty = false - ) - { - std::unique_ptr result - = algorithm::lineSubstring( io::readWkt( wkt )->as() - , start_frac - , end_frac - ); - std::unique_ptr expected = io::readWkt( expected_wkt ); - if ( verify_using_covers ) - { - BOOST_CHECK( algorithm::covers3D( *result, *expected ) ); - } + std::unique_ptr result = algorithm::lineSubstring( + io::readWkt(wkt)->as(), start_frac, end_frac); + std::unique_ptr const expected = io::readWkt(expected_wkt); + if (verify_using_covers) { + BOOST_CHECK(algorithm::covers3D(*result, *expected)); + } - if ( verify_is_empty ) - { - BOOST_CHECK( result->isEmpty() ); - } - } -} // ! anonymous namespace + if (verify_is_empty) { + BOOST_CHECK(result->isEmpty()); + } +} +} // namespace -BOOST_AUTO_TEST_SUITE( SFCGAL_algorithm_LineSubstringTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_algorithm_LineSubstringTest) -BOOST_AUTO_TEST_CASE( testIssue130 ) +BOOST_AUTO_TEST_CASE(testIssue130) { - test( "LINESTRING Z(0 0 0, 0 0 10)", 0.3, 0.7, "LINESTRING Z(0 0 3, 0 0 7)"); + test("LINESTRING Z(0 0 0, 0 0 10)", 0.3, 0.7, "LINESTRING Z(0 0 3, 0 0 7)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenForward1 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenForward1) { - test( "LINESTRING Z(0 0 0, 0 0 10)", 0.0, 0.7, "LINESTRING Z(0 0 0, 0 0 7)"); + test("LINESTRING Z(0 0 0, 0 0 10)", 0.0, 0.7, "LINESTRING Z(0 0 0, 0 0 7)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenForward2D1 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenForward2D1) { - test( "LINESTRING(0 0, 0 10)", 0.0, 0.7, "LINESTRING(0 0, 0 7)"); + test("LINESTRING(0 0, 0 10)", 0.0, 0.7, "LINESTRING(0 0, 0 7)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenForwardNegativeEnd1 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenForwardNegativeEnd1) { - test( "LINESTRING Z(0 0 0, 0 0 10)", 0.0, -0.3, "LINESTRING Z(0 0 0, 0 0 7)"); + test("LINESTRING Z(0 0 0, 0 0 10)", 0.0, -0.3, "LINESTRING Z(0 0 0, 0 0 7)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenForwardNegativeEnd2D1 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenForwardNegativeEnd2D1) { - test( "LINESTRING(0 0, 0 10)", 0.0, -0.3, "LINESTRING(0 0, 0 7)"); + test("LINESTRING(0 0, 0 10)", 0.0, -0.3, "LINESTRING(0 0, 0 7)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenForwardNegativeStart1 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenForwardNegativeStart1) { - test( "LINESTRING Z(0 0 0, 0 0 10)", -1.0, 0.7, "LINESTRING Z(0 0 0, 0 0 7)"); + test("LINESTRING Z(0 0 0, 0 0 10)", -1.0, 0.7, "LINESTRING Z(0 0 0, 0 0 7)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenForwardNegativeStart2D1 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenForwardNegativeStart2D1) { - test( "LINESTRING(0 0, 0 10)", -1.0, 0.7, "LINESTRING(0 0, 0 7)"); + test("LINESTRING(0 0, 0 10)", -1.0, 0.7, "LINESTRING(0 0, 0 7)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenForwardNegativeEnds1 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenForwardNegativeEnds1) { - test( "LINESTRING Z(0 0 0, 0 0 10)", -1.0,- 0.3, "LINESTRING Z(0 0 0, 0 0 7)"); + test("LINESTRING Z(0 0 0, 0 0 10)", -1.0, -0.3, "LINESTRING Z(0 0 0, 0 0 7)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenForwardNegativeEnds2D1 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenForwardNegativeEnds2D1) { - test( "LINESTRING(0 0, 0 10)", -1.0,- 0.3, "LINESTRING(0 0, 0 7)"); + test("LINESTRING(0 0, 0 10)", -1.0, -0.3, "LINESTRING(0 0, 0 7)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenForward2 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenForward2) { - test( "LINESTRING Z(0 0 0, 0 0 10)", 0.3, 1.0, "LINESTRING Z(0 0 3, 0 0 10)"); + test("LINESTRING Z(0 0 0, 0 0 10)", 0.3, 1.0, "LINESTRING Z(0 0 3, 0 0 10)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenForward2D2 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenForward2D2) { - test( "LINESTRING(0 0, 0 10)", 0.3, 1.0, "LINESTRING(0 3, 0 10)"); + test("LINESTRING(0 0, 0 10)", 0.3, 1.0, "LINESTRING(0 3, 0 10)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenForwardNegativeStart2 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenForwardNegativeStart2) { - test( "LINESTRING Z(0 0 0, 0 0 10)", -0.7, 1.0, "LINESTRING Z(0 0 3, 0 0 10)"); + test("LINESTRING Z(0 0 0, 0 0 10)", -0.7, 1.0, "LINESTRING Z(0 0 3, 0 0 10)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenForwardNegativeStart2D2 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenForwardNegativeStart2D2) { - test( "LINESTRING(0 0, 0 10)", -0.7, 1.0, "LINESTRING(0 3, 0 10)"); + test("LINESTRING(0 0, 0 10)", -0.7, 1.0, "LINESTRING(0 3, 0 10)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenForward3 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenForward3) { - test( "LINESTRING Z(0 0 0, 0 0 3, 0 0 7, 0 0 10)", 0.3, 1.0, "LINESTRING Z(0 0 3, 0 0 7, 0 0 10)"); + test("LINESTRING Z(0 0 0, 0 0 3, 0 0 7, 0 0 10)", 0.3, 1.0, + "LINESTRING Z(0 0 3, 0 0 7, 0 0 10)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenForward2D3 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenForward2D3) { - test( "LINESTRING(0 0, 0 3, 0 7, 0 10)", 0.3, 1.0, "LINESTRING(0 3, 0 7, 0 10)"); + test("LINESTRING(0 0, 0 3, 0 7, 0 10)", 0.3, 1.0, + "LINESTRING(0 3, 0 7, 0 10)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenForwardNegativeStart3 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenForwardNegativeStart3) { - test( "LINESTRING Z(0 0 0, 0 0 3, 0 0 7, 0 0 10)", -0.7, 1.0, "LINESTRING Z(0 0 3, 0 0 7, 0 0 10)"); + test("LINESTRING Z(0 0 0, 0 0 3, 0 0 7, 0 0 10)", -0.7, 1.0, + "LINESTRING Z(0 0 3, 0 0 7, 0 0 10)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenForwardNegativeStart2D3 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenForwardNegativeStart2D3) { - test( "LINESTRING(0 0, 0 3, 0 7, 0 10)", -0.7, 1.0, "LINESTRING(0 3, 0 7, 0 10)"); + test("LINESTRING(0 0, 0 3, 0 7, 0 10)", -0.7, 1.0, + "LINESTRING(0 3, 0 7, 0 10)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenForward4 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenForward4) { - test( "LINESTRING Z(0 0 0, 0 0 3, 0 0 7, 0 0 10)", 0.0, 0.7, "LINESTRING Z(0 0 0, 0 0 3, 0 0 7)"); + test("LINESTRING Z(0 0 0, 0 0 3, 0 0 7, 0 0 10)", 0.0, 0.7, + "LINESTRING Z(0 0 0, 0 0 3, 0 0 7)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenForward2D4 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenForward2D4) { - test( "LINESTRING(0 0, 0 3, 0 7, 0 10)", 0.0, 0.7, "LINESTRING(0 0, 0 3, 0 7)"); + test("LINESTRING(0 0, 0 3, 0 7, 0 10)", 0.0, 0.7, + "LINESTRING(0 0, 0 3, 0 7)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenForwardStart4 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenForwardStart4) { - test( "LINESTRING Z(0 0 0, 0 0 3, 0 0 7, 0 0 10)", -1.0, 0.7, "LINESTRING Z(0 0 0, 0 0 3, 0 0 7)"); + test("LINESTRING Z(0 0 0, 0 0 3, 0 0 7, 0 0 10)", -1.0, 0.7, + "LINESTRING Z(0 0 0, 0 0 3, 0 0 7)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenForwardStart2D4 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenForwardStart2D4) { - test( "LINESTRING(0 0, 0 3, 0 7, 0 10)", -1.0, 0.7, "LINESTRING(0 0, 0 3, 0 7)"); + test("LINESTRING(0 0, 0 3, 0 7, 0 10)", -1.0, 0.7, + "LINESTRING(0 0, 0 3, 0 7)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenForwardEnd4 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenForwardEnd4) { - test( "LINESTRING Z(0 0 0, 0 0 3, 0 0 7, 0 0 10)", 0.0, -0.3, "LINESTRING Z(0 0 0, 0 0 3, 0 0 7)"); + test("LINESTRING Z(0 0 0, 0 0 3, 0 0 7, 0 0 10)", 0.0, -0.3, + "LINESTRING Z(0 0 0, 0 0 3, 0 0 7)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenForwardEnd2D4 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenForwardEnd2D4) { - test( "LINESTRING(0 0, 0 3, 0 7, 0 10)", 0.0, -0.3, "LINESTRING(0 0, 0 3, 0 7)"); + test("LINESTRING(0 0, 0 3, 0 7, 0 10)", 0.0, -0.3, + "LINESTRING(0 0, 0 3, 0 7)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenForwardEnds4 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenForwardEnds4) { - test( "LINESTRING Z(0 0 0, 0 0 3, 0 0 7, 0 0 10)", -1.0, -0.3, "LINESTRING Z(0 0 0, 0 0 3, 0 0 7)"); + test("LINESTRING Z(0 0 0, 0 0 3, 0 0 7, 0 0 10)", -1.0, -0.3, + "LINESTRING Z(0 0 0, 0 0 3, 0 0 7)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenForwardEnds2D4 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenForwardEnds2D4) { - test( "LINESTRING(0 0, 0 3, 0 7, 0 10)", -1.0, -0.3, "LINESTRING(0 0, 0 3, 0 7)"); + test("LINESTRING(0 0, 0 3, 0 7, 0 10)", -1.0, -0.3, + "LINESTRING(0 0, 0 3, 0 7)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenForward5 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenForward5) { - test( "LINESTRING Z(0 0 0, 0 0 3, 0 0 5, 0 0 7, 0 0 10)", 0.3, 0.7, "LINESTRING Z(0 0 3, 0 0 5, 0 0 7)"); + test("LINESTRING Z(0 0 0, 0 0 3, 0 0 5, 0 0 7, 0 0 10)", 0.3, 0.7, + "LINESTRING Z(0 0 3, 0 0 5, 0 0 7)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenForward2D5 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenForward2D5) { - test( "LINESTRING(0 0, 0 3, 0 5, 0 7, 0 10)", 0.3, 0.7, "LINESTRING(0 3, 0 5, 0 7)"); + test("LINESTRING(0 0, 0 3, 0 5, 0 7, 0 10)", 0.3, 0.7, + "LINESTRING(0 3, 0 5, 0 7)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenForwardNegativeStart5 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenForwardNegativeStart5) { - test( "LINESTRING Z(0 0 0, 0 0 3, 0 0 5, 0 0 7, 0 0 10)", -0.7, 0.7, "LINESTRING Z(0 0 3, 0 0 5, 0 0 7)"); + test("LINESTRING Z(0 0 0, 0 0 3, 0 0 5, 0 0 7, 0 0 10)", -0.7, 0.7, + "LINESTRING Z(0 0 3, 0 0 5, 0 0 7)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenForwardNegativeStart2D5 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenForwardNegativeStart2D5) { - test( "LINESTRING(0 0, 0 3, 0 5, 0 7, 0 10)", -0.7, 0.7, "LINESTRING(0 3, 0 5, 0 7)"); + test("LINESTRING(0 0, 0 3, 0 5, 0 7, 0 10)", -0.7, 0.7, + "LINESTRING(0 3, 0 5, 0 7)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenForwardNegativeEnd5 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenForwardNegativeEnd5) { - test( "LINESTRING Z(0 0 0, 0 0 3, 0 0 5, 0 0 7, 0 0 10)", 0.3, -0.3, "LINESTRING Z(0 0 3, 0 0 5, 0 0 7)"); + test("LINESTRING Z(0 0 0, 0 0 3, 0 0 5, 0 0 7, 0 0 10)", 0.3, -0.3, + "LINESTRING Z(0 0 3, 0 0 5, 0 0 7)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenForwardNegativeEnd2D5 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenForwardNegativeEnd2D5) { - test( "LINESTRING(0 0, 0 3, 0 5, 0 7, 0 10)", 0.3, -0.3, "LINESTRING(0 3, 0 5, 0 7)"); + test("LINESTRING(0 0, 0 3, 0 5, 0 7, 0 10)", 0.3, -0.3, + "LINESTRING(0 3, 0 5, 0 7)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenForwardNegativeEnds5 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenForwardNegativeEnds5) { - test( "LINESTRING Z(0 0 0, 0 0 3, 0 0 5, 0 0 7, 0 0 10)", -0.7, -0.3, "LINESTRING Z(0 0 3, 0 0 5, 0 0 7)"); + test("LINESTRING Z(0 0 0, 0 0 3, 0 0 5, 0 0 7, 0 0 10)", -0.7, -0.3, + "LINESTRING Z(0 0 3, 0 0 5, 0 0 7)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenForwardNegativeEnds2D5 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenForwardNegativeEnds2D5) { - test( "LINESTRING(0 0, 0 3, 0 5, 0 7, 0 10)", -0.7, -0.3, "LINESTRING(0 3, 0 5, 0 7)"); + test("LINESTRING(0 0, 0 3, 0 5, 0 7, 0 10)", -0.7, -0.3, + "LINESTRING(0 3, 0 5, 0 7)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenBackward2 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenBackward2) { - test( "LINESTRING Z(0 0 0, 0 0 10)", 0.7, 0.0, "LINESTRING Z(0 0 7, 0 0 0)"); + test("LINESTRING Z(0 0 0, 0 0 10)", 0.7, 0.0, "LINESTRING Z(0 0 7, 0 0 0)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenBackward2D2 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenBackward2D2) { - test( "LINESTRING(0 0, 0 10)", 0.7, 0.0, "LINESTRING(0 7, 0 0)"); + test("LINESTRING(0 0, 0 10)", 0.7, 0.0, "LINESTRING(0 7, 0 0)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenBackwardNegativeStart2 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenBackwardNegativeStart2) { - test( "LINESTRING Z(0 0 0, 0 0 10)", -0.3, 0.0, "LINESTRING Z(0 0 7, 0 0 0)"); + test("LINESTRING Z(0 0 0, 0 0 10)", -0.3, 0.0, "LINESTRING Z(0 0 7, 0 0 0)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenBackwardNegativeStart2D2 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenBackwardNegativeStart2D2) { - test( "LINESTRING(0 0, 0 10)", -0.3, 0.0, "LINESTRING(0 7, 0 0)"); + test("LINESTRING(0 0, 0 10)", -0.3, 0.0, "LINESTRING(0 7, 0 0)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenBackwardNegativeEnd2 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenBackwardNegativeEnd2) { - test( "LINESTRING Z(0 0 0, 0 0 10)", 0.7, -1.0, "LINESTRING Z(0 0 7, 0 0 0)"); + test("LINESTRING Z(0 0 0, 0 0 10)", 0.7, -1.0, "LINESTRING Z(0 0 7, 0 0 0)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenBackwardNegativeEnd2D2 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenBackwardNegativeEnd2D2) { - test( "LINESTRING(0 0, 0 10)", 0.7, -1.0, "LINESTRING(0 7, 0 0)"); + test("LINESTRING(0 0, 0 10)", 0.7, -1.0, "LINESTRING(0 7, 0 0)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenBackwardNegativeEnds2 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenBackwardNegativeEnds2) { - test( "LINESTRING Z(0 0 0, 0 0 10)", -0.3, -1.0, "LINESTRING Z(0 0 7, 0 0 0)"); + test("LINESTRING Z(0 0 0, 0 0 10)", -0.3, -1.0, "LINESTRING Z(0 0 7, 0 0 0)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenBackwardNegativeEnds2D2 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenBackwardNegativeEnds2D2) { - test( "LINESTRING(0 0, 0 10)", -0.3, -1.0, "LINESTRING(0 7, 0 0)"); + test("LINESTRING(0 0, 0 10)", -0.3, -1.0, "LINESTRING(0 7, 0 0)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenBackward3 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenBackward3) { - test( "LINESTRING Z(0 0 0, 0 0 10)", 0.3, 1.0, "LINESTRING Z(0 0 10, 0 0 3)"); + test("LINESTRING Z(0 0 0, 0 0 10)", 0.3, 1.0, "LINESTRING Z(0 0 10, 0 0 3)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenBackward2D3 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenBackward2D3) { - test( "LINESTRING(0 0, 0 10)", 0.3, 1.0, "LINESTRING(0 10, 0 3)"); + test("LINESTRING(0 0, 0 10)", 0.3, 1.0, "LINESTRING(0 10, 0 3)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenBackwardNegativeStart3 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenBackwardNegativeStart3) { - test( "LINESTRING Z(0 0 0, 0 0 10)", -0.7, 1.0, "LINESTRING Z(0 0 10, 0 0 3)"); + test("LINESTRING Z(0 0 0, 0 0 10)", -0.7, 1.0, "LINESTRING Z(0 0 10, 0 0 3)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenBackwardNegativeStart2D3 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenBackwardNegativeStart2D3) { - test( "LINESTRING(0 0, 0 10)", -0.7, 1.0, "LINESTRING(0 10, 0 3)"); + test("LINESTRING(0 0, 0 10)", -0.7, 1.0, "LINESTRING(0 10, 0 3)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenBackward4 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenBackward4) { - test( "LINESTRING Z(0 0 0, 0 0 3, 0 0 7, 0 0 10)", 1.0, 0.3, "LINESTRING Z(0 0 10, 0 0 7, 0 0 3)"); + test("LINESTRING Z(0 0 0, 0 0 3, 0 0 7, 0 0 10)", 1.0, 0.3, + "LINESTRING Z(0 0 10, 0 0 7, 0 0 3)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenBackward2D4 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenBackward2D4) { - test( "LINESTRING(0 0, 0 3, 0 7, 0 10)", 1.0, 0.3, "LINESTRING(0 10, 0 7, 0 3)"); + test("LINESTRING(0 0, 0 3, 0 7, 0 10)", 1.0, 0.3, + "LINESTRING(0 10, 0 7, 0 3)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenBackwardNegativeEnd4 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenBackwardNegativeEnd4) { - test( "LINESTRING Z(0 0 0, 0 0 3, 0 0 7, 0 0 10)", 1.0, -0.7, "LINESTRING Z(0 0 10, 0 0 7, 0 0 3)"); + test("LINESTRING Z(0 0 0, 0 0 3, 0 0 7, 0 0 10)", 1.0, -0.7, + "LINESTRING Z(0 0 10, 0 0 7, 0 0 3)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenBackwardNegativeEnd2D4 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenBackwardNegativeEnd2D4) { - test( "LINESTRING(0 0, 0 3, 0 7, 0 10)", 1.0, -0.7, "LINESTRING(0 10, 0 7, 0 3)"); + test("LINESTRING(0 0, 0 3, 0 7, 0 10)", 1.0, -0.7, + "LINESTRING(0 10, 0 7, 0 3)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenBackward5 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenBackward5) { - test( "LINESTRING Z(0 0 0, 0 0 3, 0 0 7, 0 0 10)", 0.7, 0.0, "LINESTRING Z(0 0 7, 0 0 3, 0 0 0)"); + test("LINESTRING Z(0 0 0, 0 0 3, 0 0 7, 0 0 10)", 0.7, 0.0, + "LINESTRING Z(0 0 7, 0 0 3, 0 0 0)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenBackward2D5 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenBackward2D5) { - test( "LINESTRING(0 0, 0 3, 0 7, 0 10)", 0.7, 0.0, "LINESTRING(0 7, 0 3, 0 0)"); + test("LINESTRING(0 0, 0 3, 0 7, 0 10)", 0.7, 0.0, + "LINESTRING(0 7, 0 3, 0 0)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenBackwardNegativeStart5 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenBackwardNegativeStart5) { - test( "LINESTRING Z(0 0 0, 0 0 3, 0 0 7, 0 0 10)", -0.3, 0.0, "LINESTRING Z(0 0 7, 0 0 3, 0 0 0)"); + test("LINESTRING Z(0 0 0, 0 0 3, 0 0 7, 0 0 10)", -0.3, 0.0, + "LINESTRING Z(0 0 7, 0 0 3, 0 0 0)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenBackwardNegativeStart2D5 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenBackwardNegativeStart2D5) { - test( "LINESTRING(0 0, 0 3, 0 7, 0 10)", -0.3, 0.0, "LINESTRING(0 7, 0 3, 0 0)"); + test("LINESTRING(0 0, 0 3, 0 7, 0 10)", -0.3, 0.0, + "LINESTRING(0 7, 0 3, 0 0)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenBackwardNegativeEnd5 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenBackwardNegativeEnd5) { - test( "LINESTRING Z(0 0 0, 0 0 3, 0 0 7, 0 0 10)", 0.7, -1.0, "LINESTRING Z(0 0 7, 0 0 3, 0 0 0)"); + test("LINESTRING Z(0 0 0, 0 0 3, 0 0 7, 0 0 10)", 0.7, -1.0, + "LINESTRING Z(0 0 7, 0 0 3, 0 0 0)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenBackwardNegativeEnd2D5 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenBackwardNegativeEnd2D5) { - test( "LINESTRING(0 0, 0 3, 0 7, 0 10)", 0.7, -1.0, "LINESTRING(0 7, 0 3, 0 0)"); + test("LINESTRING(0 0, 0 3, 0 7, 0 10)", 0.7, -1.0, + "LINESTRING(0 7, 0 3, 0 0)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenBackwardNegativeEnds5 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenBackwardNegativeEnds5) { - test( "LINESTRING Z(0 0 0, 0 0 3, 0 0 7, 0 0 10)", -0.3, -1.0, "LINESTRING Z(0 0 7, 0 0 3, 0 0 0)"); + test("LINESTRING Z(0 0 0, 0 0 3, 0 0 7, 0 0 10)", -0.3, -1.0, + "LINESTRING Z(0 0 7, 0 0 3, 0 0 0)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenBackwardNegativeEnds2D5 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenBackwardNegativeEnds2D5) { - test( "LINESTRING(0 0, 0 3, 0 7, 0 10)", -0.3, -1.0, "LINESTRING(0 7, 0 3, 0 0)"); + test("LINESTRING(0 0, 0 3, 0 7, 0 10)", -0.3, -1.0, + "LINESTRING(0 7, 0 3, 0 0)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenBackward6 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenBackward6) { - test( "LINESTRING Z(0 0 0, 0 0 3, 0 0 5, 0 0 7, 0 0 10)", 0.7, 0.3, "LINESTRING Z(0 0 7, 0 0 5, 0 0 3)"); + test("LINESTRING Z(0 0 0, 0 0 3, 0 0 5, 0 0 7, 0 0 10)", 0.7, 0.3, + "LINESTRING Z(0 0 7, 0 0 5, 0 0 3)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenBackward2D6 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenBackward2D6) { - test( "LINESTRING(0 0, 0 3, 0 5, 0 7, 0 10)", 0.7, 0.3, "LINESTRING(0 7, 0 5, 0 3)"); + test("LINESTRING(0 0, 0 3, 0 5, 0 7, 0 10)", 0.7, 0.3, + "LINESTRING(0 7, 0 5, 0 3)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenBackwardNegativeStart6 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenBackwardNegativeStart6) { - test( "LINESTRING Z(0 0 0, 0 0 3, 0 0 5, 0 0 7, 0 0 10)", -0.3, 0.3, "LINESTRING Z(0 0 7, 0 0 5, 0 0 3)"); + test("LINESTRING Z(0 0 0, 0 0 3, 0 0 5, 0 0 7, 0 0 10)", -0.3, 0.3, + "LINESTRING Z(0 0 7, 0 0 5, 0 0 3)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenBackwardNegativeStart2D6 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenBackwardNegativeStart2D6) { - test( "LINESTRING Z(0 0, 0 3, 0 5, 0 7, 0 10)", -0.3, 0.3, "LINESTRING(0 7, 0 5, 0 3)"); + test("LINESTRING Z(0 0, 0 3, 0 5, 0 7, 0 10)", -0.3, 0.3, + "LINESTRING(0 7, 0 5, 0 3)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenBackwardNegativeEnd6 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenBackwardNegativeEnd6) { - test( "LINESTRING Z(0 0 0, 0 0 3, 0 0 5, 0 0 7, 0 0 10)", 0.7, -0.7, "LINESTRING Z(0 0 7, 0 0 5, 0 0 3)"); + test("LINESTRING Z(0 0 0, 0 0 3, 0 0 5, 0 0 7, 0 0 10)", 0.7, -0.7, + "LINESTRING Z(0 0 7, 0 0 5, 0 0 3)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenBackwardNegativeEnd2D6 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenBackwardNegativeEnd2D6) { - test( "LINESTRING(0 0, 0 3, 0 5, 0 7, 0 10)", 0.7, -0.7, "LINESTRING(0 7, 0 5, 0 3)"); + test("LINESTRING(0 0, 0 3, 0 5, 0 7, 0 10)", 0.7, -0.7, + "LINESTRING(0 7, 0 5, 0 3)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenBackwardNegativeEnds6 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenBackwardNegativeEnds6) { - test( "LINESTRING Z(0 0 0, 0 0 3, 0 0 5, 0 0 7, 0 0 10)", -0.3, -0.7, "LINESTRING Z(0 0 7, 0 0 5, 0 0 3)"); + test("LINESTRING Z(0 0 0, 0 0 3, 0 0 5, 0 0 7, 0 0 10)", -0.3, -0.7, + "LINESTRING Z(0 0 7, 0 0 5, 0 0 3)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenBackwardNegativeEnds2D6 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenBackwardNegativeEnds2D6) { - test( "LINESTRING Z(0 0, 0 3, 0 5, 0 7, 0 10)", -0.3, -0.7, "LINESTRING(0 7, 0 5, 0 3)"); + test("LINESTRING Z(0 0, 0 3, 0 5, 0 7, 0 10)", -0.3, -0.7, + "LINESTRING(0 7, 0 5, 0 3)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenBackward7 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenBackward7) { - test( "LINESTRING Z(0 0 0, 0 0 10)", 1.0, 0.0, "LINESTRING Z(0 0 10, 0 0 0)"); + test("LINESTRING Z(0 0 0, 0 0 10)", 1.0, 0.0, "LINESTRING Z(0 0 10, 0 0 0)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenBackward2D7 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenBackward2D7) { - test( "LINESTRING(0 0, 0 10)", 1.0, 0.0, "LINESTRING(0 10, 0 0)"); + test("LINESTRING(0 0, 0 10)", 1.0, 0.0, "LINESTRING(0 10, 0 0)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenBackwardNegativeEnd7 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenBackwardNegativeEnd7) { - test( "LINESTRING Z(0 0 0, 0 0 10)", 1.0, -1.0, "LINESTRING Z(0 0 10, 0 0 0)"); + test("LINESTRING Z(0 0 0, 0 0 10)", 1.0, -1.0, "LINESTRING Z(0 0 10, 0 0 0)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenBackwardNegativeEnd2D7 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenBackwardNegativeEnd2D7) { - test( "LINESTRING(0 0, 0 10)", 1.0, -1.0, "LINESTRING(0 10, 0 0)"); + test("LINESTRING(0 0, 0 10)", 1.0, -1.0, "LINESTRING(0 10, 0 0)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringOfEmptyLine ) +BOOST_AUTO_TEST_CASE(testLineSubstringOfEmptyLine) { - test( "LINESTRING EMPTY", 0.0, 1.0, "LINESTRING EMPTY", false, true ); + test("LINESTRING EMPTY", 0.0, 1.0, "LINESTRING EMPTY", false, true); } -BOOST_AUTO_TEST_CASE( testLineSubstringOfEmptyLine2 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOfEmptyLine2) { - test( "LINESTRING EMPTY", 0.0, 0.0, "LINESTRING EMPTY", false, true ); + test("LINESTRING EMPTY", 0.0, 0.0, "LINESTRING EMPTY", false, true); } -BOOST_AUTO_TEST_CASE( testLineSubstringOfEmptyLine3 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOfEmptyLine3) { - test( "LINESTRING EMPTY", 1.0, 0.0, "LINESTRING EMPTY", false, true ); + test("LINESTRING EMPTY", 1.0, 0.0, "LINESTRING EMPTY", false, true); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenEmptySegment1 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenEmptySegment1) { - test( "LINESTRING Z(0 0 0, 0 0 10)", 0.0, 0.0, "LINESTRING EMPTY", false, true ); + test("LINESTRING Z(0 0 0, 0 0 10)", 0.0, 0.0, "LINESTRING EMPTY", false, + true); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenEmptySegment2D1 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenEmptySegment2D1) { - test( "LINESTRING(0 0, 0 10)", 0.0, 0.0, "LINESTRING EMPTY", false, true ); + test("LINESTRING(0 0, 0 10)", 0.0, 0.0, "LINESTRING EMPTY", false, true); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenEmptySegment2 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenEmptySegment2) { - test( "LINESTRING Z(0 0 0, 0 0 10)", 0.5, 0.5, "LINESTRING EMPTY", false, true ); + test("LINESTRING Z(0 0 0, 0 0 10)", 0.5, 0.5, "LINESTRING EMPTY", false, + true); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenEmptySegment2D2 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenEmptySegment2D2) { - test( "LINESTRING(0 0, 0 10)", 0.5, 0.5, "LINESTRING EMPTY", false, true ); + test("LINESTRING(0 0, 0 10)", 0.5, 0.5, "LINESTRING EMPTY", false, true); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenEmptySegment3 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenEmptySegment3) { - test( "LINESTRING Z(0 0 0, 0 0 10)", 1.0, 1.0, "LINESTRING EMPTY", false, true ); + test("LINESTRING Z(0 0 0, 0 0 10)", 1.0, 1.0, "LINESTRING EMPTY", false, + true); } -BOOST_AUTO_TEST_CASE( testLineSubstringOpenEmptySegment2D3 ) +BOOST_AUTO_TEST_CASE(testLineSubstringOpenEmptySegment2D3) { - test( "LINESTRING(0 0, 0 10)", 1.0, 1.0, "LINESTRING EMPTY", false, true ); + test("LINESTRING(0 0, 0 10)", 1.0, 1.0, "LINESTRING EMPTY", false, true); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosed1 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosed1) { - test( "LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)" - , 0.0 - , 0.7 - , "LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3)" - ); + test("LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)", 0.0, + 0.7, "LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosed2D1 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosed2D1) { - test( "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)" - , 0.0 - , 0.7 - , "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0.5 2.5)" - ); + test("LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)", 0.0, 0.7, + "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0.5 2.5)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedNegativeStart1 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedNegativeStart1) { - test( "LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)" - , -1.0 - , 0.7 - , "LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3)" - ); + test("LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)", -1.0, + 0.7, "LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedNegativeStart2D1 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedNegativeStart2D1) { - test( "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)" - , -1.0 - , 0.7 - , "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0.5 2.5)" - ); + test("LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)", -1.0, 0.7, + "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0.5 2.5)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedNegativeEnd1 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedNegativeEnd1) { - test( "LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)" - , 0.0 - , -0.3 - , "LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3)" - ); + test("LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)", 0.0, + -0.3, "LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedNegativeEnd2D1 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedNegativeEnd2D1) { - test( "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)" - , 0.0 - , -0.3 - , "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0.5 2.5)" - ); + test("LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)", 0.0, -0.3, + "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0.5 2.5)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedNegativeEnds1 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedNegativeEnds1) { - test( "LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)" - , -1.0 - , -0.3 - , "LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3)" - ); + test("LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)", -1.0, + -0.3, "LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedNegativeEnds2D1 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedNegativeEnds2D1) { - test( "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)" - , -1.0 - , -0.3 - , "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0.5 2.5)" - ); + test("LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)", -1.0, -0.3, + "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0.5 2.5)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosed2 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosed2) { - test( "LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)" - , 0.1 - , 0.7 - , "LINESTRING Z(1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3)" - ); + test("LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)", 0.1, + 0.7, "LINESTRING Z(1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosed2D2 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosed2D2) { - test( "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)" - , 0.1 - , 0.7 - , "LINESTRING(1 0, 2.5 0, 2.5 2.5, 0.5 2.5)" - ); + test("LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)", 0.1, 0.7, + "LINESTRING(1 0, 2.5 0, 2.5 2.5, 0.5 2.5)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedNegativeStart2 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedNegativeStart2) { - test( "LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)" - , -0.9 - , 0.7 - , "LINESTRING Z(1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3)" - ); + test("LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)", -0.9, + 0.7, "LINESTRING Z(1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedNegativeStart2D2 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedNegativeStart2D2) { - test( "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)" - , -0.9 - , 0.7 - , "LINESTRING(1 0, 2.5 0, 2.5 2.5, 0.5 2.5)" - ); + test("LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)", -0.9, 0.7, + "LINESTRING(1 0, 2.5 0, 2.5 2.5, 0.5 2.5)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedNegativeEnd2 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedNegativeEnd2) { - test( "LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)" - , 0.1 - , -0.3 - , "LINESTRING Z(1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3)" - ); + test("LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)", 0.1, + -0.3, "LINESTRING Z(1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedNegativeEnd2D2 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedNegativeEnd2D2) { - test( "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)" - , 0.1 - , -0.3 - , "LINESTRING(1 0, 2.5 0, 2.5 2.5, 0.5 2.5)" - ); + test("LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)", 0.1, -0.3, + "LINESTRING(1 0, 2.5 0, 2.5 2.5, 0.5 2.5)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedNegativeEnds2 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedNegativeEnds2) { - test( "LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)" - , -0.9 - , -0.3 - , "LINESTRING Z(1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3)" - ); + test("LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)", -0.9, + -0.3, "LINESTRING Z(1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedNegativeEnds2D2 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedNegativeEnds2D2) { - test( "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)" - , -0.9 - , -0.3 - , "LINESTRING(1 0, 2.5 0, 2.5 2.5, 0.5 2.5)" - ); + test("LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)", -0.9, -0.3, + "LINESTRING(1 0, 2.5 0, 2.5 2.5, 0.5 2.5)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosed3 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosed3) { - test( "LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)" - , 0.3 - , 0.7 - , "LINESTRING Z(1 1 1, 1 1 3, 0 1 3, 0 0 3)" - ); + test("LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)", 0.3, + 0.7, "LINESTRING Z(1 1 1, 1 1 3, 0 1 3, 0 0 3)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosed2D3 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosed2D3) { - test( "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)" - , 0.3 - , 0.7 - , "LINESTRING(2.5 0.5, 2.5 2.5, 0.5 2.5)" - ); + test("LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)", 0.3, 0.7, + "LINESTRING(2.5 0.5, 2.5 2.5, 0.5 2.5)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedNegativeStart3 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedNegativeStart3) { - test( "LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)" - , -0.7 - , 0.7 - , "LINESTRING Z(1 1 1, 1 1 3, 0 1 3, 0 0 3)" - ); + test("LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)", -0.7, + 0.7, "LINESTRING Z(1 1 1, 1 1 3, 0 1 3, 0 0 3)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedNegativeStart2D3 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedNegativeStart2D3) { - test( "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)" - , -0.7 - , 0.7 - , "LINESTRING(2.5 0.5, 2.5 2.5, 0.5 2.5)" - ); + test("LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)", -0.7, 0.7, + "LINESTRING(2.5 0.5, 2.5 2.5, 0.5 2.5)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedNegativeEnd3 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedNegativeEnd3) { - test( "LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)" - , 0.3 - , -0.3 - , "LINESTRING Z(1 1 1, 1 1 3, 0 1 3, 0 0 3)" - ); + test("LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)", 0.3, + -0.3, "LINESTRING Z(1 1 1, 1 1 3, 0 1 3, 0 0 3)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedNegativeEnd2D3 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedNegativeEnd2D3) { - test( "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)" - , 0.3 - , -0.3 - , "LINESTRING(2.5 0.5, 2.5 2.5, 0.5 2.5)" - ); + test("LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)", 0.3, -0.3, + "LINESTRING(2.5 0.5, 2.5 2.5, 0.5 2.5)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedNegativeEnds3 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedNegativeEnds3) { - test( "LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)" - , -0.7 - , -0.3 - , "LINESTRING Z(1 1 1, 1 1 3, 0 1 3, 0 0 3)" - ); + test("LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)", -0.7, + -0.3, "LINESTRING Z(1 1 1, 1 1 3, 0 1 3, 0 0 3)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedNegativeEnds2D3 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedNegativeEnds2D3) { - test( "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)" - , -0.7 - , -0.3 - , "LINESTRING(2.5 0.5, 2.5 2.5, 0.5 2.5)" - ); + test("LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)", -0.7, -0.3, + "LINESTRING(2.5 0.5, 2.5 2.5, 0.5 2.5)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosed4 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosed4) { - test( "LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)" - , 0.5 - , 0.8 - , "LINESTRING Z(1 1 3, 0 1 3, 0 0 3, 0 0 2)" - ); + test("LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)", 0.5, + 0.8, "LINESTRING Z(1 1 3, 0 1 3, 0 0 3, 0 0 2)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosed2D4 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosed2D4) { - test( "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)" - , 0.5 - , 0.8 - , "LINESTRING(2.5 2.5, 0 2.5, 0 2)" - ); + test("LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)", 0.5, 0.8, + "LINESTRING(2.5 2.5, 0 2.5, 0 2)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedNegativeStart4 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedNegativeStart4) { - test( "LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)" - , -0.5 - , 0.8 - , "LINESTRING Z(1 1 3, 0 1 3, 0 0 3, 0 0 2)" - ); + test("LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)", -0.5, + 0.8, "LINESTRING Z(1 1 3, 0 1 3, 0 0 3, 0 0 2)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedNegativeStart2D4 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedNegativeStart2D4) { - test( "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)" - , -0.5 - , 0.8 - , "LINESTRING(2.5 2.5, 0 2.5, 0 2)" - ); + test("LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)", -0.5, 0.8, + "LINESTRING(2.5 2.5, 0 2.5, 0 2)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedNegativeEnd4 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedNegativeEnd4) { - test( "LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)" - , 0.5 - , -0.2 - , "LINESTRING Z(1 1 3, 0 1 3, 0 0 3, 0 0 2)" - ); + test("LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)", 0.5, + -0.2, "LINESTRING Z(1 1 3, 0 1 3, 0 0 3, 0 0 2)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedNegativeEnd2D4 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedNegativeEnd2D4) { - test( "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)" - , 0.5 - , -0.2 - , "LINESTRING(2.5 2.5, 0 2.5, 0 2)" - ); + test("LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)", 0.5, -0.2, + "LINESTRING(2.5 2.5, 0 2.5, 0 2)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedNegativeEnds4 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedNegativeEnds4) { - test( "LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)" - , -0.5 - , -0.2 - , "LINESTRING Z(1 1 3, 0 1 3, 0 0 3, 0 0 2)" - ); + test("LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)", -0.5, + -0.2, "LINESTRING Z(1 1 3, 0 1 3, 0 0 3, 0 0 2)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedNegativeEnds2D4 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedNegativeEnds2D4) { - test( "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)" - , -0.5 - , -0.2 - , "LINESTRING(2.5 2.5, 0 2.5, 0 2)" - ); + test("LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)", -0.5, -0.2, + "LINESTRING(2.5 2.5, 0 2.5, 0 2)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosed5 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosed5) { - test( "LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)" - , 0.0 - , 1.0 - , "LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)" - ); + test("LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)", 0.0, + 1.0, "LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosed2D5 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosed2D5) { - test( "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)" - , 0.0 - , 1.0 - , "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)" - ); + test("LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)", 0.0, 1.0, + "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedNegativeStart5 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedNegativeStart5) { - test( "LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)" - , -1.0 - , 1.0 - , "LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)" - ); + test("LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)", -1.0, + 1.0, "LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedNegativeStart2D5 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedNegativeStart2D5) { - test( "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)" - , -1.0 - , 1.0 - , "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)" - ); + test("LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)", -1.0, 1.0, + "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedComplement1 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedComplement1) { - test( "LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)" - , 0.7 - , 0.0 - , "LINESTRING Z(0 0 3, 0 0 0)" - ); + test("LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)", 0.7, + 0.0, "LINESTRING Z(0 0 3, 0 0 0)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedComplement2D1 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedComplement2D1) { - test( "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)" - , 0.7 - , 0.0 - , "LINESTRING(0.5 2.5, 0 2.5, 0 0)" - ); + test("LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)", 0.7, 0.0, + "LINESTRING(0.5 2.5, 0 2.5, 0 0)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedComplementNegativeStart1 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedComplementNegativeStart1) { - test( "LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)" - , -0.3 - , 0.0 - , "LINESTRING Z(0 0 3, 0 0 0)" - ); + test("LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)", -0.3, + 0.0, "LINESTRING Z(0 0 3, 0 0 0)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedComplementNegativeStart2D1 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedComplementNegativeStart2D1) { - test( "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)" - , -0.3 - , 0.0 - , "LINESTRING(0.5 2.5, 0 2.5, 0 0)" - ); + test("LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)", -0.3, 0.0, + "LINESTRING(0.5 2.5, 0 2.5, 0 0)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedComplementNegativeEnd1 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedComplementNegativeEnd1) { - test( "LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)" - , 0.7 - , -1.0 - , "LINESTRING Z(0 0 3, 0 0 0)" - ); + test("LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)", 0.7, + -1.0, "LINESTRING Z(0 0 3, 0 0 0)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedComplementNegativeEnd2D1 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedComplementNegativeEnd2D1) { - test( "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)" - , 0.7 - , -1.0 - , "LINESTRING(0.5 2.5, 0 2.5, 0 0)" - ); + test("LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)", 0.7, -1.0, + "LINESTRING(0.5 2.5, 0 2.5, 0 0)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedComplementNegativeEnds1 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedComplementNegativeEnds1) { - test( "LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)" - , -0.3 - , -1.0 - , "LINESTRING Z(0 0 3, 0 0 0)" - ); + test("LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)", -0.3, + -1.0, "LINESTRING Z(0 0 3, 0 0 0)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedComplementNegativeEnds2D1 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedComplementNegativeEnds2D1) { - test( "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)" - , -0.3 - , -1.0 - , "LINESTRING(0.5 2.5, 0 2.5, 0 0)" - ); + test("LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)", -0.3, -1.0, + "LINESTRING(0.5 2.5, 0 2.5, 0 0)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedComplement2 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedComplement2) { - test( "LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)" - , 0.7 - , 0.1 - , "LINESTRING Z(0 0 3, 0 0 0, 1 0 0)" - ); + test("LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)", 0.7, + 0.1, "LINESTRING Z(0 0 3, 0 0 0, 1 0 0)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedComplement2D2 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedComplement2D2) { - test( "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)" - , 0.7 - , 0.1 - , "LINESTRING(0.5 2.5, 0 2.5, 0 1)" - ); + test("LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)", 0.7, 0.1, + "LINESTRING(0.5 2.5, 0 2.5, 0 1)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedComplementNegativeStart2 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedComplementNegativeStart2) { - test( "LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)" - , -0.3 - , 0.1 - , "LINESTRING Z(0 0 3, 0 0 0, 1 0 0)" - ); + test("LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)", -0.3, + 0.1, "LINESTRING Z(0 0 3, 0 0 0, 1 0 0)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedComplementNegativeStart2D2 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedComplementNegativeStart2D2) { - test( "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)" - , -0.3 - , 0.1 - , "LINESTRING(0.5 2.5, 0 2.5, 0 1)" - ); + test("LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)", -0.3, 0.1, + "LINESTRING(0.5 2.5, 0 2.5, 0 1)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedComplementNegativeEnd2 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedComplementNegativeEnd2) { - test( "LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)" - , 0.7 - , -0.9 - , "LINESTRING Z(0 0 3, 0 0 0, 1 0 0)" - ); + test("LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)", 0.7, + -0.9, "LINESTRING Z(0 0 3, 0 0 0, 1 0 0)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedComplementNegativeEnd2D2 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedComplementNegativeEnd2D2) { - test( "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)" - , 0.7 - , -0.9 - , "LINESTRING(0.5 2.5, 0 2.5, 0 1)" - ); + test("LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)", 0.7, -0.9, + "LINESTRING(0.5 2.5, 0 2.5, 0 1)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedComplementNegativeEnds2 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedComplementNegativeEnds2) { - test( "LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)" - , -0.3 - , -0.9 - , "LINESTRING Z(0 0 3, 0 0 0, 1 0 0)" - ); + test("LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)", -0.3, + -0.9, "LINESTRING Z(0 0 3, 0 0 0, 1 0 0)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedComplementNegativeEnds2D2 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedComplementNegativeEnds2D2) { - test( "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)" - , -0.3 - , -0.9 - , "LINESTRING(0.5 2.5, 0 2.5, 0 1)" - ); + test("LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)", -0.3, -0.9, + "LINESTRING(0.5 2.5, 0 2.5, 0 1)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedComplement3 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedComplement3) { - test( "LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)" - , 0.7 - , 0.3 - , "LINESTRING Z(0 0 3, 0 0 0, 1 0 0, 1 1 0, 1 1 1)" - ); + test("LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)", 0.7, + 0.3, "LINESTRING Z(0 0 3, 0 0 0, 1 0 0, 1 1 0, 1 1 1)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedComplement2D3 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedComplement2D3) { - test( "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)" - , 0.7 - , 0.3 - , "LINESTRING(0.5 2.5, 0 2.5, 0 0, 2.5 0, 2.5 0.5)" - ); + test("LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)", 0.7, 0.3, + "LINESTRING(0.5 2.5, 0 2.5, 0 0, 2.5 0, 2.5 0.5)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedComplementNegativeStart3 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedComplementNegativeStart3) { - test( "LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)" - , -0.3 - , 0.3 - , "LINESTRING Z(0 0 3, 0 0 0, 1 0 0, 1 1 0, 1 1 1)" - ); + test("LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)", -0.3, + 0.3, "LINESTRING Z(0 0 3, 0 0 0, 1 0 0, 1 1 0, 1 1 1)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedComplementNegativeStart2D3 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedComplementNegativeStart2D3) { - test( "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)" - , -0.3 - , 0.3 - , "LINESTRING(0.5 2.5, 0 2.5, 0 0, 2.5 0, 2.5 0.5)" - ); + test("LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)", -0.3, 0.3, + "LINESTRING(0.5 2.5, 0 2.5, 0 0, 2.5 0, 2.5 0.5)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedComplementNegativeEnd3 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedComplementNegativeEnd3) { - test( "LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)" - , 0.7 - , -0.7 - , "LINESTRING Z(0 0 3, 0 0 0, 1 0 0, 1 1 0, 1 1 1)" - ); + test("LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)", 0.7, + -0.7, "LINESTRING Z(0 0 3, 0 0 0, 1 0 0, 1 1 0, 1 1 1)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedComplementNegativeEnd2D3 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedComplementNegativeEnd2D3) { - test( "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)" - , 0.7 - , -0.7 - , "LINESTRING(0.5 2.5, 0 2.5, 0 0, 2.5 0, 2.5 0.5)" - ); + test("LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)", 0.7, -0.7, + "LINESTRING(0.5 2.5, 0 2.5, 0 0, 2.5 0, 2.5 0.5)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedComplementNegativeEnds3 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedComplementNegativeEnds3) { - test( "LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)" - , -0.3 - , -0.7 - , "LINESTRING Z(0 0 3, 0 0 0, 1 0 0, 1 1 0, 1 1 1)" - ); + test("LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)", -0.3, + -0.7, "LINESTRING Z(0 0 3, 0 0 0, 1 0 0, 1 1 0, 1 1 1)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedComplementNegativeEnds2D3 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedComplementNegativeEnds2D3) { - test( "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)" - , -0.3 - , -0.7 - , "LINESTRING(0.5 2.5, 0 2.5, 0 0, 2.5 0, 2.5 0.5)" - ); + test("LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)", -0.3, -0.7, + "LINESTRING(0.5 2.5, 0 2.5, 0 0, 2.5 0, 2.5 0.5)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedComplement4 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedComplement4) { - test( "LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)" - , 0.8 - , 0.5 - , "LINESTRING Z(0 0 2, 0 0 0, 1 0 0, 1 1 0, 1 1 3)" - ); + test("LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)", 0.8, + 0.5, "LINESTRING Z(0 0 2, 0 0 0, 1 0 0, 1 1 0, 1 1 3)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedComplement2D4 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedComplement2D4) { - test( "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)" - , 0.8 - , 0.5 - , "LINESTRING(0 2, 0 0, 2.5 0, 2.5 2.5)" - ); + test("LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)", 0.8, 0.5, + "LINESTRING(0 2, 0 0, 2.5 0, 2.5 2.5)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedComplementNegativeStart4 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedComplementNegativeStart4) { - test( "LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)" - , -0.2 - , 0.5 - , "LINESTRING Z(0 0 2, 0 0 0, 1 0 0, 1 1 0, 1 1 3)" - ); + test("LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)", -0.2, + 0.5, "LINESTRING Z(0 0 2, 0 0 0, 1 0 0, 1 1 0, 1 1 3)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedComplementNegativeStart2D4 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedComplementNegativeStart2D4) { - test( "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)" - , -0.2 - , 0.5 - , "LINESTRING(0 2, 0 0, 2.5 0, 2.5 2.5)" - ); + test("LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)", -0.2, 0.5, + "LINESTRING(0 2, 0 0, 2.5 0, 2.5 2.5)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedComplementNegativeEnd4 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedComplementNegativeEnd4) { - test( "LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)" - , 0.8 - , -0.5 - , "LINESTRING Z(0 0 2, 0 0 0, 1 0 0, 1 1 0, 1 1 3)" - ); + test("LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)", 0.8, + -0.5, "LINESTRING Z(0 0 2, 0 0 0, 1 0 0, 1 1 0, 1 1 3)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedComplementNegativeEnd2D4 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedComplementNegativeEnd2D4) { - test( "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)" - , 0.8 - , -0.5 - , "LINESTRING(0 2, 0 0, 2.5 0, 2.5 2.5)" - ); + test("LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)", 0.8, -0.5, + "LINESTRING(0 2, 0 0, 2.5 0, 2.5 2.5)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedComplementNegativeEnds4 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedComplementNegativeEnds4) { - test( "LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)" - , -0.2 - , -0.5 - , "LINESTRING Z(0 0 2, 0 0 0, 1 0 0, 1 1 0, 1 1 3)" - ); + test("LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)", -0.2, + -0.5, "LINESTRING Z(0 0 2, 0 0 0, 1 0 0, 1 1 0, 1 1 3)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedComplementNegativeEnds2D4 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedComplementNegativeEnds2D4) { - test( "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)" - , -0.2 - , -0.5 - , "LINESTRING(0 2, 0 0, 2.5 0, 2.5 2.5)" - ); + test("LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)", -0.2, -0.5, + "LINESTRING(0 2, 0 0, 2.5 0, 2.5 2.5)"); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedComplement5 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedComplement5) { - test( "LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)" - , 1.0 - , 0.0 - , "LINESTRING EMPTY" - , false - , true - ); + test("LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)", 1.0, + 0.0, "LINESTRING EMPTY", false, true); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedComplement2D5 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedComplement2D5) { - test( "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)" - , 1.0 - , 0.0 - , "LINESTRING EMPTY" - , false - , true - ); + test("LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)", 1.0, 0.0, + "LINESTRING EMPTY", false, true); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedComplementNegativeEnd5 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedComplementNegativeEnd5) { - test( "LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)" - , 1.0 - , -1.0 - , "LINESTRING EMPTY" - , false - , true - ); + test("LINESTRING Z(0 0 0, 1 0 0, 1 1 0, 1 1 3, 0 1 3, 0 0 3, 0 0 0)", 1.0, + -1.0, "LINESTRING EMPTY", false, true); } -BOOST_AUTO_TEST_CASE( testLineSubstringClosedComplementNegativeEnd2D5 ) +BOOST_AUTO_TEST_CASE(testLineSubstringClosedComplementNegativeEnd2D5) { - test( "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)" - , 1.0 - , -1.0 - , "LINESTRING EMPTY" - , false - , true - ); + test("LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)", 1.0, -1.0, + "LINESTRING EMPTY", false, true); } -BOOST_AUTO_TEST_CASE( testLineSubstringInvalidStartFraction ) +BOOST_AUTO_TEST_CASE(testLineSubstringInvalidStartFraction) { - BOOST_CHECK_THROW( - algorithm::lineSubstring( - io::readWkt( "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)" )->as() - , 1.1 - , 1.0 - ), - Exception - ); + BOOST_CHECK_THROW( + algorithm::lineSubstring( + io::readWkt("LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)") + ->as(), + 1.1, 1.0), + Exception); } -BOOST_AUTO_TEST_CASE( testLineSubstringInvalidNegativeStartFraction ) +BOOST_AUTO_TEST_CASE(testLineSubstringInvalidNegativeStartFraction) { - BOOST_CHECK_THROW( - algorithm::lineSubstring( - io::readWkt( "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)" )->as() - , -1.1 - , 1.0 - ), - Exception - ); + BOOST_CHECK_THROW( + algorithm::lineSubstring( + io::readWkt("LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)") + ->as(), + -1.1, 1.0), + Exception); } -BOOST_AUTO_TEST_CASE( testLineSubstringInvalidEndFraction ) +BOOST_AUTO_TEST_CASE(testLineSubstringInvalidEndFraction) { - BOOST_CHECK_THROW( - algorithm::lineSubstring( - io::readWkt( "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)" )->as() - , 0.0 - , 1.1 - ), - Exception - ); + BOOST_CHECK_THROW( + algorithm::lineSubstring( + io::readWkt("LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)") + ->as(), + 0.0, 1.1), + Exception); } -BOOST_AUTO_TEST_CASE( testLineSubstringInvalidNegativeEndFraction ) +BOOST_AUTO_TEST_CASE(testLineSubstringInvalidNegativeEndFraction) { - BOOST_CHECK_THROW( - algorithm::lineSubstring( - io::readWkt( "LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)" )->as() - , 0.0 - , -1.1 - ), - Exception - ); + BOOST_CHECK_THROW( + algorithm::lineSubstring( + io::readWkt("LINESTRING(0 0, 2.5 0, 2.5 2.5, 0 2.5, 0 0)") + ->as(), + 0.0, -1.1), + Exception); } BOOST_AUTO_TEST_SUITE_END() - diff --git a/test/unit/SFCGAL/algorithm/MinkowskiSumTest.cpp b/test/unit/SFCGAL/algorithm/MinkowskiSumTest.cpp index 6912ae2e..f17c0e49 100644 --- a/test/unit/SFCGAL/algorithm/MinkowskiSumTest.cpp +++ b/test/unit/SFCGAL/algorithm/MinkowskiSumTest.cpp @@ -15,123 +15,166 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include +#include #include -#include #include -#include -#include -#include -#include -#include -#include -#include #include +#include #include #include -#include +#include +#include +#include +#include +#include +#include #include #include +#include #include -using namespace boost::unit_test ; -using namespace SFCGAL ; +using namespace boost::unit_test; +using namespace SFCGAL; -BOOST_AUTO_TEST_SUITE( SFCGAL_algorithm_MinkowskiTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_algorithm_MinkowskiTest) -BOOST_AUTO_TEST_CASE( testEmpty ) +BOOST_AUTO_TEST_CASE(testEmpty) { - std::unique_ptr< Geometry > gB( io::readWkt( "POLYGON((0 0,1 0,1 1,0 1,0 0))" ) ); + std::unique_ptr gB(io::readWkt("POLYGON((0 0,1 0,1 1,0 1,0 0))")); - tools::Registry& registry = tools::Registry::instance() ; - std::vector< std::string > typeNames = tools::Registry::instance().getGeometryTypes(); + tools::Registry const ®istry = tools::Registry::instance(); + std::vector const typeNames = + tools::Registry::instance().getGeometryTypes(); - for ( size_t i = 0; i < typeNames.size(); i++ ) { - std::unique_ptr< Geometry > g( registry.newGeometryByTypeName( typeNames[i] ) ) ; - BOOST_CHECK( algorithm::minkowskiSum( *g, gB->as< Polygon >() )->isEmpty() ); - } + for (const auto &typeName : typeNames) { + std::unique_ptr const g(registry.newGeometryByTypeName(typeName)); + BOOST_CHECK(algorithm::minkowskiSum(*g, gB->as())->isEmpty()); + } } -BOOST_AUTO_TEST_CASE( testEmptyPoint ) +BOOST_AUTO_TEST_CASE(testEmptyPoint) { - std::unique_ptr< Geometry > gA( io::readWkt( "MULTIPOINT EMPTY" ) ); - std::unique_ptr< Geometry > gB( io::readWkt( "POLYGON((0 0,1 0,1 1,0 1,0 0))" ) ); + std::unique_ptr const gA(io::readWkt("MULTIPOINT EMPTY")); + std::unique_ptr gB(io::readWkt("POLYGON((0 0,1 0,1 1,0 1,0 0))")); - std::unique_ptr< Geometry > sum( algorithm::minkowskiSum( *gA, gB->as< Polygon >() ) ); - BOOST_CHECK_EQUAL( sum->asText( 0 ), "MULTIPOLYGON EMPTY" ); + std::unique_ptr sum( + algorithm::minkowskiSum(*gA, gB->as())); + BOOST_CHECK_EQUAL(sum->asText(0), "MULTIPOLYGON EMPTY"); } -BOOST_AUTO_TEST_CASE( testPoint ) +BOOST_AUTO_TEST_CASE(testPoint) { - std::unique_ptr< Geometry > gA( io::readWkt( "POINT(0 0)" ) ); - std::unique_ptr< Geometry > gB( io::readWkt( "POLYGON((0 0,1 0,1 1,0 1,0 0))" ) ); + std::unique_ptr const gA(io::readWkt("POINT(0 0)")); + std::unique_ptr gB(io::readWkt("POLYGON((0 0,1 0,1 1,0 1,0 0))")); - std::unique_ptr< Geometry > sum( algorithm::minkowskiSum( *gA, gB->as< Polygon >() ) ); - BOOST_CHECK_EQUAL( sum->asText( 0 ), "MULTIPOLYGON(((0 0,1 0,1 1,0 1,0 0)))" ); + std::unique_ptr sum( + algorithm::minkowskiSum(*gA, gB->as())); + BOOST_CHECK_EQUAL(sum->asText(0), "MULTIPOLYGON(((0 0,1 0,1 1,0 1,0 0)))"); } -BOOST_AUTO_TEST_CASE( testLineString ) +BOOST_AUTO_TEST_CASE(testLineString) { - std::unique_ptr< Geometry > gA( io::readWkt( "LINESTRING(0 0,5 0)" ) ); - std::unique_ptr< Geometry > gB( io::readWkt( "POLYGON((-1 0,0 -1,1 0,0 1,-1 0))" ) ); - - std::unique_ptr< Geometry > sum( algorithm::minkowskiSum( *gA, gB->as< Polygon >() ) ); - BOOST_CHECK_EQUAL( sum->asText( 0 ), "MULTIPOLYGON(((5 1,0 1,-1 0,0 -1,5 -1,6 0,5 1)))" ); + std::unique_ptr const gA(io::readWkt("LINESTRING(0 0,5 0)")); + std::unique_ptr gB( + io::readWkt("POLYGON((-1 0,0 -1,1 0,0 1,-1 0))")); + + std::unique_ptr sum( + algorithm::minkowskiSum(*gA, gB->as())); + BOOST_CHECK_EQUAL(sum->asText(0), + "MULTIPOLYGON(((5 1,0 1,-1 0,0 -1,5 -1,6 0,5 1)))"); } /* * check that CGAL doesn't use the center of the polygon gB */ -BOOST_AUTO_TEST_CASE( testLineString2 ) +BOOST_AUTO_TEST_CASE(testLineString2) { - std::unique_ptr< Geometry > gA( io::readWkt( "LINESTRING(0 0,5 0)" ) ); - std::unique_ptr< Geometry > gB( io::readWkt( "POLYGON((0 0,1 -1,2 0,1 1,0 0))" ) ); + std::unique_ptr const gA(io::readWkt("LINESTRING(0 0,5 0)")); + std::unique_ptr gB(io::readWkt("POLYGON((0 0,1 -1,2 0,1 1,0 0))")); - std::unique_ptr< Geometry > sum( algorithm::minkowskiSum( *gA, gB->as< Polygon >() ) ); - BOOST_CHECK_EQUAL( sum->asText( 0 ), "MULTIPOLYGON(((6 1,1 1,0 0,1 -1,6 -1,7 0,6 1)))" ); + std::unique_ptr sum( + algorithm::minkowskiSum(*gA, gB->as())); + BOOST_CHECK_EQUAL(sum->asText(0), + "MULTIPOLYGON(((6 1,1 1,0 0,1 -1,6 -1,7 0,6 1)))"); } - - -BOOST_AUTO_TEST_CASE( testLineString3 ) +BOOST_AUTO_TEST_CASE(testLineString3) { - std::unique_ptr< Geometry > gA( io::readWkt( "LINESTRING(5 5,0 5,5 0,0 0)" ) ); - std::unique_ptr< Geometry > gB( io::readWkt( "POLYGON((-1 0,0 -1,1 0,0 1,-1 0))" ) ); - - std::unique_ptr< Geometry > sum( algorithm::minkowskiSum( *gA, gB->as< Polygon >() ) ); - BOOST_CHECK_EQUAL( sum->asText( 0 ), "MULTIPOLYGON(((5 1,2 4,5 4,6 5,5 6,0 6,-1 5,0 4,3 1,0 1,-1 0,0 -1,5 -1,6 0,5 1)))" ); + std::unique_ptr const gA( + io::readWkt("LINESTRING(5 5,0 5,5 0,0 0)")); + std::unique_ptr gB( + io::readWkt("POLYGON((-1 0,0 -1,1 0,0 1,-1 0))")); + + std::unique_ptr sum( + algorithm::minkowskiSum(*gA, gB->as())); + BOOST_CHECK_EQUAL(sum->asText(0), "MULTIPOLYGON(((5 1,2 4,5 4,6 5,5 6,0 6,-1 " + "5,0 4,3 1,0 1,-1 0,0 -1,5 -1,6 0,5 1)))"); } -BOOST_AUTO_TEST_CASE( testPolygonWithHole ) +BOOST_AUTO_TEST_CASE(testPolygonWithHole) { - std::string wkt = "POLYGON((11.966308 -10.211022,18.007885 1.872133,39.364158 2.434140,53.554839 -6.557975,43.438710 -22.856183,20.396416 -28.476254,5.643728 -25.525717,13.090323 -20.889158,32.479570 -21.310663,38.521147 -15.831093,46.248746 -9.087007,34.446595 -1.359409,22.784946 -14.988082,11.966308 -10.211022),(20.396416 -1.640412,15.900358 -7.260484,18.007885 -9.508513,22.644444 -9.368011,25.173477 -2.342921,20.396416 -1.640412),(41.050179 -0.797401,40.207168 -2.202419,47.934767 -6.557975,48.496774 -5.433961,41.050179 -0.797401))" ; - std::unique_ptr< Geometry > gA( io::readWkt( wkt ) ); - - std::unique_ptr< Geometry > gB( io::readWkt( "POLYGON((-1 0,0 -1,1 0,0 1,-1 0))" ) ); - - std::unique_ptr< Geometry > sum( algorithm::minkowskiSum( *gA, gB->as< Polygon >() ) ); - BOOST_CHECK_EQUAL( sum->asText( 6 ), "MULTIPOLYGON(((53.554839 -5.557975,39.364158 3.434140,18.007885 2.872133,17.007885 1.872133,10.966308 -10.211022,11.966308 -11.211022,22.784946 -15.988082,23.784946 -14.988082,34.539099 -2.419977,44.939408 -9.229702,38.521147 -14.831093,32.479570 -20.310663,13.090323 -19.889158,5.643728 -24.525717,4.643728 -25.525717,5.643728 -26.525717,20.396416 -29.476254,43.438710 -23.856183,44.438710 -22.856183,54.554839 -6.557975,53.554839 -5.557975),(23.881857 -3.152977,21.997385 -8.387619,18.068659 -8.506671,16.900358 -7.260484,20.575363 -2.666728,23.881857 -3.152977)))" ); - - // reverse orientation - gA->as< Polygon >().reverse() ; - sum = algorithm::minkowskiSum( *gA, gB->as< Polygon >() ) ; - BOOST_CHECK_EQUAL( sum->asText( 6 ), "MULTIPOLYGON(((53.554839 -5.557975,39.364158 3.434140,18.007885 2.872133,17.007885 1.872133,10.966308 -10.211022,11.966308 -11.211022,22.784946 -15.988082,23.784946 -14.988082,34.539099 -2.419977,44.939408 -9.229702,38.521147 -14.831093,32.479570 -20.310663,13.090323 -19.889158,5.643728 -24.525717,4.643728 -25.525717,5.643728 -26.525717,20.396416 -29.476254,43.438710 -23.856183,44.438710 -22.856183,54.554839 -6.557975,53.554839 -5.557975),(23.881857 -3.152977,21.997385 -8.387619,18.068659 -8.506671,16.900358 -7.260484,20.575363 -2.666728,23.881857 -3.152977)))" ); + std::string const wkt = + "POLYGON((11.966308 -10.211022,18.007885 1.872133,39.364158 " + "2.434140,53.554839 -6.557975,43.438710 -22.856183,20.396416 " + "-28.476254,5.643728 -25.525717,13.090323 -20.889158,32.479570 " + "-21.310663,38.521147 -15.831093,46.248746 -9.087007,34.446595 " + "-1.359409,22.784946 -14.988082,11.966308 -10.211022),(20.396416 " + "-1.640412,15.900358 -7.260484,18.007885 -9.508513,22.644444 " + "-9.368011,25.173477 -2.342921,20.396416 -1.640412),(41.050179 " + "-0.797401,40.207168 -2.202419,47.934767 -6.557975,48.496774 " + "-5.433961,41.050179 -0.797401))"; + std::unique_ptr gA(io::readWkt(wkt)); + + std::unique_ptr gB( + io::readWkt("POLYGON((-1 0,0 -1,1 0,0 1,-1 0))")); + + std::unique_ptr sum( + algorithm::minkowskiSum(*gA, gB->as())); + BOOST_CHECK_EQUAL( + sum->asText(6), + "MULTIPOLYGON(((53.554839 -5.557975,39.364158 3.434140,18.007885 " + "2.872133,17.007885 1.872133,10.966308 -10.211022,11.966308 " + "-11.211022,22.784946 -15.988082,23.784946 -14.988082,34.539099 " + "-2.419977,44.939408 -9.229702,38.521147 -14.831093,32.479570 " + "-20.310663,13.090323 -19.889158,5.643728 -24.525717,4.643728 " + "-25.525717,5.643728 -26.525717,20.396416 -29.476254,43.438710 " + "-23.856183,44.438710 -22.856183,54.554839 -6.557975,53.554839 " + "-5.557975),(23.881857 -3.152977,21.997385 -8.387619,18.068659 " + "-8.506671,16.900358 -7.260484,20.575363 -2.666728,23.881857 " + "-3.152977)))"); + + // reverse orientation + gA->as().reverse(); + sum = algorithm::minkowskiSum(*gA, gB->as()); + BOOST_CHECK_EQUAL( + sum->asText(6), + "MULTIPOLYGON(((53.554839 -5.557975,39.364158 3.434140,18.007885 " + "2.872133,17.007885 1.872133,10.966308 -10.211022,11.966308 " + "-11.211022,22.784946 -15.988082,23.784946 -14.988082,34.539099 " + "-2.419977,44.939408 -9.229702,38.521147 -14.831093,32.479570 " + "-20.310663,13.090323 -19.889158,5.643728 -24.525717,4.643728 " + "-25.525717,5.643728 -26.525717,20.396416 -29.476254,43.438710 " + "-23.856183,44.438710 -22.856183,54.554839 -6.557975,53.554839 " + "-5.557975),(23.881857 -3.152977,21.997385 -8.387619,18.068659 " + "-8.506671,16.900358 -7.260484,20.575363 -2.666728,23.881857 " + "-3.152977)))"); } -BOOST_AUTO_TEST_CASE( testMultiPoint ) +BOOST_AUTO_TEST_CASE(testMultiPoint) { - std::unique_ptr< Geometry > gA( io::readWkt( "MULTIPOINT(0 0,5 5)" ) ); - std::unique_ptr< Geometry > gB( io::readWkt( "POLYGON((-1 0,0 -1,1 0,0 1,-1 0))" ) ); - - std::unique_ptr< Geometry > sum( algorithm::minkowskiSum( *gA, gB->as< Polygon >() ) ); - BOOST_CHECK_EQUAL( sum->asText( 0 ), "MULTIPOLYGON(((0 1,-1 0,0 -1,1 0,0 1)),((5 6,4 5,5 4,6 5,5 6)))" ); + std::unique_ptr const gA(io::readWkt("MULTIPOINT(0 0,5 5)")); + std::unique_ptr gB( + io::readWkt("POLYGON((-1 0,0 -1,1 0,0 1,-1 0))")); + + std::unique_ptr sum( + algorithm::minkowskiSum(*gA, gB->as())); + BOOST_CHECK_EQUAL( + sum->asText(0), + "MULTIPOLYGON(((0 1,-1 0,0 -1,1 0,0 1)),((5 6,4 5,5 4,6 5,5 6)))"); } - - - - BOOST_AUTO_TEST_SUITE_END() - diff --git a/test/unit/SFCGAL/algorithm/NormalTest.cpp b/test/unit/SFCGAL/algorithm/NormalTest.cpp index b72f68e8..818d3d52 100644 --- a/test/unit/SFCGAL/algorithm/NormalTest.cpp +++ b/test/unit/SFCGAL/algorithm/NormalTest.cpp @@ -15,103 +15,108 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include +#include #include -#include #include -#include -#include -#include -#include -#include -#include -#include #include +#include #include #include -#include +#include +#include +#include +#include +#include +#include #include +#include -using namespace SFCGAL ; -using namespace boost::unit_test ; +using namespace SFCGAL; +using namespace boost::unit_test; -BOOST_AUTO_TEST_SUITE( SFCGAL_algorithm_NormalTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_algorithm_NormalTest) -BOOST_AUTO_TEST_CASE( testNormal1 ) +BOOST_AUTO_TEST_CASE(testNormal1) { - typedef CGAL::Vector_3< Kernel > Vector_3 ; - typedef CGAL::Point_3< Kernel > Point_3 ; + typedef CGAL::Vector_3 Vector_3; + typedef CGAL::Point_3 Point_3; - Point_3 a( 0.0, 0.0, 0.0 ); - Point_3 b( 1.0, 0.0, 0.0 ); - Point_3 c( 1.0, 1.0, 0.0 ); + Point_3 const a(0.0, 0.0, 0.0); + Point_3 const b(1.0, 0.0, 0.0); + Point_3 const c(1.0, 1.0, 0.0); - Vector_3 normal = algorithm::normal3D( a, b, c ); - BOOST_CHECK_EQUAL( normal.x(), 0.0 ); - BOOST_CHECK_EQUAL( normal.y(), 0.0 ); - BOOST_CHECK_EQUAL( normal.z(), 1.0 ); + Vector_3 const normal = algorithm::normal3D(a, b, c); + BOOST_CHECK_EQUAL(normal.x(), 0.0); + BOOST_CHECK_EQUAL(normal.y(), 0.0); + BOOST_CHECK_EQUAL(normal.z(), 1.0); } -BOOST_AUTO_TEST_CASE( testNormal2 ) +BOOST_AUTO_TEST_CASE(testNormal2) { - // a square ccw - std::unique_ptr gA( io::readWkt( "POLYGON((0 0,1 0,1 1,0 1,0 0))" ) ); - // a square cw oriented - std::unique_ptr gB( io::readWkt( "POLYGON((0 0,0 1,1 1,1 0,0 0))" ) ); - - // a pseudo-square ccw oriented, with a concave part - std::unique_ptr gC( io::readWkt( "POLYGON((0 0,0.5 0.5,1 0,1 1,0 1,0 0))" ) ); - - { - CGAL::Vector_3 normal = algorithm::normal3D( gA->as() ); - BOOST_CHECK_EQUAL( normal.x(), 0.0 ); - BOOST_CHECK_EQUAL( normal.y(), 0.0 ); - BOOST_CHECK_EQUAL( normal.z(), 2.0 ); - } - - { - CGAL::Vector_3 normal = algorithm::normal3D( gB->as() ); - BOOST_CHECK_EQUAL( normal.x(), 0.0 ); - BOOST_CHECK_EQUAL( normal.y(), 0.0 ); - BOOST_CHECK_EQUAL( normal.z(), -2.0 ); - } - - { - CGAL::Vector_3 normal = algorithm::normal3D( gC->as() ); - BOOST_CHECK_EQUAL( normal.x(), 0.0 ); - BOOST_CHECK_EQUAL( normal.y(), 0.0 ); - // ok, the normal is pointing up (z > 0) - BOOST_CHECK_EQUAL( normal.z(), 1.5 ); - } + // a square ccw + std::unique_ptr gA(io::readWkt("POLYGON((0 0,1 0,1 1,0 1,0 0))")); + // a square cw oriented + std::unique_ptr gB(io::readWkt("POLYGON((0 0,0 1,1 1,1 0,0 0))")); + + // a pseudo-square ccw oriented, with a concave part + std::unique_ptr gC( + io::readWkt("POLYGON((0 0,0.5 0.5,1 0,1 1,0 1,0 0))")); + + { + CGAL::Vector_3 const normal = + algorithm::normal3D(gA->as()); + BOOST_CHECK_EQUAL(normal.x(), 0.0); + BOOST_CHECK_EQUAL(normal.y(), 0.0); + BOOST_CHECK_EQUAL(normal.z(), 2.0); + } + + { + CGAL::Vector_3 const normal = + algorithm::normal3D(gB->as()); + BOOST_CHECK_EQUAL(normal.x(), 0.0); + BOOST_CHECK_EQUAL(normal.y(), 0.0); + BOOST_CHECK_EQUAL(normal.z(), -2.0); + } + + { + CGAL::Vector_3 const normal = + algorithm::normal3D(gC->as()); + BOOST_CHECK_EQUAL(normal.x(), 0.0); + BOOST_CHECK_EQUAL(normal.y(), 0.0); + // ok, the normal is pointing up (z > 0) + BOOST_CHECK_EQUAL(normal.z(), 1.5); + } } - -BOOST_AUTO_TEST_CASE( testNormal3 ) +BOOST_AUTO_TEST_CASE(testNormal3) { - std::unique_ptr gA( io::readWkt( "POLYGON((0 1 0,0 1 1,1 1 1,1 1 0,0 1 0))" ) ); - // exact - { - CGAL::Vector_3 normal = algorithm::normal3D( gA->as(), true ); - //std::cout << CGAL::exact(normal) << std::endl; - CGAL::Plane_3 plane( gA->as().exteriorRing().startPoint().toPoint_3(), normal ); - //std::cout << CGAL::exact(plane) << std::endl; - BOOST_CHECK( ! plane.is_degenerate() ); - } - // round - { - CGAL::Vector_3 normal = algorithm::normal3D( gA->as(), false ); - //std::cout << CGAL::exact(normal) << std::endl; - CGAL::Plane_3 plane( gA->as().exteriorRing().startPoint().toPoint_3(), normal ); - //std::cout << CGAL::exact(plane) << std::endl; - BOOST_CHECK( ! plane.is_degenerate() ); - } - + std::unique_ptr gA( + io::readWkt("POLYGON((0 1 0,0 1 1,1 1 1,1 1 0,0 1 0))")); + // exact + { + CGAL::Vector_3 const normal = + algorithm::normal3D(gA->as(), true); + // std::cout << CGAL::exact(normal) << std::endl; + CGAL::Plane_3 const plane( + gA->as().exteriorRing().startPoint().toPoint_3(), normal); + // std::cout << CGAL::exact(plane) << std::endl; + BOOST_CHECK(!plane.is_degenerate()); + } + // round + { + CGAL::Vector_3 const normal = + algorithm::normal3D(gA->as(), false); + // std::cout << CGAL::exact(normal) << std::endl; + CGAL::Plane_3 const plane( + gA->as().exteriorRing().startPoint().toPoint_3(), normal); + // std::cout << CGAL::exact(plane) << std::endl; + BOOST_CHECK(!plane.is_degenerate()); + } } - - BOOST_AUTO_TEST_SUITE_END() - diff --git a/test/unit/SFCGAL/algorithm/OffsetTest.cpp b/test/unit/SFCGAL/algorithm/OffsetTest.cpp index 538e5254..3f761d9a 100644 --- a/test/unit/SFCGAL/algorithm/OffsetTest.cpp +++ b/test/unit/SFCGAL/algorithm/OffsetTest.cpp @@ -47,19 +47,19 @@ BOOST_AUTO_TEST_SUITE(SFCGAL_algorithm_OffsetTest) BOOST_AUTO_TEST_CASE(testEmpty) { - tools::Registry ®istry = tools::Registry::instance(); - std::vector typeNames = + tools::Registry const ®istry = tools::Registry::instance(); + std::vector const typeNames = tools::Registry::instance().getGeometryTypes(); - for (auto &typeName : typeNames) { - std::unique_ptr g(registry.newGeometryByTypeName(typeName)); + for (const auto &typeName : typeNames) { + std::unique_ptr const g(registry.newGeometryByTypeName(typeName)); BOOST_CHECK(algorithm::offset(*g, 1.0)->isEmpty()); } } BOOST_AUTO_TEST_CASE(testSimple) { - std::unique_ptr gA( + std::unique_ptr const gA( io::readWkt("POLYGON((0 0,10 0,10 10,0 10,0 0))")); std::unique_ptr result(algorithm::offset(*gA, 1.0)); @@ -82,7 +82,7 @@ BOOST_AUTO_TEST_CASE(testSimple) BOOST_AUTO_TEST_CASE(testHoles) { - std::unique_ptr gA( + std::unique_ptr const gA( io::readWkt("POLYGON((13.652901 8.978070,13.921068 13.219992,20.454603 " "13.268750,18.967492 11.001516,16.432091 11.220926,15.091253 " "13.024961,14.481782 11.976670,14.676813 10.708970,15.798240 " @@ -191,8 +191,8 @@ BOOST_AUTO_TEST_CASE(testHoles) BOOST_AUTO_TEST_CASE(testPoint) { - std::unique_ptr gA(io::readWkt("POINT(1 1)")); - std::unique_ptr result(algorithm::offset(*gA, 1.0)); + std::unique_ptr const gA(io::readWkt("POINT(1 1)")); + std::unique_ptr result(algorithm::offset(*gA, 1.0)); BOOST_CHECK_EQUAL( result->asText(2), "MULTIPOLYGON(((2.00 1.00,1.75 1.66,1.50 1.87,1.25 1.97,1.00 2.00,0.75 " @@ -202,7 +202,7 @@ BOOST_AUTO_TEST_CASE(testPoint) BOOST_AUTO_TEST_CASE(testLineString) { - std::unique_ptr gA( + std::unique_ptr const gA( io::readWkt("LINESTRING(13.652901 8.978070,13.921068 13.219992,20.454603 " "13.268750,18.967492 11.001516,16.432091 11.220926,15.091253 " "13.024961,14.481782 11.976670,14.676813 10.708970,15.798240 " @@ -210,7 +210,7 @@ BOOST_AUTO_TEST_CASE(testLineString) "10.952758,17.431624 11.001516,18.162990 10.099498,18.138611 " "8.368599,14.774328 9.416890,14.530540 8.929313,13.945447 " "8.441735,13.652901 8.978070)")); - std::unique_ptr result(algorithm::offset(*gA, 0.5)); + std::unique_ptr const result(algorithm::offset(*gA, 0.5)); // BOOST_CHECK_EQUAL( result->asText(7), //"MULTIPOLYGON(((20.9546030 13.2687500,20.8916366 13.5116525,20.8286702 13.6005236,20.7657038 // 13.6601785,20.7027374 13.7028345,20.6397710 13.7331989,20.5768046 13.7535869,20.5138382 @@ -263,17 +263,17 @@ BOOST_AUTO_TEST_CASE(testLineString) BOOST_AUTO_TEST_CASE(testPolygonWithHoles) { - std::unique_ptr gA(io::readWkt( - "POLYGON((11.966308 -10.211022,18.007885 1.872133,39.364158 " - "2.434140,53.554839 -6.557975,43.438710 -22.856183,20.396416 " - "-28.476254,5.643728 -25.525717,13.090323 -20.889158,32.479570 " - "-21.310663,38.521147 -15.831093,46.248746 -9.087007,34.446595 " - "-1.359409,22.784946 -14.988082,11.966308 -10.211022),(20.396416 " - "-1.640412,15.900358 -7.260484,18.007885 -9.508513,22.644444 " - "-9.368011,25.173477 -2.342921,20.396416 -1.640412),(41.050179 " - "-0.797401,40.207168 -2.202419,47.934767 -6.557975,48.496774 " - "-5.433961,41.050179 -0.797401))")); - std::unique_ptr result(algorithm::offset(*gA, 0.5)); + std::unique_ptr const gA(io::readWkt( + "POLYGON((11.966308 -10.211022,18.007885 1.872133,39.364158 " + "2.434140,53.554839 -6.557975,43.438710 -22.856183,20.396416 " + "-28.476254,5.643728 -25.525717,13.090323 -20.889158,32.479570 " + "-21.310663,38.521147 -15.831093,46.248746 -9.087007,34.446595 " + "-1.359409,22.784946 -14.988082,11.966308 -10.211022),(20.396416 " + "-1.640412,15.900358 -7.260484,18.007885 -9.508513,22.644444 " + "-9.368011,25.173477 -2.342921,20.396416 -1.640412),(41.050179 " + "-0.797401,40.207168 -2.202419,47.934767 -6.557975,48.496774 " + "-5.433961,41.050179 -0.797401))")); + std::unique_ptr const result(algorithm::offset(*gA, 0.5)); // @todo works in Release, not in Debug... Something strange with holes? // BOOST_CHECK_EQUAL(result->asText(), @@ -433,11 +433,11 @@ BOOST_AUTO_TEST_CASE(testPolygonWithHoles) BOOST_AUTO_TEST_CASE(testMultiPoint) { - std::unique_ptr gA( + std::unique_ptr const gA( io::readWkt("MULTIPOINT(2 0,1 1,0 2,-1 1,-2 0,-1 -1,0 -2,1 -1)")); - std::unique_ptr result( + std::unique_ptr const result( io::readWkt(algorithm::offset(*gA, 1.0)->asText(7))); - std::unique_ptr expected(io::readWkt( + std::unique_ptr const expected(io::readWkt( "MULTIPOLYGON(((3.0000000 0.0000000,2.8750000 0.4841229,2.7500000 " "0.6614378,2.6250000 0.7806247,2.5000000 0.8660254,2.3750000 " "0.9270248,2.2500000 0.9682458,2.1250000 0.9921567,2.0000000 " @@ -483,10 +483,10 @@ BOOST_AUTO_TEST_CASE(testMultiPoint) BOOST_AUTO_TEST_CASE(testMultiLineString) { - std::unique_ptr gA( + std::unique_ptr const gA( io::readWkt("MULTILINESTRING((0.0 0.0,1.0 0.0),(2.0 2.0,3.0 2.0))")); - std::unique_ptr result{algorithm::offset(*gA, 1.0)}; - std::unique_ptr expected{io::readWkt( + std::unique_ptr result{algorithm::offset(*gA, 1.0)}; + std::unique_ptr const expected{io::readWkt( "MULTIPOLYGON(((2/1 0/1,15/8 4360591588697965/9007199254740992,7/4 " "2978851154656373/4503599627370496,13/8 " "3515621332314565/4503599627370496,3/2 " @@ -549,10 +549,10 @@ BOOST_AUTO_TEST_CASE(testMultiLineString) BOOST_AUTO_TEST_CASE(testMultiPolygon) { - std::unique_ptr gA( + std::unique_ptr const gA( io::readWkt("MULTIPOLYGON(((0 0,1 0,1 1,0 0)),((2 1,2 0,3 0,2 1)))")); - std::unique_ptr result{algorithm::offset(*gA, 1.0)}; - std::unique_ptr expected{io::readWkt( + std::unique_ptr result{algorithm::offset(*gA, 1.0)}; + std::unique_ptr const expected{io::readWkt( "MULTIPOLYGON(((-3184560061929027/4503599627370496 " "1592245805114451/2251799813685248,-6698880015218421/9007199254740992 " "1505295754916495/2251799813685248,-1757159976644697/2251799813685248 " @@ -626,11 +626,11 @@ BOOST_AUTO_TEST_CASE(testMultiPolygon) BOOST_AUTO_TEST_CASE(testGeometryCollection) { - std::unique_ptr gA( + std::unique_ptr const gA( io::readWkt("GEOMETRYCOLLECTION(POINT(0 0),LINESTRING(1 1,2 2))")); - std::unique_ptr result( + std::unique_ptr const result( io::readWkt(algorithm::offset(*gA, 1.0)->asText(2))); - std::unique_ptr expected(io::readWkt( + std::unique_ptr const expected(io::readWkt( "MULTIPOLYGON(((-0.00 1.00,-0.12 0.99,-0.25 0.97,-0.38 0.93,-0.50 " "0.87,-0.62 0.78,-0.75 0.66,-0.88 0.48,-1.00 0.00,-0.75 -0.66,-0.50 " "-0.87,-0.25 -0.97,0.00 -1.00,0.25 -0.97,0.50 -0.87,0.75 -0.66,1.00 " diff --git a/test/unit/SFCGAL/algorithm/OrientationTest.cpp b/test/unit/SFCGAL/algorithm/OrientationTest.cpp index ff7182d3..9e17b82c 100644 --- a/test/unit/SFCGAL/algorithm/OrientationTest.cpp +++ b/test/unit/SFCGAL/algorithm/OrientationTest.cpp @@ -15,173 +15,145 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include +#include #include -#include #include -#include -#include -#include -#include -#include -#include -#include #include +#include #include #include -#include +#include +#include +#include +#include +#include +#include #include +#include -using namespace SFCGAL ; +using namespace SFCGAL; // always after CGAL -using namespace boost::unit_test ; +using namespace boost::unit_test; -BOOST_AUTO_TEST_SUITE( SFCGAL_algorithm_OrientationTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_algorithm_OrientationTest) -//TODO COMPLETE TEST +// TODO COMPLETE TEST -//void makeValidOrientation( CGAL::Polygon_2< Kernel > & polygon ) ; -//void makeValidOrientation( CGAL::Polygon_with_holes_2< Kernel > & polygon ) ; -//void makeValidOrientation( Polygon & polygon ) ; +// void makeValidOrientation( CGAL::Polygon_2< Kernel > & polygon ) ; +// void makeValidOrientation( CGAL::Polygon_with_holes_2< Kernel > & polygon ) ; +// void makeValidOrientation( Polygon & polygon ) ; - -//bool hasConsistentOrientation3D( const TriangulatedSurface & g ) ; -BOOST_AUTO_TEST_CASE( testHasConsistentOrientation3D_basicTriangles ) +// bool hasConsistentOrientation3D( const TriangulatedSurface & g ) ; +BOOST_AUTO_TEST_CASE(testHasConsistentOrientation3D_basicTriangles) { - TriangulatedSurface triangulatedSurface; - BOOST_CHECK( algorithm::hasConsistentOrientation3D( triangulatedSurface ) ); - triangulatedSurface.addTriangle( - Triangle( - Point( 0.0,0.0,0.0 ), - Point( 1.0,0.0,0.0 ), - Point( 0.0,1.0,0.0 ) - ) - ); - BOOST_CHECK( algorithm::hasConsistentOrientation3D( triangulatedSurface ) ); - - triangulatedSurface.addTriangle( - Triangle( - Point( 0.0,0.0,0.0 ), - Point( 0.0,1.0,0.0 ), - Point( -1.0,0.0,0.0 ) - ) - ); - BOOST_CHECK( algorithm::hasConsistentOrientation3D( triangulatedSurface ) ); - - triangulatedSurface.addTriangle( - Triangle( - Point( 0.0, 0.0, 0.0 ), - Point( 1.0, 0.0, 0.0 ), - Point( 0.0,-1.0, 0.0 ) - ) - ); - BOOST_CHECK( ! algorithm::hasConsistentOrientation3D( triangulatedSurface ) ); + TriangulatedSurface triangulatedSurface; + BOOST_CHECK(algorithm::hasConsistentOrientation3D(triangulatedSurface)); + triangulatedSurface.addTriangle(Triangle( + Point(0.0, 0.0, 0.0), Point(1.0, 0.0, 0.0), Point(0.0, 1.0, 0.0))); + BOOST_CHECK(algorithm::hasConsistentOrientation3D(triangulatedSurface)); + + triangulatedSurface.addTriangle(Triangle( + Point(0.0, 0.0, 0.0), Point(0.0, 1.0, 0.0), Point(-1.0, 0.0, 0.0))); + BOOST_CHECK(algorithm::hasConsistentOrientation3D(triangulatedSurface)); + + triangulatedSurface.addTriangle(Triangle( + Point(0.0, 0.0, 0.0), Point(1.0, 0.0, 0.0), Point(0.0, -1.0, 0.0))); + BOOST_CHECK(!algorithm::hasConsistentOrientation3D(triangulatedSurface)); } +// bool hasConsistentOrientation3D( const PolyhedralSurface & g ) ; - -//bool hasConsistentOrientation3D( const PolyhedralSurface & g ) ; - -BOOST_AUTO_TEST_CASE( testHasConsistentOrientation3D_basicPolygons ) +BOOST_AUTO_TEST_CASE(testHasConsistentOrientation3D_basicPolygons) { - PolyhedralSurface polyhedralSurface ; - BOOST_CHECK( algorithm::hasConsistentOrientation3D( polyhedralSurface ) ); - - //base polygon - { - LineString ring ; - ring.addPoint( Point( 0.0,0.0,0.0 ) ); - ring.addPoint( Point( 1.0,0.0,0.0 ) ); - ring.addPoint( Point( 1.0,1.0,0.0 ) ); - ring.addPoint( Point( 0.0,1.0,0.0 ) ); - ring.addPoint( ring.startPoint() ) ; - - polyhedralSurface.addPolygon( Polygon( ring ) ); - } - BOOST_CHECK( algorithm::hasConsistentOrientation3D( polyhedralSurface ) ); - - //right polygon - { - LineString ring ; - ring.addPoint( Point( 1.0,0.0,0.0 ) ); - ring.addPoint( Point( 1.0,0.0,1.0 ) ); - ring.addPoint( Point( 1.0,1.0,1.0 ) ); - ring.addPoint( Point( 1.0,1.0,0.0 ) ); - ring.addPoint( ring.startPoint() ) ; - - polyhedralSurface.addPolygon( Polygon( ring ) ); - } - BOOST_CHECK( algorithm::hasConsistentOrientation3D( polyhedralSurface ) ); - - //left polygon (bad orientation) - { - LineString ring ; - ring.addPoint( Point( 0.0,0.0,0.0 ) ); - ring.addPoint( Point( 0.0,0.0,1.0 ) ); - ring.addPoint( Point( 0.0,1.0,1.0 ) ); - ring.addPoint( Point( 0.0,1.0,0.0 ) ); - ring.addPoint( ring.startPoint() ) ; - - polyhedralSurface.addPolygon( Polygon( ring ) ); - } - BOOST_CHECK( ! algorithm::hasConsistentOrientation3D( polyhedralSurface ) ); + PolyhedralSurface polyhedralSurface; + BOOST_CHECK(algorithm::hasConsistentOrientation3D(polyhedralSurface)); + + // base polygon + { + LineString ring; + ring.addPoint(Point(0.0, 0.0, 0.0)); + ring.addPoint(Point(1.0, 0.0, 0.0)); + ring.addPoint(Point(1.0, 1.0, 0.0)); + ring.addPoint(Point(0.0, 1.0, 0.0)); + ring.addPoint(ring.startPoint()); + + polyhedralSurface.addPolygon(Polygon(ring)); + } + BOOST_CHECK(algorithm::hasConsistentOrientation3D(polyhedralSurface)); + + // right polygon + { + LineString ring; + ring.addPoint(Point(1.0, 0.0, 0.0)); + ring.addPoint(Point(1.0, 0.0, 1.0)); + ring.addPoint(Point(1.0, 1.0, 1.0)); + ring.addPoint(Point(1.0, 1.0, 0.0)); + ring.addPoint(ring.startPoint()); + + polyhedralSurface.addPolygon(Polygon(ring)); + } + BOOST_CHECK(algorithm::hasConsistentOrientation3D(polyhedralSurface)); + + // left polygon (bad orientation) + { + LineString ring; + ring.addPoint(Point(0.0, 0.0, 0.0)); + ring.addPoint(Point(0.0, 0.0, 1.0)); + ring.addPoint(Point(0.0, 1.0, 1.0)); + ring.addPoint(Point(0.0, 1.0, 0.0)); + ring.addPoint(ring.startPoint()); + + polyhedralSurface.addPolygon(Polygon(ring)); + } + BOOST_CHECK(!algorithm::hasConsistentOrientation3D(polyhedralSurface)); } +// void makeConsistentOrientation3D( TriangulatedSurface & g ) ; - -//void makeConsistentOrientation3D( TriangulatedSurface & g ) ; - -//bool isCounterClockWiseOriented( const Polygon& ); -BOOST_AUTO_TEST_CASE( testIsCounterClockWiseOriented_Polygon ) +// bool isCounterClockWiseOriented( const Polygon& ); +BOOST_AUTO_TEST_CASE(testIsCounterClockWiseOriented_Polygon) { - LineString ring ; - ring.addPoint( Point( 0.0,0.0 ) ); - ring.addPoint( Point( 1.0,0.0 ) ); - ring.addPoint( Point( 1.0,1.0 ) ); - ring.addPoint( Point( 0.0,1.0 ) ); - ring.addPoint( ring.startPoint() ) ; - - Polygon polygon( ring ) ; - BOOST_CHECK( algorithm::isCounterClockWiseOriented( polygon ) ); - polygon.exteriorRing().reverse(); - BOOST_CHECK( ! algorithm::isCounterClockWiseOriented( polygon ) ); + LineString ring; + ring.addPoint(Point(0.0, 0.0)); + ring.addPoint(Point(1.0, 0.0)); + ring.addPoint(Point(1.0, 1.0)); + ring.addPoint(Point(0.0, 1.0)); + ring.addPoint(ring.startPoint()); + + Polygon polygon(ring); + BOOST_CHECK(algorithm::isCounterClockWiseOriented(polygon)); + polygon.exteriorRing().reverse(); + BOOST_CHECK(!algorithm::isCounterClockWiseOriented(polygon)); } -//bool isCounterClockWiseOriented( const Triangle& ); -BOOST_AUTO_TEST_CASE( testIsCounterClockWiseOriented_Triangle ) +// bool isCounterClockWiseOriented( const Triangle& ); +BOOST_AUTO_TEST_CASE(testIsCounterClockWiseOriented_Triangle) { - Triangle triangle( - Point( 0.0,0.0 ), - Point( 1.0,0.0 ), - Point( 1.0,1.0 ) - ); - BOOST_CHECK( algorithm::isCounterClockWiseOriented( triangle ) ); - triangle.reverse(); - BOOST_CHECK( ! algorithm::isCounterClockWiseOriented( triangle ) ); + Triangle triangle(Point(0.0, 0.0), Point(1.0, 0.0), Point(1.0, 1.0)); + BOOST_CHECK(algorithm::isCounterClockWiseOriented(triangle)); + triangle.reverse(); + BOOST_CHECK(!algorithm::isCounterClockWiseOriented(triangle)); } - -//bool isCounterClockWiseOriented( const LineString& ); -BOOST_AUTO_TEST_CASE( testIsCounterClockWiseOriented_LineString ) +// bool isCounterClockWiseOriented( const LineString& ); +BOOST_AUTO_TEST_CASE(testIsCounterClockWiseOriented_LineString) { - LineString ring ; - ring.addPoint( Point( 0.0,0.0 ) ) ; - ring.addPoint( Point( 1.0,0.0 ) ) ; - ring.addPoint( Point( 1.0,1.0 ) ) ; - ring.addPoint( Point( 0.0,1.0 ) ) ; - ring.addPoint( ring.startPoint() ) ; - - BOOST_CHECK( algorithm::isCounterClockWiseOriented( ring ) ); - ring.reverse(); - BOOST_CHECK( ! algorithm::isCounterClockWiseOriented( ring ) ); + LineString ring; + ring.addPoint(Point(0.0, 0.0)); + ring.addPoint(Point(1.0, 0.0)); + ring.addPoint(Point(1.0, 1.0)); + ring.addPoint(Point(0.0, 1.0)); + ring.addPoint(ring.startPoint()); + + BOOST_CHECK(algorithm::isCounterClockWiseOriented(ring)); + ring.reverse(); + BOOST_CHECK(!algorithm::isCounterClockWiseOriented(ring)); } - - - BOOST_AUTO_TEST_SUITE_END() - diff --git a/test/unit/SFCGAL/algorithm/Partition_2.cpp b/test/unit/SFCGAL/algorithm/Partition_2.cpp index e156d0b3..e3b1b2ac 100644 --- a/test/unit/SFCGAL/algorithm/Partition_2.cpp +++ b/test/unit/SFCGAL/algorithm/Partition_2.cpp @@ -24,23 +24,23 @@ BOOST_AUTO_TEST_CASE(testPartition2_NoPolygon) exteriorRing.addPoint(Point(1.0, 1.0)); exteriorRing.addPoint(Point(0.0, 2.0)); - std::unique_ptr result(algorithm::partition_2(exteriorRing, SFCGAL::algorithm::y_monotone)); + std::unique_ptr result( + algorithm::partition_2(exteriorRing, SFCGAL::algorithm::y_monotone)); BOOST_CHECK(result->isEmpty()); - std::string expectedWKT( - "GEOMETRYCOLLECTION EMPTY"); + std::string const expectedWKT("GEOMETRYCOLLECTION EMPTY"); BOOST_CHECK_EQUAL(result->asText(1), expectedWKT); } BOOST_AUTO_TEST_CASE(testPartition2_Empty) { - Polygon g; + Polygon const g; - std::unique_ptr result(algorithm::partition_2(g, SFCGAL::algorithm::y_monotone)); + std::unique_ptr result( + algorithm::partition_2(g, SFCGAL::algorithm::y_monotone)); BOOST_CHECK(result->isEmpty()); - std::string expectedWKT( - "GEOMETRYCOLLECTION EMPTY"); + std::string const expectedWKT("GEOMETRYCOLLECTION EMPTY"); BOOST_CHECK_EQUAL(result->asText(1), expectedWKT); } @@ -53,12 +53,13 @@ BOOST_AUTO_TEST_CASE(testPartition2_YMonotonePartition2) exteriorRing.addPoint(Point(1.0, 1.0)); exteriorRing.addPoint(Point(0.0, 2.0)); - Polygon g(exteriorRing); + Polygon const g(exteriorRing); - std::unique_ptr result(algorithm::partition_2(g, SFCGAL::algorithm::y_monotone)); + std::unique_ptr result( + algorithm::partition_2(g, SFCGAL::algorithm::y_monotone)); BOOST_CHECK(!result->isEmpty()); - std::string expectedWKT( + std::string const expectedWKT( "GEOMETRYCOLLECTION(POLYGON((0.0 0.0,2.0 0.0,2.0 2.0,1.0 1.0,0.0 0.0)))"); BOOST_CHECK_EQUAL(result->asText(1), expectedWKT); } @@ -82,12 +83,12 @@ BOOST_AUTO_TEST_CASE(testPartition2_YMonotonePartition2_gross) exteriorRing.addPoint(Point(441, 303)); exteriorRing.addPoint(Point(391, 374)); - Polygon g(exteriorRing); + Polygon const g(exteriorRing); std::unique_ptr result(algorithm::partition_2(g)); BOOST_CHECK(!result->isEmpty()); - std::string expectedWKT( + std::string const expectedWKT( "GEOMETRYCOLLECTION(POLYGON((134.0 390.0,68.0 186.0,154.0 259.0,134.0 " "390.0)),POLYGON((289.0 214.0,134.0 390.0,154.0 259.0,161.0 107.0,435.0 " "108.0,208.0 148.0,295.0 160.0,421.0 212.0,289.0 214.0)),POLYGON((391.0 " @@ -115,13 +116,22 @@ BOOST_AUTO_TEST_CASE(testPartition2_ApproxConvexPartition2_gross) exteriorRing.addPoint(Point(441, 303)); exteriorRing.addPoint(Point(391, 374)); - Polygon g(exteriorRing); + Polygon const g(exteriorRing); - std::unique_ptr result(algorithm::partition_2(g, SFCGAL::algorithm::approx_convex)); + std::unique_ptr result( + algorithm::partition_2(g, SFCGAL::algorithm::approx_convex)); BOOST_CHECK(!result->isEmpty()); - std::string expectedWKT( "GEOMETRYCOLLECTION(POLYGON((391.0 374.0,240.0 431.0,252.0 340.0,374.0 320.0,391.0 374.0)),POLYGON((134.0 390.0,68.0 186.0,154.0 259.0,134.0 390.0)),POLYGON((289.0 214.0,134.0 390.0,154.0 259.0,289.0 214.0)),POLYGON((161.0 107.0,435.0 108.0,208.0 148.0,161.0 107.0)),POLYGON((154.0 259.0,161.0 107.0,208.0 148.0,154.0 259.0)),POLYGON((289.0 214.0,154.0 259.0,208.0 148.0,295.0 160.0,289.0 214.0)),POLYGON((374.0 320.0,289.0 214.0,295.0 160.0,421.0 212.0,374.0 320.0)),POLYGON((391.0 374.0,374.0 320.0,421.0 212.0,441.0 303.0,391.0 374.0)))" - ); + std::string const expectedWKT( + "GEOMETRYCOLLECTION(POLYGON((391.0 374.0,240.0 431.0,252.0 340.0,374.0 " + "320.0,391.0 374.0)),POLYGON((134.0 390.0,68.0 186.0,154.0 259.0,134.0 " + "390.0)),POLYGON((289.0 214.0,134.0 390.0,154.0 259.0,289.0 " + "214.0)),POLYGON((161.0 107.0,435.0 108.0,208.0 148.0,161.0 " + "107.0)),POLYGON((154.0 259.0,161.0 107.0,208.0 148.0,154.0 " + "259.0)),POLYGON((289.0 214.0,154.0 259.0,208.0 148.0,295.0 160.0,289.0 " + "214.0)),POLYGON((374.0 320.0,289.0 214.0,295.0 160.0,421.0 212.0,374.0 " + "320.0)),POLYGON((391.0 374.0,374.0 320.0,421.0 212.0,441.0 303.0,391.0 " + "374.0)))"); BOOST_CHECK_EQUAL(result->asText(1), expectedWKT); } @@ -144,13 +154,22 @@ BOOST_AUTO_TEST_CASE(testPartition2_GreeneApproxConvexPartition2_gross) exteriorRing.addPoint(Point(441, 303)); exteriorRing.addPoint(Point(391, 374)); - Polygon g(exteriorRing); + Polygon const g(exteriorRing); - std::unique_ptr result(algorithm::partition_2(g, SFCGAL::algorithm::greene_approx_convex)); + std::unique_ptr result( + algorithm::partition_2(g, SFCGAL::algorithm::greene_approx_convex)); BOOST_CHECK(!result->isEmpty()); - std::string expectedWKT( "GEOMETRYCOLLECTION(POLYGON((134.0 390.0,68.0 186.0,154.0 259.0,134.0 390.0)),POLYGON((161.0 107.0,435.0 108.0,208.0 148.0,161.0 107.0)),POLYGON((208.0 148.0,295.0 160.0,421.0 212.0,289.0 214.0,208.0 148.0)),POLYGON((154.0 259.0,161.0 107.0,208.0 148.0,154.0 259.0)),POLYGON((289.0 214.0,134.0 390.0,154.0 259.0,208.0 148.0,289.0 214.0)),POLYGON((374.0 320.0,289.0 214.0,421.0 212.0,374.0 320.0)),POLYGON((374.0 320.0,421.0 212.0,441.0 303.0,391.0 374.0,374.0 320.0)),POLYGON((391.0 374.0,240.0 431.0,252.0 340.0,374.0 320.0,391.0 374.0)))" - ); + std::string const expectedWKT( + "GEOMETRYCOLLECTION(POLYGON((134.0 390.0,68.0 186.0,154.0 259.0,134.0 " + "390.0)),POLYGON((161.0 107.0,435.0 108.0,208.0 148.0,161.0 " + "107.0)),POLYGON((208.0 148.0,295.0 160.0,421.0 212.0,289.0 214.0,208.0 " + "148.0)),POLYGON((154.0 259.0,161.0 107.0,208.0 148.0,154.0 " + "259.0)),POLYGON((289.0 214.0,134.0 390.0,154.0 259.0,208.0 148.0,289.0 " + "214.0)),POLYGON((374.0 320.0,289.0 214.0,421.0 212.0,374.0 " + "320.0)),POLYGON((374.0 320.0,421.0 212.0,441.0 303.0,391.0 374.0,374.0 " + "320.0)),POLYGON((391.0 374.0,240.0 431.0,252.0 340.0,374.0 320.0,391.0 " + "374.0)))"); BOOST_CHECK_EQUAL(result->asText(1), expectedWKT); } @@ -173,13 +192,21 @@ BOOST_AUTO_TEST_CASE(testPartition2_OptimalConvexPartition2_gross) exteriorRing.addPoint(Point(441, 303)); exteriorRing.addPoint(Point(391, 374)); - Polygon g(exteriorRing); + Polygon const g(exteriorRing); - std::unique_ptr result(algorithm::partition_2(g, SFCGAL::algorithm::optimal_convex)); + std::unique_ptr result( + algorithm::partition_2(g, SFCGAL::algorithm::optimal_convex)); BOOST_CHECK(!result->isEmpty()); - std::string expectedWKT( "GEOMETRYCOLLECTION(POLYGON((391.0 374.0,240.0 431.0,252.0 340.0,374.0 320.0,391.0 374.0)),POLYGON((134.0 390.0,68.0 186.0,154.0 259.0,134.0 390.0)),POLYGON((161.0 107.0,435.0 108.0,208.0 148.0,161.0 107.0)),POLYGON((154.0 259.0,161.0 107.0,208.0 148.0,154.0 259.0)),POLYGON((289.0 214.0,134.0 390.0,154.0 259.0,208.0 148.0,295.0 160.0,289.0 214.0)),POLYGON((374.0 320.0,289.0 214.0,295.0 160.0,421.0 212.0,441.0 303.0,374.0 320.0)),POLYGON((391.0 374.0,374.0 320.0,441.0 303.0,391.0 374.0)))" - ); + std::string const expectedWKT( + "GEOMETRYCOLLECTION(POLYGON((391.0 374.0,240.0 431.0,252.0 340.0,374.0 " + "320.0,391.0 374.0)),POLYGON((134.0 390.0,68.0 186.0,154.0 259.0,134.0 " + "390.0)),POLYGON((161.0 107.0,435.0 108.0,208.0 148.0,161.0 " + "107.0)),POLYGON((154.0 259.0,161.0 107.0,208.0 148.0,154.0 " + "259.0)),POLYGON((289.0 214.0,134.0 390.0,154.0 259.0,208.0 148.0,295.0 " + "160.0,289.0 214.0)),POLYGON((374.0 320.0,289.0 214.0,295.0 160.0,421.0 " + "212.0,441.0 303.0,374.0 320.0)),POLYGON((391.0 374.0,374.0 320.0,441.0 " + "303.0,391.0 374.0)))"); BOOST_CHECK_EQUAL(result->asText(1), expectedWKT); } BOOST_AUTO_TEST_SUITE_END() diff --git a/test/unit/SFCGAL/algorithm/PlaneTest.cpp b/test/unit/SFCGAL/algorithm/PlaneTest.cpp index 8a4021a2..02202c3c 100644 --- a/test/unit/SFCGAL/algorithm/PlaneTest.cpp +++ b/test/unit/SFCGAL/algorithm/PlaneTest.cpp @@ -15,92 +15,103 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include +#include #include -#include #include -#include -#include -#include -#include -#include -#include -#include #include +#include #include #include -#include +#include +#include +#include +#include +#include +#include #include +#include -using namespace SFCGAL ; -using namespace boost::unit_test ; +using namespace SFCGAL; +using namespace boost::unit_test; -BOOST_AUTO_TEST_SUITE( SFCGAL_algorithm_PlaneTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_algorithm_PlaneTest) -BOOST_AUTO_TEST_CASE( testPlane1 ) +BOOST_AUTO_TEST_CASE(testPlane1) { - std::unique_ptr gA( io::readWkt( "POLYGON((0 0,1 0,1 1,0 1,0 0))" ) ); + std::unique_ptr gA(io::readWkt("POLYGON((0 0,1 0,1 1,0 1,0 0))")); - CGAL::Plane_3 plane = algorithm::plane3D( gA->as() ); - BOOST_CHECK_EQUAL( plane.a(), 0.0 ); - BOOST_CHECK_EQUAL( plane.b(), 0.0 ); - BOOST_CHECK_EQUAL( plane.c(), 2.0 ); + CGAL::Plane_3 const plane = + algorithm::plane3D(gA->as()); + BOOST_CHECK_EQUAL(plane.a(), 0.0); + BOOST_CHECK_EQUAL(plane.b(), 0.0); + BOOST_CHECK_EQUAL(plane.c(), 2.0); } -BOOST_AUTO_TEST_CASE( testPlane ) +BOOST_AUTO_TEST_CASE(testPlane) { - struct TestCase { - const std::string _wkt; - const bool _isPlane; - }; - const TestCase test[] = { - {"LINESTRING(1 2 3,4 5 6)", true}, // only two points - {"LINESTRING(1 2 3,1 2 3,1 2 3,1 2 3)", true}, // all points in the same place - {"LINESTRING(1 2 3,2 4 6,3 6 9,4 8 12)", true}, // all points aliged - {"LINESTRING(1 2 3,6 5 4,7 8 9)", true}, // triangle must be plane - {"LINESTRING(0 0 0,1 0 0,1 1 0,0 1 0,0 0 0)", true}, // all point in the plane z=0 - {"LINESTRING(2 1 0,2 0 0,2 1 0,2 1 0,2 0 3)", true}, // all points in the plane x=2 - {"LINESTRING(2 1 0,2 0 0,2 1 1,2 1 0,1 0 3)", false}, // one point out of plane - {"LINESTRING(0 0 0, 1e-5 0 0, 1e-5 1e-5 0, 0 1e-5 1e-5)", false}, // fix #247 - }; - const size_t numTest = sizeof( test ) / sizeof( TestCase ); - - for ( size_t t=0; t != numTest; ++t ) { - //std::cout << "test = " << t << "\n"; - std::unique_ptr g( io::readWkt( test[t]._wkt ) ); - const LineString* l = dynamic_cast( g.get() ); - BOOST_CHECK_MESSAGE( - algorithm::isPlane3D< Kernel >( *l, 1.e-9 ) == test[t]._isPlane, - ( boost::format( "LineString %d: %s %s" ) % t % test[t]._wkt % ( test[t]._isPlane ? "is plane" : "isn't plane" ) ) - ); - } + struct TestCase { + const std::string _wkt; + const bool _isPlane; + }; + const TestCase test[] = { + {"LINESTRING(1 2 3,4 5 6)", true}, // only two points + {"LINESTRING(1 2 3,1 2 3,1 2 3,1 2 3)", + true}, // all points in the same place + {"LINESTRING(1 2 3,2 4 6,3 6 9,4 8 12)", true}, // all points aliged + {"LINESTRING(1 2 3,6 5 4,7 8 9)", true}, // triangle must be plane + {"LINESTRING(0 0 0,1 0 0,1 1 0,0 1 0,0 0 0)", + true}, // all point in the plane z=0 + {"LINESTRING(2 1 0,2 0 0,2 1 0,2 1 0,2 0 3)", + true}, // all points in the plane x=2 + {"LINESTRING(2 1 0,2 0 0,2 1 1,2 1 0,1 0 3)", + false}, // one point out of plane + {"LINESTRING(0 0 0, 1e-5 0 0, 1e-5 1e-5 0, 0 1e-5 1e-5)", + false}, // fix #247 + }; + const size_t numTest = sizeof(test) / sizeof(TestCase); + + for (size_t t = 0; t != numTest; ++t) { + // std::cout << "test = " << t << "\n"; + std::unique_ptr const g(io::readWkt(test[t]._wkt)); + const LineString *l = dynamic_cast(g.get()); + BOOST_CHECK_MESSAGE( + algorithm::isPlane3D(*l, 1.e-9) == test[t]._isPlane, + (boost::format("LineString %d: %s %s") % t % test[t]._wkt % + (test[t]._isPlane ? "is plane" : "isn't plane"))); + } } -BOOST_AUTO_TEST_CASE( testPlane3DDivideByZeroCrash ) +BOOST_AUTO_TEST_CASE(testPlane3DDivideByZeroCrash) { - std::unique_ptr< Geometry > degenerate_polygon = io::readWkt("POLYGON((1 -1 -1,1 0.5 0.5,1 0.5 0.5,1 -1 -1))"); - BOOST_CHECK( degenerate_polygon->geometryTypeId() == TYPE_POLYGON ); - - // Should return degenerate plane without throwing - auto degenerate_plane = algorithm::plane3D< Kernel >( degenerate_polygon->as() ); - - // See triangulatePolygon3D for this pattern - if (algorithm::hasPlane3D< Kernel >(degenerate_polygon->as())) - { - // Should not get here, OR plane3D with Plane3DInexactUnsafe should not divide by zero - auto div_by_zero_check = algorithm::plane3D< Kernel >( degenerate_polygon->as(), algorithm::Plane3DInexactUnsafe() ); - } - - std::unique_ptr< Geometry > ok_polygon = io::readWkt("POLYGON((1 0.5 0.5,1.5 1.5 0.5,1.5 0.5 0.5,1 0.5 0.5))"); - BOOST_CHECK( ok_polygon->geometryTypeId() == TYPE_POLYGON ); - - BOOST_CHECK( algorithm::hasPlane3D< Kernel >(ok_polygon->as()) ); - - auto valid_plane = algorithm::plane3D< Kernel >( ok_polygon->as(), algorithm::Plane3DInexactUnsafe() ); + std::unique_ptr degenerate_polygon = + io::readWkt("POLYGON((1 -1 -1,1 0.5 0.5,1 0.5 0.5,1 -1 -1))"); + BOOST_CHECK(degenerate_polygon->geometryTypeId() == TYPE_POLYGON); + + // Should return degenerate plane without throwing + auto degenerate_plane = + algorithm::plane3D(degenerate_polygon->as()); + + // See triangulatePolygon3D for this pattern + if (algorithm::hasPlane3D(degenerate_polygon->as())) { + // Should not get here, OR plane3D with Plane3DInexactUnsafe should not + // divide by zero + auto div_by_zero_check = algorithm::plane3D( + degenerate_polygon->as(), algorithm::Plane3DInexactUnsafe()); + } + + std::unique_ptr ok_polygon = + io::readWkt("POLYGON((1 0.5 0.5,1.5 1.5 0.5,1.5 0.5 0.5,1 0.5 0.5))"); + BOOST_CHECK(ok_polygon->geometryTypeId() == TYPE_POLYGON); + + BOOST_CHECK(algorithm::hasPlane3D(ok_polygon->as())); + + auto valid_plane = algorithm::plane3D( + ok_polygon->as(), algorithm::Plane3DInexactUnsafe()); } - BOOST_AUTO_TEST_SUITE_END() diff --git a/test/unit/SFCGAL/algorithm/StraightSkeletonTest.cpp b/test/unit/SFCGAL/algorithm/StraightSkeletonTest.cpp index 6036a618..d2cac869 100644 --- a/test/unit/SFCGAL/algorithm/StraightSkeletonTest.cpp +++ b/test/unit/SFCGAL/algorithm/StraightSkeletonTest.cpp @@ -49,7 +49,7 @@ BOOST_AUTO_TEST_CASE(testTriangle) { std::unique_ptr g(io::readWkt("TRIANGLE((1 1,2 1,2 2,1 1))")); - std::string expectedWKT( + std::string const expectedWKT( "MULTILINESTRING((1.0 1.0,1.7 1.3),(2.0 1.0,1.7 1.3),(2.0 2.0,1.7 1.3))"); { std::unique_ptr result(algorithm::straightSkeleton(*g)); @@ -70,7 +70,7 @@ BOOST_AUTO_TEST_CASE(testPolygon) std::unique_ptr g( io::readWkt("POLYGON((1 1,11 1,11 11,1 11,1 1))")); - std::string expectedWKT( + std::string const expectedWKT( "MULTILINESTRING((1 1,6 6),(11 1,6 6),(11 11,6 6),(1 11,6 6))"); { std::unique_ptr result(algorithm::straightSkeleton(*g)); @@ -88,7 +88,7 @@ BOOST_AUTO_TEST_CASE(testPolygon) BOOST_AUTO_TEST_CASE(testPolygonWithHole) { - std::unique_ptr g( + std::unique_ptr const g( io::readWkt("POLYGON( (-1.0 -1.0,1.0 -1.0,1.0 1.0,-1.0 1.0,-1.0 -1.0)" ", (-0.5 -0.5,-0.5 0.5,0.5 0.5,-0.5 -0.5)" ")")); @@ -124,14 +124,14 @@ BOOST_AUTO_TEST_CASE(testPolygonWithHole) // To avoid rounding errors in the results (-3730904090310553/9007199254740992 // vs -466363011288819/1125899906842624), a text comparison is used. This is // not optimal. - std::unique_ptr r(io::readWkt(result->asText(10))); - std::unique_ptr e(io::readWkt(expected->asText(10))); + std::unique_ptr const r(io::readWkt(result->asText(10))); + std::unique_ptr const e(io::readWkt(expected->asText(10))); BOOST_CHECK(algorithm::covers(*r, *e)); } BOOST_AUTO_TEST_CASE(testPolygonWithHoleTouchingShell) { - std::unique_ptr g( + std::unique_ptr const g( io::readWkt("POLYGON((-1.0 -1.0,1.0 -1.0,1.0 1.0,-1.0 1.0,-1.0 " "-1.0),(-0.5 -0.5,-0.5 0.5,0.5 0.5,1.0 -0.5,-0.5 -0.5))")); BOOST_CHECK_THROW(algorithm::straightSkeleton(*g), NotImplementedException); @@ -139,7 +139,7 @@ BOOST_AUTO_TEST_CASE(testPolygonWithHoleTouchingShell) BOOST_AUTO_TEST_CASE(testPolygonWithTouchingHoles) { - std::unique_ptr g( + std::unique_ptr const g( io::readWkt("POLYGON((-1.0 -1.0,1.0 -1.0,1.0 1.0,-1.0 1.0,-1.0 " "-1.0),(-0.5 -0.5,-0.5 0.5,-0.1 0.5,0.1 -0.5,-0.5 -0.5),(0.1 " "-0.5,0.1 0.5,0.5 0.5,0.5 -0.5,0.1 -0.5))")); @@ -149,43 +149,43 @@ BOOST_AUTO_TEST_CASE(testPolygonWithTouchingHoles) BOOST_AUTO_TEST_CASE(testMultiPolygon) { - std::unique_ptr g(io::readWkt( + std::unique_ptr const g(io::readWkt( "MULTIPOLYGON(((3.000000 0.000000,2.875000 0.484123,2.750000 " - "0.661438,2.625000 0.780625,2.500000 0.866025,2.375000 0.927025,2.250000 " - "0.968246,2.125000 0.992157,2.000000 1.000000,1.875000 1.484123,1.750000 " - "1.661438,1.625000 1.780625,1.500000 1.866025,1.375000 1.927025,1.250000 " - "1.968246,1.125000 1.992157,1.000000 2.000000,0.750000 2.661438,0.500000 " - "2.866025,0.250000 2.968246,0.000000 3.000000,-0.250000 " - "2.968246,-0.500000 2.866025,-0.750000 2.661438,-1.000000 " - "2.000000,-1.125000 1.992157,-1.250000 1.968246,-1.375000 " - "1.927025,-1.500000 1.866025,-1.625000 1.780625,-1.750000 " - "1.661438,-1.875000 1.484123,-2.000000 1.000000,-2.125000 " - "0.992157,-2.250000 0.968246,-2.375000 0.927025,-2.500000 " - "0.866025,-2.625000 0.780625,-2.750000 0.661438,-2.875000 " - "0.484123,-3.000000 0.000000,-2.875000 -0.484123,-2.750000 " - "-0.661438,-2.625000 -0.780625,-2.500000 -0.866025,-2.375000 " - "-0.927025,-2.250000 -0.968246,-2.125000 -0.992157,-2.000000 " - "-1.000000,-1.875000 -1.484123,-1.750000 -1.661438,-1.625000 " - "-1.780625,-1.500000 -1.866025,-1.375000 -1.927025,-1.250000 " - "-1.968246,-1.125000 -1.992157,-1.000000 -2.000000,-0.750000 " - "-2.661438,-0.500000 -2.866025,-0.250000 -2.968246,0.000000 " - "-3.000000,0.250000 -2.968246,0.500000 -2.866025,0.750000 " - "-2.661438,1.000000 -2.000000,1.125000 -1.992157,1.250000 " - "-1.968246,1.375000 -1.927025,1.500000 -1.866025,1.625000 " - "-1.780625,1.750000 -1.661438,1.875000 -1.484123,2.000000 " - "-1.000000,2.125000 -0.992157,2.250000 -0.968246,2.375000 " - "-0.927025,2.500000 -0.866025,2.625000 -0.780625,2.750000 " - "-0.661438,2.875000 -0.484123,3.000000 0.000000),(0.000000 " - "1.000000,0.125000 0.515877,0.250000 0.338562,0.375000 0.219375,0.500000 " - "0.133975,0.625000 0.072975,0.750000 0.031754,0.875000 0.007843,1.000000 " - "0.000000,0.875000 -0.007843,0.750000 -0.031754,0.625000 " - "-0.072975,0.500000 -0.133975,0.375000 -0.219375,0.250000 " - "-0.338562,0.125000 -0.515877,0.000000 -1.000000,-0.125000 " - "-0.515877,-0.250000 -0.338562,-0.375000 -0.219375,-0.500000 " - "-0.133975,-0.625000 -0.072975,-0.750000 -0.031754,-0.875000 " - "-0.007843,-1.000000 0.000000,-0.875000 0.007843,-0.750000 " - "0.031754,-0.625000 0.072975,-0.500000 0.133975,-0.375000 " - "0.219375,-0.250000 0.338562,-0.125000 0.515877,0.000000 1.000000)))")); + "0.661438,2.625000 0.780625,2.500000 0.866025,2.375000 0.927025,2.250000 " + "0.968246,2.125000 0.992157,2.000000 1.000000,1.875000 1.484123,1.750000 " + "1.661438,1.625000 1.780625,1.500000 1.866025,1.375000 1.927025,1.250000 " + "1.968246,1.125000 1.992157,1.000000 2.000000,0.750000 2.661438,0.500000 " + "2.866025,0.250000 2.968246,0.000000 3.000000,-0.250000 " + "2.968246,-0.500000 2.866025,-0.750000 2.661438,-1.000000 " + "2.000000,-1.125000 1.992157,-1.250000 1.968246,-1.375000 " + "1.927025,-1.500000 1.866025,-1.625000 1.780625,-1.750000 " + "1.661438,-1.875000 1.484123,-2.000000 1.000000,-2.125000 " + "0.992157,-2.250000 0.968246,-2.375000 0.927025,-2.500000 " + "0.866025,-2.625000 0.780625,-2.750000 0.661438,-2.875000 " + "0.484123,-3.000000 0.000000,-2.875000 -0.484123,-2.750000 " + "-0.661438,-2.625000 -0.780625,-2.500000 -0.866025,-2.375000 " + "-0.927025,-2.250000 -0.968246,-2.125000 -0.992157,-2.000000 " + "-1.000000,-1.875000 -1.484123,-1.750000 -1.661438,-1.625000 " + "-1.780625,-1.500000 -1.866025,-1.375000 -1.927025,-1.250000 " + "-1.968246,-1.125000 -1.992157,-1.000000 -2.000000,-0.750000 " + "-2.661438,-0.500000 -2.866025,-0.250000 -2.968246,0.000000 " + "-3.000000,0.250000 -2.968246,0.500000 -2.866025,0.750000 " + "-2.661438,1.000000 -2.000000,1.125000 -1.992157,1.250000 " + "-1.968246,1.375000 -1.927025,1.500000 -1.866025,1.625000 " + "-1.780625,1.750000 -1.661438,1.875000 -1.484123,2.000000 " + "-1.000000,2.125000 -0.992157,2.250000 -0.968246,2.375000 " + "-0.927025,2.500000 -0.866025,2.625000 -0.780625,2.750000 " + "-0.661438,2.875000 -0.484123,3.000000 0.000000),(0.000000 " + "1.000000,0.125000 0.515877,0.250000 0.338562,0.375000 0.219375,0.500000 " + "0.133975,0.625000 0.072975,0.750000 0.031754,0.875000 0.007843,1.000000 " + "0.000000,0.875000 -0.007843,0.750000 -0.031754,0.625000 " + "-0.072975,0.500000 -0.133975,0.375000 -0.219375,0.250000 " + "-0.338562,0.125000 -0.515877,0.000000 -1.000000,-0.125000 " + "-0.515877,-0.250000 -0.338562,-0.375000 -0.219375,-0.500000 " + "-0.133975,-0.625000 -0.072975,-0.750000 -0.031754,-0.875000 " + "-0.007843,-1.000000 0.000000,-0.875000 0.007843,-0.750000 " + "0.031754,-0.625000 0.072975,-0.500000 0.133975,-0.375000 " + "0.219375,-0.250000 0.338562,-0.125000 0.515877,0.000000 1.000000)))")); std::unique_ptr result(algorithm::straightSkeleton(*g)); BOOST_CHECK_EQUAL(result->numGeometries(), 220U); } @@ -193,13 +193,11 @@ BOOST_AUTO_TEST_CASE(testMultiPolygon) BOOST_AUTO_TEST_CASE(testInvalidTypes) { std::vector wkt; - wkt.push_back("POINT(1 2)"); - wkt.push_back("LINESTRING(0 0,1 1)"); + wkt.emplace_back("POINT(1 2)"); + wkt.emplace_back("LINESTRING(0 0,1 1)"); - for (std::vector::const_iterator it = wkt.begin(), - itE = wkt.end(); - it != itE; ++it) { - std::unique_ptr g(io::readWkt(*it)); + for (auto &it : wkt) { + std::unique_ptr const g(io::readWkt(it)); std::unique_ptr result(algorithm::straightSkeleton(*g)); BOOST_CHECK_EQUAL(result->numGeometries(), 0U); } @@ -208,7 +206,7 @@ BOOST_AUTO_TEST_CASE(testInvalidTypes) // See https://github.com/Oslandia/SFCGAL/issues/75 BOOST_AUTO_TEST_CASE(testPostgisIssue3107) { - std::unique_ptr g(io::readWkt( + std::unique_ptr const g(io::readWkt( "POLYGON((1347259.25 7184745.94,1347273.17 7184758.16,1347280.39 " "7184749.95,1347278.04 7184747.88,1347281.66 7184743.76,1347284.01 " "7184745.83,1347293.5 7184735.05,1347279.61 7184722.85,1347269.29 " @@ -222,7 +220,7 @@ BOOST_AUTO_TEST_CASE(testPostgisIssue3107) // See https://github.com/Oslandia/SFCGAL/issues/91 BOOST_AUTO_TEST_CASE(testMultiPolygonWithTouchingHoles) { - std::unique_ptr g(io::readWkt( + std::unique_ptr const g(io::readWkt( "MULTIPOLYGON(((1347259.25 7184745.94,1347273.17 7184758.16,1347280.39 " "7184749.95,1347278.04 7184747.88,1347281.66 7184743.76,1347284.01 " "7184745.83,1347293.5 7184735.05,1347279.61 7184722.85,1347269.29 " @@ -235,28 +233,29 @@ BOOST_AUTO_TEST_CASE(testMultiPolygonWithTouchingHoles) BOOST_AUTO_TEST_CASE(testDistanceInM) { - std::unique_ptr g(io::readWkt("POLYGON((0 0,1 0,1 1,0 1,0 0))")); + std::unique_ptr const g( + io::readWkt("POLYGON((0 0,1 0,1 1,0 1,0 0))")); std::unique_ptr out(algorithm::straightSkeleton( *g, /* autoOrientation */ true, /* innerOnly */ false, /* outputDistanceInM */ true)); - std::string expectedWKT( + std::string const expectedWKT( "MULTILINESTRING M((0.0 0.0 0.0,0.5 0.5 0.5),(1.0 0.0 0.0,0.5 0.5 " - "0.5),(1.0 1.0 0.0,0.5 0.5 0.5),(0.0 1.0 0.0,0.5 0.5 0.5))"); + "0.5),(1.0 1.0 0.0,0.5 0.5 0.5),(0.0 1.0 0.0,0.5 0.5 0.5))"); BOOST_CHECK_EQUAL(out->asText(1), expectedWKT); } BOOST_AUTO_TEST_CASE(testMultiEmptyEmpty) { - std::unique_ptr g(io::readWkt("MULTIPOLYGON(EMPTY,EMPTY)")); - std::unique_ptr out(algorithm::straightSkeleton(*g)); - std::string expectedWKT("MULTILINESTRING EMPTY"); + std::unique_ptr const g(io::readWkt("MULTIPOLYGON(EMPTY,EMPTY)")); + std::unique_ptr out(algorithm::straightSkeleton(*g)); + std::string const expectedWKT("MULTILINESTRING EMPTY"); BOOST_CHECK_EQUAL(out->asText(1), expectedWKT); } // See https://gitlab.com/Oslandia/SFCGAL/-/issues/194 BOOST_AUTO_TEST_CASE(testDegenerateMultiLineString) { - std::unique_ptr g(io::readWkt( + std::unique_ptr const g(io::readWkt( "Polygon ((1294585.78643762995488942 200985.78643762698629871, 1294000 " "202400, 1294000 212400, 1294585.78643762995488942 " "213814.21356237301370129, 1296000 214400, 1297000 214400, " @@ -265,8 +264,9 @@ BOOST_AUTO_TEST_CASE(testDegenerateMultiLineString) "1297000 200400, 1296000 200400, 1294585.78643762995488942 " "200985.78643762698629871),(1297000 202400, 1297000 212400, 1296000 " "212400, 1296000 202400, 1297000 202400))")); - const double tolerance = 1e-8; - std::unique_ptr out(algorithm::straightSkeleton(*g, tolerance)); + const double tolerance = 1e-8; + std::unique_ptr out( + algorithm::straightSkeleton(*g, tolerance != 0.0)); for (size_t i = 0; i < out->numGeometries(); i++) { BOOST_CHECK(algorithm::length(out->geometryN(i)) > tolerance); } @@ -275,11 +275,11 @@ BOOST_AUTO_TEST_CASE(testDegenerateMultiLineString) BOOST_AUTO_TEST_CASE(testExtrudeStraightSkeleton) { - std::unique_ptr g( + std::unique_ptr const g( io::readWkt("POLYGON (( 0 0, 5 0, 5 5, 4 5, 4 4, 0 4, 0 0 ))")); std::unique_ptr out( algorithm::extrudeStraightSkeleton(*g, 2.0)); - std::string expectedWKT( + std::string const expectedWKT( "POLYHEDRALSURFACE Z(((4.00 5.00 0.00,5.00 5.00 0.00,4.00 4.00 0.00,4.00 " "5.00 0.00)),((0.00 4.00 0.00,4.00 4.00 0.00,0.00 0.00 0.00,0.00 4.00 " "0.00)),((4.00 4.00 0.00,5.00 0.00 0.00,0.00 0.00 0.00,4.00 4.00 " @@ -303,12 +303,12 @@ BOOST_AUTO_TEST_CASE(testExtrudeStraightSkeleton) BOOST_AUTO_TEST_CASE(testExtrudeStraightSkeletonPolygonWithHole) { - std::unique_ptr g( + std::unique_ptr const g( io::readWkt("POLYGON (( 0 0, 5 0, 5 5, 4 5, 4 4, 0 4, 0 0 ), (1 1, 1 2, " "2 2, 2 1, 1 1))")); std::unique_ptr out( algorithm::extrudeStraightSkeleton(*g, 2.0)); - std::string expectedWKT( + std::string const expectedWKT( "POLYHEDRALSURFACE Z(((4.00 5.00 0.00,5.00 5.00 0.00,4.00 4.00 0.00,4.00 " "5.00 0.00)),((2.00 1.00 0.00,5.00 0.00 0.00,0.00 0.00 0.00,2.00 1.00 " "0.00)),((5.00 5.00 0.00,5.00 0.00 0.00,4.00 4.00 0.00,5.00 5.00 " @@ -354,12 +354,12 @@ BOOST_AUTO_TEST_CASE(testExtrudeStraightSkeletonPolygonWithHole) BOOST_AUTO_TEST_CASE(testExtrudeStraightSkeletonGenerateBuilding) { - std::unique_ptr g( + std::unique_ptr const g( io::readWkt("POLYGON (( 0 0, 5 0, 5 5, 4 5, 4 4, 0 4, 0 0 ), (1 1, 1 2, " "2 2, 2 1, 1 1))")); std::unique_ptr out( algorithm::extrudeStraightSkeleton(*g, 9.0, 2.0)); - std::string expectedWKT( + std::string const expectedWKT( "POLYHEDRALSURFACE Z(((0.00 0.00 0.00,0.00 4.00 0.00,4.00 4.00 0.00,4.00 " "5.00 0.00,5.00 5.00 0.00,5.00 0.00 0.00,0.00 0.00 0.00),(1.00 1.00 " "0.00,2.00 1.00 0.00,2.00 2.00 0.00,1.00 2.00 0.00,1.00 1.00 " diff --git a/test/unit/SFCGAL/algorithm/TesselateTest.cpp b/test/unit/SFCGAL/algorithm/TesselateTest.cpp index dcc3cf83..5206e774 100644 --- a/test/unit/SFCGAL/algorithm/TesselateTest.cpp +++ b/test/unit/SFCGAL/algorithm/TesselateTest.cpp @@ -15,99 +15,102 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include -#include -#include -#include -#include -#include -#include -#include #include -#include +#include #include +#include #include #include -#include +#include +#include +#include +#include +#include +#include #include +#include #include -using namespace SFCGAL ; +using namespace SFCGAL; // always after CGAL -using namespace boost::unit_test ; - -BOOST_AUTO_TEST_SUITE( SFCGAL_algorithm_TesselateTest ) +using namespace boost::unit_test; +BOOST_AUTO_TEST_SUITE(SFCGAL_algorithm_TesselateTest) -BOOST_AUTO_TEST_CASE( testEmpty ) +BOOST_AUTO_TEST_CASE(testEmpty) { - tools::Registry& registry = tools::Registry::instance() ; + tools::Registry const ®istry = tools::Registry::instance(); - std::vector< std::string > geometryTypes = registry.getGeometryTypes() ; + std::vector const geometryTypes = registry.getGeometryTypes(); - for ( size_t i = 0; i < geometryTypes.size(); i++ ) { - std::unique_ptr< Geometry > g( registry.newGeometryByTypeName( geometryTypes[i] ) ) ; - BOOST_TEST_MESSAGE( boost::format( "tesselate(%s)" ) % g->asText() ); - std::unique_ptr< Geometry > result = algorithm::tesselate( *g ) ; - BOOST_CHECK( result->isEmpty() ); - } + for (const auto &geometryType : geometryTypes) { + std::unique_ptr g(registry.newGeometryByTypeName(geometryType)); + BOOST_TEST_MESSAGE(boost::format("tesselate(%s)") % g->asText()); + std::unique_ptr result = algorithm::tesselate(*g); + BOOST_CHECK(result->isEmpty()); + } } /* * test invariants (Point,LineString & co) */ -BOOST_AUTO_TEST_CASE( testPoint ) +BOOST_AUTO_TEST_CASE(testPoint) { - std::string wkt = "POINT(3.0 4.0)" ; - std::unique_ptr< Geometry > g( io::readWkt( wkt ) ); - BOOST_CHECK_EQUAL( algorithm::tesselate( *g )->asText( 1 ), wkt ); + std::string const wkt = "POINT(3.0 4.0)"; + std::unique_ptr const g(io::readWkt(wkt)); + BOOST_CHECK_EQUAL(algorithm::tesselate(*g)->asText(1), wkt); } -BOOST_AUTO_TEST_CASE( testLineString ) +BOOST_AUTO_TEST_CASE(testLineString) { - std::string wkt = "LINESTRING(0.0 0.0,1.0 1.0)" ; - std::unique_ptr< Geometry > g( io::readWkt( wkt ) ); - BOOST_CHECK_EQUAL( algorithm::tesselate( *g )->asText( 1 ), wkt ); + std::string const wkt = "LINESTRING(0.0 0.0,1.0 1.0)"; + std::unique_ptr const g(io::readWkt(wkt)); + BOOST_CHECK_EQUAL(algorithm::tesselate(*g)->asText(1), wkt); } -BOOST_AUTO_TEST_CASE( testMultiPoint ) +BOOST_AUTO_TEST_CASE(testMultiPoint) { - std::string wkt = "MULTIPOINT((3.0 4.0),(5.0 6.0))" ; - std::unique_ptr< Geometry > g( io::readWkt( wkt ) ); - BOOST_CHECK_EQUAL( algorithm::tesselate( *g )->asText( 1 ), wkt ); + std::string const wkt = "MULTIPOINT((3.0 4.0),(5.0 6.0))"; + std::unique_ptr const g(io::readWkt(wkt)); + BOOST_CHECK_EQUAL(algorithm::tesselate(*g)->asText(1), wkt); } -BOOST_AUTO_TEST_CASE( testMultiLineString ) +BOOST_AUTO_TEST_CASE(testMultiLineString) { - std::string wkt = "MULTILINESTRING((0.0 0.0,1.0 1.0),(1.0 1.0,2.0 2.0))" ; - std::unique_ptr< Geometry > g( io::readWkt( wkt ) ); - BOOST_CHECK_EQUAL( algorithm::tesselate( *g )->asText( 1 ), wkt ); + std::string const wkt = + "MULTILINESTRING((0.0 0.0,1.0 1.0),(1.0 1.0,2.0 2.0))"; + std::unique_ptr const g(io::readWkt(wkt)); + BOOST_CHECK_EQUAL(algorithm::tesselate(*g)->asText(1), wkt); } - /* * test with polygon, MultiPolygon & co */ -BOOST_AUTO_TEST_CASE( testPolygon ) +BOOST_AUTO_TEST_CASE(testPolygon) { - std::string wkt = "POLYGON((0.0 0.0,1.0 0.0,1.0 1.0,0.0 1.0,0.0 0.0))" ; - std::string wktOut = "TIN(((0.0 1.0,1.0 0.0,1.0 1.0,0.0 1.0)),((0.0 1.0,0.0 0.0,1.0 0.0,0.0 1.0)))" ; - std::unique_ptr< Geometry > g( io::readWkt( wkt ) ); - std::unique_ptr< Geometry > result( algorithm::tesselate( *g ) ); - BOOST_CHECK_EQUAL( result->asText( 1 ), wktOut ); + std::string const wkt = "POLYGON((0.0 0.0,1.0 0.0,1.0 1.0,0.0 1.0,0.0 0.0))"; + std::string const wktOut = "TIN(((0.0 1.0,1.0 0.0,1.0 1.0,0.0 1.0)),((0.0 " + "1.0,0.0 0.0,1.0 0.0,0.0 1.0)))"; + std::unique_ptr const g(io::readWkt(wkt)); + std::unique_ptr result(algorithm::tesselate(*g)); + BOOST_CHECK_EQUAL(result->asText(1), wktOut); } -BOOST_AUTO_TEST_CASE( testMultiPolygon ) +BOOST_AUTO_TEST_CASE(testMultiPolygon) { - std::string wkt = "MULTIPOLYGON(((0.0 0.0,1.0 0.0,1.0 1.0,0.0 1.0,0.0 0.0)),((2.0 0.0,3.0 0.0,3.0 1.0,2.0 1.0,2.0 0.0)))" ; - std::string wktOut = "GEOMETRYCOLLECTION(TIN(((0.0 1.0,1.0 0.0,1.0 1.0,0.0 1.0)),((0.0 1.0,0.0 0.0,1.0 0.0,0.0 1.0))),TIN(((2.0 1.0,3.0 0.0,3.0 1.0,2.0 1.0)),((2.0 1.0,2.0 0.0,3.0 0.0,2.0 1.0))))" ; - std::unique_ptr< Geometry > g( io::readWkt( wkt ) ); - std::unique_ptr< Geometry > result( algorithm::tesselate( *g ) ); - BOOST_CHECK_EQUAL( result->asText( 1 ), wktOut ); + std::string const wkt = "MULTIPOLYGON(((0.0 0.0,1.0 0.0,1.0 1.0,0.0 1.0,0.0 " + "0.0)),((2.0 0.0,3.0 0.0,3.0 1.0,2.0 1.0,2.0 0.0)))"; + std::string const wktOut = + "GEOMETRYCOLLECTION(TIN(((0.0 1.0,1.0 0.0,1.0 1.0,0.0 1.0)),((0.0 " + "1.0,0.0 0.0,1.0 0.0,0.0 1.0))),TIN(((2.0 1.0,3.0 0.0,3.0 1.0,2.0 " + "1.0)),((2.0 1.0,2.0 0.0,3.0 0.0,2.0 1.0))))"; + std::unique_ptr const g(io::readWkt(wkt)); + std::unique_ptr result(algorithm::tesselate(*g)); + BOOST_CHECK_EQUAL(result->asText(1), wktOut); } - BOOST_AUTO_TEST_SUITE_END() - diff --git a/test/unit/SFCGAL/algorithm/TranslateTest.cpp b/test/unit/SFCGAL/algorithm/TranslateTest.cpp index ba4e22c6..cb546bc0 100644 --- a/test/unit/SFCGAL/algorithm/TranslateTest.cpp +++ b/test/unit/SFCGAL/algorithm/TranslateTest.cpp @@ -15,51 +15,50 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include +#include #include -#include #include -#include -#include -#include -#include -#include -#include -#include #include +#include #include #include -#include +#include +#include +#include +#include +#include +#include #include +#include #include -using namespace boost::unit_test ; -using namespace SFCGAL ; - -BOOST_AUTO_TEST_SUITE( SFCGAL_algorithm_TranslateTest ) +using namespace boost::unit_test; +using namespace SFCGAL; +BOOST_AUTO_TEST_SUITE(SFCGAL_algorithm_TranslateTest) -BOOST_AUTO_TEST_CASE( testEmpty ) +BOOST_AUTO_TEST_CASE(testEmpty) { - tools::Registry& registry = tools::Registry::instance() ; - std::vector< std::string > typeNames = tools::Registry::instance().getGeometryTypes(); + tools::Registry const ®istry = tools::Registry::instance(); + std::vector const typeNames = + tools::Registry::instance().getGeometryTypes(); - for ( size_t i = 0; i < typeNames.size(); i++ ) { - BOOST_TEST_MESSAGE( typeNames[i] ) ; + for (const auto &typeName : typeNames) { + BOOST_TEST_MESSAGE(typeName); - std::unique_ptr< Geometry > g( registry.newGeometryByTypeName( typeNames[i] ) ) ; - BOOST_REQUIRE( g.get() != NULL ) ; - algorithm::translate( *g, 1.0, 1.0, 1.0 ); - BOOST_CHECK( g->isEmpty() ); - } + std::unique_ptr g(registry.newGeometryByTypeName(typeName)); + BOOST_REQUIRE(g.get() != NULL); + algorithm::translate(*g, 1.0, 1.0, 1.0); + BOOST_CHECK(g->isEmpty()); + } } -//TODO complete with 2D/3D test after having renamed translate to translate3D - +// TODO complete with 2D/3D test after having renamed translate to translate3D BOOST_AUTO_TEST_SUITE_END() - diff --git a/test/unit/SFCGAL/algorithm/UnionTest.cpp b/test/unit/SFCGAL/algorithm/UnionTest.cpp index 1d52d6b3..45ba9580 100644 --- a/test/unit/SFCGAL/algorithm/UnionTest.cpp +++ b/test/unit/SFCGAL/algorithm/UnionTest.cpp @@ -15,374 +15,411 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include +#include #include +#include +#include #include #include -#include -#include #include -#include #include -#include #include +#include #include -#define DEBUG_OUT if (0) std::cerr << __FILE__ << ":" << __LINE__ << " debug: " +#define DEBUG_OUT \ + if (0) \ + std::cerr << __FILE__ << ":" << __LINE__ << " debug: " using namespace SFCGAL; -using namespace boost::unit_test ; +using namespace boost::unit_test; -BOOST_AUTO_TEST_SUITE( SFCGAL_algorithm_UnionTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_algorithm_UnionTest) -BOOST_AUTO_TEST_CASE( Handle1 ) +BOOST_AUTO_TEST_CASE(Handle1) { - std::unique_ptr a = io::readWkt( "POINT(0 1)" ); - std::unique_ptr b = io::readWkt( "POINT(0 1)" ); - std::unique_ptr u = algorithm::union_( *a, *b ); - DEBUG_OUT << u->asText() <<"\n"; - BOOST_CHECK( *u == *io::readWkt( "POINT(0 1)" ) ); + std::unique_ptr const a = io::readWkt("POINT(0 1)"); + std::unique_ptr const b = io::readWkt("POINT(0 1)"); + std::unique_ptr u = algorithm::union_(*a, *b); + DEBUG_OUT << u->asText() << "\n"; + BOOST_CHECK(*u == *io::readWkt("POINT(0 1)")); } -BOOST_AUTO_TEST_CASE( Handle2 ) +BOOST_AUTO_TEST_CASE(Handle2) { - std::unique_ptr a = io::readWkt( "MULTIPOINT(0 1,0 1,0 1)" ); - std::unique_ptr b = io::readWkt( "POINT(0 1)" ); - std::unique_ptr u = algorithm::union_( *a, *b ); - DEBUG_OUT << u->asText() <<"\n"; - BOOST_CHECK( *u == *io::readWkt( "POINT(0 1)" ) ); + std::unique_ptr const a = io::readWkt("MULTIPOINT(0 1,0 1,0 1)"); + std::unique_ptr const b = io::readWkt("POINT(0 1)"); + std::unique_ptr u = algorithm::union_(*a, *b); + DEBUG_OUT << u->asText() << "\n"; + BOOST_CHECK(*u == *io::readWkt("POINT(0 1)")); } -BOOST_AUTO_TEST_CASE( PointPoint ) +BOOST_AUTO_TEST_CASE(PointPoint) { - { - std::unique_ptr a = io::readWkt( "POINT(0 1)" ); - std::unique_ptr b = io::readWkt( "POINT(0 1)" ); - std::unique_ptr u = algorithm::union_( *a, *b ); - DEBUG_OUT << u->asText() <<"\n"; - BOOST_CHECK( *u == *io::readWkt( "POINT(0 1)" ) ); - } - { - std::unique_ptr a = io::readWkt( "POINT(0 0)" ); - std::unique_ptr b = io::readWkt( "POINT(0 1)" ); - std::unique_ptr u = algorithm::union_( *a, *b ); - DEBUG_OUT << u->asText() <<"\n"; - BOOST_CHECK( *u == *io::readWkt( "MULTIPOINT(0 0,0 1)" ) ); - } - { - std::unique_ptr a = io::readWkt( "POINT(0 1 1)" ); - std::unique_ptr b = io::readWkt( "POINT(0 1 1)" ); - std::unique_ptr u = algorithm::union3D( *a, *b ); - DEBUG_OUT << u->asText() <<"\n"; - BOOST_CHECK( *u == *io::readWkt( "POINT(0 1 1)" ) ); - } - { - std::unique_ptr a = io::readWkt( "POINT(0 0 0)" ); - std::unique_ptr b = io::readWkt( "POINT(0 0 1)" ); - std::unique_ptr u = algorithm::union3D( *a, *b ); - DEBUG_OUT << u->asText() <<"\n"; - BOOST_CHECK( *u == *io::readWkt( "MULTIPOINT(0 0 0,0 0 1)" ) ); - } + { + std::unique_ptr const a = io::readWkt("POINT(0 1)"); + std::unique_ptr const b = io::readWkt("POINT(0 1)"); + std::unique_ptr u = algorithm::union_(*a, *b); + DEBUG_OUT << u->asText() << "\n"; + BOOST_CHECK(*u == *io::readWkt("POINT(0 1)")); + } + { + std::unique_ptr const a = io::readWkt("POINT(0 0)"); + std::unique_ptr const b = io::readWkt("POINT(0 1)"); + std::unique_ptr u = algorithm::union_(*a, *b); + DEBUG_OUT << u->asText() << "\n"; + BOOST_CHECK(*u == *io::readWkt("MULTIPOINT(0 0,0 1)")); + } + { + std::unique_ptr const a = io::readWkt("POINT(0 1 1)"); + std::unique_ptr const b = io::readWkt("POINT(0 1 1)"); + std::unique_ptr u = algorithm::union3D(*a, *b); + DEBUG_OUT << u->asText() << "\n"; + BOOST_CHECK(*u == *io::readWkt("POINT(0 1 1)")); + } + { + std::unique_ptr const a = io::readWkt("POINT(0 0 0)"); + std::unique_ptr const b = io::readWkt("POINT(0 0 1)"); + std::unique_ptr u = algorithm::union3D(*a, *b); + DEBUG_OUT << u->asText() << "\n"; + BOOST_CHECK(*u == *io::readWkt("MULTIPOINT(0 0 0,0 0 1)")); + } } -BOOST_AUTO_TEST_CASE( PointLine ) +BOOST_AUTO_TEST_CASE(PointLine) { - { - std::unique_ptr a = io::readWkt( "POINT(.5 0)" ); - std::unique_ptr b = io::readWkt( "LINESTRING(-1 0,1 0)" ); - std::unique_ptr u = algorithm::union_( *a, *b ); - DEBUG_OUT << u->asText() <<"\n"; - BOOST_CHECK( *u == *io::readWkt( "LINESTRING(-1 0,.5 0,1 0)" ) ); - } - { - std::unique_ptr a = io::readWkt( "POINT(0 0 .5)" ); - std::unique_ptr b = io::readWkt( "LINESTRING(0 0 -1,0 0 1)" ); - std::unique_ptr u = algorithm::union3D( *a, *b ); - DEBUG_OUT << u->asText() <<"\n"; - BOOST_CHECK( *u == *io::readWkt( "LINESTRING(0 0 -1,0 0 .5,0 0 1)" ) ); - } + { + std::unique_ptr const a = io::readWkt("POINT(.5 0)"); + std::unique_ptr const b = io::readWkt("LINESTRING(-1 0,1 0)"); + std::unique_ptr u = algorithm::union_(*a, *b); + DEBUG_OUT << u->asText() << "\n"; + BOOST_CHECK(*u == *io::readWkt("LINESTRING(-1 0,.5 0,1 0)")); + } + { + std::unique_ptr const a = io::readWkt("POINT(0 0 .5)"); + std::unique_ptr const b = io::readWkt("LINESTRING(0 0 -1,0 0 1)"); + std::unique_ptr u = algorithm::union3D(*a, *b); + DEBUG_OUT << u->asText() << "\n"; + BOOST_CHECK(*u == *io::readWkt("LINESTRING(0 0 -1,0 0 .5,0 0 1)")); + } } -BOOST_AUTO_TEST_CASE( LineLine ) +BOOST_AUTO_TEST_CASE(LineLine) { - { - std::unique_ptr a = io::readWkt( "LINESTRING(-1 0,1 0)" ); - std::unique_ptr b = io::readWkt( "LINESTRING(-1 1,1 1)" ); - std::unique_ptr u = algorithm::union_( *a, *b ); - DEBUG_OUT << u->asText() <<"\n"; - BOOST_CHECK( *u == *io::readWkt( "MULTILINESTRING((-1 0,1 0),(-1 1,1 1))" ) ); - } - { - std::unique_ptr a = io::readWkt( "LINESTRING(-1 0,1 0)" ); - std::unique_ptr b = io::readWkt( "LINESTRING(0 -1,0 1)" ); - std::unique_ptr u = algorithm::union_( *a, *b ); - DEBUG_OUT << u->asText() <<"\n"; - BOOST_CHECK( *u == *io::readWkt( "MULTILINESTRING((-1 0,0 0),(0 0,1 0),(0 -1,0 0),(0 0,0 1))" ) ); - } + { + std::unique_ptr const a = io::readWkt("LINESTRING(-1 0,1 0)"); + std::unique_ptr const b = io::readWkt("LINESTRING(-1 1,1 1)"); + std::unique_ptr u = algorithm::union_(*a, *b); + DEBUG_OUT << u->asText() << "\n"; + BOOST_CHECK(*u == *io::readWkt("MULTILINESTRING((-1 0,1 0),(-1 1,1 1))")); + } + { + std::unique_ptr const a = io::readWkt("LINESTRING(-1 0,1 0)"); + std::unique_ptr const b = io::readWkt("LINESTRING(0 -1,0 1)"); + std::unique_ptr u = algorithm::union_(*a, *b); + DEBUG_OUT << u->asText() << "\n"; + BOOST_CHECK( + *u == + *io::readWkt( + "MULTILINESTRING((-1 0,0 0),(0 0,1 0),(0 -1,0 0),(0 0,0 1))")); + } } -BOOST_AUTO_TEST_CASE( LineVolume ) +BOOST_AUTO_TEST_CASE(LineVolume) { - std::unique_ptr a = io::readWkt( "LINESTRING(-1 -1 -1,2 2 2)" ); - std::unique_ptr b = io::readWkt( - "SOLID((((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)),\ + std::unique_ptr const a = io::readWkt("LINESTRING(-1 -1 -1,2 2 2)"); + std::unique_ptr const b = + io::readWkt("SOLID((((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)),\ ((0 0 0, 0 0 1, 0 1 1, 0 1 0, 0 0 0)),\ ((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)),\ ((1 1 1, 0 1 1, 0 0 1, 1 0 1, 1 1 1)),\ ((1 1 1, 1 0 1, 1 0 0, 1 1 0, 1 1 1)),\ - ((1 1 1, 1 1 0, 0 1 0, 0 1 1, 1 1 1))))" ); - std::unique_ptr u = algorithm::union3D( *a, *b ); - BOOST_CHECK( u->geometryTypeId() == TYPE_GEOMETRYCOLLECTION ); - BOOST_CHECK( u->geometryN( 0 ).geometryTypeId() == TYPE_LINESTRING ); - BOOST_CHECK( u->geometryN( 1 ).geometryTypeId() == TYPE_LINESTRING ); - BOOST_CHECK( u->geometryN( 2 ).geometryTypeId() == TYPE_SOLID ); + ((1 1 1, 1 1 0, 0 1 0, 0 1 1, 1 1 1))))"); + std::unique_ptr u = algorithm::union3D(*a, *b); + BOOST_CHECK(u->geometryTypeId() == TYPE_GEOMETRYCOLLECTION); + BOOST_CHECK(u->geometryN(0).geometryTypeId() == TYPE_LINESTRING); + BOOST_CHECK(u->geometryN(1).geometryTypeId() == TYPE_LINESTRING); + BOOST_CHECK(u->geometryN(2).geometryTypeId() == TYPE_SOLID); } -BOOST_AUTO_TEST_CASE( PointSurface ) +BOOST_AUTO_TEST_CASE(PointSurface) { - { - std::unique_ptr a = io::readWkt( "TRIANGLE((0 0,0 1,1 0,0 0))" ); - std::unique_ptr b = io::readWkt( "POINT(.1 .1)" ); - std::unique_ptr u = algorithm::union_( *a, *b ); - DEBUG_OUT << u->asText() <<"\n"; - BOOST_CHECK( *u == *io::readWkt( "TRIANGLE((0 0,0 1,1 0,0 0))" ) ); - } - { - std::unique_ptr a = io::readWkt( "TRIANGLE((0 0 1,0 1 1,1 0 1,0 0 1))" ); - std::unique_ptr b = io::readWkt( "POINT(.1 .1 1)" ); - std::unique_ptr u = algorithm::union3D( *a, *b ); - DEBUG_OUT << u->asText() <<"\n"; - BOOST_CHECK( *u == *io::readWkt( "TRIANGLE((0 0 1,0 1 1,1 0 1,0 0 1))" ) ); - } + { + std::unique_ptr const a = + io::readWkt("TRIANGLE((0 0,0 1,1 0,0 0))"); + std::unique_ptr const b = io::readWkt("POINT(.1 .1)"); + std::unique_ptr u = algorithm::union_(*a, *b); + DEBUG_OUT << u->asText() << "\n"; + BOOST_CHECK(*u == *io::readWkt("TRIANGLE((0 0,0 1,1 0,0 0))")); + } + { + std::unique_ptr const a = + io::readWkt("TRIANGLE((0 0 1,0 1 1,1 0 1,0 0 1))"); + std::unique_ptr const b = io::readWkt("POINT(.1 .1 1)"); + std::unique_ptr u = algorithm::union3D(*a, *b); + DEBUG_OUT << u->asText() << "\n"; + BOOST_CHECK(*u == *io::readWkt("TRIANGLE((0 0 1,0 1 1,1 0 1,0 0 1))")); + } } -BOOST_AUTO_TEST_CASE( PointVolume ) +BOOST_AUTO_TEST_CASE(PointVolume) { - std::unique_ptr a = io::readWkt( - "SOLID((((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)),\ + std::unique_ptr const a = + io::readWkt("SOLID((((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)),\ ((0 0 0, 0 0 1, 0 1 1, 0 1 0, 0 0 0)),\ ((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)),\ ((1 1 1, 0 1 1, 0 0 1, 1 0 1, 1 1 1)),\ ((1 1 1, 1 0 1, 1 0 0, 1 1 0, 1 1 1)),\ - ((1 1 1, 1 1 0, 0 1 0, 0 1 1, 1 1 1))))" ); - { - std::unique_ptr b = io::readWkt( "POINT(.1 .1 1)" ); - std::unique_ptr u = algorithm::union3D( *a, *b ); - BOOST_CHECK( u->geometryTypeId() == TYPE_SOLID ); - } - { - std::unique_ptr b = io::readWkt( "POINT(-.1 .1 1)" ); - std::unique_ptr u = algorithm::union3D( *a, *b ); - BOOST_CHECK( u->geometryTypeId() == TYPE_GEOMETRYCOLLECTION ); - } + ((1 1 1, 1 1 0, 0 1 0, 0 1 1, 1 1 1))))"); + { + std::unique_ptr const b = io::readWkt("POINT(.1 .1 1)"); + std::unique_ptr u = algorithm::union3D(*a, *b); + BOOST_CHECK(u->geometryTypeId() == TYPE_SOLID); + } + { + std::unique_ptr const b = io::readWkt("POINT(-.1 .1 1)"); + std::unique_ptr u = algorithm::union3D(*a, *b); + BOOST_CHECK(u->geometryTypeId() == TYPE_GEOMETRYCOLLECTION); + } } -BOOST_AUTO_TEST_CASE( TriangleTriangle ) +BOOST_AUTO_TEST_CASE(TriangleTriangle) { - { - std::unique_ptr a = io::readWkt( "TRIANGLE((0 0,1 0,0 1,0 0))" ); - std::unique_ptr b = io::readWkt( "TRIANGLE((0 0,1 0,0 1,0 0))" ); - std::unique_ptr u = algorithm::union_( *a, *b ); - DEBUG_OUT << u->asText() <<"\n"; - BOOST_CHECK( *u == *io::readWkt( "TRIANGLE((0 0,0 1,1 0,0 0))" ) ); - } + { + std::unique_ptr const a = + io::readWkt("TRIANGLE((0 0,1 0,0 1,0 0))"); + std::unique_ptr const b = + io::readWkt("TRIANGLE((0 0,1 0,0 1,0 0))"); + std::unique_ptr u = algorithm::union_(*a, *b); + DEBUG_OUT << u->asText() << "\n"; + BOOST_CHECK(*u == *io::readWkt("TRIANGLE((0 0,0 1,1 0,0 0))")); + } } -BOOST_AUTO_TEST_CASE( PolygonPolygon1 ) +BOOST_AUTO_TEST_CASE(PolygonPolygon1) { - { - std::unique_ptr a = io::readWkt( "POLYGON((-1 -1,1 -1,1 1,-1 1,-1 -1))" ); - std::unique_ptr b = io::readWkt( "POLYGON((-1 -1,1 -1,1 1,-1 1,-1 -1),(-0.5 -0.5,-0.5 0.5,0.5 0.5,0.5 -0.5,-0.5 -0.5))" ); - std::unique_ptr u = algorithm::union_( *a, *b ); - BOOST_CHECK( *u == *io::readWkt( "POLYGON((-1 -1,1 -1,1 1,-1 1,-1 -1))" ) ); - } - - { - std::unique_ptr a = io::readWkt( "POLYGON((0 0,1 0,1 1,0 1,0 0))" ); - std::unique_ptr b = io::readWkt( "POLYGON((1 0,2 0,2 1,1 1,1 0))" ); - std::unique_ptr u = algorithm::union_( *a, *b ); - DEBUG_OUT << u->asText() <<"\n"; - BOOST_CHECK( *u == *io::readWkt( "POLYGON((0 0,1 0,2 0,2 1,1 1,0 1,0 0))" ) ); - } + { + std::unique_ptr const a = + io::readWkt("POLYGON((-1 -1,1 -1,1 1,-1 1,-1 -1))"); + std::unique_ptr const b = + io::readWkt("POLYGON((-1 -1,1 -1,1 1,-1 1,-1 -1),(-0.5 -0.5,-0.5 " + "0.5,0.5 0.5,0.5 -0.5,-0.5 -0.5))"); + std::unique_ptr const u = algorithm::union_(*a, *b); + BOOST_CHECK(*u == *io::readWkt("POLYGON((-1 -1,1 -1,1 1,-1 1,-1 -1))")); + } + + { + std::unique_ptr const a = + io::readWkt("POLYGON((0 0,1 0,1 1,0 1,0 0))"); + std::unique_ptr const b = + io::readWkt("POLYGON((1 0,2 0,2 1,1 1,1 0))"); + std::unique_ptr u = algorithm::union_(*a, *b); + DEBUG_OUT << u->asText() << "\n"; + BOOST_CHECK(*u == *io::readWkt("POLYGON((0 0,1 0,2 0,2 1,1 1,0 1,0 0))")); + } } -BOOST_AUTO_TEST_CASE( PolygonPolygon2 ) +BOOST_AUTO_TEST_CASE(PolygonPolygon2) { - { - std::unique_ptr base = io::readWkt( "POLYGON((0 0,1 0,1 1,0 1,0 0))" ); - Polygon a( base->as() ); - algorithm::translate( a, .75, 0, 0 ); //disjoined - GeometryCollection b; - b.addGeometry( base->as() ); - b.addGeometry( base->as() ); - algorithm::translate( b.geometryN( 1 ), 1.5, 0, 0 ); - - std::unique_ptr u = algorithm::union_( a, b ); - DEBUG_OUT << u->asText() << "\n"; - DEBUG_OUT << "area " << algorithm::area3D( *u ) <<"\n"; - BOOST_CHECK( u->geometryTypeId() == TYPE_POLYGON ); - BOOST_CHECK( algorithm::area3D( *u ) == 2.5 ); - - u = algorithm::union3D( a, b ); - DEBUG_OUT << u->asText() <<"\n"; - DEBUG_OUT << "area " << algorithm::area3D( *u ) <<"\n"; - BOOST_CHECK( u->geometryTypeId() == TYPE_TRIANGULATEDSURFACE ); - BOOST_CHECK( algorithm::area3D( *u ) == 2.5 ); - } + { + std::unique_ptr base = + io::readWkt("POLYGON((0 0,1 0,1 1,0 1,0 0))"); + Polygon a(base->as()); + algorithm::translate(a, .75, 0, 0); // disjoined + GeometryCollection b; + b.addGeometry(base->as()); + b.addGeometry(base->as()); + algorithm::translate(b.geometryN(1), 1.5, 0, 0); + + std::unique_ptr u = algorithm::union_(a, b); + DEBUG_OUT << u->asText() << "\n"; + DEBUG_OUT << "area " << algorithm::area3D(*u) << "\n"; + BOOST_CHECK(u->geometryTypeId() == TYPE_POLYGON); + BOOST_CHECK(algorithm::area3D(*u) == 2.5); + + u = algorithm::union3D(a, b); + DEBUG_OUT << u->asText() << "\n"; + DEBUG_OUT << "area " << algorithm::area3D(*u) << "\n"; + BOOST_CHECK(u->geometryTypeId() == TYPE_TRIANGULATEDSURFACE); + BOOST_CHECK(algorithm::area3D(*u) == 2.5); + } } -BOOST_AUTO_TEST_CASE( PolygonPolygon3 ) +BOOST_AUTO_TEST_CASE(PolygonPolygon3) { - std::unique_ptr base = io::readWkt( "POLYGON((0 0,1 0,1 1,0 1,0 0))" ); - GeometryCollection a; - GeometryCollection b; - - for ( unsigned i = 0; i<4; ++i ) { - for ( unsigned j = 0; j<4; ++j ) { - Polygon p( base->as() ); - algorithm::translate( p, std::pow( i, 1.3 ), std::pow( j, 1.3 ), 0 ); - a.addGeometry( p ); - algorithm::translate( p, .5, .5, 0 ); - b.addGeometry( p ); - } + std::unique_ptr base = + io::readWkt("POLYGON((0 0,1 0,1 1,0 1,0 0))"); + GeometryCollection a; + GeometryCollection b; + + for (unsigned i = 0; i < 4; ++i) { + for (unsigned j = 0; j < 4; ++j) { + Polygon p(base->as()); + algorithm::translate(p, std::pow(i, 1.3), std::pow(j, 1.3), 0); + a.addGeometry(p); + algorithm::translate(p, .5, .5, 0); + b.addGeometry(p); } - - std::unique_ptr u = algorithm::union_( a, b ); - DEBUG_OUT << "surface " << algorithm::area( *u ) << "\n"; - BOOST_CHECK( std::abs( algorithm::area( *u ) - 25.56 ) < .01 ); - //TriangulatedSurface ts; - //triangulate::triangulatePolygon3D( *u, ts ); - //io::vtk( ts, "out.vtk" ); - u = algorithm::union3D( a, b ); - BOOST_CHECK( std::abs( algorithm::area3D( *u ) - 25.56 ) < .01 ); - //io::vtk( *u, "out.vtk" ); + } + + std::unique_ptr u = algorithm::union_(a, b); + DEBUG_OUT << "surface " << algorithm::area(*u) << "\n"; + BOOST_CHECK(std::abs(algorithm::area(*u) - 25.56) < .01); + // TriangulatedSurface ts; + // triangulate::triangulatePolygon3D( *u, ts ); + // io::vtk( ts, "out.vtk" ); + u = algorithm::union3D(a, b); + BOOST_CHECK(std::abs(algorithm::area3D(*u) - 25.56) < .01); + // io::vtk( *u, "out.vtk" ); } -BOOST_AUTO_TEST_CASE( GardenFailures1 ) +BOOST_AUTO_TEST_CASE(GardenFailures1) { - // cgal precondition violation - { - std::unique_ptr a = io::readWkt( "POLYGON((0 0,10 0,10 0,10 10,0 10,0 0),(2 2,2 5,5 5,5 2,2 2))" ); - std::unique_ptr b = io::readWkt( "TRIANGLE((-1 -1,1 -1,-1 1,-1 -1))" ); - std::unique_ptr u = algorithm::union_( *a, *b ); - DEBUG_OUT << u->asText() <<"\n"; - BOOST_CHECK( algorithm::area( *a ) + algorithm::area( *b ) == algorithm::area( *u ) ); - } + // cgal precondition violation + { + std::unique_ptr const a = io::readWkt( + "POLYGON((0 0,10 0,10 0,10 10,0 10,0 0),(2 2,2 5,5 5,5 2,2 2))"); + std::unique_ptr const b = + io::readWkt("TRIANGLE((-1 -1,1 -1,-1 1,-1 -1))"); + std::unique_ptr u = algorithm::union_(*a, *b); + DEBUG_OUT << u->asText() << "\n"; + BOOST_CHECK(algorithm::area(*a) + algorithm::area(*b) == + algorithm::area(*u)); + } } -BOOST_AUTO_TEST_CASE( GardenFailures2 ) +BOOST_AUTO_TEST_CASE(GardenFailures2) { - // cgal assertion - { - std::unique_ptr a = io::readWkt( "POLYGON((-1 -1,1 -1,1 1,-1 1,-1 -1),(-.5 -.5,-.5 .5,.5 .5,.5 -.5,-.5 -.5))" ); - std::unique_ptr b = io::readWkt( "POLYGON((-1 -1,1 -1,1 1,-1 1,-1 -1),(-.5 -.5,-.5 .5,.5 .5,.5 -.5,-.5 -.5))" ); - std::unique_ptr u = algorithm::union3D( *a, *b ); - DEBUG_OUT << u->asText() <<"\n"; - } + // cgal assertion + { + std::unique_ptr const a = + io::readWkt("POLYGON((-1 -1,1 -1,1 1,-1 1,-1 -1),(-.5 -.5,-.5 .5,.5 " + ".5,.5 -.5,-.5 -.5))"); + std::unique_ptr const b = + io::readWkt("POLYGON((-1 -1,1 -1,1 1,-1 1,-1 -1),(-.5 -.5,-.5 .5,.5 " + ".5,.5 -.5,-.5 -.5))"); + std::unique_ptr u = algorithm::union3D(*a, *b); + DEBUG_OUT << u->asText() << "\n"; + } } -BOOST_AUTO_TEST_CASE( GardenFailures3 ) +BOOST_AUTO_TEST_CASE(GardenFailures3) { - // crash (valgrind err) with invalidated iterator after push_back - { - std::unique_ptr a = io::readWkt( "LINESTRING(-1 -1,1 1)" ); - std::unique_ptr b = io::readWkt( "MULTILINESTRING((1/1 -1/1 -1/1,1/1 1/1 1/1),(1/1 1/1 1/1,1/1 1/1 -1/1))" ); - std::unique_ptr u = algorithm::union3D( *a, *b ); - DEBUG_OUT << u->asText() <<"\n"; - } + // crash (valgrind err) with invalidated iterator after push_back + { + std::unique_ptr const a = io::readWkt("LINESTRING(-1 -1,1 1)"); + std::unique_ptr const b = + io::readWkt("MULTILINESTRING((1/1 -1/1 -1/1,1/1 1/1 1/1),(1/1 1/1 " + "1/1,1/1 1/1 -1/1))"); + std::unique_ptr u = algorithm::union3D(*a, *b); + DEBUG_OUT << u->asText() << "\n"; + } } -BOOST_AUTO_TEST_CASE( GardenFailures4 ) +BOOST_AUTO_TEST_CASE(GardenFailures4) { - // infinite loop - { - std::unique_ptr a = io::readWkt( "POLYGON((-1 -1,1 -1,1 1,-1 1,-1 -1))" ); - std::unique_ptr b = io::readWkt( "POLYGON((0 0,10 0,10 0,10 10,0 10,0 0))" ); - std::unique_ptr u = algorithm::union3D( *a, *b ); - DEBUG_OUT << u->asText() <<"\n"; - } + // infinite loop + { + std::unique_ptr const a = + io::readWkt("POLYGON((-1 -1,1 -1,1 1,-1 1,-1 -1))"); + std::unique_ptr const b = + io::readWkt("POLYGON((0 0,10 0,10 0,10 10,0 10,0 0))"); + std::unique_ptr u = algorithm::union3D(*a, *b); + DEBUG_OUT << u->asText() << "\n"; + } } -BOOST_AUTO_TEST_CASE( GardenFailures5 ) +BOOST_AUTO_TEST_CASE(GardenFailures5) { - // infinite loop - { - std::unique_ptr a = io::readWkt( "MULTIPOLYGON(((-3 -1,-1 -1,-1 1,-3 1,-3 -1)),((1 -1,3 -1,3 1,1 1,1 -1)))" ); - std::unique_ptr b = io::readWkt( "MULTIPOLYGON(((-3 -1,-1 -1,-1 1,-3 1,-3 -1)),((1 -1,3 -1,3 1,1 1,1 -1)))" ); - std::unique_ptr u = algorithm::union_( *a, *b ); - DEBUG_OUT << u->asText() <<"\n"; - } + // infinite loop + { + std::unique_ptr const a = + io::readWkt("MULTIPOLYGON(((-3 -1,-1 -1,-1 1,-3 1,-3 -1)),((1 -1,3 " + "-1,3 1,1 1,1 -1)))"); + std::unique_ptr const b = + io::readWkt("MULTIPOLYGON(((-3 -1,-1 -1,-1 1,-3 1,-3 -1)),((1 -1,3 " + "-1,3 1,1 1,1 -1)))"); + std::unique_ptr u = algorithm::union_(*a, *b); + DEBUG_OUT << u->asText() << "\n"; + } } -BOOST_AUTO_TEST_CASE( GardenFailures6 ) +BOOST_AUTO_TEST_CASE(GardenFailures6) { - // segfault - { - std::unique_ptr a = io::readWkt( "POLYGON((-1 -1,1 -1,1 1,-1 1,-1 -1))" ); - std::unique_ptr b = io::readWkt( "POLYGON((-1 -1,1 -1,1 1,-1 1,-1 -1),(-0.5 -0.5,-0.5 0.5,0.5 0.5,0.5 -0.5,-0.5 -0.5))" ); - std::unique_ptr u = algorithm::union3D( *a, *b ); - DEBUG_OUT << u->asText() <<"\n"; - } + // segfault + { + std::unique_ptr const a = + io::readWkt("POLYGON((-1 -1,1 -1,1 1,-1 1,-1 -1))"); + std::unique_ptr const b = + io::readWkt("POLYGON((-1 -1,1 -1,1 1,-1 1,-1 -1),(-0.5 -0.5,-0.5 " + "0.5,0.5 0.5,0.5 -0.5,-0.5 -0.5))"); + std::unique_ptr u = algorithm::union3D(*a, *b); + DEBUG_OUT << u->asText() << "\n"; + } } -BOOST_AUTO_TEST_CASE( GardenFailures7 ) +BOOST_AUTO_TEST_CASE(GardenFailures7) { - std::unique_ptr a = io::readWkt( "LINESTRING(-1 -1,1 1)" ); - std::unique_ptr b = io::readWkt( "POLYGON((-1 -1,1 -1,1 1,-1 1,-1 -1),(-.5 -.5,-.5 .5,.5 .5,1 -.5,-.5 -.5))" ); - std::unique_ptr u = algorithm::union3D( *a, *b ); - DEBUG_OUT << u->asText() <<"\n"; + std::unique_ptr const a = io::readWkt("LINESTRING(-1 -1,1 1)"); + std::unique_ptr const b = + io::readWkt("POLYGON((-1 -1,1 -1,1 1,-1 1,-1 -1),(-.5 -.5,-.5 .5,.5 .5,1 " + "-.5,-.5 -.5))"); + std::unique_ptr u = algorithm::union3D(*a, *b); + DEBUG_OUT << u->asText() << "\n"; } -BOOST_AUTO_TEST_CASE( VolumeVolume ) +BOOST_AUTO_TEST_CASE(VolumeVolume) { - std::unique_ptr a = io::readWkt( - "SOLID((((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)),\ + std::unique_ptr a = + io::readWkt("SOLID((((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)),\ ((0 0 0, 0 0 1, 0 1 1, 0 1 0, 0 0 0)),\ ((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)),\ ((1 1 1, 0 1 1, 0 0 1, 1 0 1, 1 1 1)),\ ((1 1 1, 1 0 1, 1 0 0, 1 1 0, 1 1 1)),\ - ((1 1 1, 1 1 0, 0 1 0, 0 1 1, 1 1 1))))" ); - { - Solid b = a->as(); - algorithm::translate( b, 2, 0, 0 ); //disjoined - std::unique_ptr u = algorithm::union3D( *a, b ); - BOOST_CHECK( u->geometryTypeId() == TYPE_MULTISOLID ); - BOOST_CHECK( algorithm::volume( *u ) == 2 ); - } - { - Solid b = a->as(); - algorithm::translate( b, .5, 0, 0 ); - std::unique_ptr u = algorithm::union3D( *a, b ); - BOOST_CHECK( u->geometryTypeId() == TYPE_SOLID ); - BOOST_CHECK( algorithm::volume( *u ) == 1.5 ); - } - { - Solid b = a->as(); - algorithm::translate( b, 1, 0, 0 ); - std::unique_ptr u = algorithm::union3D( *a, b ); - BOOST_CHECK( u->geometryTypeId() == TYPE_SOLID ); - BOOST_CHECK( algorithm::volume( *u ) == 2 ); - } - - { - Solid b = a->as(); - algorithm::translate( b, 1, 1, 0 ); - std::unique_ptr u = algorithm::union3D( *a, b ); - BOOST_CHECK( u->geometryTypeId() == TYPE_MULTISOLID ); - BOOST_CHECK( algorithm::volume( *u ) == 2 ); - } - - { - Solid b = a->as(); - algorithm::translate( b, 1, 1, 1 ); // share a corner - std::unique_ptr u = algorithm::union3D( *a, b ); - BOOST_CHECK( u->geometryTypeId() == TYPE_MULTISOLID ); - BOOST_CHECK( algorithm::volume( *u ) == 2 ); - } + ((1 1 1, 1 1 0, 0 1 0, 0 1 1, 1 1 1))))"); + { + Solid b = a->as(); + algorithm::translate(b, 2, 0, 0); // disjoined + std::unique_ptr u = algorithm::union3D(*a, b); + BOOST_CHECK(u->geometryTypeId() == TYPE_MULTISOLID); + BOOST_CHECK(algorithm::volume(*u) == 2); + } + { + Solid b = a->as(); + algorithm::translate(b, .5, 0, 0); + std::unique_ptr u = algorithm::union3D(*a, b); + BOOST_CHECK(u->geometryTypeId() == TYPE_SOLID); + BOOST_CHECK(algorithm::volume(*u) == 1.5); + } + { + Solid b = a->as(); + algorithm::translate(b, 1, 0, 0); + std::unique_ptr u = algorithm::union3D(*a, b); + BOOST_CHECK(u->geometryTypeId() == TYPE_SOLID); + BOOST_CHECK(algorithm::volume(*u) == 2); + } + + { + Solid b = a->as(); + algorithm::translate(b, 1, 1, 0); + std::unique_ptr u = algorithm::union3D(*a, b); + BOOST_CHECK(u->geometryTypeId() == TYPE_MULTISOLID); + BOOST_CHECK(algorithm::volume(*u) == 2); + } + + { + Solid b = a->as(); + algorithm::translate(b, 1, 1, 1); // share a corner + std::unique_ptr u = algorithm::union3D(*a, b); + BOOST_CHECK(u->geometryTypeId() == TYPE_MULTISOLID); + BOOST_CHECK(algorithm::volume(*u) == 2); + } } BOOST_AUTO_TEST_SUITE_END() diff --git a/test/unit/SFCGAL/algorithm/Visibility.cpp b/test/unit/SFCGAL/algorithm/Visibility.cpp index aaf0df7d..1ad078c7 100644 --- a/test/unit/SFCGAL/algorithm/Visibility.cpp +++ b/test/unit/SFCGAL/algorithm/Visibility.cpp @@ -39,21 +39,21 @@ BOOST_AUTO_TEST_SUITE(SFCGAL_algorithm_VisibilityTest) BOOST_AUTO_TEST_CASE(testVisibility_PointInPolygon) { std::vector points; - points.push_back(Point(0.0, 4.0)); - points.push_back(Point(0.0, 0.0)); - points.push_back(Point(3.0, 2.0)); - points.push_back(Point(4.0, 0.0)); - points.push_back(Point(4.0, 4.0)); - points.push_back(Point(1.0, 2.0)); - points.push_back(Point(0.0, 4.0)); + points.emplace_back(0.0, 4.0); + points.emplace_back(0.0, 0.0); + points.emplace_back(3.0, 2.0); + points.emplace_back(4.0, 0.0); + points.emplace_back(4.0, 4.0); + points.emplace_back(1.0, 2.0); + points.emplace_back(0.0, 4.0); - LineString lineString(points); - Polygon poly(lineString); + LineString const lineString(points); + Polygon const poly(lineString); - Point queryPoint(0.5, 2.0); + Point const queryPoint(0.5, 2.0); std::unique_ptr result(algorithm::visibility(poly, queryPoint)); - std::string expectedWkt = + std::string const expectedWkt = "POLYGON((3.0 2.0,1.0 2.0,0.0 4.0,0.0 0.0,3.0 2.0))"; BOOST_CHECK_EQUAL(result->asText(1), expectedWkt); } @@ -105,31 +105,32 @@ BOOST_AUTO_TEST_CASE(testVisibility_PointVertexOnPolygon) BOOST_AUTO_TEST_CASE(testVisibility_PointInPolygonHole) { std::vector points; - points.push_back(Point(0.0, 4.0)); - points.push_back(Point(0.0, 0.0)); - points.push_back(Point(3.0, 2.0)); - points.push_back(Point(4.0, 0.0)); - points.push_back(Point(4.0, 4.0)); - points.push_back(Point(1.0, 2.0)); - points.push_back(Point(0.0, 4.0)); + points.emplace_back(0.0, 4.0); + points.emplace_back(0.0, 0.0); + points.emplace_back(3.0, 2.0); + points.emplace_back(4.0, 0.0); + points.emplace_back(4.0, 4.0); + points.emplace_back(1.0, 2.0); + points.emplace_back(0.0, 4.0); std::vector points_hole; - points_hole.push_back(Point(0.2, 1.75)); - points_hole.push_back(Point(0.9, 1.8)); - points_hole.push_back(Point(0.7, 1.2)); - points_hole.push_back(Point(0.2, 1.75)); + points_hole.emplace_back(0.2, 1.75); + points_hole.emplace_back(0.9, 1.8); + points_hole.emplace_back(0.7, 1.2); + points_hole.emplace_back(0.2, 1.75); - LineString lineString(points); - LineString hole(points_hole); + LineString const lineString(points); + LineString const hole(points_hole); Polygon poly(lineString); poly.addInteriorRing(hole); - Point queryPoint(0.5, 2.0); + Point const queryPoint(0.5, 2.0); std::unique_ptr result(algorithm::visibility(poly, queryPoint)); - std::string expectedWkt = "POLYGON((0.0 1.6,0.2 1.8,0.9 1.8,1.9 1.3,3.0 " - "2.0,1.0 2.0,0.0 4.0,0.0 1.6))"; + std::string const expectedWkt = + "POLYGON((0.0 1.6,0.2 1.8,0.9 1.8,1.9 1.3,3.0 " + "2.0,1.0 2.0,0.0 4.0,0.0 1.6))"; BOOST_CHECK_EQUAL(result->asText(1), expectedWkt); } @@ -259,23 +260,23 @@ BOOST_AUTO_TEST_CASE(testVisibility_PointVertexOnHolePolygonHole) BOOST_AUTO_TEST_CASE(testVisibility_SegmentInPolygon) { std::vector points; - points.push_back(Point(0.0, 4.0)); - points.push_back(Point(0.0, 0.0)); - points.push_back(Point(3.0, 2.0)); - points.push_back(Point(4.0, 0.0)); - points.push_back(Point(4.0, 4.0)); - points.push_back(Point(1.0, 2.0)); - points.push_back(Point(0.0, 4.0)); + points.emplace_back(0.0, 4.0); + points.emplace_back(0.0, 0.0); + points.emplace_back(3.0, 2.0); + points.emplace_back(4.0, 0.0); + points.emplace_back(4.0, 4.0); + points.emplace_back(1.0, 2.0); + points.emplace_back(0.0, 4.0); - LineString lineString(points); - Polygon poly(lineString); + LineString const lineString(points); + Polygon const poly(lineString); - Point startPoint(1.0, 2.0); - Point endPoint(4.0, 4.0); + Point const startPoint(1.0, 2.0); + Point const endPoint(4.0, 4.0); std::unique_ptr result( algorithm::visibility(poly, startPoint, endPoint)); - std::string expectedWkt = + std::string const expectedWkt = "POLYGON((4.0 0.0,4.0 4.0,1.0 2.0,0.0 1.3,0.0 0.0,3.0 2.0,4.0 0.0))"; BOOST_CHECK_EQUAL(result->asText(1), expectedWkt); } @@ -283,39 +284,39 @@ BOOST_AUTO_TEST_CASE(testVisibility_SegmentInPolygon) BOOST_AUTO_TEST_CASE(testVisibility_SegmentInPolygonHole) { std::vector points; - points.push_back(Point(1.0, 2.0)); - points.push_back(Point(12.0, 3.0)); - points.push_back(Point(19.0, -2.0)); - points.push_back(Point(12.0, 6.0)); - points.push_back(Point(14.0, 14.0)); - points.push_back(Point(9.0, 5.0)); - points.push_back(Point(1.0, 2.0)); + points.emplace_back(1.0, 2.0); + points.emplace_back(12.0, 3.0); + points.emplace_back(19.0, -2.0); + points.emplace_back(12.0, 6.0); + points.emplace_back(14.0, 14.0); + points.emplace_back(9.0, 5.0); + points.emplace_back(1.0, 2.0); std::vector points_hole1; - points_hole1.push_back(Point(8.0, 3.0)); - points_hole1.push_back(Point(8.0, 4.0)); - points_hole1.push_back(Point(10.0, 3.0)); - points_hole1.push_back(Point(8.0, 3.0)); + points_hole1.emplace_back(8.0, 3.0); + points_hole1.emplace_back(8.0, 4.0); + points_hole1.emplace_back(10.0, 3.0); + points_hole1.emplace_back(8.0, 3.0); std::vector points_hole2; - points_hole2.push_back(Point(10.0, 6.0)); - points_hole2.push_back(Point(11.0, 7.0)); - points_hole2.push_back(Point(11.0, 6.0)); - points_hole2.push_back(Point(10.0, 6.0)); + points_hole2.emplace_back(10.0, 6.0); + points_hole2.emplace_back(11.0, 7.0); + points_hole2.emplace_back(11.0, 6.0); + points_hole2.emplace_back(10.0, 6.0); - LineString lineString(points); - LineString hole1(points_hole1); - LineString hole2(points_hole2); + LineString const lineString(points); + LineString const hole1(points_hole1); + LineString const hole2(points_hole2); Polygon poly(lineString); poly.addInteriorRing(hole1); poly.addInteriorRing(hole2); - Point startPoint(19.0, -2.0); - Point endPoint(12.0, 6.0); + Point const startPoint(19.0, -2.0); + Point const endPoint(12.0, 6.0); std::unique_ptr result( algorithm::visibility(poly, startPoint, endPoint)); - std::string expectedWkt = + std::string const expectedWkt = "POLYGON((19.0 -2.0,12.0 6.0,14.0 14.0,10.4 7.6,11.0 7.0,11.0 6.0,10.0 " "6.0,9.6 6.0,9.0 5.0,1.0 2.0,4.7 2.3,8.0 4.0,10.0 3.0,9.9 2.8,12.0 " "3.0,19.0 -2.0))"; diff --git a/test/unit/SFCGAL/algorithm/VolumeTest.cpp b/test/unit/SFCGAL/algorithm/VolumeTest.cpp index 2bcd456f..822e93f5 100644 --- a/test/unit/SFCGAL/algorithm/VolumeTest.cpp +++ b/test/unit/SFCGAL/algorithm/VolumeTest.cpp @@ -62,14 +62,14 @@ BOOST_AUTO_TEST_CASE(cubeWithHoleVolume) ((.2 .8 .2,.8 .8 .2,.8 .8 .8,.2 .8 .8,.2 .8 .2))))"); const Kernel::FT c(.6); const Kernel::FT ref = 1 - c * c * c; - BOOST_CHECK(algorithm::volume( - s->as(), algorithm::NoValidityCheck()) - - ref < 0.001); + BOOST_CHECK(algorithm::volume(s->as(), algorithm::NoValidityCheck()) - + ref < + 0.001); } BOOST_AUTO_TEST_CASE(invertedCubeVolume) { - std::unique_ptr s = + std::unique_ptr const s = io::readWkt("SOLID((((0 0 0,0 1 0,0 1 1,0 0 1,0 0 0)),\ ((0 0 0,1 0 0,1 1 0,0 1 0,0 0 0)),\ ((0 0 0,0 0 1,1 0 1,1 0 0,0 0 0)),\ @@ -88,10 +88,10 @@ BOOST_AUTO_TEST_CASE(polyhedronVolume) "((1 0 0, 0 1 0, 0 0 1, 1 0 0 )) )"); std::unique_ptr geometry0(io::readWkt(block0)); - Solid solid(geometry0->as()); + Solid const solid(geometry0->as()); auto vol{algorithm::volume(solid)}; BOOST_CHECK_EQUAL(vol * 6, 1.0); - CGAL::Nef_polyhedron_3 n; + CGAL::Nef_polyhedron_3 const n; } BOOST_AUTO_TEST_SUITE_END() diff --git a/test/unit/SFCGAL/capi/sfcgal_cTest.cpp b/test/unit/SFCGAL/capi/sfcgal_cTest.cpp index a3b03a2b..e18f068f 100644 --- a/test/unit/SFCGAL/capi/sfcgal_cTest.cpp +++ b/test/unit/SFCGAL/capi/sfcgal_cTest.cpp @@ -15,136 +15,138 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ -#include -#include -#include -#include -#include -#include -#include -#include #include -#include +#include #include +#include #include #include +#include +#include +#include +#include +#include +#include +#include #include #include -using namespace boost::unit_test ; -using namespace SFCGAL ; +using namespace boost::unit_test; +using namespace SFCGAL; -BOOST_AUTO_TEST_SUITE( SFCGAL_sfcgal_cTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_sfcgal_cTest) bool hasError = false; -int on_error( const char* /*msg*/, ... ) +auto +on_error(const char * /*msg*/, ...) -> int { - hasError = true; - return 0; + hasError = true; + return 0; } /// Coordinate() ; -BOOST_AUTO_TEST_CASE( testErrorOnBadGeometryType ) +BOOST_AUTO_TEST_CASE(testErrorOnBadGeometryType) { - sfcgal_set_error_handlers( printf, on_error ); + sfcgal_set_error_handlers(printf, on_error); - std::unique_ptr l( io::readWkt( "LINESTRING(0 0, 0 1)" ) ); - std::unique_ptr p( io::readWkt( "POINT(0 2)" ) ); - sfcgal_geometry_t* gl = l.get(); + std::unique_ptr const l(io::readWkt("LINESTRING(0 0, 0 1)")); + std::unique_ptr p(io::readWkt("POINT(0 2)")); + sfcgal_geometry_t *gl = l.get(); - hasError = false; - BOOST_CHECK_EQUAL( 2, sfcgal_linestring_num_points( gl ) ); // should succeed - BOOST_CHECK( hasError == false ); + hasError = false; + BOOST_CHECK_EQUAL(2, sfcgal_linestring_num_points(gl)); // should succeed + BOOST_CHECK(hasError == false); - hasError = false; - BOOST_CHECK( sfcgal_triangle_vertex( gl, 0 ) == 0 ); // should fail - BOOST_CHECK( hasError == true ); + hasError = false; + BOOST_CHECK(sfcgal_triangle_vertex(gl, 0) == nullptr); // should fail + BOOST_CHECK(hasError == true); - sfcgal_geometry_t* gp = p.release(); - hasError = false; - sfcgal_linestring_add_point( gl, gp ); // should succeed - BOOST_CHECK( hasError == false ); + sfcgal_geometry_t *gp = p.release(); + hasError = false; + sfcgal_linestring_add_point(gl, gp); // should succeed + BOOST_CHECK(hasError == false); - hasError = false; - sfcgal_linestring_add_point( gl, gl ); // should fail - BOOST_CHECK( hasError == true ); + hasError = false; + sfcgal_linestring_add_point(gl, gl); // should fail + BOOST_CHECK(hasError == true); } -BOOST_AUTO_TEST_CASE( testStraightSkeletonPolygon ) +BOOST_AUTO_TEST_CASE(testStraightSkeletonPolygon) { - sfcgal_set_error_handlers( printf, on_error ); + sfcgal_set_error_handlers(printf, on_error); - std::unique_ptr g( io::readWkt( -"POLYGON((0 0, 20 0, 20 10, 0 10, 0 0))" - ) ); + std::unique_ptr const g( + io::readWkt("POLYGON((0 0, 20 0, 20 10, 0 10, 0 0))")); - hasError = false; - sfcgal_geometry_t* sk = sfcgal_geometry_straight_skeleton( g.get() ); - BOOST_CHECK( hasError == false ); - BOOST_CHECK_EQUAL( 5, sfcgal_geometry_collection_num_geometries( sk ) ); + hasError = false; + sfcgal_geometry_t *sk = sfcgal_geometry_straight_skeleton(g.get()); + BOOST_CHECK(hasError == false); + BOOST_CHECK_EQUAL(5, sfcgal_geometry_collection_num_geometries(sk)); } -BOOST_AUTO_TEST_CASE( testStraightSkeletonMultiPolygon ) +BOOST_AUTO_TEST_CASE(testStraightSkeletonMultiPolygon) { - sfcgal_set_error_handlers( printf, on_error ); + sfcgal_set_error_handlers(printf, on_error); - std::unique_ptr g( io::readWkt( -"MULTIPOLYGON(((0 0, 20 0, 20 10, 0 10, 0 0)),((100 0,200 0,150 100,100 0)))" - ) ); + std::unique_ptr const g( + io::readWkt("MULTIPOLYGON(((0 0, 20 0, 20 10, 0 10, 0 0)),((100 0,200 " + "0,150 100,100 0)))")); - hasError = false; - sfcgal_geometry_t* sk = sfcgal_geometry_straight_skeleton( g.get() ); - BOOST_CHECK( hasError == false ); - BOOST_CHECK_EQUAL( 8, sfcgal_geometry_collection_num_geometries( sk ) ); + hasError = false; + sfcgal_geometry_t *sk = sfcgal_geometry_straight_skeleton(g.get()); + BOOST_CHECK(hasError == false); + BOOST_CHECK_EQUAL(8, sfcgal_geometry_collection_num_geometries(sk)); } -BOOST_AUTO_TEST_CASE( testApproximateMedialAxis ) +BOOST_AUTO_TEST_CASE(testApproximateMedialAxis) { - sfcgal_set_error_handlers( printf, on_error ); - - std::unique_ptr g( io::readWkt( -"POLYGON((-42 9,-44 9,-42 8,-22 7,-22 21,1 22,-5 13,-5 12,-4 13,2 23,-23 22,-23 8,-42 9))" - ) ); - - hasError = false; - sfcgal_geometry_t* sk = sfcgal_geometry_approximate_medial_axis( g.get() ); - BOOST_CHECK( hasError == false ); - // TODO: check length = 71.5634135885843 - // NOTE: length not available in C-API - // algorithm::length - //BOOST_CHECK_EQUAL( 71.56, round(algorithm::length(sk)*100)/100; ); - BOOST_CHECK_EQUAL( 11, sfcgal_geometry_collection_num_geometries( sk ) ); - - sfcgal_geometry_delete(sk); + sfcgal_set_error_handlers(printf, on_error); + + std::unique_ptr const g( + io::readWkt("POLYGON((-42 9,-44 9,-42 8,-22 7,-22 21,1 22,-5 13,-5 12,-4 " + "13,2 23,-23 22,-23 8,-42 9))")); + + hasError = false; + sfcgal_geometry_t *sk = sfcgal_geometry_approximate_medial_axis(g.get()); + BOOST_CHECK(hasError == false); + // TODO: check length = 71.5634135885843 + // NOTE: length not available in C-API + // algorithm::length + // BOOST_CHECK_EQUAL( 71.56, round(algorithm::length(sk)*100)/100; ); + BOOST_CHECK_EQUAL(11, sfcgal_geometry_collection_num_geometries(sk)); + + sfcgal_geometry_delete(sk); } -BOOST_AUTO_TEST_CASE( testCovers ) +BOOST_AUTO_TEST_CASE(testCovers) { - sfcgal_set_error_handlers( printf, on_error ); + sfcgal_set_error_handlers(printf, on_error); - std::unique_ptr g1( io::readWkt( -"MULTIPOLYGON(((0 0, 20 0, 20 10, 0 10, 0 0)),((100 0,200 0,150 100,100 0)))" - ) ); - std::unique_ptr g2( io::readWkt( -"MULTIPOLYGON(((100 0,200 0,150 100,100 0)), ((0 0, 20 0, 20 10, 0 10, 0 0)))" - ) ); + std::unique_ptr const g1( + io::readWkt("MULTIPOLYGON(((0 0, 20 0, 20 10, 0 10, 0 0)),((100 0,200 " + "0,150 100,100 0)))")); + std::unique_ptr const g2( + io::readWkt("MULTIPOLYGON(((100 0,200 0,150 100,100 0)), ((0 0, 20 0, 20 " + "10, 0 10, 0 0)))")); - BOOST_CHECK( sfcgal_geometry_covers( g1.get(), g2.get() ) ); + BOOST_CHECK(sfcgal_geometry_covers(g1.get(), g2.get())); } -BOOST_AUTO_TEST_CASE( testLineSubstring ) +BOOST_AUTO_TEST_CASE(testLineSubstring) { - sfcgal_set_error_handlers( printf, on_error ); - std::unique_ptr g1( io::readWkt( "LINESTRING Z(0 0 0, 0 0 10)" ) ); - std::unique_ptr g2( io::readWkt( "LINESTRING Z(0 0 3, 0 0 7)" ) ); - hasError = false; - sfcgal_geometry_t* ls = sfcgal_geometry_line_sub_string( g1.get(), 0.3, 0.7); - BOOST_CHECK( hasError == false ); - - BOOST_CHECK( sfcgal_geometry_covers_3d( ls, g2.get() ) ); + sfcgal_set_error_handlers(printf, on_error); + std::unique_ptr const g1( + io::readWkt("LINESTRING Z(0 0 0, 0 0 10)")); + std::unique_ptr const g2(io::readWkt("LINESTRING Z(0 0 3, 0 0 7)")); + hasError = false; + sfcgal_geometry_t *ls = sfcgal_geometry_line_sub_string(g1.get(), 0.3, 0.7); + BOOST_CHECK(hasError == false); + + BOOST_CHECK(sfcgal_geometry_covers_3d(ls, g2.get())); } BOOST_AUTO_TEST_SUITE_END() diff --git a/test/unit/SFCGAL/detail/ComplexComparatorTest.cpp b/test/unit/SFCGAL/detail/ComplexComparatorTest.cpp index 977b8ca7..3b4286e6 100644 --- a/test/unit/SFCGAL/detail/ComplexComparatorTest.cpp +++ b/test/unit/SFCGAL/detail/ComplexComparatorTest.cpp @@ -15,31 +15,34 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include #include #include -using namespace SFCGAL ; -using namespace SFCGAL::detail ; +using namespace SFCGAL; +using namespace SFCGAL::detail; // always after CGAL -using namespace boost::unit_test ; +using namespace boost::unit_test; +BOOST_AUTO_TEST_SUITE(SFCGAL_detail_ComplexComparatorTest) -BOOST_AUTO_TEST_SUITE( SFCGAL_detail_ComplexComparatorTest ) - -BOOST_AUTO_TEST_CASE( testComparator ) +BOOST_AUTO_TEST_CASE(testComparator) { - ComplexComparator less ; - - BOOST_CHECK( ! less( std::complex< double >( 1.0,0.0 ), std::complex< double >( 0.0,0.0 ) ) ); - BOOST_CHECK( ! less( std::complex< double >( 0.0,0.0 ), std::complex< double >( 0.0,0.0 ) ) ); - BOOST_CHECK( less( std::complex< double >( 0.0,0.0 ), std::complex< double >( 1.0,0.0 ) ) ); - BOOST_CHECK( less( std::complex< double >( 0.0,0.0 ), std::complex< double >( 0.0,1.0 ) ) ); + ComplexComparator const less; + + BOOST_CHECK( + !less(std::complex(1.0, 0.0), std::complex(0.0, 0.0))); + BOOST_CHECK( + !less(std::complex(0.0, 0.0), std::complex(0.0, 0.0))); + BOOST_CHECK( + less(std::complex(0.0, 0.0), std::complex(1.0, 0.0))); + BOOST_CHECK( + less(std::complex(0.0, 0.0), std::complex(0.0, 1.0))); } BOOST_AUTO_TEST_SUITE_END() - diff --git a/test/unit/SFCGAL/detail/IntervalTest.cpp b/test/unit/SFCGAL/detail/IntervalTest.cpp index 0b1ef5c3..41586fcc 100644 --- a/test/unit/SFCGAL/detail/IntervalTest.cpp +++ b/test/unit/SFCGAL/detail/IntervalTest.cpp @@ -15,146 +15,142 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include #include #include -using namespace SFCGAL ; -using namespace SFCGAL::detail ; +using namespace SFCGAL; +using namespace SFCGAL::detail; // always after CGAL -using namespace boost::unit_test ; +using namespace boost::unit_test; +BOOST_AUTO_TEST_SUITE(SFCGAL_detail_IntervalTest) -BOOST_AUTO_TEST_SUITE( SFCGAL_detail_IntervalTest ) - -//Interval() ; -BOOST_AUTO_TEST_CASE( testDefaultConstructor ) +// Interval() ; +BOOST_AUTO_TEST_CASE(testDefaultConstructor) { - Interval bound; - BOOST_CHECK( std::isnan( bound.lower() ) ); - BOOST_CHECK( std::isnan( bound.upper() ) ); + Interval const bound; + BOOST_CHECK(std::isnan(bound.lower())); + BOOST_CHECK(std::isnan(bound.upper())); } -//Interval( const double & value ) ; -BOOST_AUTO_TEST_CASE( testConstructorWithValue ) +// Interval( const double & value ) ; +BOOST_AUTO_TEST_CASE(testConstructorWithValue) { - Interval bound( 5.0 ); - BOOST_CHECK_EQUAL( bound.lower(), 5.0 ); - BOOST_CHECK_EQUAL( bound.upper(), 5.0 ); + Interval const bound(5.0); + BOOST_CHECK_EQUAL(bound.lower(), 5.0); + BOOST_CHECK_EQUAL(bound.upper(), 5.0); } -//Interval( const double & v1, const double & v2 ) ; -BOOST_AUTO_TEST_CASE( testConstructorWithTwoValues ) +// Interval( const double & v1, const double & v2 ) ; +BOOST_AUTO_TEST_CASE(testConstructorWithTwoValues) { - Interval bound( 5.0,3.0 ); - BOOST_CHECK_EQUAL( bound.lower(), 3.0 ); - BOOST_CHECK_EQUAL( bound.upper(), 5.0 ); + Interval const bound(5.0, 3.0); + BOOST_CHECK_EQUAL(bound.lower(), 3.0); + BOOST_CHECK_EQUAL(bound.upper(), 5.0); } - -//Interval( const Interval & other ) ; -//Interval& operator = ( const Interval & other ) ; +// Interval( const Interval & other ) ; +// Interval& operator = ( const Interval & other ) ; //~Interval() ; -//bool isEmpty() const ; -BOOST_AUTO_TEST_CASE( testEmpty ) +// bool isEmpty() const ; +BOOST_AUTO_TEST_CASE(testEmpty) { - Interval bound ; - BOOST_CHECK( bound.isEmpty() ); + Interval const bound; + BOOST_CHECK(bound.isEmpty()); } -BOOST_AUTO_TEST_CASE( testNotEmpty ) +BOOST_AUTO_TEST_CASE(testNotEmpty) { - Interval bound( 5.0 ); - BOOST_CHECK( ! bound.isEmpty() ); + Interval const bound(5.0); + BOOST_CHECK(!bound.isEmpty()); } -//inline const double & lower() const { return _lower; } -//inline const double & upper() const { return _upper; } -//inline double width() const { return _upper - _lower ; } -BOOST_AUTO_TEST_CASE( testWidth ) +// inline const double & lower() const { return _lower; } +// inline const double & upper() const { return _upper; } +// inline double width() const { return _upper - _lower ; } +BOOST_AUTO_TEST_CASE(testWidth) { - Interval bound( 4.0,5.0 ); - BOOST_CHECK_EQUAL( bound.width(), 1.0 ); + Interval const bound(4.0, 5.0); + BOOST_CHECK_EQUAL(bound.width(), 1.0); } -//void expandBy( const double & d ) ; -BOOST_AUTO_TEST_CASE( testExpandByEmpty ) +// void expandBy( const double & d ) ; +BOOST_AUTO_TEST_CASE(testExpandByEmpty) { - Interval bound ; - bound.expandBy( 5.0 ) ; - BOOST_CHECK( bound.isEmpty() ); + Interval bound; + bound.expandBy(5.0); + BOOST_CHECK(bound.isEmpty()); } -//void expandToInclude( const Interval & other ) ; -BOOST_AUTO_TEST_CASE( testExpandToIncludeInterval_emptyExpanded ) +// void expandToInclude( const Interval & other ) ; +BOOST_AUTO_TEST_CASE(testExpandToIncludeInterval_emptyExpanded) { - Interval bound ; - bound.expandToInclude( Interval( 0.0,1.0 ) ); - BOOST_CHECK_EQUAL( bound.lower(), 0.0 ); - BOOST_CHECK_EQUAL( bound.upper(), 1.0 ); + Interval bound; + bound.expandToInclude(Interval(0.0, 1.0)); + BOOST_CHECK_EQUAL(bound.lower(), 0.0); + BOOST_CHECK_EQUAL(bound.upper(), 1.0); } -BOOST_AUTO_TEST_CASE( testExpandToIncludeInterval_expandByEmpty ) +BOOST_AUTO_TEST_CASE(testExpandToIncludeInterval_expandByEmpty) { - Interval bound( 0.0,1.0 ); - bound.expandToInclude( Interval() ); - BOOST_CHECK_EQUAL( bound.lower(), 0.0 ); - BOOST_CHECK_EQUAL( bound.upper(), 1.0 ); + Interval bound(0.0, 1.0); + bound.expandToInclude(Interval()); + BOOST_CHECK_EQUAL(bound.lower(), 0.0); + BOOST_CHECK_EQUAL(bound.upper(), 1.0); } -BOOST_AUTO_TEST_CASE( testExpandToIncludeInterval_classic ) +BOOST_AUTO_TEST_CASE(testExpandToIncludeInterval_classic) { - Interval bound( 0.0,1.0 ); - bound.expandToInclude( Interval( -1.0,2.0 ) ); - BOOST_CHECK_EQUAL( bound.lower(),-1.0 ); - BOOST_CHECK_EQUAL( bound.upper(), 2.0 ); + Interval bound(0.0, 1.0); + bound.expandToInclude(Interval(-1.0, 2.0)); + BOOST_CHECK_EQUAL(bound.lower(), -1.0); + BOOST_CHECK_EQUAL(bound.upper(), 2.0); } - -//void expandToInclude( const double & value ) ; -BOOST_AUTO_TEST_CASE( testExpandToIncludeValue_classic1 ) +// void expandToInclude( const double & value ) ; +BOOST_AUTO_TEST_CASE(testExpandToIncludeValue_classic1) { - Interval bound( 0.0,1.0 ); - bound.expandToInclude( 2.0 ); - BOOST_CHECK_EQUAL( bound.lower(), 0.0 ); - BOOST_CHECK_EQUAL( bound.upper(), 2.0 ); + Interval bound(0.0, 1.0); + bound.expandToInclude(2.0); + BOOST_CHECK_EQUAL(bound.lower(), 0.0); + BOOST_CHECK_EQUAL(bound.upper(), 2.0); } -BOOST_AUTO_TEST_CASE( testExpandToIncludeValue_classic2 ) +BOOST_AUTO_TEST_CASE(testExpandToIncludeValue_classic2) { - Interval bound( 0.0,1.0 ); - bound.expandToInclude( -2.0 ); - BOOST_CHECK_EQUAL( bound.lower(), -2.0 ); - BOOST_CHECK_EQUAL( bound.upper(), 1.0 ); + Interval bound(0.0, 1.0); + bound.expandToInclude(-2.0); + BOOST_CHECK_EQUAL(bound.lower(), -2.0); + BOOST_CHECK_EQUAL(bound.upper(), 1.0); } -//bool intersects( const Interval & other ) const ; -BOOST_AUTO_TEST_CASE( testIntersects_emptyBehavior ) +// bool intersects( const Interval & other ) const ; +BOOST_AUTO_TEST_CASE(testIntersects_emptyBehavior) { - BOOST_CHECK( ! Interval().intersects( Interval() ) ); - BOOST_CHECK( ! Interval( 0.0,1.0 ).intersects( Interval() ) ); - BOOST_CHECK( ! Interval().intersects( Interval( 0.0,1.0 ) ) ); + BOOST_CHECK(!Interval().intersects(Interval())); + BOOST_CHECK(!Interval(0.0, 1.0).intersects(Interval())); + BOOST_CHECK(!Interval().intersects(Interval(0.0, 1.0))); } -BOOST_AUTO_TEST_CASE( testIntersects_normalBehavior ) +BOOST_AUTO_TEST_CASE(testIntersects_normalBehavior) { - BOOST_CHECK( Interval( 0.0,1.0 ).intersects( Interval( -1.0,0.5 ) ) ); - BOOST_CHECK( Interval( 0.0,1.0 ).intersects( Interval( 0.3,0.5 ) ) ); - BOOST_CHECK( Interval( 0.0,1.0 ).intersects( Interval( 0.5,2.0 ) ) ); + BOOST_CHECK(Interval(0.0, 1.0).intersects(Interval(-1.0, 0.5))); + BOOST_CHECK(Interval(0.0, 1.0).intersects(Interval(0.3, 0.5))); + BOOST_CHECK(Interval(0.0, 1.0).intersects(Interval(0.5, 2.0))); - BOOST_CHECK( ! Interval( 0.0,1.0 ).intersects( Interval( 2.0,3.0 ) ) ); - BOOST_CHECK( ! Interval( 2.0,3.0 ).intersects( Interval( 0.0,1.0 ) ) ); + BOOST_CHECK(!Interval(0.0, 1.0).intersects(Interval(2.0, 3.0))); + BOOST_CHECK(!Interval(2.0, 3.0).intersects(Interval(0.0, 1.0))); } -BOOST_AUTO_TEST_CASE( testIntersects_limitBehavior ) +BOOST_AUTO_TEST_CASE(testIntersects_limitBehavior) { - BOOST_CHECK( Interval( 0.0,1.0 ).intersects( Interval( 1.0,2.0 ) ) ); - BOOST_CHECK( Interval( 0.0,1.0 ).intersects( Interval( -1.0,0.0 ) ) ); + BOOST_CHECK(Interval(0.0, 1.0).intersects(Interval(1.0, 2.0))); + BOOST_CHECK(Interval(0.0, 1.0).intersects(Interval(-1.0, 0.0))); - BOOST_CHECK( Interval( 1.0,2.0 ).intersects( Interval( 0.0,1.0 ) ) ); - BOOST_CHECK( Interval( -1.0,0.0 ).intersects( Interval( 0.0,1.0 ) ) ); + BOOST_CHECK(Interval(1.0, 2.0).intersects(Interval(0.0, 1.0))); + BOOST_CHECK(Interval(-1.0, 0.0).intersects(Interval(0.0, 1.0))); } - BOOST_AUTO_TEST_SUITE_END() - diff --git a/test/unit/SFCGAL/graph/GeometryGraphBuilderTest.cpp b/test/unit/SFCGAL/graph/GeometryGraphBuilderTest.cpp index 60cb4eef..056aca13 100644 --- a/test/unit/SFCGAL/graph/GeometryGraphBuilderTest.cpp +++ b/test/unit/SFCGAL/graph/GeometryGraphBuilderTest.cpp @@ -15,76 +15,70 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include - #include #include -using namespace boost::unit_test ; - -using namespace SFCGAL ; -using namespace SFCGAL::graph ; +using namespace boost::unit_test; +using namespace SFCGAL; +using namespace SFCGAL::graph; -BOOST_AUTO_TEST_SUITE( SFCGAL_GeometryGraphBuilderTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_GeometryGraphBuilderTest) -BOOST_AUTO_TEST_CASE( addPoint ) +BOOST_AUTO_TEST_CASE(addPoint) { - typedef GeometryGraph::vertex_descriptor vertex_descriptor ; - //typedef GeometryGraph::edge_descriptor edge_descriptor ; - GeometryGraph graph; - GeometryGraphBuilder graphBuilder( graph ); + typedef GeometryGraph::vertex_descriptor vertex_descriptor; + // typedef GeometryGraph::edge_descriptor edge_descriptor ; + GeometryGraph graph; + GeometryGraphBuilder graphBuilder(graph); - vertex_descriptor a = graphBuilder.addPoint( Point( 0.0,0.0,0.0 ) ); - vertex_descriptor b = graphBuilder.addPoint( Point( 1.0,1.0,1.0 ) ); - vertex_descriptor c = graphBuilder.addPoint( Point( 2.0,2.0,2.0 ) ); + vertex_descriptor a = graphBuilder.addPoint(Point(0.0, 0.0, 0.0)); + vertex_descriptor b = graphBuilder.addPoint(Point(1.0, 1.0, 1.0)); + vertex_descriptor c = graphBuilder.addPoint(Point(2.0, 2.0, 2.0)); - //b duplicate - vertex_descriptor d = graphBuilder.addPoint( Point( 1.0,1.0,1.0 ) ); + // b duplicate + vertex_descriptor d = graphBuilder.addPoint(Point(1.0, 1.0, 1.0)); - BOOST_CHECK_EQUAL( graph.numVertices(), 3U ); - BOOST_CHECK_EQUAL( graph.numEdges(), 0U ); - BOOST_CHECK_EQUAL( b, d ); + BOOST_CHECK_EQUAL(graph.numVertices(), 3U); + BOOST_CHECK_EQUAL(graph.numEdges(), 0U); + BOOST_CHECK_EQUAL(b, d); - BOOST_CHECK( graph[ a ].coordinate == Coordinate( 0.0,0.0,0.0 ) ); - BOOST_CHECK( graph[ b ].coordinate == Coordinate( 1.0,1.0,1.0 ) ); - BOOST_CHECK( graph[ c ].coordinate == Coordinate( 2.0,2.0,2.0 ) ); + BOOST_CHECK(graph[a].coordinate == Coordinate(0.0, 0.0, 0.0)); + BOOST_CHECK(graph[b].coordinate == Coordinate(1.0, 1.0, 1.0)); + BOOST_CHECK(graph[c].coordinate == Coordinate(2.0, 2.0, 2.0)); } - - -BOOST_AUTO_TEST_CASE( addLineString ) +BOOST_AUTO_TEST_CASE(addLineString) { - //typedef GeometryGraph::vertex_descriptor vertex_descriptor ; - typedef GeometryGraph::edge_descriptor edge_descriptor ; - GeometryGraph graph; - GeometryGraphBuilder graphBuilder( graph ); - - std::vector< Point > points ; - points.push_back( Point( 0.0,0.0,0.0 ) ); - points.push_back( Point( 1.0,0.0,0.0 ) ); - points.push_back( Point( 1.0,1.0,0.0 ) ); - points.push_back( Point( 0.0,1.0,0.0 ) ); - points.push_back( Point( 0.0,0.0,0.0 ) ); - - LineString lineString( points ); - std::vector< edge_descriptor > sharedLineString = graphBuilder.addLineString( lineString ); - - BOOST_CHECK_EQUAL( graph.numVertices(), 4U ); - BOOST_CHECK_EQUAL( graph.numEdges(), 4U ); - - //check closed - for ( size_t i = 0; i < sharedLineString.size(); i++ ) { - BOOST_CHECK( graph.target( sharedLineString[ i ] ) == graph.source( sharedLineString[ ( i+1 ) % 4 ] ) ) ; - } + // typedef GeometryGraph::vertex_descriptor vertex_descriptor ; + typedef GeometryGraph::edge_descriptor edge_descriptor; + GeometryGraph graph; + GeometryGraphBuilder graphBuilder(graph); + + std::vector points; + points.emplace_back(0.0, 0.0, 0.0); + points.emplace_back(1.0, 0.0, 0.0); + points.emplace_back(1.0, 1.0, 0.0); + points.emplace_back(0.0, 1.0, 0.0); + points.emplace_back(0.0, 0.0, 0.0); + + LineString const lineString(points); + std::vector sharedLineString = + graphBuilder.addLineString(lineString); + + BOOST_CHECK_EQUAL(graph.numVertices(), 4U); + BOOST_CHECK_EQUAL(graph.numEdges(), 4U); + + // check closed + for (size_t i = 0; i < sharedLineString.size(); i++) { + BOOST_CHECK(graph.target(sharedLineString[i]) == + graph.source(sharedLineString[(i + 1) % 4])); + } } - BOOST_AUTO_TEST_SUITE_END() - - - - diff --git a/test/unit/SFCGAL/graph/GeometryGraphTest.cpp b/test/unit/SFCGAL/graph/GeometryGraphTest.cpp index 60bb3f91..8bf2e7f1 100644 --- a/test/unit/SFCGAL/graph/GeometryGraphTest.cpp +++ b/test/unit/SFCGAL/graph/GeometryGraphTest.cpp @@ -15,103 +15,92 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include - #include -using namespace boost::unit_test ; -using namespace SFCGAL ; -using namespace SFCGAL::graph ; - +using namespace boost::unit_test; +using namespace SFCGAL; +using namespace SFCGAL::graph; -BOOST_AUTO_TEST_SUITE( SFCGAL_GeometryGraphTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_GeometryGraphTest) -BOOST_AUTO_TEST_CASE( addVertexAndEdges ) +BOOST_AUTO_TEST_CASE(addVertexAndEdges) { - GeometryGraph graph; - typedef GeometryGraph::vertex_descriptor vertex_descriptor ; - typedef GeometryGraph::edge_descriptor edge_descriptor ; + GeometryGraph graph; + typedef GeometryGraph::vertex_descriptor vertex_descriptor; + typedef GeometryGraph::edge_descriptor edge_descriptor; - vertex_descriptor a = graph.addVertex( Coordinate( 0.0,0.0 ) ); - vertex_descriptor b = graph.addVertex( Coordinate( 1.0,1.0 ) ); + vertex_descriptor a = graph.addVertex(Coordinate(0.0, 0.0)); + vertex_descriptor b = graph.addVertex(Coordinate(1.0, 1.0)); - edge_descriptor ab = graph.addEdge( a, b ); - BOOST_CHECK_EQUAL( graph.source( ab ), a ); - BOOST_CHECK_EQUAL( graph.target( ab ), b ); + edge_descriptor const ab = graph.addEdge(a, b); + BOOST_CHECK_EQUAL(graph.source(ab), a); + BOOST_CHECK_EQUAL(graph.target(ab), b); - BOOST_CHECK_EQUAL( graph.numVertices(), 2U ); - BOOST_CHECK_EQUAL( graph.numEdges(), 1U ); + BOOST_CHECK_EQUAL(graph.numVertices(), 2U); + BOOST_CHECK_EQUAL(graph.numEdges(), 1U); } - - -BOOST_AUTO_TEST_CASE( adjacentVertices ) +BOOST_AUTO_TEST_CASE(adjacentVertices) { - GeometryGraph graph; - typedef GeometryGraph::vertex_descriptor vertex_descriptor ; - //typedef GeometryGraph::edge_descriptor edge_descriptor ; - - vertex_descriptor a = graph.addVertex( Coordinate( 0.0,0.0 ) ); - vertex_descriptor b = graph.addVertex( Coordinate( 1.0,1.0 ) ); - vertex_descriptor c = graph.addVertex( Coordinate( 2.0,2.0 ) ); - vertex_descriptor d = graph.addVertex( Coordinate( 2.0,2.0 ) ); - - graph.addEdge( a, b ); - graph.addEdge( b, c ); - graph.addEdge( c, d ); - - std::set< vertex_descriptor > bAjacentVertices = graph.adjacentVertices( b ); - BOOST_CHECK_EQUAL( bAjacentVertices.size(), 2U ); - BOOST_CHECK_EQUAL( bAjacentVertices.count( a ), 1U ); - BOOST_CHECK_EQUAL( bAjacentVertices.count( c ), 1U ); + GeometryGraph graph; + typedef GeometryGraph::vertex_descriptor vertex_descriptor; + // typedef GeometryGraph::edge_descriptor edge_descriptor ; + + vertex_descriptor a = graph.addVertex(Coordinate(0.0, 0.0)); + vertex_descriptor b = graph.addVertex(Coordinate(1.0, 1.0)); + vertex_descriptor c = graph.addVertex(Coordinate(2.0, 2.0)); + vertex_descriptor d = graph.addVertex(Coordinate(2.0, 2.0)); + + graph.addEdge(a, b); + graph.addEdge(b, c); + graph.addEdge(c, d); + + std::set const bAjacentVertices = + graph.adjacentVertices(b); + BOOST_CHECK_EQUAL(bAjacentVertices.size(), 2U); + BOOST_CHECK_EQUAL(bAjacentVertices.count(a), 1U); + BOOST_CHECK_EQUAL(bAjacentVertices.count(c), 1U); } - - -BOOST_AUTO_TEST_CASE( inOutEdges ) +BOOST_AUTO_TEST_CASE(inOutEdges) { - GeometryGraph graph; - typedef GeometryGraph::vertex_descriptor vertex_descriptor ; - typedef GeometryGraph::edge_descriptor edge_descriptor ; - typedef GeometryGraph::directed_edge_descriptor directed_edge_descriptor ; - - vertex_descriptor a = graph.addVertex( Coordinate( 0.0,0.0 ) ); - vertex_descriptor b = graph.addVertex( Coordinate( 1.0,1.0 ) ); - vertex_descriptor c = graph.addVertex( Coordinate( 2.0,2.0 ) ); - vertex_descriptor d = graph.addVertex( Coordinate( 2.0,2.0 ) ); - - edge_descriptor ab = graph.addEdge( a, b ); - edge_descriptor bc = graph.addEdge( b, c ); - /*edge_descriptor cd =*/ - graph.addEdge( c, d ); - - std::vector< edge_descriptor > inEdges = graph.inEdges( b ); - std::vector< edge_descriptor > outEdges = graph.outEdges( b ); - std::vector< directed_edge_descriptor > inOutEdges = graph.inOutEdges( b ); - - BOOST_REQUIRE_EQUAL( inEdges.size(), 1U ); - BOOST_CHECK_EQUAL( inEdges[0], ab ); - - BOOST_REQUIRE_EQUAL( outEdges.size(), 1U ); - BOOST_CHECK_EQUAL( outEdges[0], bc ); - - BOOST_REQUIRE_EQUAL( inOutEdges.size(), 2U ); - //ab is in inOutEdges - BOOST_CHECK( ( inOutEdges[0].first == ab && inOutEdges[0].second == REVERSE ) - || ( inOutEdges[1].first == ab && inOutEdges[1].second == REVERSE ) ); - //bc is in inOutEdges - BOOST_CHECK( ( inOutEdges[0].first == bc && inOutEdges[0].second == DIRECT ) - || ( inOutEdges[1].first == bc && inOutEdges[1].second == DIRECT ) ); + GeometryGraph graph; + typedef GeometryGraph::vertex_descriptor vertex_descriptor; + typedef GeometryGraph::edge_descriptor edge_descriptor; + typedef GeometryGraph::directed_edge_descriptor directed_edge_descriptor; + + vertex_descriptor a = graph.addVertex(Coordinate(0.0, 0.0)); + vertex_descriptor b = graph.addVertex(Coordinate(1.0, 1.0)); + vertex_descriptor c = graph.addVertex(Coordinate(2.0, 2.0)); + vertex_descriptor d = graph.addVertex(Coordinate(2.0, 2.0)); + + edge_descriptor const ab = graph.addEdge(a, b); + edge_descriptor const bc = graph.addEdge(b, c); + /*edge_descriptor cd =*/ + graph.addEdge(c, d); + + std::vector inEdges = graph.inEdges(b); + std::vector outEdges = graph.outEdges(b); + std::vector inOutEdges = graph.inOutEdges(b); + + BOOST_REQUIRE_EQUAL(inEdges.size(), 1U); + BOOST_CHECK_EQUAL(inEdges[0], ab); + + BOOST_REQUIRE_EQUAL(outEdges.size(), 1U); + BOOST_CHECK_EQUAL(outEdges[0], bc); + + BOOST_REQUIRE_EQUAL(inOutEdges.size(), 2U); + // ab is in inOutEdges + BOOST_CHECK((inOutEdges[0].first == ab && inOutEdges[0].second == REVERSE) || + (inOutEdges[1].first == ab && inOutEdges[1].second == REVERSE)); + // bc is in inOutEdges + BOOST_CHECK((inOutEdges[0].first == bc && inOutEdges[0].second == DIRECT) || + (inOutEdges[1].first == bc && inOutEdges[1].second == DIRECT)); } - - - BOOST_AUTO_TEST_SUITE_END() - - - - diff --git a/test/unit/SFCGAL/graph/algorithm/IsHalfEdgeTest.cpp b/test/unit/SFCGAL/graph/algorithm/IsHalfEdgeTest.cpp index b400b2d2..870dd5db 100644 --- a/test/unit/SFCGAL/graph/algorithm/IsHalfEdgeTest.cpp +++ b/test/unit/SFCGAL/graph/algorithm/IsHalfEdgeTest.cpp @@ -15,66 +15,59 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include #include #include -using namespace boost::unit_test ; -using namespace SFCGAL ; -using namespace SFCGAL::graph ; +using namespace boost::unit_test; +using namespace SFCGAL; +using namespace SFCGAL::graph; +BOOST_AUTO_TEST_SUITE(SFCGAL_graph_algorithm_IsHalfEdgeTest) -BOOST_AUTO_TEST_SUITE( SFCGAL_graph_algorithm_IsHalfEdgeTest ) - - -BOOST_AUTO_TEST_CASE( basicTestCase ) +BOOST_AUTO_TEST_CASE(basicTestCase) { - GeometryGraph graph; - typedef GeometryGraph::vertex_descriptor vertex_descriptor ; - - /* - d c f h - - a b e g - */ - - vertex_descriptor a = graph.addVertex( Coordinate( 0.0,0.0 ) ) ; - vertex_descriptor b = graph.addVertex( Coordinate( 1.0,0.0 ) ) ; - vertex_descriptor c = graph.addVertex( Coordinate( 1.0,1.0 ) ) ; - vertex_descriptor d = graph.addVertex( Coordinate( 0.0,1.0 ) ) ; - - vertex_descriptor e = graph.addVertex( Coordinate( 2.0,0.0 ) ) ; - vertex_descriptor f = graph.addVertex( Coordinate( 2.0,1.0 ) ) ; - - vertex_descriptor g = graph.addVertex( Coordinate( 3.0,0.0 ) ) ; - vertex_descriptor h = graph.addVertex( Coordinate( 3.0,1.0 ) ) ; - - - graph.addEdge( a, b ); - graph.addEdge( b, c ); - graph.addEdge( c, d ); - graph.addEdge( d, a ); - BOOST_CHECK( algorithm::isHalfEdge( graph ) ); - graph.addEdge( c, b ); - graph.addEdge( c, f ); - graph.addEdge( f, e ); - graph.addEdge( e, b ); - BOOST_CHECK( algorithm::isHalfEdge( graph ) ); - - graph.addEdge( e, g ); - graph.addEdge( g, h ); - graph.addEdge( h, f ); - BOOST_CHECK( algorithm::isHalfEdge( graph ) ); - graph.addEdge( f, e ); - BOOST_CHECK( ! algorithm::isHalfEdge( graph ) ); + GeometryGraph graph; + typedef GeometryGraph::vertex_descriptor vertex_descriptor; + + /* + d c f h + + a b e g + */ + + vertex_descriptor a = graph.addVertex(Coordinate(0.0, 0.0)); + vertex_descriptor b = graph.addVertex(Coordinate(1.0, 0.0)); + vertex_descriptor c = graph.addVertex(Coordinate(1.0, 1.0)); + vertex_descriptor d = graph.addVertex(Coordinate(0.0, 1.0)); + + vertex_descriptor e = graph.addVertex(Coordinate(2.0, 0.0)); + vertex_descriptor f = graph.addVertex(Coordinate(2.0, 1.0)); + + vertex_descriptor g = graph.addVertex(Coordinate(3.0, 0.0)); + vertex_descriptor h = graph.addVertex(Coordinate(3.0, 1.0)); + + graph.addEdge(a, b); + graph.addEdge(b, c); + graph.addEdge(c, d); + graph.addEdge(d, a); + BOOST_CHECK(algorithm::isHalfEdge(graph)); + graph.addEdge(c, b); + graph.addEdge(c, f); + graph.addEdge(f, e); + graph.addEdge(e, b); + BOOST_CHECK(algorithm::isHalfEdge(graph)); + + graph.addEdge(e, g); + graph.addEdge(g, h); + graph.addEdge(h, f); + BOOST_CHECK(algorithm::isHalfEdge(graph)); + graph.addEdge(f, e); + BOOST_CHECK(!algorithm::isHalfEdge(graph)); } - BOOST_AUTO_TEST_SUITE_END() - - - - diff --git a/test/unit/SFCGAL/io/SerializationTest.cpp b/test/unit/SFCGAL/io/SerializationTest.cpp index 1094a72a..7e39adb8 100644 --- a/test/unit/SFCGAL/io/SerializationTest.cpp +++ b/test/unit/SFCGAL/io/SerializationTest.cpp @@ -15,143 +15,172 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include #include -#include -#include -#include -#include -#include -#include -#include #include -#include +#include +#include #include +#include #include #include -#include +#include +#include +#include +#include +#include +#include #include -#include #include +#include #include -using namespace boost::unit_test ; +using namespace boost::unit_test; -using namespace SFCGAL ; +using namespace SFCGAL; -BOOST_AUTO_TEST_SUITE( SFCGAL_io_SerializationTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_io_SerializationTest) -BOOST_AUTO_TEST_CASE( textTest ) +BOOST_AUTO_TEST_CASE(textTest) { - Coordinate pt1( 2.3, 8.9 ); - Coordinate rpt1; - // 2/3 - CGAL::Gmpq q1( 2, 3 ); - CGAL::Gmpq rq1; - - std::ostringstream ostr; - boost::archive::text_oarchive arc( ostr ); - arc << pt1; - arc << q1; - - std::string str = ostr.str(); - - std::istringstream istr( str ); - boost::archive::text_iarchive iarc( istr ); - iarc >> rpt1; - iarc >> rq1; - - BOOST_CHECK( pt1 == rpt1 ); - BOOST_CHECK( q1 == rq1 ); + Coordinate const pt1(2.3, 8.9); + Coordinate rpt1; + // 2/3 + CGAL::Gmpq const q1(2, 3); + CGAL::Gmpq rq1; + + std::ostringstream ostr; + boost::archive::text_oarchive arc(ostr); + arc << pt1; + arc << q1; + + std::string const str = ostr.str(); + + std::istringstream istr(str); + boost::archive::text_iarchive iarc(istr); + iarc >> rpt1; + iarc >> rq1; + + BOOST_CHECK(pt1 == rpt1); + BOOST_CHECK(q1 == rq1); } -BOOST_AUTO_TEST_CASE( binaryTest ) +BOOST_AUTO_TEST_CASE(binaryTest) { - Coordinate pt( 2.3, 4.5 ); - Coordinate rpt; + Coordinate const pt(2.3, 4.5); + Coordinate rpt; - std::ostringstream ostr; - io::BinarySerializer arc( ostr ); - arc << pt; + std::ostringstream ostr; + io::BinarySerializer arc(ostr); + arc << pt; - std::string str = ostr.str(); + std::string const str = ostr.str(); - std::istringstream istr( str ); - io::BinaryUnserializer iarc( istr ); - iarc >> rpt; + std::istringstream istr(str); + io::BinaryUnserializer iarc(istr); + iarc >> rpt; - BOOST_CHECK( pt == rpt ); + BOOST_CHECK(pt == rpt); } -BOOST_AUTO_TEST_CASE( geometryTest ) +BOOST_AUTO_TEST_CASE(geometryTest) { - std::unique_ptr g1 = io::readWkt( "POINT( 3.4 4.5 5.6 )" ); - std::unique_ptr g2 = io::readWkt( "LINESTRING( 3.4 4.5 5.6, 5 6 8 )" ); - std::unique_ptr g3 = io::readWkt( "TRIANGLE(( 0 0 0, 3.4 5.6 6.7,2 3 4, 0 0 0))" ); - std::unique_ptr g4 = io::readWkt( "POLYGON(( 0 0 0, 1 1 1, 3.4 5.6 6.7,2 3 4, 0 0 0))" ); - std::unique_ptr g5 = io::readWkt( "TIN((( 0 0 0, 3.4 5.6 6.7,2 3 4, 0 0 0)), ((0 0 0,0 1 0,1 1 0,0 0 0)))" ); - std::unique_ptr g6 = io::readWkt( "POLYHEDRALSURFACE((( 0 0 0, 3.4 5.6 6.7,2 3 4, 0 0 0)), ((0 0 0,0 1 0,1 1 0,1 0 0,0 0 0)))" ); - std::unique_ptr g7 = io::readWkt( "SOLID(((( 0 0 0, 3.4 5.6 6.7,2 3 4, 0 0 0)), ((0 0 0,0 1 0,1 1 0,1 0 0,0 0 0))))" ); - std::unique_ptr g8 = io::readWkt( "MULTIPOINT(( 3.4 4.5 5.6 ))" ); - std::unique_ptr g9 = io::readWkt( "MULTILINESTRING(( 3.4 4.5 5.6, 5 6 8 ))" ); - std::unique_ptr g10 = io::readWkt( "MULTIPOLYGON((( 0 0 0, 1 1 1, 3.4 5.6 6.7,2 3 4, 0 0 0)))" ); - std::unique_ptr g11 = io::readWkt( "MULTISOLID((((( 0 0 0, 3.4 5.6 6.7,2 3 4, 0 0 0)), ((0 0 0,0 1 0,1 1 0,1 0 0,0 0 0)))))" ); - - BOOST_CHECK( io::readBinaryGeometry( io::writeBinaryGeometry( *g1 ) )->asText() == g1->asText() ); - BOOST_CHECK( io::readBinaryGeometry( io::writeBinaryGeometry( *g2 ) )->asText() == g2->asText() ); - BOOST_CHECK( io::readBinaryGeometry( io::writeBinaryGeometry( *g3 ) )->asText() == g3->asText() ); - BOOST_CHECK( io::readBinaryGeometry( io::writeBinaryGeometry( *g4 ) )->asText() == g4->asText() ); - BOOST_CHECK( io::readBinaryGeometry( io::writeBinaryGeometry( *g5 ) )->asText() == g5->asText() ); - BOOST_CHECK( io::readBinaryGeometry( io::writeBinaryGeometry( *g6 ) )->asText() == g6->asText() ); - BOOST_CHECK( io::readBinaryGeometry( io::writeBinaryGeometry( *g7 ) )->asText() == g7->asText() ); - BOOST_CHECK( io::readBinaryGeometry( io::writeBinaryGeometry( *g8 ) )->asText() == g8->asText() ); - BOOST_CHECK( io::readBinaryGeometry( io::writeBinaryGeometry( *g9 ) )->asText() == g9->asText() ); - BOOST_CHECK( io::readBinaryGeometry( io::writeBinaryGeometry( *g10 ) )->asText() == g10->asText() ); - BOOST_CHECK( io::readBinaryGeometry( io::writeBinaryGeometry( *g11 ) )->asText() == g11->asText() ); - + std::unique_ptr g1 = io::readWkt("POINT( 3.4 4.5 5.6 )"); + std::unique_ptr g2 = + io::readWkt("LINESTRING( 3.4 4.5 5.6, 5 6 8 )"); + std::unique_ptr g3 = + io::readWkt("TRIANGLE(( 0 0 0, 3.4 5.6 6.7,2 3 4, 0 0 0))"); + std::unique_ptr g4 = + io::readWkt("POLYGON(( 0 0 0, 1 1 1, 3.4 5.6 6.7,2 3 4, 0 0 0))"); + std::unique_ptr g5 = io::readWkt( + "TIN((( 0 0 0, 3.4 5.6 6.7,2 3 4, 0 0 0)), ((0 0 0,0 1 0,1 1 0,0 0 0)))"); + std::unique_ptr g6 = + io::readWkt("POLYHEDRALSURFACE((( 0 0 0, 3.4 5.6 6.7,2 3 4, 0 0 0)), ((0 " + "0 0,0 1 0,1 1 0,1 0 0,0 0 0)))"); + std::unique_ptr g7 = + io::readWkt("SOLID(((( 0 0 0, 3.4 5.6 6.7,2 3 4, 0 0 0)), ((0 0 0,0 1 " + "0,1 1 0,1 0 0,0 0 0))))"); + std::unique_ptr g8 = io::readWkt("MULTIPOINT(( 3.4 4.5 5.6 ))"); + std::unique_ptr g9 = + io::readWkt("MULTILINESTRING(( 3.4 4.5 5.6, 5 6 8 ))"); + std::unique_ptr g10 = + io::readWkt("MULTIPOLYGON((( 0 0 0, 1 1 1, 3.4 5.6 6.7,2 3 4, 0 0 0)))"); + std::unique_ptr g11 = + io::readWkt("MULTISOLID((((( 0 0 0, 3.4 5.6 6.7,2 3 4, 0 0 0)), ((0 0 " + "0,0 1 0,1 1 0,1 0 0,0 0 0)))))"); + + BOOST_CHECK(io::readBinaryGeometry(io::writeBinaryGeometry(*g1))->asText() == + g1->asText()); + BOOST_CHECK(io::readBinaryGeometry(io::writeBinaryGeometry(*g2))->asText() == + g2->asText()); + BOOST_CHECK(io::readBinaryGeometry(io::writeBinaryGeometry(*g3))->asText() == + g3->asText()); + BOOST_CHECK(io::readBinaryGeometry(io::writeBinaryGeometry(*g4))->asText() == + g4->asText()); + BOOST_CHECK(io::readBinaryGeometry(io::writeBinaryGeometry(*g5))->asText() == + g5->asText()); + BOOST_CHECK(io::readBinaryGeometry(io::writeBinaryGeometry(*g6))->asText() == + g6->asText()); + BOOST_CHECK(io::readBinaryGeometry(io::writeBinaryGeometry(*g7))->asText() == + g7->asText()); + BOOST_CHECK(io::readBinaryGeometry(io::writeBinaryGeometry(*g8))->asText() == + g8->asText()); + BOOST_CHECK(io::readBinaryGeometry(io::writeBinaryGeometry(*g9))->asText() == + g9->asText()); + BOOST_CHECK(io::readBinaryGeometry(io::writeBinaryGeometry(*g10))->asText() == + g10->asText()); + BOOST_CHECK(io::readBinaryGeometry(io::writeBinaryGeometry(*g11))->asText() == + g11->asText()); } -BOOST_AUTO_TEST_CASE( caseTest ) +BOOST_AUTO_TEST_CASE(caseTest) { - std::unique_ptr g1 = io::readWkt( "PoInT( 3.4 4.5 5.6 )" ); - BOOST_CHECK( io::readBinaryGeometry( io::writeBinaryGeometry( *g1 ) )->asText() == g1->asText() ); + std::unique_ptr g1 = io::readWkt("PoInT( 3.4 4.5 5.6 )"); + BOOST_CHECK(io::readBinaryGeometry(io::writeBinaryGeometry(*g1))->asText() == + g1->asText()); } -BOOST_AUTO_TEST_CASE( extBinaryTest ) +BOOST_AUTO_TEST_CASE(extBinaryTest) { - std::unique_ptr ng1 = io::readWkt( "POLYGON((9.70065196277574 -2.37991360574961,3.74221071600914 5.33515858836472,-4.30443822173402 -2.37991360574961,3.74221071600914 -12.1891073728912,9.70065196277574 -2.37991360574961))" ); - SFCGAL::Geometry* mg1 = ng1.release(); - SFCGAL::Geometry* ng2 = nullptr; - - std::string str; - std::ostringstream ostr( str ); - io::BinarySerializer arc( ostr ); - arc << mg1; - - std::istringstream istr( ostr.str() ); - io::BinaryUnserializer iarc( istr ); - iarc >> ng2; - - BOOST_CHECK( mg1->asText() == ng2->asText() ); - delete mg1; - delete ng2; + std::unique_ptr ng1 = io::readWkt( + "POLYGON((9.70065196277574 -2.37991360574961,3.74221071600914 " + "5.33515858836472,-4.30443822173402 -2.37991360574961,3.74221071600914 " + "-12.1891073728912,9.70065196277574 -2.37991360574961))"); + SFCGAL::Geometry *mg1 = ng1.release(); + SFCGAL::Geometry *ng2 = nullptr; + + std::string const str; + std::ostringstream ostr(str); + io::BinarySerializer arc(ostr); + arc << mg1; + + std::istringstream istr(ostr.str()); + io::BinaryUnserializer iarc(istr); + iarc >> ng2; + + BOOST_CHECK(mg1->asText() == ng2->asText()); + delete mg1; + delete ng2; } -BOOST_AUTO_TEST_CASE( preparedGeometryTest ) +BOOST_AUTO_TEST_CASE(preparedGeometryTest) { - std::unique_ptr g1 = io::readEwkt( "POINT( 3.4 4.5 5.6 )" ); - std::unique_ptr g2 = io::readEwkt( "srid=0;POINT( 3.4 4.5 5.6 )" ); - std::unique_ptr g3 = io::readEwkt( "srid=4326;POINT( 3.4 4.5 5.6 )" ); - - BOOST_CHECK( io::readBinaryPrepared( io::writeBinaryPrepared( *g1 ) )->asEWKT() == g1->asEWKT() ); - BOOST_CHECK( io::readBinaryPrepared( io::writeBinaryPrepared( *g2 ) )->asEWKT() == g2->asEWKT() ); - BOOST_CHECK( io::readBinaryPrepared( io::writeBinaryPrepared( *g3 ) )->asEWKT() == g3->asEWKT() ); + std::unique_ptr g1 = io::readEwkt("POINT( 3.4 4.5 5.6 )"); + std::unique_ptr g2 = + io::readEwkt("srid=0;POINT( 3.4 4.5 5.6 )"); + std::unique_ptr g3 = + io::readEwkt("srid=4326;POINT( 3.4 4.5 5.6 )"); + + BOOST_CHECK(io::readBinaryPrepared(io::writeBinaryPrepared(*g1))->asEWKT() == + g1->asEWKT()); + BOOST_CHECK(io::readBinaryPrepared(io::writeBinaryPrepared(*g2))->asEWKT() == + g2->asEWKT()); + BOOST_CHECK(io::readBinaryPrepared(io::writeBinaryPrepared(*g3))->asEWKT() == + g3->asEWKT()); } BOOST_AUTO_TEST_SUITE_END() - - - diff --git a/test/unit/SFCGAL/io/WkbWriterTest.cpp b/test/unit/SFCGAL/io/WkbWriterTest.cpp index 1c2268cd..8cba6247 100644 --- a/test/unit/SFCGAL/io/WkbWriterTest.cpp +++ b/test/unit/SFCGAL/io/WkbWriterTest.cpp @@ -104,7 +104,7 @@ BOOST_AUTO_TEST_CASE(PostgisEWkb) while (std::getline(ifs, inputWkb)) { std::getline(efs, expectedWkt); std::unique_ptr gWkt(io::readWkt(expectedWkt)); - std::string ewkt = "SRID=3946;" + expectedWkt; + std::string const ewkt = "SRID=3946;" + expectedWkt; std::unique_ptr gEwkt(io::readEwkt(ewkt)); if (!(expectedWkt.find("EMPTY") != std::string::npos) && !inputWkb.empty()) { diff --git a/test/unit/SFCGAL/io/WktReaderTest.cpp b/test/unit/SFCGAL/io/WktReaderTest.cpp index 9a12f921..f8404320 100644 --- a/test/unit/SFCGAL/io/WktReaderTest.cpp +++ b/test/unit/SFCGAL/io/WktReaderTest.cpp @@ -15,290 +15,272 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include #include -#include -#include -#include -#include -#include -#include -#include #include -#include +#include #include +#include #include #include +#include +#include +#include +#include +#include +#include #include #include -using namespace boost::unit_test ; - -using namespace SFCGAL ; -using namespace SFCGAL::io ; +using namespace boost::unit_test; +using namespace SFCGAL; +using namespace SFCGAL::io; -BOOST_AUTO_TEST_SUITE( SFCGAL_io_WktReaderTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_io_WktReaderTest) //-- WKT POINT -BOOST_AUTO_TEST_CASE( pointEmpty ) +BOOST_AUTO_TEST_CASE(pointEmpty) { - std::unique_ptr< Geometry > g( readWkt( "POINT EMPTY" ) ); - BOOST_CHECK( g->is< Point >() ); - BOOST_CHECK( g->isEmpty() ); + std::unique_ptr g(readWkt("POINT EMPTY")); + BOOST_CHECK(g->is()); + BOOST_CHECK(g->isEmpty()); } - -BOOST_AUTO_TEST_CASE( pointXY ) +BOOST_AUTO_TEST_CASE(pointXY) { - std::unique_ptr< Geometry > g( readWkt( "POINT(4.0 6.0)" ) ); - BOOST_CHECK( g->is< Point >() ); - BOOST_CHECK( ! g->isEmpty() ); + std::unique_ptr g(readWkt("POINT(4.0 6.0)")); + BOOST_CHECK(g->is()); + BOOST_CHECK(!g->isEmpty()); - BOOST_CHECK_EQUAL( g->as< Point >().x(), 4.0 ); - BOOST_CHECK_EQUAL( g->as< Point >().y(), 6.0 ); + BOOST_CHECK_EQUAL(g->as().x(), 4.0); + BOOST_CHECK_EQUAL(g->as().y(), 6.0); } -BOOST_AUTO_TEST_CASE( pointXYZ_implicit ) +BOOST_AUTO_TEST_CASE(pointXYZ_implicit) { - std::unique_ptr< Geometry > g( readWkt( "POINT(4.0 5.0 6.0)" ) ); - BOOST_CHECK( g->is< Point >() ); - BOOST_CHECK( ! g->isEmpty() ); + std::unique_ptr g(readWkt("POINT(4.0 5.0 6.0)")); + BOOST_CHECK(g->is()); + BOOST_CHECK(!g->isEmpty()); - BOOST_CHECK( g->is3D() ); - BOOST_CHECK( ! g->isMeasured() ); + BOOST_CHECK(g->is3D()); + BOOST_CHECK(!g->isMeasured()); - BOOST_CHECK_EQUAL( g->as< Point >().x(), 4.0 ); - BOOST_CHECK_EQUAL( g->as< Point >().y(), 5.0 ); - BOOST_CHECK_EQUAL( g->as< Point >().z(), 6.0 ); + BOOST_CHECK_EQUAL(g->as().x(), 4.0); + BOOST_CHECK_EQUAL(g->as().y(), 5.0); + BOOST_CHECK_EQUAL(g->as().z(), 6.0); } -BOOST_AUTO_TEST_CASE( pointXYZ_explicit ) +BOOST_AUTO_TEST_CASE(pointXYZ_explicit) { - std::unique_ptr< Geometry > g( readWkt( "POINT Z(4.0 5.0 6.0)" ) ); - BOOST_CHECK( g->is< Point >() ); - BOOST_CHECK( ! g->isEmpty() ); + std::unique_ptr g(readWkt("POINT Z(4.0 5.0 6.0)")); + BOOST_CHECK(g->is()); + BOOST_CHECK(!g->isEmpty()); - BOOST_CHECK( g->is3D() ); - BOOST_CHECK( ! g->isMeasured() ); + BOOST_CHECK(g->is3D()); + BOOST_CHECK(!g->isMeasured()); - BOOST_CHECK_EQUAL( g->as< Point >().x(), 4.0 ); - BOOST_CHECK_EQUAL( g->as< Point >().y(), 5.0 ); - BOOST_CHECK_EQUAL( g->as< Point >().z(), 6.0 ); + BOOST_CHECK_EQUAL(g->as().x(), 4.0); + BOOST_CHECK_EQUAL(g->as().y(), 5.0); + BOOST_CHECK_EQUAL(g->as().z(), 6.0); } - -BOOST_AUTO_TEST_CASE( pointXYM_explicit ) +BOOST_AUTO_TEST_CASE(pointXYM_explicit) { - std::unique_ptr< Geometry > g( readWkt( "POINT M(4.0 5.0 6.0)" ) ); - BOOST_CHECK( g->is< Point >() ); - BOOST_CHECK( ! g->isEmpty() ); + std::unique_ptr g(readWkt("POINT M(4.0 5.0 6.0)")); + BOOST_CHECK(g->is()); + BOOST_CHECK(!g->isEmpty()); - BOOST_CHECK( ! g->is3D() ); - BOOST_CHECK( g->isMeasured() ); + BOOST_CHECK(!g->is3D()); + BOOST_CHECK(g->isMeasured()); - BOOST_CHECK_EQUAL( g->as< Point >().x(), 4.0 ); - BOOST_CHECK_EQUAL( g->as< Point >().y(), 5.0 ); - BOOST_CHECK_EQUAL( g->as< Point >().m(), 6.0 ); + BOOST_CHECK_EQUAL(g->as().x(), 4.0); + BOOST_CHECK_EQUAL(g->as().y(), 5.0); + BOOST_CHECK_EQUAL(g->as().m(), 6.0); } //-- WKT LINESTRING - -BOOST_AUTO_TEST_CASE( lineStringEmpty ) +BOOST_AUTO_TEST_CASE(lineStringEmpty) { - std::unique_ptr< Geometry > g( readWkt( "LINESTRING EMPTY" ) ); - BOOST_CHECK( g->is< LineString >() ); - BOOST_CHECK( g->isEmpty() ); + std::unique_ptr g(readWkt("LINESTRING EMPTY")); + BOOST_CHECK(g->is()); + BOOST_CHECK(g->isEmpty()); } -BOOST_AUTO_TEST_CASE( lineString_twoPoints ) +BOOST_AUTO_TEST_CASE(lineString_twoPoints) { - std::unique_ptr< Geometry > g( readWkt( "LINESTRING(0.0 0.0,1.0 1.0)" ) ); - BOOST_CHECK( g->is< LineString >() ); - BOOST_CHECK( ! g->isEmpty() ); - BOOST_CHECK_EQUAL( g->as< LineString >().numPoints(), 2U ); + std::unique_ptr g(readWkt("LINESTRING(0.0 0.0,1.0 1.0)")); + BOOST_CHECK(g->is()); + BOOST_CHECK(!g->isEmpty()); + BOOST_CHECK_EQUAL(g->as().numPoints(), 2U); } -BOOST_AUTO_TEST_CASE( lineString_twoPoints3D ) +BOOST_AUTO_TEST_CASE(lineString_twoPoints3D) { - std::unique_ptr< Geometry > g( readWkt( "LINESTRING(0.0 0.0 0.0,1.0 1.0 1.0)" ) ); - BOOST_CHECK( g->is< LineString >() ); - BOOST_CHECK( ! g->isEmpty() ); - BOOST_REQUIRE_EQUAL( g->as< LineString >().numPoints(), 2U ); - BOOST_CHECK( g->as< LineString >().pointN( 0 ).is3D() ); - BOOST_CHECK( g->as< LineString >().pointN( 1 ).is3D() ); + std::unique_ptr g(readWkt("LINESTRING(0.0 0.0 0.0,1.0 1.0 1.0)")); + BOOST_CHECK(g->is()); + BOOST_CHECK(!g->isEmpty()); + BOOST_REQUIRE_EQUAL(g->as().numPoints(), 2U); + BOOST_CHECK(g->as().pointN(0).is3D()); + BOOST_CHECK(g->as().pointN(1).is3D()); } //-- WKT POLYGON - -BOOST_AUTO_TEST_CASE( polygonEmpty ) +BOOST_AUTO_TEST_CASE(polygonEmpty) { - std::unique_ptr< Geometry > g( readWkt( "POLYGON EMPTY" ) ); - BOOST_CHECK( g->is< Polygon >() ); - BOOST_CHECK( g->isEmpty() ); + std::unique_ptr g(readWkt("POLYGON EMPTY")); + BOOST_CHECK(g->is()); + BOOST_CHECK(g->isEmpty()); } - // 4 points polygon (triangle) -BOOST_AUTO_TEST_CASE( polygonWithFourPoints ) +BOOST_AUTO_TEST_CASE(polygonWithFourPoints) { - std::unique_ptr< Geometry > g( readWkt( "POLYGON((0 0,1 0,1 1,0 0))" ) ); - BOOST_CHECK( g->is< Polygon >() ); - BOOST_CHECK( ! g->isEmpty() ); - BOOST_CHECK_EQUAL( g->as< Polygon >().exteriorRing().numPoints(), 4U ); + std::unique_ptr g(readWkt("POLYGON((0 0,1 0,1 1,0 0))")); + BOOST_CHECK(g->is()); + BOOST_CHECK(!g->isEmpty()); + BOOST_CHECK_EQUAL(g->as().exteriorRing().numPoints(), 4U); } - - - //-- WKT MULTIPOINT -BOOST_AUTO_TEST_CASE( multiPointEmpty ) +BOOST_AUTO_TEST_CASE(multiPointEmpty) { - std::unique_ptr< Geometry > g( readWkt( "MULTIPOINT EMPTY" ) ); - BOOST_CHECK( g->is< MultiPoint >() ); - BOOST_CHECK( g->isEmpty() ); + std::unique_ptr g(readWkt("MULTIPOINT EMPTY")); + BOOST_CHECK(g->is()); + BOOST_CHECK(g->isEmpty()); } -BOOST_AUTO_TEST_CASE( multiPointEmpty2 ) +BOOST_AUTO_TEST_CASE(multiPointEmpty2) { - std::unique_ptr< Geometry > g( readWkt( "MULTIPOINT(0 0,1 1,EMPTY)" ) ); - BOOST_CHECK( g->asText() == "MULTIPOINT((0/1 0/1),(1/1 1/1))" ); - BOOST_CHECK( g->is< MultiPoint >() ); - BOOST_CHECK( g->numGeometries() == 2 ); + std::unique_ptr g(readWkt("MULTIPOINT(0 0,1 1,EMPTY)")); + BOOST_CHECK(g->asText() == "MULTIPOINT((0/1 0/1),(1/1 1/1))"); + BOOST_CHECK(g->is()); + BOOST_CHECK(g->numGeometries() == 2); } -BOOST_AUTO_TEST_CASE( multiPointEmpty3 ) +BOOST_AUTO_TEST_CASE(multiPointEmpty3) { - std::unique_ptr< Geometry > g( readWkt( "MULTIPOINT(EMPTY,EMPTY)" ) ); - BOOST_CHECK( g->asText() == "MULTIPOINT EMPTY" ); - BOOST_CHECK( g->is< MultiPoint >() ); - BOOST_CHECK( g->isEmpty() ); + std::unique_ptr g(readWkt("MULTIPOINT(EMPTY,EMPTY)")); + BOOST_CHECK(g->asText() == "MULTIPOINT EMPTY"); + BOOST_CHECK(g->is()); + BOOST_CHECK(g->isEmpty()); } //-- WKT MULTILINESTRING -BOOST_AUTO_TEST_CASE( multiLineStringEmpty ) +BOOST_AUTO_TEST_CASE(multiLineStringEmpty) { - std::unique_ptr< Geometry > g( readWkt( "MULTILINESTRING EMPTY" ) ); - BOOST_CHECK( g->is< MultiLineString >() ); - BOOST_CHECK( g->isEmpty() ); + std::unique_ptr g(readWkt("MULTILINESTRING EMPTY")); + BOOST_CHECK(g->is()); + BOOST_CHECK(g->isEmpty()); } - //-- WKT MULTIPOLYGON -BOOST_AUTO_TEST_CASE( multiPolygonEmpty ) +BOOST_AUTO_TEST_CASE(multiPolygonEmpty) { - std::unique_ptr< Geometry > g( readWkt( "MULTIPOLYGON EMPTY" ) ); - BOOST_CHECK( g->is< MultiPolygon >() ); - BOOST_CHECK( g->isEmpty() ); + std::unique_ptr g(readWkt("MULTIPOLYGON EMPTY")); + BOOST_CHECK(g->is()); + BOOST_CHECK(g->isEmpty()); } - - //-- WKT GEOMETRYCOLLECTION -BOOST_AUTO_TEST_CASE( geometryCollectionEmpty ) +BOOST_AUTO_TEST_CASE(geometryCollectionEmpty) { - std::unique_ptr< Geometry > g( readWkt( "GEOMETRYCOLLECTION EMPTY" ) ); - BOOST_CHECK( g->is< GeometryCollection >() ); - BOOST_CHECK( g->isEmpty() ); + std::unique_ptr g(readWkt("GEOMETRYCOLLECTION EMPTY")); + BOOST_CHECK(g->is()); + BOOST_CHECK(g->isEmpty()); } - - //-- WKT TRIANGULATEDSURFACE -BOOST_AUTO_TEST_CASE( triangulatedSurface_Empty ) +BOOST_AUTO_TEST_CASE(triangulatedSurface_Empty) { - std::unique_ptr< Geometry > g( readWkt( "TIN EMPTY" ) ); - BOOST_CHECK( g->is< TriangulatedSurface >() ); - BOOST_CHECK( g->isEmpty() ); + std::unique_ptr g(readWkt("TIN EMPTY")); + BOOST_CHECK(g->is()); + BOOST_CHECK(g->isEmpty()); } -BOOST_AUTO_TEST_CASE( triangulatedSurface_fourTriangles ) +BOOST_AUTO_TEST_CASE(triangulatedSurface_fourTriangles) { - std::string wkt = "TIN(" - "((0 0 0, 0 0 1, 0 1 0, 0 0 0))," - "((0 0 0, 0 1 0, 1 0 0, 0 0 0))," - "((0 0 0, 1 0 0, 0 0 1, 0 0 0))," - "((1 0 0, 0 1 0, 0 0 1, 1 0 0))" - ")"; - std::unique_ptr< Geometry > g( readWkt( wkt ) ); - BOOST_CHECK( g->is< TriangulatedSurface >() ); - BOOST_CHECK( ! g->isEmpty() ); - - BOOST_CHECK_EQUAL( g->as< TriangulatedSurface >().numGeometries(), 4U ); + std::string const wkt = "TIN(" + "((0 0 0, 0 0 1, 0 1 0, 0 0 0))," + "((0 0 0, 0 1 0, 1 0 0, 0 0 0))," + "((0 0 0, 1 0 0, 0 0 1, 0 0 0))," + "((1 0 0, 0 1 0, 0 0 1, 1 0 0))" + ")"; + std::unique_ptr g(readWkt(wkt)); + BOOST_CHECK(g->is()); + BOOST_CHECK(!g->isEmpty()); + + BOOST_CHECK_EQUAL(g->as().numGeometries(), 4U); } -BOOST_AUTO_TEST_CASE( wkt_exactTest ) +BOOST_AUTO_TEST_CASE(wkt_exactTest) { - std::unique_ptr< Geometry > g( readWkt( "LINESTRING(2/3 3/2,5/4 2/3)" ) ); - BOOST_CHECK( g->is< LineString >() ); - BOOST_CHECK( ! g->isEmpty() ); - BOOST_REQUIRE_EQUAL( g->as< LineString >().numPoints(), 2U ); - Kernel::Exact_kernel::FT x = CGAL::exact( g->as().pointN( 0 ).x() ); - Kernel::Exact_kernel::FT y = CGAL::exact( g->as().pointN( 0 ).y() ); - - CGAL::Fraction_traits::Numerator_type xn, xd, yn, yd; - CGAL::Fraction_traits::Decompose decomp; - decomp(x, xn, xd); - decomp(y, yn, yd); - - BOOST_CHECK_EQUAL( xn, 2 ); - BOOST_CHECK_EQUAL( xd, 3 ); - BOOST_CHECK_EQUAL( yn, 3 ); - BOOST_CHECK_EQUAL( yd, 2 ); + std::unique_ptr g(readWkt("LINESTRING(2/3 3/2,5/4 2/3)")); + BOOST_CHECK(g->is()); + BOOST_CHECK(!g->isEmpty()); + BOOST_REQUIRE_EQUAL(g->as().numPoints(), 2U); + Kernel::Exact_kernel::FT const x = + CGAL::exact(g->as().pointN(0).x()); + Kernel::Exact_kernel::FT const y = + CGAL::exact(g->as().pointN(0).y()); + + CGAL::Fraction_traits::Numerator_type xn; + CGAL::Fraction_traits::Numerator_type xd; + CGAL::Fraction_traits::Numerator_type yn; + CGAL::Fraction_traits::Numerator_type yd; + CGAL::Fraction_traits::Decompose decomp; + decomp(x, xn, xd); + decomp(y, yn, yd); + + BOOST_CHECK_EQUAL(xn, 2); + BOOST_CHECK_EQUAL(xd, 3); + BOOST_CHECK_EQUAL(yn, 3); + BOOST_CHECK_EQUAL(yd, 2); } -BOOST_AUTO_TEST_CASE( charArrayRead ) +BOOST_AUTO_TEST_CASE(charArrayRead) { - char str[] = "LINESTRING(0.0 0.0,1.0 1.0)"; - std::unique_ptr< Geometry > g( readWkt( str, strlen( str ) ) ); - BOOST_CHECK( g->is< LineString >() ); - BOOST_CHECK( ! g->isEmpty() ); - BOOST_CHECK_EQUAL( g->as< LineString >().numPoints(), 2U ); + char str[] = "LINESTRING(0.0 0.0,1.0 1.0)"; + std::unique_ptr g(readWkt(str, strlen(str))); + BOOST_CHECK(g->is()); + BOOST_CHECK(!g->isEmpty()); + BOOST_CHECK_EQUAL(g->as().numPoints(), 2U); } -BOOST_AUTO_TEST_CASE( wktExtraCharacters ) +BOOST_AUTO_TEST_CASE(wktExtraCharacters) { - bool threw = false; - try - { - std::unique_ptr< Geometry > g( readWkt( "POINT(0 0)POINT(1 0)" ) ); - } - catch ( WktParseException& e ) - { - std::string err( e.what() ); - BOOST_CHECK_EQUAL( err, "Extra characters in WKT: POINT(1 0)" ); - threw = true; - } - BOOST_CHECK( threw ); - - threw = false; - try - { - char str[] = "POINT(0 0)POINT(1 0)"; - std::unique_ptr< Geometry > g( readWkt( str, strlen( str ) ) ); - } - catch ( WktParseException& e ) - { - std::string err( e.what() ); - BOOST_CHECK_EQUAL( err, "Extra characters in WKT: POINT(1 0)" ); - threw = true; - } - BOOST_CHECK( threw ); + bool threw = false; + try { + std::unique_ptr const g(readWkt("POINT(0 0)POINT(1 0)")); + } catch (WktParseException &e) { + std::string const err(e.what()); + BOOST_CHECK_EQUAL(err, "Extra characters in WKT: POINT(1 0)"); + threw = true; + } + BOOST_CHECK(threw); + + threw = false; + try { + char str[] = "POINT(0 0)POINT(1 0)"; + std::unique_ptr const g(readWkt(str, strlen(str))); + } catch (WktParseException &e) { + std::string const err(e.what()); + BOOST_CHECK_EQUAL(err, "Extra characters in WKT: POINT(1 0)"); + threw = true; + } + BOOST_CHECK(threw); } - BOOST_AUTO_TEST_SUITE_END() - - - diff --git a/test/unit/SFCGAL/transform/AffineTransform2Test.cpp b/test/unit/SFCGAL/transform/AffineTransform2Test.cpp index dbd2950a..b5f5ec29 100644 --- a/test/unit/SFCGAL/transform/AffineTransform2Test.cpp +++ b/test/unit/SFCGAL/transform/AffineTransform2Test.cpp @@ -15,7 +15,8 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include @@ -23,31 +24,23 @@ #include #include -using namespace boost::unit_test ; -using namespace SFCGAL ; +using namespace boost::unit_test; +using namespace SFCGAL; -BOOST_AUTO_TEST_SUITE( SFCGAL_transform_AffineTransform2Test ) +BOOST_AUTO_TEST_SUITE(SFCGAL_transform_AffineTransform2Test) -BOOST_AUTO_TEST_CASE( simpleTranslate ) +BOOST_AUTO_TEST_CASE(simpleTranslate) { - LineString g( Point( 0.0,0.0 ), Point( 1.0,1.0 ) ) ; + LineString g(Point(0.0, 0.0), Point(1.0, 1.0)); - CGAL::Aff_transformation_2< Kernel > affine( - CGAL::TRANSLATION, - CGAL::Vector_2< Kernel >( 1.0,2.0 ) - ); + CGAL::Aff_transformation_2 const affine( + CGAL::TRANSLATION, CGAL::Vector_2(1.0, 2.0)); - transform::AffineTransform2 transform( affine ) ; - g.accept( transform ); + transform::AffineTransform2 transform(affine); + g.accept(transform); - BOOST_CHECK_EQUAL( g.pointN( 0 ).asText( 5 ), "POINT(1.00000 2.00000)" ); - BOOST_CHECK_EQUAL( g.pointN( 1 ).asText( 5 ), "POINT(2.00000 3.00000)" ); + BOOST_CHECK_EQUAL(g.pointN(0).asText(5), "POINT(1.00000 2.00000)"); + BOOST_CHECK_EQUAL(g.pointN(1).asText(5), "POINT(2.00000 3.00000)"); } - - BOOST_AUTO_TEST_SUITE_END() - - - - diff --git a/test/unit/SFCGAL/transform/ForceZOrderPointsTest.cpp b/test/unit/SFCGAL/transform/ForceZOrderPointsTest.cpp index 779506e4..01f78e98 100644 --- a/test/unit/SFCGAL/transform/ForceZOrderPointsTest.cpp +++ b/test/unit/SFCGAL/transform/ForceZOrderPointsTest.cpp @@ -15,39 +15,34 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include #include -#include -#include #include +#include #include +#include -using namespace boost::unit_test ; -using namespace SFCGAL ; +using namespace boost::unit_test; +using namespace SFCGAL; -BOOST_AUTO_TEST_SUITE( SFCGAL_transform_ForceZOrderPointsTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_transform_ForceZOrderPointsTest) -BOOST_AUTO_TEST_CASE( simple ) +BOOST_AUTO_TEST_CASE(simple) { - std::unique_ptr g1 = io::readWkt( "POLYGON((0 0,0 1,1 1,1 0,0 0))" ); + std::unique_ptr g1 = io::readWkt("POLYGON((0 0,0 1,1 1,1 0,0 0))"); - const Polygon& p = g1->as(); - BOOST_CHECK( ! p.isCounterClockWiseOriented() ); + const Polygon &p = g1->as(); + BOOST_CHECK(!p.isCounterClockWiseOriented()); - transform::ForceZOrderPoints forceZ; - g1->accept( forceZ ); + transform::ForceZOrderPoints forceZ; + g1->accept(forceZ); - BOOST_CHECK( g1->is3D() ); - BOOST_CHECK( g1->as().isCounterClockWiseOriented() ); + BOOST_CHECK(g1->is3D()); + BOOST_CHECK(g1->as().isCounterClockWiseOriented()); } - - BOOST_AUTO_TEST_SUITE_END() - - - - diff --git a/test/unit/SFCGAL/transform/RoundTest.cpp b/test/unit/SFCGAL/transform/RoundTest.cpp index 8976a93c..a1098a14 100644 --- a/test/unit/SFCGAL/transform/RoundTest.cpp +++ b/test/unit/SFCGAL/transform/RoundTest.cpp @@ -15,45 +15,42 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include -#include -#include -#include -#include -#include -#include -#include #include -#include +#include #include +#include #include #include +#include +#include +#include +#include +#include +#include #include -using namespace boost::unit_test ; -using namespace SFCGAL ; +using namespace boost::unit_test; +using namespace SFCGAL; -BOOST_AUTO_TEST_SUITE( SFCGAL_CoordinateTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_CoordinateTest) -BOOST_AUTO_TEST_CASE( testRoundPoint ) +BOOST_AUTO_TEST_CASE(testRoundPoint) { - std::unique_ptr< Geometry > g( io::readWkt( "POINT(1.5 2.6 3.4)" ) ); - g->round(); - BOOST_CHECK_EQUAL( g->asText(), "POINT Z(2/1 3/1 3/1)" ); + std::unique_ptr g(io::readWkt("POINT(1.5 2.6 3.4)")); + g->round(); + BOOST_CHECK_EQUAL(g->asText(), "POINT Z(2/1 3/1 3/1)"); } -BOOST_AUTO_TEST_CASE( testRoundLineString ) +BOOST_AUTO_TEST_CASE(testRoundLineString) { - std::unique_ptr< Geometry > g( io::readWkt( "LINESTRING(0.5 0.5,1.5 1.5)" ) ); - g->round( 10 ); - BOOST_CHECK_EQUAL( g->asText(), "LINESTRING(1/2 1/2,3/2 3/2)" ); + std::unique_ptr g(io::readWkt("LINESTRING(0.5 0.5,1.5 1.5)")); + g->round(10); + BOOST_CHECK_EQUAL(g->asText(), "LINESTRING(1/2 1/2,3/2 3/2)"); } BOOST_AUTO_TEST_SUITE_END() - - - - diff --git a/test/unit/SFCGAL/triangulate/ConstraintDelaunayTriangulationTest.cpp b/test/unit/SFCGAL/triangulate/ConstraintDelaunayTriangulationTest.cpp index e3ec7161..10dedb25 100644 --- a/test/unit/SFCGAL/triangulate/ConstraintDelaunayTriangulationTest.cpp +++ b/test/unit/SFCGAL/triangulate/ConstraintDelaunayTriangulationTest.cpp @@ -15,7 +15,8 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include @@ -23,92 +24,87 @@ #include #include -using namespace boost::unit_test ; -using namespace SFCGAL ; -using namespace SFCGAL::triangulate ; +using namespace boost::unit_test; +using namespace SFCGAL; +using namespace SFCGAL::triangulate; -BOOST_AUTO_TEST_SUITE( SFCGAL_triangulate_ConstraintDelaunayTriangulationTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_triangulate_ConstraintDelaunayTriangulationTest) /// Coordinate() ; -BOOST_AUTO_TEST_CASE( testDefaultConstructor ) +BOOST_AUTO_TEST_CASE(testDefaultConstructor) { - ConstraintDelaunayTriangulation triangulation ; - BOOST_CHECK_EQUAL( triangulation.numVertices(), 0U ); - BOOST_CHECK_EQUAL( triangulation.numTriangles(), 0U ); + ConstraintDelaunayTriangulation const triangulation; + BOOST_CHECK_EQUAL(triangulation.numVertices(), 0U); + BOOST_CHECK_EQUAL(triangulation.numTriangles(), 0U); } -BOOST_AUTO_TEST_CASE( testTriangulateSquare ) +BOOST_AUTO_TEST_CASE(testTriangulateSquare) { - ConstraintDelaunayTriangulation triangulation ; - typedef ConstraintDelaunayTriangulation::Vertex_handle Vertex_handle ; - typedef ConstraintDelaunayTriangulation::Face_handle Face_handle ; - typedef ConstraintDelaunayTriangulation::All_faces_iterator All_faces_iterator ; - //typedef ConstraintDelaunayTriangulation::Finite_faces_iterator Finite_faces_iterator ; - - Vertex_handle a = triangulation.addVertex( Coordinate( 0.0,0.0 ) ) ; - Vertex_handle b = triangulation.addVertex( Coordinate( 1.0,0.0 ) ) ; - Vertex_handle c = triangulation.addVertex( Coordinate( 1.0,1.0 ) ) ; - Vertex_handle d = triangulation.addVertex( Coordinate( 0.0,1.0 ) ) ; - - BOOST_CHECK_EQUAL( triangulation.numVertices(), 4U ); - BOOST_CHECK_EQUAL( triangulation.numTriangles(), 2U ); - - triangulation.addConstraint( a, b ); - triangulation.addConstraint( b, c ); - triangulation.addConstraint( c, d ); - triangulation.addConstraint( d, a ); - - // constraint have no impact - BOOST_CHECK_EQUAL( triangulation.numVertices(), 4U ); - BOOST_CHECK_EQUAL( triangulation.numTriangles(), 2U ); - - - /* - * nesting level - */ - for ( All_faces_iterator it = triangulation.all_faces_begin(); it != triangulation.all_faces_end(); ++it ) { - BOOST_CHECK_EQUAL( it->info().nestingLevel, -1 ); - } - - // check mark domains - triangulation.markDomains(); - - for ( All_faces_iterator it = triangulation.all_faces_begin(); it != triangulation.all_faces_end(); ++it ) { - Face_handle face = it ; - - if ( triangulation.isInfinite( face ) ) { - BOOST_CHECK_EQUAL( it->info().nestingLevel, 0 ); - } - else { - BOOST_CHECK_EQUAL( it->info().nestingLevel, 1 ); - } + ConstraintDelaunayTriangulation triangulation; + typedef ConstraintDelaunayTriangulation::Vertex_handle Vertex_handle; + typedef ConstraintDelaunayTriangulation::Face_handle Face_handle; + typedef ConstraintDelaunayTriangulation::All_faces_iterator + All_faces_iterator; + // typedef ConstraintDelaunayTriangulation::Finite_faces_iterator + // Finite_faces_iterator ; + + Vertex_handle const a = triangulation.addVertex(Coordinate(0.0, 0.0)); + Vertex_handle const b = triangulation.addVertex(Coordinate(1.0, 0.0)); + Vertex_handle const c = triangulation.addVertex(Coordinate(1.0, 1.0)); + Vertex_handle const d = triangulation.addVertex(Coordinate(0.0, 1.0)); + + BOOST_CHECK_EQUAL(triangulation.numVertices(), 4U); + BOOST_CHECK_EQUAL(triangulation.numTriangles(), 2U); + + triangulation.addConstraint(a, b); + triangulation.addConstraint(b, c); + triangulation.addConstraint(c, d); + triangulation.addConstraint(d, a); + + // constraint have no impact + BOOST_CHECK_EQUAL(triangulation.numVertices(), 4U); + BOOST_CHECK_EQUAL(triangulation.numTriangles(), 2U); + + /* + * nesting level + */ + for (All_faces_iterator it = triangulation.all_faces_begin(); + it != triangulation.all_faces_end(); ++it) { + BOOST_CHECK_EQUAL(it->info().nestingLevel, -1); + } + + // check mark domains + triangulation.markDomains(); + + for (All_faces_iterator it = triangulation.all_faces_begin(); + it != triangulation.all_faces_end(); ++it) { + Face_handle const face = it; + + if (triangulation.isInfinite(face)) { + BOOST_CHECK_EQUAL(it->info().nestingLevel, 0); + } else { + BOOST_CHECK_EQUAL(it->info().nestingLevel, 1); } + } } - - - -BOOST_AUTO_TEST_CASE( testProjectionPlane ) +BOOST_AUTO_TEST_CASE(testProjectionPlane) { - ConstraintDelaunayTriangulation triangulation ; - //typedef ConstraintDelaunayTriangulation::Vertex_handle Vertex_handle ; - //typedef ConstraintDelaunayTriangulation::Face_handle Face_handle ; + ConstraintDelaunayTriangulation triangulation; + // typedef ConstraintDelaunayTriangulation::Vertex_handle Vertex_handle ; + // typedef ConstraintDelaunayTriangulation::Face_handle Face_handle + // ; - triangulation.setProjectionPlane( Kernel::Plane_3( Kernel::RT( 1 ), Kernel::RT( 0 ), Kernel::RT( 0 ), Kernel::RT( 0 ) ) ); + triangulation.setProjectionPlane(Kernel::Plane_3( + Kernel::RT(1), Kernel::RT(0), Kernel::RT(0), Kernel::RT(0))); - triangulation.addVertex( Coordinate( 1.0,0.0,0.0 ) ) ; - triangulation.addVertex( Coordinate( 1.0,1.0,0.0 ) ) ; - triangulation.addVertex( Coordinate( 1.0,1.0,1.0 ) ) ; - triangulation.addVertex( Coordinate( 1.0,0.0,1.0 ) ) ; + triangulation.addVertex(Coordinate(1.0, 0.0, 0.0)); + triangulation.addVertex(Coordinate(1.0, 1.0, 0.0)); + triangulation.addVertex(Coordinate(1.0, 1.0, 1.0)); + triangulation.addVertex(Coordinate(1.0, 0.0, 1.0)); - BOOST_CHECK_EQUAL( triangulation.numVertices(), 4U ); - BOOST_CHECK_EQUAL( triangulation.numTriangles(), 2U ); + BOOST_CHECK_EQUAL(triangulation.numVertices(), 4U); + BOOST_CHECK_EQUAL(triangulation.numTriangles(), 2U); } - - BOOST_AUTO_TEST_SUITE_END() - - - - diff --git a/test/unit/SFCGAL/triangulate/Triangulate2DZTest.cpp b/test/unit/SFCGAL/triangulate/Triangulate2DZTest.cpp index c726077f..86c46622 100644 --- a/test/unit/SFCGAL/triangulate/Triangulate2DZTest.cpp +++ b/test/unit/SFCGAL/triangulate/Triangulate2DZTest.cpp @@ -15,7 +15,8 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #include @@ -23,78 +24,113 @@ #include #include -using namespace boost::unit_test ; -using namespace SFCGAL ; -using namespace SFCGAL::triangulate ; +using namespace boost::unit_test; +using namespace SFCGAL; +using namespace SFCGAL::triangulate; -BOOST_AUTO_TEST_SUITE( SFCGAL_triangulate_Triangulate2DZTest ) +BOOST_AUTO_TEST_SUITE(SFCGAL_triangulate_Triangulate2DZTest) -BOOST_AUTO_TEST_CASE( testPoint ) +BOOST_AUTO_TEST_CASE(testPoint) { - std::unique_ptr< Geometry > g( io::readWkt( "POINT(1.0 2.0 3.0)" ) ) ; - ConstraintDelaunayTriangulation triangulation = triangulate2DZ( *g ); - BOOST_CHECK_EQUAL( triangulation.numVertices(), 1U ); - BOOST_CHECK_EQUAL( triangulation.numTriangles(), 0U ); + std::unique_ptr const g(io::readWkt("POINT(1.0 2.0 3.0)")); + ConstraintDelaunayTriangulation const triangulation = triangulate2DZ(*g); + BOOST_CHECK_EQUAL(triangulation.numVertices(), 1U); + BOOST_CHECK_EQUAL(triangulation.numTriangles(), 0U); } -BOOST_AUTO_TEST_CASE( testLineString ) +BOOST_AUTO_TEST_CASE(testLineString) { - std::unique_ptr< Geometry > g( io::readWkt( "LINESTRING(0.0 0.0,1.0 0.0,1.0 1.0,2.0 1.0)" ) ) ; - ConstraintDelaunayTriangulation triangulation = triangulate2DZ( *g ); - BOOST_CHECK_EQUAL( triangulation.numVertices(), 4U ); - BOOST_CHECK_EQUAL( triangulation.numTriangles(), 2U ); + std::unique_ptr const g( + io::readWkt("LINESTRING(0.0 0.0,1.0 0.0,1.0 1.0,2.0 1.0)")); + ConstraintDelaunayTriangulation const triangulation = triangulate2DZ(*g); + BOOST_CHECK_EQUAL(triangulation.numVertices(), 4U); + BOOST_CHECK_EQUAL(triangulation.numTriangles(), 2U); } -BOOST_AUTO_TEST_CASE( testPolygonWithHole ) +BOOST_AUTO_TEST_CASE(testPolygonWithHole) { - std::unique_ptr< Geometry > g( io::readWkt( "POLYGON((0.0 0.0,1.0 0.0,1.0 1.0,0.0 1.0,0.0 0.0),(0.2 0.2,0.2 0.8,0.8 0.8,0.8 0.2,0.2 0.2))" ) ) ; - ConstraintDelaunayTriangulation triangulation = triangulate2DZ( *g ); - BOOST_CHECK_EQUAL( triangulation.numVertices(), 8U ); - BOOST_CHECK_EQUAL( triangulation.numTriangles(), 10U ); + std::unique_ptr const g( + io::readWkt("POLYGON((0.0 0.0,1.0 0.0,1.0 1.0,0.0 1.0,0.0 0.0),(0.2 " + "0.2,0.2 0.8,0.8 0.8,0.8 0.2,0.2 0.2))")); + ConstraintDelaunayTriangulation const triangulation = triangulate2DZ(*g); + BOOST_CHECK_EQUAL(triangulation.numVertices(), 8U); + BOOST_CHECK_EQUAL(triangulation.numTriangles(), 10U); } - -BOOST_AUTO_TEST_CASE( testMultiPoint ) +BOOST_AUTO_TEST_CASE(testMultiPoint) { - std::unique_ptr< Geometry > g( io::readWkt( "MULTIPOINT((1.0 2.0 3.0),(2.0 3.0 6.0),(8.0 6.0 7.0),(2.0 1.0 6.0))" ) ) ; - ConstraintDelaunayTriangulation triangulation = triangulate2DZ( *g ); - BOOST_CHECK_EQUAL( triangulation.numVertices(), 4U ); - BOOST_CHECK_EQUAL( triangulation.numTriangles(), 2U ); + std::unique_ptr const g(io::readWkt( + "MULTIPOINT((1.0 2.0 3.0),(2.0 3.0 6.0),(8.0 6.0 7.0),(2.0 1.0 6.0))")); + ConstraintDelaunayTriangulation const triangulation = triangulate2DZ(*g); + BOOST_CHECK_EQUAL(triangulation.numVertices(), 4U); + BOOST_CHECK_EQUAL(triangulation.numTriangles(), 2U); } -//MultiLineString -//MultiPolygon -//GeometryCollection -BOOST_AUTO_TEST_CASE( testMultiPolygon ) +// MultiLineString +// MultiPolygon +// GeometryCollection +BOOST_AUTO_TEST_CASE(testMultiPolygon) { - std::unique_ptr< Geometry > g( io::readWkt( "GEOMETRYCOLLECTION(LINESTRING(-1.52451708766716 0.583952451708767,-1.5408618127786 0.361069836552749,-1.47251114413076 0.317979197622586,-1.30163447251114 0.398216939078752,-1.32095096582467 0.482912332838039,-1.08320950965825 0.598811292719168,-0.809806835066865 0.570579494799406,-0.517087667161962 0.662704309063893),POLYGON((-1.46508172362556 0.615156017830609,-1.35215453194651 0.806835066864785,-1.08320950965825 0.754829123328381,-1.10401188707281 0.630014858841011,-1.2407132243685 0.557206537890045,-1.46508172362556 0.615156017830609)),POLYGON((-1.2778603268945 0.316493313521545,-0.925705794947994 0.540861812778603,-0.557206537890045 0.37444279346211,-1.09806835066865 0.0267459138187223,-1.2927191679049 0.197622585438336,-1.2778603268945 0.316493313521545),(-0.922734026745914 0.448736998514116,-1.03566121842496 0.393759286775632,-1.0297176820208 0.329866270430907,-0.87369985141159 0.286775631500743,-0.739970282317979 0.332838038632987,-0.922734026745914 0.448736998514116),(-1.12778603268945 0.295690936106984,-1.21545319465082 0.280832095096583,-1.23476968796434 0.225854383358098,-1.14858841010401 0.184249628528975,-1.0520059435364 0.210995542347697,-1.12778603268945 0.295690936106984)),POINT(-1.22288261515602 0.438335809806835),POINT(-1.1887072808321 0.24962852897474),POINT(-1.09658246656761 0.526002971768202),POINT(-0.967310549777118 0.225854383358098),POINT(-0.936106983655275 0.472511144130758),POINT(-0.882615156017831 0.335809806835067),POINT(-0.821693907875186 0.607726597325409),POINT(-0.708766716196137 0.243684992570579),POINT(-0.643387815750372 0.471025260029718),POINT(-0.632986627043091 0.674591381872214),POINT(-0.476968796433878 0.242199108469539),POINT(-0.456166419019317 0.573551263001486),POINT(-0.349182763744428 0.386329866270431))" ) ); - ConstraintDelaunayTriangulation triangulation = triangulate2DZ( *g ); - BOOST_CHECK_EQUAL( triangulation.numVertices(), 41U ); - BOOST_CHECK_EQUAL( triangulation.numTriangles(), 72U ); -// std::cout << triangulation.getTriangulatedSurface()->asText(5) << std::endl ; + std::unique_ptr const g(io::readWkt( + "GEOMETRYCOLLECTION(LINESTRING(-1.52451708766716 " + "0.583952451708767,-1.5408618127786 0.361069836552749,-1.47251114413076 " + "0.317979197622586,-1.30163447251114 0.398216939078752,-1.32095096582467 " + "0.482912332838039,-1.08320950965825 " + "0.598811292719168,-0.809806835066865 " + "0.570579494799406,-0.517087667161962 " + "0.662704309063893),POLYGON((-1.46508172362556 " + "0.615156017830609,-1.35215453194651 0.806835066864785,-1.08320950965825 " + "0.754829123328381,-1.10401188707281 0.630014858841011,-1.2407132243685 " + "0.557206537890045,-1.46508172362556 " + "0.615156017830609)),POLYGON((-1.2778603268945 " + "0.316493313521545,-0.925705794947994 " + "0.540861812778603,-0.557206537890045 0.37444279346211,-1.09806835066865 " + "0.0267459138187223,-1.2927191679049 0.197622585438336,-1.2778603268945 " + "0.316493313521545),(-0.922734026745914 " + "0.448736998514116,-1.03566121842496 0.393759286775632,-1.0297176820208 " + "0.329866270430907,-0.87369985141159 " + "0.286775631500743,-0.739970282317979 " + "0.332838038632987,-0.922734026745914 " + "0.448736998514116),(-1.12778603268945 " + "0.295690936106984,-1.21545319465082 0.280832095096583,-1.23476968796434 " + "0.225854383358098,-1.14858841010401 0.184249628528975,-1.0520059435364 " + "0.210995542347697,-1.12778603268945 " + "0.295690936106984)),POINT(-1.22288261515602 " + "0.438335809806835),POINT(-1.1887072808321 " + "0.24962852897474),POINT(-1.09658246656761 " + "0.526002971768202),POINT(-0.967310549777118 " + "0.225854383358098),POINT(-0.936106983655275 " + "0.472511144130758),POINT(-0.882615156017831 " + "0.335809806835067),POINT(-0.821693907875186 " + "0.607726597325409),POINT(-0.708766716196137 " + "0.243684992570579),POINT(-0.643387815750372 " + "0.471025260029718),POINT(-0.632986627043091 " + "0.674591381872214),POINT(-0.476968796433878 " + "0.242199108469539),POINT(-0.456166419019317 " + "0.573551263001486),POINT(-0.349182763744428 0.386329866270431))")); + ConstraintDelaunayTriangulation const triangulation = triangulate2DZ(*g); + BOOST_CHECK_EQUAL(triangulation.numVertices(), 41U); + BOOST_CHECK_EQUAL(triangulation.numTriangles(), 72U); + // std::cout << triangulation.getTriangulatedSurface()->asText(5) << + // std::endl ; } -//Solid +// Solid -BOOST_AUTO_TEST_CASE( testSolid ) +BOOST_AUTO_TEST_CASE(testSolid) { - std::unique_ptr< Geometry > g( io::readWkt( "SOLID((((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)),\ + std::unique_ptr const g( + io::readWkt("SOLID((((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)),\ ((0 0 0, 0 0 1, 0 1 1, 0 1 0, 0 0 0)),\ ((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)),\ ((1 1 1, 0 1 1, 0 0 1, 1 0 1, 1 1 1)),\ ((1 1 1, 1 0 1, 1 0 0, 1 1 0, 1 1 1)),\ - ((1 1 1, 1 1 0, 0 1 0, 0 1 1, 1 1 1))))" ) ); + ((1 1 1, 1 1 0, 0 1 0, 0 1 1, 1 1 1))))")); - BOOST_CHECK_THROW( triangulate2DZ( *g ), GeometryInvalidityException ); + BOOST_CHECK_THROW(triangulate2DZ(*g), GeometryInvalidityException); } - -//MultiSolid - +// MultiSolid BOOST_AUTO_TEST_SUITE_END() - - - - diff --git a/test/unit/TestModule.cpp b/test/unit/TestModule.cpp index 9b1f7c82..10f887a3 100644 --- a/test/unit/TestModule.cpp +++ b/test/unit/TestModule.cpp @@ -15,27 +15,22 @@ * Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, see . + * License along with this library; if not, see + . */ #define BOOST_TEST_MODULE UnitTestSFCGAL #define BOOST_TEST_ALTERNATIVE_INIT_API #include -using namespace boost::unit_test ; +using namespace boost::unit_test; #include -test_suite* init_unit_test_suite( int, char** const ) +auto +init_unit_test_suite(int /*unused*/, char **const /*unused*/) -> test_suite * { -// std::cerr << "init test suite" << std::endl; - SFCGAL::Logger::get()->setLogLevel( SFCGAL::Logger::Info ); - return 0; + // std::cerr << "init test suite" << std::endl; + SFCGAL::Logger::get()->setLogLevel(SFCGAL::Logger::Info); + return nullptr; } - - - - - - -