-
-
Notifications
You must be signed in to change notification settings - Fork 147
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
MultiPolygonにarea()とperimeter()を追加(#1185) #1187
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 箇所の修正をお願いします。
double MultiPolygon::area() const noexcept | ||
{ | ||
double total = 0; | ||
for (const auto& polygon : *this) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
わずかな変更でもう一歩だけ改善できます。
range-based for は https://cpprefjp.github.io/lang/cpp17/generalizing_the_range-based_for_loop.html のように展開されます。ここで *this
を使うと begin-expr
は MultiPolygon::begin()
になります。すると
MultiPolygon::begin()
→MultiPolygon::base_type::begin()
→std::vector<Polygon>::begin()
のような呼び出しになります。
一方で m_data
を使うと
MultiPolygon::base_type::begin()
→std::vector<Polygon>::begin()
のように 1 つ減らせます。
登場するすべての begin()
はインライン関数なので、最適化が有効であれば最終的に同じコードになって差は生じませんが、Debug ビルドなどで最適化を無効にしている場合は少しだけコストが嵩むことになります。修正をお願いします。
- 生成されるコード: https://godbolt.org/z/a85aeaK3d
double MultiPolygon::perimeter() const noexcept | ||
{ | ||
double total = 0; | ||
for (const auto& polygon : *this) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.area()
のコメントと同じです。
フィードバックありがとうございます! |
ご指摘のとおりです。他の箇所も |
Merged. Thanks! ◆ 初めて Siv3D にコミットした方へのご案内コミッタの方の名前を AUTHORS に記載します。 ◆ Organization への招待についてOpenSiv3D 本体および Siv3D ドキュメントのリポジトリにコミットをした方、その他顕著な貢献をされた方には、GitHub の Siv3D Organization メンバー への招待が送られます。 |
ありがとうございます! |
MultiPolygonにnoexceptなconstメンバ変数であるarea()とperimeter()を実装