diff --git a/libgimpmath/gimpvector.c b/libgimpmath/gimpvector.c index c963ea7a1119af10476e472bf8f6d79849a8f712..bb5318237eae34dab99bff8b41d114bfeb29a975 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 4ec383b7beb77049aebc1acc57022f7e58e65d2d..f6f38c1499e9f4eb7faa91d2860ad434614797d1 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 */ /* ================================== */