[cairo] [PATCH 3/6] matrix: Refactor out two temporary variables

Bryce Harrington bryce at osg.samsung.com
Fri Nov 28 20:31:21 PST 2014


From: Bryce Harrington <b.harrington at samsung.com>

This makes the similarities and differences between
cairo_matrix_transform_distance and cairo_matrix_transform_point easier
to spot.

Signed-off-by: Bryce Harrington <bryce at osg.samsung.com>
---
 src/cairo-matrix.c |   15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/src/cairo-matrix.c b/src/cairo-matrix.c
index 21c717e..6d6e344 100644
--- a/src/cairo-matrix.c
+++ b/src/cairo-matrix.c
@@ -399,8 +399,8 @@ _cairo_matrix_multiply (cairo_matrix_t *r,
  * the returned vector is as follows:
  *
  * <programlisting>
- * dx2 = dx1 * a + dy1 * c;
- * dy2 = dx1 * b + dy1 * d;
+ * dx2 = (dx1 * a + dy1 * c) / (dx1 * e + dy1 * f);
+ * dy2 = (dx1 * b + dy1 * d) / (dx1 * e + dy1 * f);
  * </programlisting>
  *
  * Affine transformations are position invariant, so the same vector
@@ -413,16 +413,11 @@ _cairo_matrix_multiply (cairo_matrix_t *r,
 void
 cairo_matrix_transform_distance (const cairo_matrix_t *matrix, double *dx, double *dy)
 {
-    double new_x, new_y, new_p;
+    double new_p;
 
-    new_x = (matrix->xx * *dx + matrix->xy * *dy);
-    new_y = (matrix->yx * *dx + matrix->yy * *dy);
     new_p = matrix->px * *dx + matrix->py * *dy + 1;
-    new_x = new_x / new_p;
-    new_y = new_y / new_p;
-
-    *dx = new_x;
-    *dy = new_y;
+    *dx = (matrix->xx * *dx + matrix->xy * *dy) / new_p;
+    *dy = (matrix->yx * *dx + matrix->yy * *dy) / new_p;
 }
 slim_hidden_def(cairo_matrix_transform_distance);
 
-- 
1.7.9.5



More information about the cairo mailing list