mirror of
https://github.com/HarmonyHoney/ROTA.git
synced 2026-07-17 16:46:17 +00:00
optimize Rectangle.gd to merge overlapping points! (=
This commit is contained in:
parent
b1a8526046
commit
1653cca227
1 changed files with 11 additions and 3 deletions
|
|
@ -6,6 +6,8 @@ export var rect_offset := Vector2.ZERO setget set_offset
|
|||
export var radius := Plane(0, -1, -1, -1) setget set_radius
|
||||
export var points := 8 setget set_points
|
||||
|
||||
var vertex_merge := 0.05
|
||||
|
||||
func _draw():
|
||||
if !is_poly and gon.size() > 2: draw_colored_polygon(gon, Color.white, PoolVector2Array(), null, null, true)
|
||||
|
||||
|
|
@ -17,15 +19,21 @@ func shape():
|
|||
|
||||
for i in 4:
|
||||
var r = rad[0] if rad[i] == -1 else rad[i]
|
||||
if r == -2: r = min(size.x, size.y)
|
||||
r = clamp(r, 0, min(size.x, size.y) - 0.01)
|
||||
r = clamp(INF if r == -2 else r, 0, min(size.x, size.y))
|
||||
|
||||
if points > 1 and r > 0:
|
||||
var v = vec[i] * size - (vec[i] * r)
|
||||
|
||||
for p in points:
|
||||
var a = ((PI*.5) * i) + ((PI*.5) * (float(p) / (points - 1)))
|
||||
gon.append(rect_offset + v + Vector2(r, 0).rotated(a))
|
||||
var vertex = rect_offset + v + Vector2(r, 0).rotated(a)
|
||||
var is_do = true
|
||||
|
||||
if i > 0 and (p == 0 or (i == 3 and p == points - 1)):
|
||||
is_do = vertex.distance_to(gon[-1 if p == 0 else 0]) > vertex_merge
|
||||
|
||||
if is_do:
|
||||
gon.append(vertex)
|
||||
else:
|
||||
gon.append(rect_offset + vec[i] * size)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue