Skip to content

Commit

Permalink
[共通] MultiPolygon::computeConvexHull() #1195
Browse files Browse the repository at this point in the history
  • Loading branch information
Reputeless committed Feb 1, 2024
1 parent cb9bbeb commit 0c1488b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Siv3D/include/Siv3D/MultiPolygon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,11 @@ namespace s3d
[[nodiscard]]
Vec2 centroid() const;

/// @brief 全体の凸包を計算して返します。
/// @return 全体の凸包
[[nodiscard]]
Polygon computeConvexHull() const;

[[nodiscard]]
RectF computeBoundingRect() const noexcept;

Expand Down
12 changes: 12 additions & 0 deletions Siv3D/src/Siv3D/MultiPolygon/SivMultiPolygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,18 @@ namespace s3d
return weightedCoordsTotal / areaTotal;
}

Polygon MultiPolygon::computeConvexHull() const
{
Array<Vec2> points;

for (const auto& polygon : m_data)
{
points.append(polygon.outer());
}

return Geometry2D::ConvexHull(points);
}

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

0 comments on commit 0c1488b

Please sign in to comment.