diff --git a/src/utilities/geometry/Intersection.cpp b/src/utilities/geometry/Intersection.cpp index f1309a244af..43fe0e9eff8 100644 --- a/src/utilities/geometry/Intersection.cpp +++ b/src/utilities/geometry/Intersection.cpp @@ -1054,11 +1054,7 @@ std::vector simplify(const std::vector& vertices, bool removeC return result; } -/// /// Converts a Polygon to a BoostPolygon -/// -/// -/// boost::optional BoostPolygonFromPolygon(const Polygon3d& polygon) { BoostPolygon boostPolygon; diff --git a/src/utilities/geometry/Polygon.cpp b/src/utilities/geometry/Polygon.cpp index 9349bbf2451..7755a9c81b0 100644 --- a/src/utilities/geometry/Polygon.cpp +++ b/src/utilities/geometry/Polygon.cpp @@ -35,47 +35,46 @@ namespace openstudio { Polygon3d::Polygon3d() {} -Polygon3d::Polygon3d(Point3dVector outerPath) { - for (auto p : outerPath) { - outerPath.push_back(p); +Polygon3d::Polygon3d(const Point3dVector& outerPath) { + for (const auto& p : outerPath) { + m_outerPath.emplace_back(p); } } -Polygon3d::Polygon3d(Point3dVector outerPath, Point3dVectorVector innerPaths) { - for (auto p : outerPath) { - outerPath.push_back(p); +Polygon3d::Polygon3d(const Point3dVector& outerPath, const Point3dVectorVector& innerPaths) { + for (const auto& p : outerPath) { + m_outerPath.emplace_back(p); } - for (auto innerPath : innerPaths) { + for (const auto& innerPath : innerPaths) { addHole(innerPath); } } +/// Adds a point to the polygon perimeter void Polygon3d::addPoint(const Point3d& point) { - outerPath.push_back(point); + m_outerPath.emplace_back(point); } - -void Polygon3d::setOuterPath(Point3dVector outerPath) { - outerPath = outerPath; +/// Sets the perimeter of the polygon +void Polygon3d::setOuterPath(const Point3dVector& outerPath) { + m_outerPath = outerPath; } Point3dVector Polygon3d::getOuterPath() const { - return outerPath; + return m_outerPath; } Point3dVectorVector Polygon3d::getInnerPaths() const { - return innerPaths; + return m_innerPaths; } -void Polygon3d::addHole(Point3dVector hole) { - innerPaths.push_back(hole); +void Polygon3d::addHole(const Point3dVector& hole) { + m_innerPaths.emplace_back(hole); } -Vector3d Polygon3d::newellVector() { - OptionalVector3d v = openstudio::getNewallVector(outerPath); - - if (v) { +Vector3d Polygon3d::newallVector() { + if (OptionalVector3d v = openstudio::getNewallVector(m_outerPath)) { return v.get(); } @@ -83,25 +82,25 @@ Vector3d Polygon3d::newellVector() { } Vector3d Polygon3d::outwardNormal() { - return openstudio::getOutwardNormal(outerPath).get(); + return openstudio::getOutwardNormal(m_outerPath).get(); } double Polygon3d::grossArea() { - boost::optional area = openstudio::getArea(outerPath); - if (area == boost::none) - return 0; - else + if (boost::optional area = openstudio::getArea(m_outerPath)) { return area.get(); + } + return 0; } double Polygon3d::netArea() { double netArea = grossArea(); - for (auto hole : innerPaths) { - boost::optional area = openstudio::getArea(hole); - if (area != boost::none) netArea -= area.get(); + for (const auto& hole : m_innerPaths) { + if (boost::optional area = openstudio::getArea(hole)) { + netArea -= area.get(); + } } return netArea; @@ -110,9 +109,9 @@ double Polygon3d::netArea() { double Polygon3d::perimeter() { double perimeter = 0; - for (size_t i = 0; i < outerPath.size(); i++) { - Point3d p1 = outerPath[i]; - Point3d p2 = outerPath[(i + 1) % outerPath.size()]; + for (size_t i = 0; i < m_outerPath.size(); i++) { + Point3d p1 = m_outerPath[i]; + Point3d p2 = m_outerPath[(i + 1) % m_outerPath.size()]; perimeter += openstudio::getDistance(p1, p2); } @@ -120,19 +119,19 @@ double Polygon3d::perimeter() { } bool Polygon3d::isClockwise() { - OptionalVector3d normal = getOutwardNormal(outerPath); - if (normal == boost::none) - return true; - else + if (OptionalVector3d normal = getOutwardNormal(m_outerPath)) { return normal.get().z() > 0; + } + + return true; } Point3d Polygon3d::centroid() { - boost::optional p = openstudio::getCentroid(outerPath); - if (p == boost::none) - return Point3d(); - else + if (auto p = openstudio::getCentroid(m_outerPath)) { return p.get(); + } + + return Point3d(); } //bool Polygon3d::PointInPolygon(Point3d testPoint) { diff --git a/src/utilities/geometry/Polygon.hpp b/src/utilities/geometry/Polygon.hpp index 11a3d4981dc..5442a75f87c 100644 --- a/src/utilities/geometry/Polygon.hpp +++ b/src/utilities/geometry/Polygon.hpp @@ -42,33 +42,32 @@ class Vector3d; class UTILITIES_API Polygon3d { public: - // Constructs an empty polygon Polygon3d(); // Construct a polygon with an outer path - Polygon3d(Point3dVector outerPath); + Polygon3d(const Point3dVector& outerPath); - // COnstructs a polygon with an oiyer path and pone or more inner paths - Polygon3d(Point3dVector outerPath, Point3dVectorVector innerPaths); + // Constructs a polygon with an outer path and one or more inner paths + Polygon3d(const Point3dVector& outerPath, const Point3dVectorVector& innerPaths); // Assigns an outer path for the polygon - void setOuterPath(Point3dVector outerPath); + void setOuterPath(const Point3dVector& outerPath); // Returns the polygon's outer path Point3dVector getOuterPath() const; - // Returns the polygonm's inner paths + // Returns the polygon's inner paths Point3dVectorVector getInnerPaths() const; // Adds a point to the outer path of the polygon void addPoint(const Point3d& point); // Adds an inner path to the polygon - void addHole(Point3dVector hole); + void addHole(const Point3dVector& hole); - // Calculates the Newell VEctor for the polygon - Vector3d newellVector(); + // Calculates the Newall Vector for the polygon + Vector3d newallVector(); // Calculates the outward normal of the polygon Vector3d outwardNormal(); @@ -82,19 +81,18 @@ class UTILITIES_API Polygon3d // Gets the perimeter of the outer path of the polygon double perimeter(); - // Determines whether the polygon os clockwise (normal down) or anti-clockwise (normal up) + // Determines whether the polygon os clockwise (normal down) or anti-clockwise (normal up) bool isClockwise(); - + // Calculates the centroid of the polygon Point3d centroid(); private: - // The polygon's outer path - Point3dVector outerPath; + Point3dVector m_outerPath; // The polygons inner paths - Point3dVectorVector innerPaths; + Point3dVectorVector m_innerPaths; }; } // namespace openstudio diff --git a/src/utilities/geometry/Test/Geometry_GTest.cpp b/src/utilities/geometry/Test/Geometry_GTest.cpp index 23998109e99..74033464ed2 100644 --- a/src/utilities/geometry/Test/Geometry_GTest.cpp +++ b/src/utilities/geometry/Test/Geometry_GTest.cpp @@ -1117,13 +1117,7 @@ TEST_F(GeometryFixture, PointLatLon_Elevation) { EXPECT_NEAR(30.0, test.z(), 0.001); } -// Digital Alchemy - -/// /// Basic polygon functionality tests -/// -/// -/// TEST_F(GeometryFixture, Polygon_Basic) { Polygon3d testPolygon; @@ -1152,11 +1146,7 @@ TEST_F(GeometryFixture, Polygon_Basic) { EXPECT_EQ(grossArea, openstudio::getArea(testPolygon.getOuterPath()).get()); } -/// /// Angled polygon (taken from a roof) -/// -/// -/// TEST_F(GeometryFixture, Polygon_Basic_Angled) { Polygon3d testPolygon; diff --git a/src/utilities/geometry/Test/Intersection_GTest.cpp b/src/utilities/geometry/Test/Intersection_GTest.cpp index f67fd120760..c2f1f856695 100644 --- a/src/utilities/geometry/Test/Intersection_GTest.cpp +++ b/src/utilities/geometry/Test/Intersection_GTest.cpp @@ -1861,8 +1861,6 @@ TEST_F(GeometryFixture, simplify7) { /// | | /// +----------------------------+ /// -/// -/// TEST_F(GeometryFixture, Polygon3d_Join) { Polygon3d polygonA; @@ -1907,13 +1905,7 @@ TEST_F(GeometryFixture, Polygon3d_Join) { } // joinAll fails on cases with an inner loop -/// - -/// /// joinAll method that takes a list of polygons and returns a list of polygons -/// -/// -/// TEST_F(GeometryFixture, Polygon3d_JoinAll_1614) { double tol = 0.01; @@ -1991,11 +1983,6 @@ TEST_F(GeometryFixture, Polygon3d_JoinAll_1614) { // double perimeter = result.front().getPerimeter(); } -/// -/// joinAll method that takes a list of Point3d vectors and returns a list of polygons -/// -/// -/// TEST_F(GeometryFixture, Polygon3d_JoinAllPolygons_1614) { double tol = 0.01;