Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions Delaunator.gd
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
class_name Delaunator

const EPSILON = pow(2, -52)
const EDGE_STACK = []
var EDGE_STACK = []

var coords := PoolRealArray()
var halfedges := PoolIntArray()
var hull := [] # This array should be a PoolIntArray but we need to use the .slice() function on it.
var triangles := PoolIntArray()
var coords := PackedFloat32Array()
var halfedges := PackedInt32Array()
var hull := [] # This array should be a PackedInt32Array but we need to use the .slice() function on it.
var triangles := PackedInt32Array()
var triangles_len := 0
var _cx: float
var _cy: float
var _dists := PoolRealArray()
var _halfedges := [] # This array should be a PoolIntArray but we need to use the .slice() function on it.
var _dists := PackedFloat32Array()
var _halfedges := [] # This array should be a PackedInt32Array but we need to use the .slice() function on it.
var _hash_size: int
var _hull_hash := PoolIntArray()
var _hull_next := PoolIntArray()
var _hull_prev := PoolIntArray()
var _hull_hash := PackedInt32Array()
var _hull_next := PackedInt32Array()
var _hull_prev := PackedInt32Array()
var _hull_start: int
var _hull_tri := PoolIntArray()
var _ids := [] # PoolIntArray, but causes errors if not an array
var _triangles := [] # This array should be a PoolIntArray but we need to use the .slice() function on it.
var _hull_tri := PackedInt32Array()
var _ids := [] # PackedInt32Array, but causes errors if not an array
var _triangles := [] # This array should be a PackedInt32Array but we need to use the .slice() function on it.


func _init(points: PoolVector2Array) -> void:
func _init(points: PackedVector2Array) -> void:
if points.size() < 3:
push_error(ProjectSettings.get_setting("application/config/name") + " needs at least 3 points.")
return
Expand Down Expand Up @@ -152,7 +152,7 @@ func update() -> void:
hull[j] = id
j += 1
d0 = _dists[id]
hull = hull.slice(0, j - 1)
hull = hull.slice(0, j)
triangles = []
halfedges = []

Expand Down Expand Up @@ -292,8 +292,8 @@ func update() -> void:
e = _hull_next[e]

# Trim typed triangle mesh arrays.
triangles = _triangles.slice(0, triangles_len - 1)
halfedges = _halfedges.slice(0, triangles_len - 1)
triangles = _triangles.slice(0, triangles_len)
halfedges = _halfedges.slice(0, triangles_len)


func _hash_key(x: float, y: float) -> float:
Expand Down Expand Up @@ -408,7 +408,7 @@ func _add_triangle(i0: int, i1: int, i2: int, a: int, b: int, c: int) -> int:

# Monotonically increases with real angle, but doesn't need expensive trigonometry.
func pseudo_angle(dx: float, dy: float) -> float:
var p := dx / (abs(dx) + abs(dy))
var p := dx / (absf(dx) + absf(dy))

if (dy > 0):
return (3.0 - p) / 4.0 # [0..1]
Expand Down