mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-04 09:28:11 +00:00
bezier working, needs more tests
This commit is contained in:
1 parent
91eac7e940
commit
8541de78bf
1 file changed
+24
-24
+24
-24
@@ -1,31 +1,31 @@
|
||||
|
||||
|
||||
/*
|
||||
@staticmethod
|
||||
def cubicBezierEased(t: float, x1: float, y1: float, x2: float, y2: float) -> float:
|
||||
def bezier(u: float):
|
||||
omu = 1.0 - u
|
||||
b1 = 3.0 * omu * omu * u
|
||||
b2 = 3.0 * omu * u * u
|
||||
b3 = u * u * u
|
||||
x = b1 * x1 + b2 * x2 + b3
|
||||
y = b1 * y1 + b2 * y2 + b3
|
||||
return x, y
|
||||
|
||||
lo, hi = 0.0, 1.0
|
||||
for _ in range(80):
|
||||
mid = 0.5 * (lo + hi)
|
||||
if bezier(mid)[0] < t:
|
||||
lo = mid
|
||||
else:
|
||||
hi = mid
|
||||
u = 0.5 * (lo + hi)
|
||||
return bezier(u)[1]
|
||||
*/
|
||||
|
||||
pub fn signature_cubic_bezier_eased(t: f64, x1: f64, y1: f64, x2: f64, y2: f64) -> f64 {
|
||||
/*
|
||||
@staticmethod
|
||||
def cubicBezierEased(t: float, x1: float, y1: float, x2: float, y2: float) -> float:
|
||||
def bezier(u: float):
|
||||
omu = 1.0 - u
|
||||
b1 = 3.0 * omu * omu * u
|
||||
b2 = 3.0 * omu * u * u
|
||||
b3 = u * u * u
|
||||
x = b1 * x1 + b2 * x2 + b3
|
||||
y = b1 * y1 + b2 * y2 + b3
|
||||
return x, y
|
||||
|
||||
lo, hi = 0.0, 1.0
|
||||
for _ in range(80):
|
||||
mid = 0.5 * (lo + hi)
|
||||
if bezier(mid)[0] < t:
|
||||
lo = mid
|
||||
else:
|
||||
hi = mid
|
||||
u = 0.5 * (lo + hi)
|
||||
return bezier(u)[1]
|
||||
*/
|
||||
|
||||
let mut lo = 0.0;
|
||||
let mut hi = 0.0;
|
||||
let mut hi = 1.0;
|
||||
|
||||
for _ in 0..80 {
|
||||
let mid = 0.5 * (lo + hi);
|
||||
|
||||
Reference in new issue
Block a user