[gimp/soc-2010-cage-2] libgimpmath: add a function that compute the normal vector to an other



commit 884bc9b0f56ee2ce4e6dd7b592b908791d09edfc
Author: Michael Muré <batolettre gmail com>
Date:   Wed Jul 14 23:51:04 2010 +0200

    libgimpmath: add a function that compute the normal vector to an other

 libgimpmath/gimpvector.c |   42 ++++++++++++++++++++++++++++++++++++++++++
 libgimpmath/gimpvector.h |    2 ++
 2 files changed, 44 insertions(+), 0 deletions(-)
---
diff --git a/libgimpmath/gimpvector.c b/libgimpmath/gimpvector.c
index c963ea7..bb53182 100644
--- a/libgimpmath/gimpvector.c
+++ b/libgimpmath/gimpvector.c
@@ -451,6 +451,48 @@ gimp_vector2_rotate_val (GimpVector2 vector,
   return result;
 }
 
+/**
+ * gimp_vector2_normal:
+ * @vector: a pointer to a #GimpVector2.
+ *
+ * Compute a normalized perpendicular vector to @vector
+ *
+ * Returns: a #GimpVector2 perpendicular to @vector, with a length of 1.0.
+ **/
+GimpVector2
+gimp_vector2_normal (GimpVector2  *vector)
+{
+  GimpVector2 result;
+  
+  result.x = vector->y;
+  result.y = - vector->x;
+  
+  gimp_vector2_normalize (vector);
+  
+  return result;
+}
+
+/**
+ * gimp_vector2_normal_val:
+ * @vector: a #GimpVector2.
+ *
+ * This function is identical to gimp_vector2_normal() but the vector
+ * is passed by value rather than by reference.
+ *
+ * Returns: a #GimpVector2 perpendicular to @vector, with a length of 1.0.
+ **/
+GimpVector2
+gimp_vector2_normal_val (GimpVector2  vector)
+{
+  GimpVector2 result;
+  
+  result.x = vector.y;
+  result.y = - vector.x;
+  
+  gimp_vector2_normalize (&result);
+  
+  return result;
+}
 /**************************************/
 /* Three dimensional vector functions */
 /**************************************/
diff --git a/libgimpmath/gimpvector.h b/libgimpmath/gimpvector.h
index 4ec383b..f6f38c1 100644
--- a/libgimpmath/gimpvector.h
+++ b/libgimpmath/gimpvector.h
@@ -85,6 +85,8 @@ void        gimp_vector2_rotate            (GimpVector2       *vector,
                                             gdouble            alpha);
 GimpVector2 gimp_vector2_rotate_val        (GimpVector2        vector,
                                             gdouble            alpha);
+GimpVector2 gimp_vector2_normal            (GimpVector2       *vector);
+GimpVector2 gimp_vector2_normal_val        (GimpVector2        vector);
 
 /* Three dimensional vector functions */
 /* ================================== */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]