diff --git a/Siv3D/include/Siv3D/MultiPolygon.hpp b/Siv3D/include/Siv3D/MultiPolygon.hpp index af0a08f06..3df41f908 100644 --- a/Siv3D/include/Siv3D/MultiPolygon.hpp +++ b/Siv3D/include/Siv3D/MultiPolygon.hpp @@ -411,6 +411,12 @@ namespace s3d MultiPolygon& scaleAt(Vec2 pos, Vec2 s); + [[nodiscard]] + double area() const noexcept; + + [[nodiscard]] + double perimeter() const noexcept; + [[nodiscard]] RectF computeBoundingRect() const noexcept; diff --git a/Siv3D/src/Siv3D/MultiPolygon/SivMultiPolygon.cpp b/Siv3D/src/Siv3D/MultiPolygon/SivMultiPolygon.cpp index d63a12e71..a6e72719b 100644 --- a/Siv3D/src/Siv3D/MultiPolygon/SivMultiPolygon.cpp +++ b/Siv3D/src/Siv3D/MultiPolygon/SivMultiPolygon.cpp @@ -306,6 +306,30 @@ namespace s3d return *this; } + double MultiPolygon::area() const noexcept + { + double total = 0.0; + + for (const auto& polygon : m_data) + { + total += polygon.area(); + } + + return total; + } + + double MultiPolygon::perimeter() const noexcept + { + double total = 0.0; + + for (const auto& polygon : m_data) + { + total += polygon.perimeter(); + } + + return total; + } + RectF MultiPolygon::computeBoundingRect() const noexcept { if (isEmpty())