godot icon indicating copy to clipboard operation
godot copied to clipboard

Refactor `CurveEdit` to use consistent world/view transforms

Open anvilfolk opened this issue 1 year ago • 2 comments

Currently, CurveEdit uses a couple of different ways to ensure that points and lines are drawn in the right space. This makes the code harder to understand and maintain.

This PR makes the curve be drawn in view coordinates by transforming every point from world/curve-space into view-space. This ensures there is a single way to scale from curve-space to view-space and vice-versa. By drawing in view-space, we can keep anti-aliasing, which was the main point of the previous changes! 🥳

Other minor changes, resulting in fewer lines of code overall:

  • Removed CanvasItemPlotCurve, since it was only used in a single place
  • Moved plot_curve_accurate to CurveEdit so it can make use of _world_to_view transform and related functions
  • Did a pass to make sure vectors are passed around as const Vector2 &

anvilfolk avatar May 29 '23 16:05 anvilfolk