Skip to content

The efficiency of Geometry2D polygon offset with JOIN_ROUND operation has slowed down significantly in 4.3 #97964

Closed
@mikhaelmartin

Description

@mikhaelmartin

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]

result from 4.2:
image

result from 4.3:
image

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

Minimal reproduction project (MRP)

geometry 2d test 4.2.zip
geometry 2d test 4.3.zip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions