Skip to content

Commit

Permalink
MultiPolygonにarea()とperimeter()を追加(#1185) (#1187)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ogame3334 authored Jan 18, 2024
1 parent 3a5a293 commit 0e0b5fc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Siv3D/include/Siv3D/MultiPolygon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
24 changes: 24 additions & 0 deletions Siv3D/src/Siv3D/MultiPolygon/SivMultiPolygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit 0e0b5fc

Please sign in to comment.