Curves with domain other than [0, 1]

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By stefanbuettner

Hey there,

I’m trying to use a Curve to interpolated some samples in a script. I could not find a way to change the domain from [0, 1] from within the editor nor from a script. Here’s a minimal example of what I would like to have:

var myCurve = Curve.new()
myCurve.max_value = 10.0
myCurve.add_point(Vector2(0, 0), 1, 1, Curve.TANGENT_LINEAR, Curve.TANGENT_LINEAR)
myCurve.add_point(Vector2(5, 10), 1, 1, Curve.TANGENT_LINEAR, Curve.TANGENT_LINEAR)
for i in range(0, 50):
	var x = i / 10.
	var y = myCurve.sample(x)
	print(Vector2(x, y))

which yields

(0, 0)
(0.1, 1)
(0.2, 2)
(0.3, 3)
(0.4, 4)
(0.5, 5)
(0.6, 6.000001)
(0.7, 7)
(0.8, 8)
(0.9, 8.999999)
(1, 10)
(1.1, 10)
(1.2, 10)
(1.3, 10)

I could scale my input values to [0, 1]. But I wanted to know whether there is a possibility to extend the domain of Curves and if not, why this is prohibited.

Thanks a lot,
Stefan

I guessing because Curves are normalized and 1 is 100% and 100% is max

Moreus | 2023-03-12 18:56

:bust_in_silhouette: Reply From: jgodfrey

It looks like there’s a proposal (and a PR) to do just this, but it’s not currently merged. See here for details:

For now, I think you’ll have to scale your values.

Great! Thanks for the MR/Issue link. Will follow it’s progress. Thanks

stefanbuettner | 2023-03-13 15:20

1 Like