2次元の多角形を表す構造体.
[詳解]
#include <math_polygon2.h>
2次元の多角形を表す構造体.
頂点は反時計回り,或いは時計回りに並んでいる必要がある. そうでない場合はいくつかの関数が正常に動作しない.
また,頂点の数は最大でkMaxVertexNum個までしか登録できない. これは動作の高速化のために確保した配列のサイズを固定しているためである. この値を変更する場合は,コード中のkMaxVertexNumの値を変更する必要がある.
なお,コード中の max 関数,min関数については以下を参照.
参照
math_polygon2.h の 38 行目に定義があります。
◆ Polygon2() [1/2]
constexpr designlab::Polygon2::Polygon2 |
( |
| ) |
|
|
inlineconstexpr |
◆ Polygon2() [2/2]
designlab::Polygon2::Polygon2 |
( |
const std::vector< Vector2 > & |
vertex | ) |
|
|
explicit |
◆ AddVertex()
constexpr void designlab::Polygon2::AddVertex |
( |
const Vector2 & |
v | ) |
|
|
inlineconstexpr |
◆ AddVertexCheckForDuplicates()
bool designlab::Polygon2::AddVertexCheckForDuplicates |
( |
const Vector2 & |
v | ) |
|
頂点を追加する関数.他の頂点と重なっている場合は追加しない.
- 引数
-
- 覚え書き
- 他の頂点と重なっている場合は追加しない. この処理の分だけ遅くなるので,重なることがない場合は AddVertex を使うこと.
- 戻り値
-
true | 追加できた, |
false | 追加できなかった. |
math_polygon2.cpp の 27 行目に定義があります。
◆ GetMaxX()
constexpr float designlab::Polygon2::GetMaxX |
( |
| ) |
const |
|
inlineconstexpr |
◆ GetMaxY()
constexpr float designlab::Polygon2::GetMaxY |
( |
| ) |
const |
|
inlineconstexpr |
◆ GetMinX()
constexpr float designlab::Polygon2::GetMinX |
( |
| ) |
const |
|
inlineconstexpr |
◆ GetMinY()
constexpr float designlab::Polygon2::GetMinY |
( |
| ) |
const |
|
inlineconstexpr |
◆ GetVertex()
constexpr Vector2 designlab::Polygon2::GetVertex |
( |
const int |
i | ) |
const |
|
inlineconstexpr |
◆ GetVertexNum()
constexpr int designlab::Polygon2::GetVertexNum |
( |
| ) |
const |
|
inlineconstexpr |
◆ GetVertexOpt()
constexpr std::optional< Vector2 > designlab::Polygon2::GetVertexOpt |
( |
const int |
i | ) |
const |
|
inlineconstexpr |
頂点の座標を返す関数.std::optional を使っているので, 存在しない頂点を指定した場合は std::nullopt を返す.
- 引数
-
- 戻り値
- 頂点の座標.存在しない頂点を指定した場合は std::nullopt を返す.
math_polygon2.h の 117 行目に定義があります。
◆ IsConvex()
bool designlab::Polygon2::IsConvex |
( |
| ) |
const |
◆ IsInside()
bool designlab::Polygon2::IsInside |
( |
const Vector2 & |
point | ) |
const |
点が多角形の内部にあるかどうか調べる関数. 多角形が凸でない場合は正しく判定できない.
- 引数
-
- 戻り値
- bool 内部にあるなら true,外部にあるなら false
- 覚え書き
- 点が時計回り,反時計回りのいずれかの順番で頂点が並んでいる必要がある.
-
点が多角形の辺上にある場合は内部にあると判定する.
-
多角形が凸でない場合は正しく判定できない.
math_polygon2.cpp の 97 行目に定義があります。
◆ RemoveLastVertex()
constexpr void designlab::Polygon2::RemoveLastVertex |
( |
| ) |
|
|
inlineconstexpr |
◆ RemoveVertex()
void designlab::Polygon2::RemoveVertex |
( |
const int |
index | ) |
|
頂点を削除する関数.遅いので多用するべきではない.
- 引数
-
- 覚え書き
- 存在しない頂点を指定した場合は何もしない.
-
削除した頂点のインデックスは変わるので注意.
math_polygon2.cpp の 45 行目に定義があります。
◆ Reset()
constexpr void designlab::Polygon2::Reset |
( |
| ) |
|
|
inlineconstexpr |
◆ ToString()
std::string designlab::Polygon2::ToString |
( |
| ) |
const |
この構造体詳解は次のファイルから抽出されました: