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

Bryce Harrington <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <[email protected]>
From: Bryce Harrington <[email protected]>

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

Signed-off-by: Bryce Harrington <[email protected]>
---
 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

-- 
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.