-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
switch to tesselated fill rendering with earcut
- Loading branch information
Showing
7 changed files
with
144 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
'use strict'; | ||
|
||
module.exports = classifyRings; | ||
|
||
// classifies an array of rings into polygons with outer rings and holes | ||
|
||
function classifyRings(rings) { | ||
var len = rings.length; | ||
|
||
if (len <= 1) return [rings]; | ||
|
||
var polygons = [], | ||
polygon, | ||
ccw; | ||
|
||
for (var i = 0; i < len; i++) { | ||
var area = signedArea(rings[i]); | ||
if (area === 0) continue; | ||
|
||
if (!ccw) ccw = area < 0; | ||
|
||
if (ccw === area < 0) { | ||
if (polygon) polygons.push(polygon); | ||
polygon = [rings[i]]; | ||
|
||
} else { | ||
polygon.push(rings[i]); | ||
} | ||
} | ||
polygons.push(polygon); | ||
|
||
return polygons; | ||
} | ||
|
||
function signedArea(ring) { | ||
var sum = 0; | ||
for (var i = 0, len = ring.length, j = len - 1, p1, p2; i < len; j = i++) { | ||
p1 = ring[i]; | ||
p2 = ring[j]; | ||
sum += (p2[0] - p1[0]) * (p1[1] + p2[1]); | ||
} | ||
return sum; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters