earcut.jsのC ++ポート、高速のヘッダーのみのポリゴン三角測量ライブラリ。
ライブラリは、Zオーダー曲線のハッシュで最適化された修正耳スライシングアルゴリズムを実装し、穴、ねじれたポリゴン、縮退、自己誘惑を処理するように拡張され、三角測量の正しさを保証しないが、地理的形状のような実用的なデータに対して常に許容可能な結果を生成しようとします。
それは拳からのアイデアに基づいています:David Eberlyによる耳の切り抜きによるMartin Helldによるポリゴンの高速産業強度三角測量。
# include < earcut.hpp > // The number type to use for tessellation
using Coord = double ;
// The index type. Defaults to uint32_t, but you can also pass uint16_t if you know that your
// data won't have more than 65536 vertices.
using N = uint32_t ;
// Create array
using Point = std::array<Coord, 2 >;
std::vector<std::vector< Point >> polygon;
// Fill polygon structure with actual data. Any winding order works.
// The first polyline defines the main polygon.
polygon.push_back({{ 100 , 0 }, { 100 , 100 }, { 0 , 100 }, { 0 , 0 }});
// Following polylines define holes.
polygon.push_back({{ 75 , 25 }, { 75 , 75 }, { 25 , 75 }, { 25 , 25 }});
// Run tessellation
// Returns array of indices that refer to the vertices of the input polygon.
// e.g: the index 6 would refer to {25, 75} in this example.
// Three subsequent indices form a triangle. Output triangles are clockwise.
std::vector<N> indices = mapbox::earcut<N>(polygon);イヤーカットは、穴を含む巻き上げ順序の単純な平面ポリゴンを三角測量できます。それは、非シンプルなポヨンに対して堅牢で許容可能なソリューションを返します。イヤーカットは2Dプレーンで動作します。 3つ以上の寸法がある場合は、三角測量の前にそれらを2D表面に投影するか、タスクに適したライブラリ(CGALなど)を使用できます。
カスタムポイントタイプを入力として使用することもできます。 std::tuple 、 std::pair 、 std::array用に定義されたデフォルトのアクセサがあります。カスタムタイプ(ClipperのIntPointタイプなど)の場合、これを行います。
// struct IntPoint {
// int64_t X, Y;
// };
namespace mapbox {
namespace util {
template <>
struct nth < 0 , IntPoint> {
inline static auto get ( const IntPoint &t) {
return t. X ;
};
};
template <>
struct nth < 1 , IntPoint> {
inline static auto get ( const IntPoint &t) {
return t. Y ;
};
};
} // namespace util
} // namespace mapboxポリゴンにカスタムコンテナタイプを使用することもできます。 std :: vectorと同様に、特定のsize() 、 empty() 、およびoperator[]のコンテナの要件を満たす必要があります。
イヤーカット三角測量ライブラリを使用するだけの場合。プロジェクトにヘッダーファイル<earcut.hpp>をコピーして含め、セクションの使用状況で文書化された手順に従ってください。
代わりに、テスト、ベンチマーク、視覚化プログラムを構築する場合は、次の手順に従ってください。
続行する前に、次のツールとライブラリをインストールするようにしてください。
注:Windowsなどの一部のオペレーティングシステムでは、パス環境変数にCmakeとGitを追加するには手動の手順が必要です。
git clone --recursive https://github.com/mapbox/earcut.hpp.git
cd earcut.hpp
mkdir build
cd build
cmake ..
make
# ./tests
# ./bench
# ./vizgit clone --recursive https://github.com/mapbox/earcut.hpp.git
cd earcut.hpp
mkdir project
cd project
cmake .. -G " Visual Studio 14 2015 "
:: you can also generate projects for "Visual Studio 12 2013", "XCode", "Eclipse CDT4 - Unix Makefiles"完了後、IDEで生成されたプロジェクトを開きます。
https://github.com/mapbox/earcut.hpp.gitからプロジェクトをインポートしてください。
これは現在、Earcut 2.2.4に基づいています。