From 4d2028c60cf501e09c945871e74cc4862afd804f Mon Sep 17 00:00:00 2001 From: Per Lindstrand Date: Sat, 6 Apr 2024 12:54:09 +0200 Subject: [PATCH 1/4] Changed EDGE_STACK from const to var for Godot 4 In Godot 4 const arrays cannot be modified so the EDGE_STACK variable should be var, not const. --- Delaunator.gd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Delaunator.gd b/Delaunator.gd index 5976fa1..7448f97 100644 --- a/Delaunator.gd +++ b/Delaunator.gd @@ -1,7 +1,7 @@ class_name Delaunator const EPSILON = pow(2, -52) -const EDGE_STACK = [] +var EDGE_STACK = [] var coords := PoolRealArray() var halfedges := PoolIntArray() From 0fcb068f85689d4bd0ddcb77b8e124565a568b77 Mon Sep 17 00:00:00 2001 From: Per Lindstrand Date: Sat, 6 Apr 2024 12:57:50 +0200 Subject: [PATCH 2/4] Changed array types to be compatible with Godot 4 This commit changes the types of various arrays from Pool* to Packed* to be compatible with Godot 4. --- Delaunator.gd | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Delaunator.gd b/Delaunator.gd index 7448f97..4a1a3ff 100644 --- a/Delaunator.gd +++ b/Delaunator.gd @@ -3,26 +3,26 @@ class_name Delaunator const EPSILON = pow(2, -52) 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 From 72e94dd12e4034088ff966f0e3ee5d3c49bce748 Mon Sep 17 00:00:00 2001 From: Per Lindstrand Date: Sat, 6 Apr 2024 12:58:50 +0200 Subject: [PATCH 3/4] Fixed off-by-one slice end index for Godot 4 In Godot 4 the slice method's end index parameter is now exclusive. This commit updates the code to reflect that change. --- Delaunator.gd | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Delaunator.gd b/Delaunator.gd index 4a1a3ff..f94f924 100644 --- a/Delaunator.gd +++ b/Delaunator.gd @@ -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 = [] @@ -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: From e0f061f658e1b10438c101704c74f2c1c64cfe95 Mon Sep 17 00:00:00 2001 From: Per Lindstrand Date: Sat, 6 Apr 2024 13:02:44 +0200 Subject: [PATCH 4/4] Fix type warning for Godot 4 This commit fixes a small type warning for Godot 4 by using the absf() method instead of abs(). --- Delaunator.gd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Delaunator.gd b/Delaunator.gd index f94f924..221047b 100644 --- a/Delaunator.gd +++ b/Delaunator.gd @@ -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]