[gegl] reflect.c: remove unneeded square root computation & structure to minimize recomputation
- From: Nicolas Robidoux <nrobidoux src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl] reflect.c: remove unneeded square root computation & structure to minimize recomputation
- Date: Wed, 21 Nov 2012 15:20:12 +0000 (UTC)
commit 3e6ebdf61d5280cada705d5165870ed51298c488
Author: Nicolas Robidoux <nrobidoux git gnome org>
Date: Wed Nov 21 10:20:07 2012 -0500
reflect.c: remove unneeded square root computation & structure to minimize recomputation
operations/transform/reflect.c | 27 +++++++++++----------------
1 files changed, 11 insertions(+), 16 deletions(-)
---
diff --git a/operations/transform/reflect.c b/operations/transform/reflect.c
index a9851ed..0a7687c 100644
--- a/operations/transform/reflect.c
+++ b/operations/transform/reflect.c
@@ -36,27 +36,22 @@ gegl_chant_double (y, -G_MAXDOUBLE, G_MAXDOUBLE, 0.0,
#define GEGL_CHANT_SELF "reflect.c"
#include "chant.h"
-#include <math.h>
-
static void
create_matrix (OpTransform *op,
GeglMatrix3 *matrix)
{
GeglChantOperation *chant = GEGL_CHANT_OPERATION (op);
- gdouble ux = 0, uy = 0;
- gdouble l;
-
- ux = chant->x;
- uy = chant->y;
-
- l = sqrt(uy*uy + ux*ux);
- ux /= l;
- uy /= l;
-
- matrix->coeff [0][0] = 2*ux*ux - 1;
- matrix->coeff [1][1] = 2*uy*uy - 1;
- matrix->coeff [0][1] = matrix->coeff [1][0] = 2*ux*uy;
+ const gdouble ux = chant->x;
+ const gdouble uy = chant->y;
+ /*
+ * There probably should be an assertion or check that dot != 0.
+ */
+ const gdouble dot = uy*uy + ux*ux;
+ const gdouble two_over_dot = (gdouble) 2 / dot;
+
+ matrix->coeff [0][0] = ux*ux*two_over_dot - (gdouble) 1;
+ matrix->coeff [1][1] = uy*uy*two_over_dot - (gdouble) 1;
+ matrix->coeff [0][1] = matrix->coeff [1][0] = ux*uy*two_over_dot;
}
-
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]