Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MultiPolygonにarea()とperimeter()を追加(#1185) #1187

Merged
merged 3 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
20 changes: 20 additions & 0 deletions Siv3D/src/Siv3D/MultiPolygon/SivMultiPolygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,26 @@ namespace s3d
return *this;
}

double MultiPolygon::area() const noexcept
{
double total = 0;
for (const auto& polygon : m_data)
{
total += polygon.area();
}
return total;
}

double MultiPolygon::perimeter() const noexcept
{
double total = 0;
for (const auto& polygon : m_data)
{
total += polygon.perimeter();
}
return total;
}

RectF MultiPolygon::computeBoundingRect() const noexcept
{
if (isEmpty())
Expand Down