From 85f2009edc65171dbc6a06f8bfb4dc7405ed69eb Mon Sep 17 00:00:00 2001
From: namark <namark@disroot.org>
Date: Sun, 9 Aug 2020 17:06:11 +0400
Subject: [PATCH] Make way, you lerp!

---
 bunny.cpp             | 16 ++++++++--------
 common/math.hpp       | 10 ++--------
 common/sketchbook.hpp |  2 +-
 no_trig_rotation.cpp  |  2 +-
 notanorgan.cpp        |  2 +-
 starry_night_sky.cpp  |  2 +-
 6 files changed, 14 insertions(+), 20 deletions(-)

diff --git a/bunny.cpp b/bunny.cpp
index 3528b35..ead5734 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 d7d761c..010a5ea 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 5ab76f6..6eccd26 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 db03c65..ffc4654 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 bc3ac11..f47898a 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 aef11f7..d73ea02 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()))
 			;
 		}
 
-- 
GitLab