diff --git a/bunny.cpp b/bunny.cpp index 3528b35defd0b78445c3791edb1cea6ccb120333..ead5734a49dd9000a48d5dc7a687a52f72cbd881 100644 --- a/bunny.cpp +++ b/bunny.cpp @@ -49,7 +49,7 @@ bool convex_contains(polygon polygon, float2 point) }); } -void lerplerp_lerp(range<vertex*> buffer) +void bezier_way(range<vertex*> buffer) { auto start = (buffer.begin()+0)->origin; auto middle = (buffer.begin()+1)->origin; @@ -58,10 +58,10 @@ void lerplerp_lerp(range<vertex*> buffer) auto ratio = 0.f; for(auto&& vertex : buffer) { - vertex.origin = lerp + vertex.origin = way ( - lerp(start, middle, ratio), - lerp(middle, end, ratio), + way(start, middle, ratio), + way(middle, end, ratio), ratio ), float2{}; ratio += step; @@ -103,9 +103,9 @@ polygon make_nose(float2 aspect) auto& curr = nose_control[i].origin; auto& next = nose_control[wrap(i+1, nose_control.size())].origin; auto& prev = nose_control[wrap(i-1, nose_control.size())].origin; - auto curve_control_prev = lerp(curr, prev, 1.f/2); + auto curve_control_prev = way(curr, prev, 1.f/2); auto curve_control_curr = curr; - auto curve_control_next = lerp(curr, next, 1.f/2); + auto curve_control_next = way(curr, next, 1.f/2); auto length = std::max( geom::length(curve_control_curr - curve_control_prev), geom::length(curve_control_curr - curve_control_next) @@ -117,7 +117,7 @@ polygon make_nose(float2 aspect) vertices[start+0] = vertex{curve_control_prev}; vertices[start+1] = vertex{curve_control_curr}; vertices[start+2] = vertex{curve_control_next}; - lerplerp_lerp({ + bezier_way({ vertices.data() + start, vertices.data() + vertices.size() }); @@ -253,7 +253,7 @@ void start(Program& program) constexpr float fade_in = 2; constexpr float fade_out = 2; float fade = std::min(ratio*fade_in, (1-ratio)*fade_out); - return lerp(0.f,std::sin(ratio * 170 * poke_ratio), std::min(fade, 1.f)); + return way(0.f,std::sin(ratio * 170 * poke_ratio), std::min(fade, 1.f)); }, 100ms}, 0); poke = melody( poke_motion{float2::zero(), offset/2, 100ms}, diff --git a/common/math.hpp b/common/math.hpp index d7d761ce215a73cf2ac0c6b3af9bd6f0898f0615..010a5ea1f78f4d4ceda35a896d7e63be0955fefd 100644 --- a/common/math.hpp +++ b/common/math.hpp @@ -11,13 +11,6 @@ using namespace simple; constexpr auto half = geom::vector<float,2>::one(.5f); const float tau = 2*std::acos(-1); -template <typename Number, typename Ratio = float> -[[nodiscard]] constexpr -Number lerp(Number from, Number to, Ratio ratio) -{ - return from + (to - from) * ratio; -} - template <typename Vector> [[nodiscard]] constexpr Vector project_on_unit(Vector x, Vector surface) @@ -139,7 +132,8 @@ class protractor Value index = factor * (protractor::circle.size() - 1); int whole = index; Value fraction = index - whole; - return lerp(circle[whole], circle[whole+1], fraction); + using support::way; + return way(circle[whole], circle[whole+1], fraction); } static constexpr vector tau() diff --git a/common/sketchbook.hpp b/common/sketchbook.hpp index 5ab76f6576cf3940d431f8d4e5bb24a4eb549632..6eccd2638a0038e0aeadab730f627ec34c6fdfc6 100644 --- a/common/sketchbook.hpp +++ b/common/sketchbook.hpp @@ -50,7 +50,7 @@ using rgba32 = graphical::rgba_pixel; using scancode = interactive::scancode; using keycode = interactive::keycode; using mouse_button = interactive::mouse_button; -using common::lerp; +using simple::support::way; using simple::support::make_range; constexpr int max_int = std::numeric_limits<int>::max(); diff --git a/no_trig_rotation.cpp b/no_trig_rotation.cpp index db03c6536e16ac5de237b4020d44285fc503d890..ffc4654197c05e26ee43c9c41d1f6c0d17cd8169 100644 --- a/no_trig_rotation.cpp +++ b/no_trig_rotation.cpp @@ -116,7 +116,7 @@ class protractor Value index = factor * (protractor::circle.size() - 1); int whole = index; Value fraction = index - whole; - return lerp(circle[whole], circle[whole+1], fraction); + return way(circle[whole], circle[whole+1], fraction); // linear interpolation more or less works thanks to normalizing/dividing projection // otherwise this method is no good } diff --git a/notanorgan.cpp b/notanorgan.cpp index bc3ac11f6f68e455b2f92012d1ef80b6d536565e..f47898aaff27862579f868786664373477acaaa3 100644 --- a/notanorgan.cpp +++ b/notanorgan.cpp @@ -85,7 +85,7 @@ void start(Program& program) constexpr float fade_in = 2; constexpr float fade_out = 2; float fade = std::min(ratio*fade_in, (1-ratio)*fade_out); - return lerp(0.f,sinus(ratio * note), std::min(fade, 1.f)); + return way(0.f,sinus(ratio * note), std::min(fade, 1.f)); }; int canal = 32; diff --git a/starry_night_sky.cpp b/starry_night_sky.cpp index aef11f72ee3dc8ac6f4463abbb5a7282218c2eca..d73ea020c230b5754ce250c84bb8a148bbf80f29 100644 --- a/starry_night_sky.cpp +++ b/starry_night_sky.cpp @@ -70,7 +70,7 @@ void start(Program& program) frame.begin_sketch() .line_width(2) .line({0.f,i},{frame.size.x(),i}) - .outline(lerp(skyColorFrom,skyColorTo,i/frame.size.y())) + .outline(way(skyColorFrom,skyColorTo,i/frame.size.y())) ; }