Description
Tested versions
4.3.stable
System information
Godot v4.3.stable - Fedora Linux 40 (Workstation Edition) - X11 - GLES3 (Compatibility) - AMD Radeon Graphics (radeonsi, renoir, LLVM 18.1.6, DRM 3.57, 6.10.12-200.fc40.x86_64) - AMD Ryzen 7 5700G with Radeon Graphics (16 Threads)
Issue description
My game use Geometry2D.polygon_offset heavily in animating polygons. i need it to be executed each frame for several polygons. After updating from Godot 4.2.2 to 4.3 I noticed significant performance hit.
This performance hit is only when using Geometry2D.polygon_offset with JOIN_ROUND.
I believe this is related to recent update from clipper1 to clipper2 library #90153
my testing with the same input polygon the resulting offset has significantly more points, could be due to precision change.
code for test:
extends Polygon2D
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
var poly = polygon
prints("input polygon:",poly,"\n")
var poly_offset = []
var start_time = Time.get_ticks_usec()
for i in 10000:
poly_offset = Geometry2D.offset_polygon(poly,10,Geometry2D.JOIN_ROUND)
prints("4.3 offset join round:")
prints("execution time:", Time.get_ticks_usec() - start_time)
prints("result size:",poly_offset[0].size(),"\n")
start_time = Time.get_ticks_usec()
for i in 10000:
poly_offset = Geometry2D.offset_polygon(poly,10,Geometry2D.JOIN_MITER)
prints("4.3 offset join miter:")
prints("execution time:", Time.get_ticks_usec() - start_time)
prints("result size:",poly_offset[0].size(),"\n")
polygon = poly_offset[0]
For compatibility reason, new polygon_offset should have the same precision with previous godot version. Or even better expose precision as an option argument to polygon_offset
Steps to reproduce
- execute Geometry2d.polygon_offset with JOIN_ROUND as argument