[cairo-commit] test/get-path-extents.c
Chris Wilson
ickle at kemper.freedesktop.org
Thu Jun 20 06:13:58 PDT 2013
test/get-path-extents.c | 30 +++++++++++++++++++++---------
1 file changed, 21 insertions(+), 9 deletions(-)
New commits:
commit 9ea5993b036f5930179263baaf3162eeebb7c153
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Thu Jun 20 14:11:38 2013 +0100
test/get-path-extents: Check exact matches within tolerance
When we refine geometry, we do so to a tolerance as specified by the
user. This means that we can not expect tessellated results to have
exact results, but always they should match within the specified
tolerance.
Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
diff --git a/test/get-path-extents.c b/test/get-path-extents.c
index 5ea2d4a..3b80d1e 100644
--- a/test/get-path-extents.c
+++ b/test/get-path-extents.c
@@ -31,6 +31,19 @@ enum ExtentsType { FILL, STROKE, PATH };
enum Relation { EQUALS, APPROX_EQUALS, CONTAINS };
+
+static cairo_bool_t within_tolerance(double x1, double y1,
+ double x2, double y2,
+ double expected_x1, double expected_y1,
+ double expected_x2, double expected_y2,
+ double tolerance)
+{
+ return (fabs (expected_x1 - x1) < tolerance &&
+ fabs (expected_y1 - y1) < tolerance &&
+ fabs (expected_x2 - x2) < tolerance &&
+ fabs (expected_y2 - y2) < tolerance);
+}
+
static cairo_bool_t
check_extents (const cairo_test_context_t *ctx,
const char *message, cairo_t *cr, enum ExtentsType type,
@@ -65,18 +78,17 @@ check_extents (const cairo_test_context_t *ctx,
default:
case EQUALS:
relation_string = "equal";
- if (ext_x1 == x && ext_y1 == y && ext_x2 == x + width && ext_y2 == y + height)
- return 1;
+ if (within_tolerance(x, y, x + width, y + height,
+ ext_x1, ext_y1, ext_x2, ext_y2,
+ cairo_get_tolerance(cr)))
+ return 1;
break;
case APPROX_EQUALS:
relation_string = "approx. equal";
- if (fabs (ext_x1 - x) < 1. &&
- fabs (ext_y1 - y) < 1. &&
- fabs (ext_x2 - (x + width)) < 1. &&
- fabs (ext_y2 - (y + height)) < 1.)
- {
- return 1;
- }
+ if (within_tolerance(x, y, x + width, y + height,
+ ext_x1, ext_y1, ext_x2, ext_y2,
+ 1.))
+ return 1;
break;
case CONTAINS:
relation_string = "contain";
More information about the cairo-commit
mailing list