Skip to content

Commit

Permalink
fix interior rings
Browse files Browse the repository at this point in the history
  • Loading branch information
bertt committed Sep 3, 2024
1 parent 5290551 commit 94c332b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/triangulator.tests/TriangulateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@ namespace Triangulate.Tests
{
public class Tests
{
[Test]
public void CreateGlbFromOvertureBuildingIssue210()
{
var wkt = "MULTIPOLYGON Z(((5.7945897 45.2104504 0, 5.794611 45.2104414 0, 5.794616 45.210422 0, 5.794607 45.210411 0, 5.794653 45.210392 0, 5.794662 45.210404 0, 5.794693 45.21041 0, 5.794708 45.210403 0, 5.7947283 45.2104284 0, 5.7950367 45.2103109 0, 5.795016 45.210285 0, 5.795032 45.210277 0, 5.79504 45.210257 0, 5.795032 45.210246 0, 5.7950659 45.2102338 0, 5.7949016 45.2100206 0, 5.7948693 45.2100324 0, 5.794856 45.210015 0, 5.794833 45.21001 0, 5.79481 45.210018 0, 5.794786 45.209986 0, 5.794805 45.209977 0, 5.794811 45.209959 0, 5.794802 45.209947 0, 5.794849 45.209929 0, 5.794857 45.209942 0, 5.794883 45.209948 0, 5.794903 45.20994 0, 5.794922 45.2099659 0, 5.7952283 45.209848 0, 5.795208 45.209823 0, 5.795229 45.209814 0, 5.795236 45.209798 0, 5.7952263 45.2097839 0, 5.7952595 45.2097718 0, 5.7950922 45.2095571 0, 5.7950614 45.2095698 0, 5.79505 45.209554 0, 5.795025 45.209548 0, 5.795005 45.209556 0, 5.794978 45.209522 0, 5.794998 45.209515 0, 5.795003 45.209498 0, 5.794993 45.209485 0, 5.795043 45.209466 0, 5.795051 45.20948 0, 5.795078 45.209484 0, 5.795093 45.209479 0, 5.7951129 45.209504 0, 5.7954223 45.2093852 0, 5.795401 45.209357 0, 5.795421 45.209349 0, 5.795427 45.209333 0, 5.795419 45.20932 0, 5.795466 45.209303 0, 5.795474 45.209315 0, 5.795501 45.209321 0, 5.795521 45.209314 0, 5.795545 45.209346 0, 5.795526 45.209353 0, 5.79552 45.209372 0, 5.79553 45.209386 0, 5.7954975 45.2093987 0, 5.7956662 45.2096167 0, 5.795697 45.209604 0, 5.795706 45.209617 0, 5.795736 45.209621 0, 5.795751 45.209614 0, 5.7957717 45.209638 0, 5.7960757 45.2095206 0, 5.796056 45.209496 0, 5.796073 45.20949 0, 5.796083 45.209472 0, 5.796073 45.209459 0, 5.796121 45.209442 0, 5.796127 45.209453 0, 5.796155 45.209459 0, 5.79617 45.209453 0, 5.796198 45.209486 0, 5.796181 45.209491 0, 5.796175 45.209513 0, 5.796182 45.209523 0, 5.796159 45.209533 0, 5.796325 45.209751 0, 5.796349 45.209741 0, 5.796356 45.209752 0, 5.796386 45.209758 0, 5.796404 45.209751 0, 5.796427 45.209782 0, 5.796409 45.209791 0, 5.796402 45.20981 0, 5.79641 45.209822 0, 5.796365 45.20984 0, 5.796356 45.20983 0, 5.796327 45.209823 0, 5.796313 45.209829 0, 5.796301 45.209814 0, 5.795994 45.20993 0, 5.796006 45.209948 0, 5.795986 45.209955 0, 5.795978 45.209972 0, 5.795989 45.209986 0, 5.795967 45.209995 0, 5.79613 45.21021 0, 5.796153 45.210199 0, 5.796163 45.210214 0, 5.796193 45.210221 0, 5.796212 45.210213 0, 5.796223 45.210229 0, 5.796529 45.210111 0, 5.796517 45.210095 0, 5.796536 45.210088 0, 5.796545 45.210067 0, 5.796537 45.210056 0, 5.796576 45.210039 0, 5.796586 45.21005 0, 5.79662 45.210058 0, 5.796634 45.210051 0, 5.796659 45.210083 0, 5.79664 45.210091 0, 5.796631 45.210107 0, 5.796641 45.210121 0, 5.796621 45.21013 0, 5.796786 45.210347 0, 5.796809 45.210337 0, 5.79682 45.210351 0, 5.796846 45.210356 0, 5.796864 45.210348 0, 5.796889 45.210383 0, 5.79687 45.210389 0, 5.796862 45.210406 0, 5.796873 45.21042 0, 5.796827 45.210438 0, 5.796817 45.210426 0, 5.796791 45.210421 0, 5.796775 45.210427 0, 5.796763 45.210411 0, 5.796454 45.210528 0, 5.796466 45.210544 0, 5.796448 45.210552 0, 5.796439 45.21057 0, 5.79645 45.210584 0, 5.796405 45.210601 0, 5.796396 45.210589 0, 5.796368 45.210583 0, 5.796349 45.210588 0, 5.796325 45.210556 0, 5.796341 45.21055 0, 5.79635 45.210532 0, 5.796339 45.21052 0, 5.796359 45.210511 0, 5.796197 45.210294 0, 5.796173 45.210303 0, 5.796164 45.210292 0, 5.796134 45.210283 0, 5.796117 45.210289 0, 5.796106 45.210275 0, 5.7958 45.210393 0, 5.795812 45.210408 0, 5.795792 45.210416 0, 5.795787 45.210434 0, 5.795797 45.210447 0, 5.7957652 45.2104616 0, 5.7959346 45.2106796 0, 5.7959674 45.2106678 0, 5.7959744 45.2106808 0, 5.796002 45.2106868 0, 5.796022 45.2106793 0, 5.796047 45.2107141 0, 5.796028 45.2107206 0, 5.7960217 45.2107387 0, 5.7960324 45.2107511 0, 5.7959834 45.2107701 0, 5.7959734 45.2107549 0, 5.7959477 45.2107503 0, 5.7959297 45.2107573 0, 5.7959115 45.2107336 0, 5.7956061 45.2108505 0, 5.79562 45.210871 0, 5.7956077 45.2108772 0, 5.7956024 45.2108975 0, 5.7956117 45.2109137 0, 5.795558 45.2109328 0, 5.795548 45.210917 0, 5.795527 45.2109138 0, 5.7955077 45.2109217 0, 5.795473 45.210882 0, 5.795493 45.210876 0, 5.7955 45.210857 0, 5.795493 45.2108459 0, 5.7955288 45.2108345 0, 5.7953639 45.21062 0, 5.7953314 45.2106337 0, 5.795318 45.210617 0, 5.795298 45.2106119 0, 5.795275 45.2106218 0, 5.7952551 45.2105982 0, 5.7949514 45.2107133 0, 5.794967 45.210735 0, 5.79495 45.210741 0, 5.79494 45.210762 0, 5.79495 45.2107764 0, 5.7949047 45.2107944 0, 5.794894 45.210781 0, 5.7948694 45.2107774 0, 5.7948497 45.2107843 0, 5.7948247 45.2107503 0, 5.7948447 45.2107429 0, 5.794845 45.210719 0, 5.794842 45.210718 0, 5.794837 45.2107099 0, 5.7948729 45.2106981 0, 5.794709 45.210483 0, 5.794674 45.2104954 0, 5.794664 45.210484 0, 5.7946377 45.2104774 0, 5.7946194 45.2104848 0, 5.7945897 45.2104504 0), (5.7948218 45.2105268 0, 5.7948814 45.2106058 0, 5.7949205 45.210613 0, 5.7950307 45.2105723 0, 5.7950428 45.2105461 0, 5.794982 45.2104669 0, 5.7949441 45.2104594 0, 5.7948339 45.2105001 0, 5.7948218 45.2105268 0), (5.795077 45.2100413 0, 5.795136 45.2101188 0, 5.7951722 45.2101254 0, 5.7952808 45.2100857 0, 5.7952942 45.2100574 0, 5.7952318 45.2099785 0, 5.7951936 45.2099723 0, 5.795087 45.2100139 0, 5.795077 45.2100413 0), (5.7951149 45.2103275 0, 5.7951617 45.2103887 0, 5.7951924 45.2103881 0, 5.7952172 45.2103963 0, 5.7952376 45.2104137 0, 5.7952468 45.2104334 0, 5.7952454 45.2104499 0, 5.7952252 45.2104728 0, 5.7952748 45.2105395 0, 5.795311 45.2105278 0, 5.7953192 45.210541 0, 5.7953488 45.2105475 0, 5.7953696 45.2105399 0, 5.7953864 45.2105616 0, 5.7954845 45.2105228 0, 5.7954751 45.210511 0, 5.7954779 45.2104953 0, 5.7954913 45.2104816 0, 5.7955088 45.2104698 0, 5.7955318 45.2104649 0, 5.7955548 45.2104638 0, 5.7955758 45.2104684 0, 5.7955928 45.2104815 0, 5.7956888 45.210445 0, 5.7956721 45.2104225 0, 5.7956917 45.2104142 0, 5.7956985 45.2103947 0, 5.7956877 45.2103806 0, 5.7957202 45.2103691 0, 5.7956679 45.210303 0, 5.7956457 45.2103037 0, 5.7956249 45.2103016 0, 5.7956035 45.2102957 0, 5.7955874 45.2102851 0, 5.7955801 45.210269 0, 5.795581 45.2102529 0, 5.7955858 45.2102359 0, 5.7956054 45.2102208 0, 5.7955551 45.2101547 0, 5.795519 45.210168 0, 5.795509 45.210155 0, 5.795481 45.210149 0, 5.795465 45.210155 0, 5.7954507 45.2101334 0, 5.795351 45.2101691 0, 5.7953559 45.2101851 0, 5.7953541 45.2102002 0, 5.7953422 45.2102124 0, 5.7953223 45.2102237 0, 5.7952936 45.2102302 0, 5.7952645 45.2102273 0, 5.7952434 45.2102103 0, 5.795143 45.2102488 0, 5.795157 45.2102667 0, 5.7951378 45.2102728 0, 5.7951282 45.2103013 0, 5.7951408 45.2103175 0, 5.7951149 45.2103275 0), (5.7952513 45.2095852 0, 5.7953103 45.209665 0, 5.795374 45.2096773 0, 5.795488 45.2096353 0, 5.7955088 45.209588 0, 5.7954484 45.2095101 0, 5.7953847 45.2094954 0, 5.7952707 45.2095389 0, 5.7952513 45.2095852 0), (5.7953063 45.2098656 0, 5.7954689 45.2100792 0, 5.7955044 45.2100655 0, 5.7955165 45.2100806 0, 5.7955433 45.2100853 0, 5.7955601 45.2100783 0, 5.7955782 45.2101014 0, 5.7958819 45.2099847 0, 5.7958638 45.2099587 0, 5.7958806 45.2099526 0, 5.7958913 45.2099337 0, 5.7958813 45.2099191 0, 5.7959141 45.2099063 0, 5.7957488 45.2096945 0, 5.7957153 45.2097078 0, 5.7957086 45.2096945 0, 5.7956804 45.209686 0, 5.7956603 45.2096926 0, 5.7956442 45.2096709 0, 5.7953371 45.2097881 0, 5.7953532 45.2098108 0, 5.7953251 45.2098211 0, 5.7953183 45.2098372 0, 5.7953318 45.2098542 0, 5.7953063 45.2098656 0), (5.7957333 45.2101765 0, 5.7957933 45.2102544 0, 5.7958263 45.2102615 0, 5.7959357 45.210222 0, 5.7959511 45.210196 0, 5.7958921 45.2101167 0, 5.795855 45.2101077 0, 5.795748 45.2101481 0, 5.7957333 45.2101765 0), (5.796387 45.2103131 0, 5.7964487 45.2103919 0, 5.7964794 45.2103985 0, 5.7965921 45.2103586 0, 5.7966071 45.2103294 0, 5.7965458 45.2102503 0, 5.7965087 45.2102438 0, 5.7963983 45.2102865 0, 5.796387 45.2103131 0)))";
var g = (MultiPolygon)Geometry.Deserialize<WktSerializer>(wkt);

var triangles = (MultiPolygon)Triangulator.Triangulate(g);
Assert.That(triangles.Geometries.Count == 350);

GltfCreator.CreateGltf(triangles, @"overture_building2.gltf");


}


[Test]
public void TriangulateMultiLineString()
{
Expand Down
2 changes: 1 addition & 1 deletion src/triangulator/Triangulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ private static List<int> Tesselate(Polygon footprint)

foreach (var interiorRing in footprint.InteriorRings)
{
holeIndices.Add((data.Count / 2) + 1);
holeIndices.Add(data.Count/2);
foreach (var p in interiorRing.Points)
{
data.Add((double)p.X);
Expand Down

0 comments on commit 94c332b

Please sign in to comment.