2012-08-27 14:11:33 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2012-07-02 20:27:02 +00:00
|
|
|
#include "CurveUtilities.h"
|
2012-02-03 22:07:47 +00:00
|
|
|
#include "Intersection_Tests.h"
|
2012-01-10 21:46:10 +00:00
|
|
|
#include "LineIntersection.h"
|
|
|
|
|
2012-01-25 18:57:23 +00:00
|
|
|
// FIXME: add tests for intersecting, non-intersecting, degenerate, coincident
|
2012-01-10 21:46:10 +00:00
|
|
|
const _Line tests[][2] = {
|
2012-02-03 22:07:47 +00:00
|
|
|
{{{0, 0}, {1, 0}}, {{1, 0}, {0, 0}}},
|
|
|
|
{{{0, 0}, {0, 0}}, {{0, 0}, {1, 0}}},
|
|
|
|
{{{0, 1}, {0, 1}}, {{0, 0}, {0, 2}}},
|
|
|
|
{{{0, 0}, {1, 0}}, {{0, 0}, {2, 0}}},
|
|
|
|
{{{1, 1}, {2, 2}}, {{0, 0}, {3, 3}}},
|
2012-08-23 18:14:13 +00:00
|
|
|
{{{166.86950047022856, 112.69654129527828}, {166.86948801592692, 112.69655741235339}},
|
2012-02-03 22:07:47 +00:00
|
|
|
{{166.86960700313026, 112.6965477747386}, {166.86925794355412, 112.69656471103423}}}
|
2012-01-10 21:46:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const size_t tests_count = sizeof(tests) / sizeof(tests[0]);
|
|
|
|
|
2012-02-03 22:07:47 +00:00
|
|
|
const _Line noIntersect[][2] = {
|
|
|
|
{{{0, 0}, {1, 0}}, {{3, 0}, {2, 0}}},
|
|
|
|
{{{0, 0}, {0, 0}}, {{1, 0}, {2, 0}}},
|
|
|
|
{{{0, 1}, {0, 1}}, {{0, 3}, {0, 2}}},
|
|
|
|
{{{0, 0}, {1, 0}}, {{2, 0}, {3, 0}}},
|
|
|
|
{{{1, 1}, {2, 2}}, {{4, 4}, {3, 3}}},
|
|
|
|
};
|
|
|
|
|
|
|
|
const size_t noIntersect_count = sizeof(noIntersect) / sizeof(noIntersect[0]);
|
|
|
|
|
2012-01-10 21:46:10 +00:00
|
|
|
static size_t firstLineIntersectionTest = 0;
|
2012-02-03 22:07:47 +00:00
|
|
|
static size_t firstNoIntersectionTest = 0;
|
2012-01-10 21:46:10 +00:00
|
|
|
|
|
|
|
void LineIntersection_Test() {
|
2012-02-03 22:07:47 +00:00
|
|
|
size_t index;
|
|
|
|
for (index = firstLineIntersectionTest; index < tests_count; ++index) {
|
2012-01-10 21:46:10 +00:00
|
|
|
const _Line& line1 = tests[index][0];
|
|
|
|
const _Line& line2 = tests[index][1];
|
2013-02-14 15:29:11 +00:00
|
|
|
Intersections ts;
|
|
|
|
int pts = intersect(line1, line2, ts);
|
2012-02-03 22:07:47 +00:00
|
|
|
if (!pts) {
|
|
|
|
printf("%s [%zu] no intersection found\n", __FUNCTION__, index);
|
|
|
|
}
|
|
|
|
for (int i = 0; i < pts; ++i) {
|
|
|
|
_Point result1, result2;
|
2013-02-14 15:29:11 +00:00
|
|
|
xy_at_t(line1, ts.fT[0][i], result1.x, result1.y);
|
|
|
|
xy_at_t(line2, ts.fT[1][i], result2.x, result2.y);
|
2012-02-03 22:07:47 +00:00
|
|
|
if (!result1.approximatelyEqual(result2)) {
|
|
|
|
if (pts == 1) {
|
|
|
|
printf("%s [%zu] not equal\n", __FUNCTION__, index);
|
|
|
|
} else {
|
2013-02-14 15:29:11 +00:00
|
|
|
xy_at_t(line2, ts.fT[1][i ^ 1], result2.x, result2.y);
|
2012-02-03 22:07:47 +00:00
|
|
|
if (!result1.approximatelyEqual(result2)) {
|
|
|
|
printf("%s [%zu] not equal\n", __FUNCTION__, index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (index = firstNoIntersectionTest; index < noIntersect_count; ++index) {
|
|
|
|
const _Line& line1 = noIntersect[index][0];
|
|
|
|
const _Line& line2 = noIntersect[index][1];
|
2013-02-14 15:29:11 +00:00
|
|
|
Intersections ts;
|
|
|
|
int pts = intersect(line1, line2, ts);
|
2012-02-03 22:07:47 +00:00
|
|
|
if (pts) {
|
|
|
|
printf("%s [%zu] no intersection expected\n", __FUNCTION__, index);
|
|
|
|
}
|
2012-01-10 21:46:10 +00:00
|
|
|
}
|
|
|
|
}
|