From a7fdbd618e3eafc8df39dbd6d6cf279d8b810db8 Mon Sep 17 00:00:00 2001
From: faiface <faiface@ksp.sk>
Date: Wed, 1 Mar 2017 23:12:48 +0100
Subject: [PATCH] add Vec.Apply

---
 geometry.go | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/geometry.go b/geometry.go
index b426686..d89217f 100644
--- a/geometry.go
+++ b/geometry.go
@@ -97,6 +97,15 @@ func (u Vec) Cross(v Vec) float64 {
 	return u.X()*v.Y() - v.X()*u.Y()
 }
 
+// Apply applies the function f to both x and y components of the vector u and returns the modified
+// vector.
+func (u Vec) Apply(f func(float64) float64) Vec {
+	return V(
+		f(u.X()),
+		f(u.Y()),
+	)
+}
+
 // Rect is a 2D rectangle aligned with the axes of the coordinate system. It has a position
 // and a size.
 //
-- 
GitLab