work in progress

git-svn-id: http://skia.googlecode.com/svn/trunk@3443 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
caryclark@google.com 2012-03-20 21:11:59 +00:00
parent 8570b5c869
commit 2e7f4c810d
14 changed files with 2876 additions and 258 deletions

View File

@ -1,5 +1,19 @@
#include "DataTypes.h"
#include <sys/types.h>
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#endif
void *memcpy(void *, const void *, size_t);
#ifdef __cplusplus
}
#endif
const double PointEpsilon = 0.000001;
const double SquaredEpsilon = PointEpsilon * PointEpsilon;
@ -111,3 +125,58 @@ void xy_at_t(const Quadratic& quad, double t, double& x, double& y) {
y = a * quad[0].y + b * quad[1].y + c * quad[2].y;
}
}
// from http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
union Float_t
{
Float_t(float num = 0.0f) : f(num) {}
// Portable extraction of components.
bool Negative() const { return (i >> 31) != 0; }
int32_t RawMantissa() const { return i & ((1 << 23) - 1); }
int32_t RawExponent() const { return (i >> 23) & 0xFF; }
int32_t i;
float f;
#ifdef _DEBUG
struct
{ // Bitfields for exploration. Do not use in production code.
uint32_t mantissa : 23;
uint32_t exponent : 8;
uint32_t sign : 1;
} parts;
#endif
};
bool AlmostEqualUlps(float A, float B, int maxUlpsDiff)
{
Float_t uA(A);
Float_t uB(B);
// Different signs means they do not match.
if (uA.Negative() != uB.Negative())
{
// Check for equality to make sure +0==-0
return A == B;
}
// Find the difference in ULPs.
int ulpsDiff = abs(uA.i - uB.i);
return ulpsDiff <= maxUlpsDiff;
}
int UlpsDiff(float A, float B)
{
Float_t uA(A);
Float_t uB(B);
return abs(uA.i - uB.i);
}
int FloatAsInt(float A)
{
Float_t uA(A);
return uA.i;
}

View File

@ -1,6 +1,16 @@
#ifndef __DataTypes_h__
#define __DataTypes_h__
#ifdef __cplusplus
extern "C" {
#endif
extern double fabs( double );
#ifdef __cplusplus
}
#endif
extern const double PointEpsilon;
extern const double SquaredEpsilon;
@ -123,4 +133,8 @@ void xy_at_t(const Cubic& , double t, double& x, double& y);
void xy_at_t(const _Line& , double t, double& x, double& y);
void xy_at_t(const Quadratic& , double t, double& x, double& y);
bool AlmostEqualUlps(float A, float B, int maxUlpsDiff);
int UlpsDiff(float A, float B);
int FloatAsInt(float A);
#endif // __DataTypes_h__

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,9 @@
/*
* EdgeWalkerPolygons_Mismatches.h
* edge
*
* Created by Cary Clark on 3/6/12.
* Copyright 2012 __MyCompanyName__. All rights reserved.
*
*/

View File

@ -12,8 +12,8 @@ static void testSimplifyTriangle() {
path.lineTo(10,30); // /_|
path.lineTo(20,30);
path.close();
simplify(path, true, out); // expect |\/|
comparePaths(path, out); // |__|
testSimplify(path, true, out); // expect |\/|
// |__|
}
static void testSimplifyTriangle3() {
@ -26,8 +26,7 @@ static void testSimplifyTriangle3() {
path.lineTo(1, 0);
path.lineTo(3, 1);
path.close();
simplify(path, true, out);
comparePaths(path, out);
testSimplify(path, true, out);
}
static void testSimplifyTriangle4() {
@ -40,8 +39,7 @@ static void testSimplifyTriangle4() {
path.lineTo(1, 0);
path.lineTo(2, 1);
path.close();
simplify(path, true, out);
comparePaths(path, out);
testSimplify(path, true, out);
}
static void testSimplifyTriangle5() {
@ -54,8 +52,7 @@ static void testSimplifyTriangle5() {
path.lineTo(1, 1);
path.lineTo(2, 1);
path.close();
simplify(path, true, out);
comparePaths(path, out);
testSimplify(path, true, out);
}
static void testSimplifyTriangle6() {
@ -70,8 +67,7 @@ static void testSimplifyTriangle6() {
path.lineTo(3, 1);
path.lineTo(0, 0);
path.close();
simplify(path, true, out);
comparePaths(path, out);
testSimplify(path, true, out);
}
static void testSimplifyTriangle7() {
@ -86,8 +82,7 @@ static void testSimplifyTriangle7() {
path.lineTo(0, 2);
path.lineTo(0, 0);
path.close();
simplify(path, true, out);
comparePaths(path, out);
testSimplify(path, true, out);
}
static void testSimplifyTriangle8() {
@ -102,8 +97,7 @@ static void testSimplifyTriangle8() {
path.lineTo(1, 3);
path.lineTo(0, 1);
path.close();
simplify(path, true, out);
comparePaths(path, out);
testSimplify(path, true, out);
}
static void testSimplifyTriangle9() {
@ -118,8 +112,7 @@ static void testSimplifyTriangle9() {
path.lineTo(2, 1);
path.lineTo(0, 0);
path.close();
simplify(path, true, out);
comparePaths(path, out);
testSimplify(path, true, out);
}
static void testSimplifyTriangle10() {
@ -134,8 +127,7 @@ static void testSimplifyTriangle10() {
path.lineTo(0, 1);
path.lineTo(0, 0);
path.close();
simplify(path, true, out);
comparePaths(path, out);
testSimplify(path, true, out);
}
static void testSimplifyTriangle11() {
@ -150,8 +142,7 @@ static void testSimplifyTriangle11() {
path.lineTo(2, 2);
path.lineTo(0, 0);
path.close();
simplify(path, true, out);
comparePaths(path, out);
testSimplify(path, true, out);
}
static void testSimplifyTriangle12() {
@ -166,8 +157,7 @@ static void testSimplifyTriangle12() {
path.lineTo(1, 1);
path.lineTo(2, 0);
path.close();
simplify(path, true, out);
comparePaths(path, out);
testSimplify(path, true, out);
}
static void testSimplifyTriangle13() {
@ -182,8 +172,7 @@ static void testSimplifyTriangle13() {
path.lineTo(1, 1);
path.lineTo(3, 0);
path.close();
simplify(path, true, out);
comparePaths(path, out);
testSimplify(path, true, out);
}
static void testSimplifyTriangle14() {
@ -198,8 +187,7 @@ static void testSimplifyTriangle14() {
path.lineTo(0, 1);
path.lineTo(0, 0);
path.close();
simplify(path, true, out);
comparePaths(path, out);
testSimplify(path, true, out);
}
static void testSimplifyTriangle15() {
@ -213,8 +201,7 @@ static void testSimplifyTriangle15() {
path.lineTo(0, 1);
path.lineTo(2, 2);
path.close();
simplify(path, true, out);
comparePaths(path, out);
testSimplify(path, true, out);
}
static void testSimplifyTriangle16() {
@ -227,8 +214,7 @@ static void testSimplifyTriangle16() {
path.lineTo(0, 1);
path.lineTo(1, 3);
path.close();
simplify(path, true, out);
comparePaths(path, out);
testSimplify(path, true, out);
}
static void testSimplifyTriangle17() {
@ -241,8 +227,7 @@ static void testSimplifyTriangle17() {
path.lineTo(1, 3);
path.lineTo(0, 1);
path.close();
simplify(path, true, out);
comparePaths(path, out);
testSimplify(path, true, out);
}
static void testSimplifyTriangle18() {
@ -255,8 +240,7 @@ static void testSimplifyTriangle18() {
path.lineTo(0, 1);
path.lineTo(0, 3);
path.close();
simplify(path, true, out);
comparePaths(path, out);
testSimplify(path, true, out);
}
static void testSimplifyTriangle19() {
@ -270,8 +254,7 @@ static void testSimplifyTriangle19() {
path.lineTo(1, 1);
path.lineTo(2, 1);
path.close();
simplify(path, true, out);
comparePaths(path, out);
testSimplify(path, true, out);
}
static void testSimplifyTriangle20() {
@ -284,8 +267,7 @@ static void testSimplifyTriangle20() {
path.lineTo(3, 2);
path.lineTo(0, 3);
path.close();
simplify(path, true, out);
comparePaths(path, out);
testSimplify(path, true, out);
}
static void testSimplifyTriangle21() {
@ -298,8 +280,7 @@ static void testSimplifyTriangle21() {
path.lineTo(2, 1);
path.lineTo(0, 3);
path.close();
simplify(path, true, out);
comparePaths(path, out);
testSimplify(path, true, out);
}
static void testSimplifyDegenerateTriangle1() {
@ -312,8 +293,7 @@ static void testSimplifyDegenerateTriangle1() {
path.lineTo(0, 0);
path.lineTo(0, 0);
path.close();
simplify(path, true, out);
comparePaths(path, out);
testSimplify(path, true, out);
}
static void testSimplifyDegenerateTriangle2() {
@ -326,8 +306,7 @@ static void testSimplifyDegenerateTriangle2() {
path.lineTo(2, 2);
path.lineTo(3, 3);
path.close();
simplify(path, true, out);
comparePaths(path, out);
testSimplify(path, true, out);
}
static void testSimplifyWindingParallelogram() {
@ -343,9 +322,9 @@ static void testSimplifyWindingParallelogram() {
path.lineTo(20,30); // /_/
path.lineTo(30,10);
path.close();
simplify(path, true, out); // expect _
comparePaths(path, out); // / \ .
} // /___\ .
testSimplify(path, true, out); // expect _
// / \ .
} // /___\ .
static void testSimplifyXorParallelogram() {
SkPath path, out;
@ -360,9 +339,8 @@ static void testSimplifyXorParallelogram() {
path.lineTo(20,30); // /_/
path.lineTo(30,10);
path.close();
simplify(path, true, out); // expect _
comparePaths(path, out); // \ /
} //
testSimplify(path, true, out); // expect _
} // \ /
static void testSimplifyTriangle2() {
SkPath path, out;
@ -374,10 +352,9 @@ static void testSimplifyTriangle2() {
path.moveTo(10,10); // triangle _
path.lineTo(20,10); // \ |
path.lineTo(20,30); // \|
path.close(); // _
simplify(path, true, out); // expect | |
comparePaths(path, out); // |_|
}
path.close(); // _
testSimplify(path, true, out); // expect | |
} // |_|
static void testSimplifyNondegenerate4x4Triangles() {
char pathStr[1024];
@ -433,11 +410,9 @@ static void testSimplifyNondegenerate4x4Triangles() {
str += sprintf(str, " path.lineTo(%d, %d);\n", fx, fy);
str += sprintf(str, " path.close();");
}
simplify(path, true, out);
comparePaths(path, out);
testSimplify(path, true, out);
path.setFillType(SkPath::kEvenOdd_FillType);
simplify(path, true, out);
comparePaths(path, out);
testSimplify(path, true, out);
}
}
}
@ -494,11 +469,9 @@ static void testSimplifyDegenerate4x4Triangles() {
str += sprintf(str, " path.lineTo(%d, %d);\n", fx, fy);
str += sprintf(str, " path.close();");
}
simplify(path, true, out);
comparePaths(path, out);
testSimplify(path, true, out);
path.setFillType(SkPath::kEvenOdd_FillType);
simplify(path, true, out);
comparePaths(path, out);
testSimplify(path, true, out);
}
}
}
@ -527,7 +500,165 @@ static void testPathTriangleRendering() {
}
}
static void testSimplifySkinnyTriangle1() {
for (int x = 1; x < 255; ++x) {
SkPath path, out;
path.moveTo((x * 101) % 10, 0);
path.lineTo((x * 91) % 10, 1000);
path.lineTo((x * 71) % 10, 2000);
path.lineTo((x * 51) % 10, 3000);
path.close();
path.moveTo((x * 101) % 20, 0);
path.lineTo((x * 91) % 20, 1000);
path.lineTo((x * 71) % 20, 2000);
path.lineTo((x * 51) % 20, 3000);
path.close();
path.moveTo((x * 101) % 30, 0);
path.lineTo((x * 91) % 30, 1000);
path.lineTo((x * 71) % 30, 2000);
path.lineTo((x * 51) % 30, 3000);
path.close();
testSimplify(path, true, out);
}
}
static void testSimplifySkinnyTriangle2() {
SkPath path, out;
#if 01
path.moveTo(591.091064, 627.534851);
path.lineTo(541.088135, 560.707642);
path.lineTo(491.085175, 493.880310);
path.lineTo(441.082214, 427.053101);
//path.lineTo(591.091064, 627.534851);
path.close();
#endif
path.moveTo(317.093445, 592.013306);
path.lineTo(366.316162, 542.986572);
path.lineTo(416.051514, 486.978577);
path.lineTo(465.786865, 430.970581);
//path.lineTo(317.093445, 592.013306);
path.close();
#if 0
path.moveTo(289.392517, 517.138489);
path.lineTo(249.886078, 508.598022);
path.lineTo(217.110916, 450.916443);
path.lineTo(196.621033, 394.917633);
//path.lineTo(289.392517, 517.138489);
path.close();
#endif
testSimplify(path, true, out);
}
static void testSimplifySkinnyTriangle3() {
SkPath path, out;
path.moveTo(591, 627.534851);
path.lineTo(541, 560.707642);
path.lineTo(491, 493.880310);
path.lineTo(441, 427.053101);
path.close();
path.moveTo(317, 592.013306);
path.lineTo(366, 542.986572);
path.lineTo(416, 486.978577);
path.lineTo(465, 430.970581);
path.close();
testSimplify(path, true, out);
}
static void testSimplifySkinnyTriangle4() {
SkPath path, out;
path.moveTo(572.655212, 614.959961);
path.lineTo(524.618896, 549.339600);
path.lineTo(476.582581, 483.719269);
path.lineTo(428.546265, 418.098938);
path.lineTo(572.655212, 614.959961);
path.close();
path.moveTo(312.166382, 583.723083);
path.lineTo(361.047791, 529.824219);
path.lineTo(409.929230, 475.925354);
path.lineTo(458.810669, 422.026520);
path.lineTo(312.166382, 583.723083);
path.close();
path.moveTo(278.742737, 508.065643);
path.lineTo(241.475800, 493.465118);
path.lineTo(210.344177, 437.315125);
path.lineTo(197.019455, 383.794556);
path.lineTo(278.742737, 508.065643);
path.close();
testSimplify(path, true, out);
}
static void testSimplifySkinnyTriangle5() {
SkPath path, out;
path.moveTo(554.690613, 602.286072);
path.lineTo(508.590057, 537.906250);
path.lineTo(462.489441, 473.526520);
path.lineTo(416.388855, 409.146729);
path.lineTo(554.690613, 602.286072);
path.close();
path.moveTo(307.216949, 575.189270);
path.lineTo(355.826965, 516.804688);
path.lineTo(403.815918, 464.990753);
path.lineTo(451.804871, 413.176819);
path.lineTo(307.216949, 575.189270);
path.close();
path.moveTo(271.998901, 521.301025);
path.lineTo(234.619705, 499.687683);
path.lineTo(203.059692, 441.332336);
path.lineTo(195.994370, 386.856506);
path.lineTo(271.998901, 521.301025);
path.close();
testSimplify(path, true, out);
}
static void testSimplifyTriangle22() {
SkPath path, out;
path.moveTo(0, 0);
path.lineTo(1, 0);
path.lineTo(0, 2);
path.close();
path.moveTo(1, 0);
path.lineTo(0, 2);
path.lineTo(0, 1);
path.close();
testSimplify(path, true, out);
}
static void testSimplifyTriangle23() {
SkPath path, out;
path.moveTo(0, 0);
path.lineTo(0, 0);
path.lineTo(0, 0);
path.close();
path.moveTo(0, 0);
path.lineTo(0, 1);
path.lineTo(1, 2);
path.close();
testSimplify(path, true, out);
}
static void testSimplifyTriangle24() {
SkPath path, out;
path.moveTo(0, 0);
path.lineTo(0, 0);
path.lineTo(0, 1);
path.close();
path.moveTo(0, 0);
path.lineTo(1, 0);
path.lineTo(0, 1);
path.close();
testSimplify(path, true, out);
}
static void (*simplifyTests[])() = {
testSimplifySkinnyTriangle5,
testSimplifySkinnyTriangle4,
testSimplifySkinnyTriangle3,
testSimplifySkinnyTriangle2,
testSimplifySkinnyTriangle1,
testSimplifyTriangle24,
testSimplifyTriangle23,
testSimplifyTriangle22,
testSimplifyDegenerateTriangle2,
testSimplifyDegenerateTriangle1,
testSimplifyTriangle21,
@ -560,7 +691,7 @@ static void (*simplifyTests[])() = {
static size_t simplifyTestsCount = sizeof(simplifyTests) / sizeof(simplifyTests[0]);
static void (*firstTest)() = 0;
static void (*firstTest)() = testSimplifySkinnyTriangle4;
void SimplifyPolygonPaths_Test() {
size_t index = 0;
@ -569,8 +700,10 @@ void SimplifyPolygonPaths_Test() {
++index;
}
}
bool firstTestComplete = false;
for ( ; index < simplifyTestsCount; ++index) {
(*simplifyTests[index])();
firstTestComplete = true;
}
}

View File

@ -13,8 +13,82 @@ static void testSimplifyQuad1() {
path.lineTo(1, 3);
path.lineTo(1, 3);
path.close();
simplify(path, true, out);
comparePaths(path, out);
testSimplify(path, true, out);
}
static void testSimplifyQuad2() {
SkPath path, out;
path.moveTo(0, 0);
path.lineTo(0, 0);
path.lineTo(0, 0);
path.lineTo(0, 2);
path.close();
path.moveTo(0, 1);
path.lineTo(0, 1);
path.lineTo(1, 1);
path.lineTo(0, 2);
path.close();
testSimplify(path, true, out);
}
static void testSimplifyQuad3() {
SkPath path, out;
path.moveTo(0, 0);
path.lineTo(0, 0);
path.lineTo(1, 0);
path.lineTo(1, 2);
path.close();
path.moveTo(0, 1);
path.lineTo(1, 1);
path.lineTo(2, 1);
path.lineTo(0, 2);
path.close();
testSimplify(path, true, out);
}
static void testSimplifyQuad4() {
SkPath path, out;
path.moveTo(0, 0);
path.lineTo(0, 0);
path.lineTo(1, 0);
path.lineTo(2, 2);
path.close();
path.moveTo(0, 0);
path.lineTo(2, 1);
path.lineTo(3, 1);
path.lineTo(3, 3);
path.close();
testSimplify(path, true, out);
}
static void testSimplifyQuad5() {
SkPath path, out;
path.moveTo(0, 0);
path.lineTo(0, 0);
path.lineTo(1, 0);
path.lineTo(3, 2);
path.close();
path.moveTo(0, 1);
path.lineTo(1, 1);
path.lineTo(2, 1);
path.lineTo(0, 2);
path.close();
testSimplify(path, true, out);
}
static void testSimplifyQuad6() {
SkPath path, out;
path.moveTo(0, 0);
path.lineTo(1, 0);
path.lineTo(1, 1);
path.lineTo(3, 3);
path.close();
path.moveTo(1, 1);
path.lineTo(1, 1);
path.lineTo(1, 1);
path.lineTo(2, 2);
path.close();
testSimplify(path, true, out);
}
static void testSimplify4x4Quadralaterals() {
@ -41,7 +115,7 @@ static void testSimplify4x4Quadralaterals() {
for (int g = f ; g < 16; ++g) {
int gx = g & 0x03;
int gy = g >> 2;
for (int h = g ; g < 16; ++g) {
for (int h = g ; h < 16; ++h) {
int hx = h & 0x03;
int hy = h >> 2;
SkPath path, out;
@ -56,7 +130,7 @@ static void testSimplify4x4Quadralaterals() {
path.lineTo(gx, gy);
path.lineTo(hx, hy);
path.close();
if (1) {
if (1) { // gdb: set print elements 400
char* str = pathStr;
str += sprintf(str, " path.moveTo(%d, %d);\n", ax, ay);
str += sprintf(str, " path.lineTo(%d, %d);\n", bx, by);
@ -69,11 +143,15 @@ static void testSimplify4x4Quadralaterals() {
str += sprintf(str, " path.lineTo(%d, %d);\n", hx, hy);
str += sprintf(str, " path.close();");
}
simplify(path, true, out);
comparePaths(path, out);
if (!testSimplify(path, true, out)) {
SkDebugf("*/\n{ SkPath::kWinding_FillType, %d, %d, %d, %d, %d, %d, %d, %d },\n/*\n",
a, b, c, d, e, f, g, h);
}
path.setFillType(SkPath::kEvenOdd_FillType);
simplify(path, true, out);
comparePaths(path, out);
if (!testSimplify(path, true, out)) {
SkDebugf("*/\n{ SkPath::kEvenOdd_FillType, %d, %d, %d, %d, %d, %d, %d, %d },\n/*\n",
a, b, c, d, e, f, g, h);
}
}
}
}
@ -87,6 +165,11 @@ static void testSimplify4x4Quadralaterals() {
static void (*simplifyTests[])() = {
testSimplifyQuad6,
testSimplifyQuad5,
testSimplifyQuad4,
testSimplifyQuad3,
testSimplifyQuad2,
testSimplifyQuad1,
testSimplify4x4Quadralaterals,
};

View File

@ -1,6 +1,15 @@
#include "EdgeWalker_Test.h"
#include "Intersection_Tests.h"
static void testSimplifyCoincidentInner() {
SkPath path, out;
path.setFillType(SkPath::kWinding_FillType);
path.addRect(10, 10, 60, 60, SkPath::kCCW_Direction);
path.addRect(20, 20, 50, 50, SkPath::kCW_Direction);
path.addRect(20, 30, 40, 40, SkPath::kCW_Direction);
testSimplify(path, true, out);
}
static void testSimplifyCoincidentVertical() {
SkPath path, out;
path.setFillType(SkPath::kWinding_FillType);
@ -295,8 +304,7 @@ static void testSimplifyOverlap() {
SkPath path, out;
path.addRect(rect1, static_cast<SkPath::Direction>(dir));
path.addRect(rect2, static_cast<SkPath::Direction>(dir));
simplify(path, true, out);
comparePaths(path, out);
testSimplify(path, true, out);
}
}
}
@ -409,6 +417,7 @@ static void testSimplifyDegenerate1() {
}
static void (*simplifyTests[])() = {
testSimplifyCoincidentInner,
testSimplifyOverlapTiny,
testSimplifyDegenerate1,
testSimplifyCorner,

View File

@ -3,7 +3,10 @@
#include "SkPath.h"
extern void contourBounds(const SkPath& path, SkTDArray<SkRect>& boundsArray);
extern void comparePaths(const SkPath& one, const SkPath& two);
extern bool comparePaths(const SkPath& one, const SkPath& two);
extern void comparePathsTiny(const SkPath& one, const SkPath& two);
extern void drawAsciiPaths(const SkPath& one, const SkPath& two,
bool drawPaths);
extern void simplify(const SkPath& path, bool asFill, SkPath& simple);
extern void showPath(const SkPath& path, const char* str = NULL);
extern bool testSimplify(const SkPath& path, bool fill, SkPath& out);

View File

@ -4,32 +4,31 @@
#include "SkCanvas.h"
#include "SkPaint.h"
static bool gDrawLastAsciiPaths = true;
static bool gShowPath = false;
static bool gDrawLastAsciiPaths = false;
static bool gDrawAllAsciiPaths = false;
static bool gShowPath = true;
static bool gShowAsciiPaths = false;
static bool gComparePathsAssert = false;
static void showPath(const char* str, const SkPath& path) {
if (!gShowPath) {
return;
}
SkDebugf("%s\n", str);
void showPath(const SkPath& path, const char* str) {
SkDebugf("%s\n", str ? "original:" : str);
SkPath::Iter iter(path, true);
uint8_t verb;
SkPoint pts[4];
while ((verb = iter.next(pts)) != SkPath::kDone_Verb) {
switch (verb) {
case SkPath::kMove_Verb:
SkDebugf("path.moveTo(%g, %g);\n", pts[0].fX, pts[0].fY);
SkDebugf("path.moveTo(%3.6g, %3.6g);\n", pts[0].fX, pts[0].fY);
continue;
case SkPath::kLine_Verb:
SkDebugf("path.lineTo(%g, %g);\n", pts[1].fX, pts[1].fY);
SkDebugf("path.lineTo(%3.6g, %3.6g);\n", pts[1].fX, pts[1].fY);
break;
case SkPath::kQuad_Verb:
SkDebugf("path.quadTo(%g, %g, %g, %g);\n",
SkDebugf("path.quadTo(%3.6g, %3.6g, %3.6g, %3.6g);\n",
pts[1].fX, pts[1].fY, pts[2].fX, pts[2].fY);
break;
case SkPath::kCubic_Verb:
SkDebugf("path.cubicTo(%g, %g, %g, %g);\n",
SkDebugf("path.cubicTo(%3.6g, %3.6g, %3.6g, %3.6g);\n",
pts[1].fX, pts[1].fY, pts[2].fX, pts[2].fY,
pts[3].fX, pts[3].fY);
break;
@ -77,14 +76,14 @@ static bool pathsDrawTheSame(const SkPath& one, const SkPath& two) {
return true;
}
static void drawAsciiPaths(const SkPath& one, const SkPath& two,
void drawAsciiPaths(const SkPath& one, const SkPath& two,
bool drawPaths) {
if (!drawPaths) {
return;
}
if (0) {
showPath("one:", one);
showPath("two:", two);
if (gShowAsciiPaths) {
showPath(one, "one:");
showPath(two, "two:");
}
const SkRect& bounds1 = one.getBounds();
const SkRect& bounds2 = two.getBounds();
@ -139,22 +138,25 @@ static bool scaledDrawTheSame(const SkPath& one, const SkPath& two,
return false;
}
void comparePaths(const SkPath& one, const SkPath& two) {
bool comparePaths(const SkPath& one, const SkPath& two) {
if (pathsDrawTheSame(one, two)) {
return;
return true;
}
drawAsciiPaths(one, two, gDrawAllAsciiPaths);
for (int x = 9; x <= 33; ++x) {
if (scaledDrawTheSame(one, two, x, x - (x >> 2), gDrawAllAsciiPaths)) {
return;
return true;
}
}
if (!gDrawAllAsciiPaths) {
scaledDrawTheSame(one, two, 9, 7, gDrawLastAsciiPaths);
}
showPath("original:", one);
showPath("simplified:", two);
SkASSERT(0);
if (gComparePathsAssert) {
showPath(one);
showPath(two, "simplified:");
SkASSERT(0);
}
return false;
}
// doesn't work yet
@ -188,3 +190,10 @@ void comparePathsTiny(const SkPath& one, const SkPath& two) {
}
}
bool testSimplify(const SkPath& path, bool fill, SkPath& out) {
if (gShowPath) {
showPath(path);
}
simplify(path, fill, out);
return comparePaths(path, out);
}

View File

@ -17,8 +17,8 @@ void Intersection_Tests() {
LineQuadraticIntersection_Test();
LineCubicIntersection_Test();
SimplifyRectangularPaths_Test();
SimplifyPolygonPaths_Test();
SimplifyRectangularPaths_Test();
SimplifyQuadralateralPaths_Test();
QuadraticCoincidence_Test();

View File

@ -100,6 +100,28 @@ int horizontalIntersect(const _Line& line, double y, double tRange[2]) {
return 1;
}
// OPTIMIZATION Given: dy = line[1].y - line[0].y
// and: xIntercept / (y - line[0].y) == (line[1].x - line[0].x) / dy
// then: xIntercept * dy == (line[1].x - line[0].x) * (y - line[0].y)
// Assuming that dy is always > 0, the line segment intercepts if:
// left * dy <= xIntercept * dy <= right * dy
// thus: left * dy <= (line[1].x - line[0].x) * (y - line[0].y) <= right * dy
// (clever as this is, it does not give us the t value, so may be useful only
// as a quick reject -- and maybe not then; it takes 3 muls, 3 adds, 2 cmps)
int horizontalLineIntersect(const _Line& line, double left, double right,
double y, double tRange[2]) {
int result = horizontalIntersect(line, y, tRange);
if (result != 1) {
return result;
}
// FIXME: this is incorrect if result == 2
double xIntercept = line[0].x + tRange[0] * (line[1].x - line[0].x);
if (xIntercept > right || xIntercept < left) {
return 0;
}
return result;
}
// from http://www.bryceboe.com/wordpress/wp-content/uploads/2006/10/intersect.py
// 4 subs, 2 muls, 1 cmp
static bool ccw(const _Point& A, const _Point& B, const _Point& C) {

View File

@ -2,5 +2,7 @@
#include "DataTypes.h"
int horizontalIntersect(const _Line& line, double y, double tRange[2]);
int horizontalLineIntersect(const _Line& line, double left, double right,
double y, double tRange[2]);
int intersect(const _Line& a, const _Line& b, double aRange[2], double bRange[2]);
bool testIntersect(const _Line& a, const _Line& b);

View File

@ -11,6 +11,7 @@
8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; };
FE3201C8144DCC68006DDA67 /* skia_mac.mm in Sources */ = {isa = PBXBuildFile; fileRef = FE3201C6144DCC68006DDA67 /* skia_mac.mm */; };
FE3201C9144DCC68006DDA67 /* SkOSWindow_Mac.mm in Sources */ = {isa = PBXBuildFile; fileRef = FE3201C7144DCC68006DDA67 /* SkOSWindow_Mac.mm */; };
FE3DBAFE150E4A680006ADF4 /* junk.htm in Resources */ = {isa = PBXBuildFile; fileRef = FE3DBAFD150E4A680006ADF4 /* junk.htm */; };
FE7130A114CE0EEB0008E392 /* LineQuadraticIntersection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FE7130A014CE0EEB0008E392 /* LineQuadraticIntersection.cpp */; };
FE7131C414CF5A960008E392 /* LineQuadraticIntersection_Test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FE7131C314CF5A960008E392 /* LineQuadraticIntersection_Test.cpp */; };
FE7131EE14D03AED0008E392 /* LineCubicIntersection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FE7131ED14D03AED0008E392 /* LineCubicIntersection.cpp */; };
@ -59,6 +60,7 @@
FECAA6E114BDDF2D00B35E2C /* QuadraticReduceOrder_Test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FECAA6E014BDDF2D00B35E2C /* QuadraticReduceOrder_Test.cpp */; };
FED53C391483CB9400F6359E /* Inline_Tests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FED53C381483CB9400F6359E /* Inline_Tests.cpp */; };
FED865F915056A79006F4508 /* EdgeWalkerQuadralaterals_Test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FED865F815056A79006F4508 /* EdgeWalkerQuadralaterals_Test.cpp */; };
FED866D715066642006F4508 /* EdgeWalkerPolygons_Mismatches.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FED866D615066642006F4508 /* EdgeWalkerPolygons_Mismatches.cpp */; };
FEED7245144DD2250059E97B /* SkEventNotifier.mm in Sources */ = {isa = PBXBuildFile; fileRef = FEED723E144DD2250059E97B /* SkEventNotifier.mm */; };
FEED7292144DD4610059E97B /* libexperimental.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FEED726E144DD4050059E97B /* libexperimental.a */; };
FEED7293144DD4620059E97B /* libskgr.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FEED7276144DD4140059E97B /* libskgr.a */; };
@ -237,6 +239,8 @@
8D1107320486CEB800E47090 /* edge.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = edge.app; sourceTree = BUILT_PRODUCTS_DIR; };
FE3201C6144DCC68006DDA67 /* skia_mac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = skia_mac.mm; path = ../../src/utils/mac/skia_mac.mm; sourceTree = SOURCE_ROOT; };
FE3201C7144DCC68006DDA67 /* SkOSWindow_Mac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = SkOSWindow_Mac.mm; path = ../../src/utils/mac/SkOSWindow_Mac.mm; sourceTree = SOURCE_ROOT; };
FE3DB8C9150A48320006ADF4 /* junk.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = junk.txt; sourceTree = "<group>"; };
FE3DBAFD150E4A680006ADF4 /* junk.htm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; name = junk.htm; path = ../../../../../junk.htm; sourceTree = SOURCE_ROOT; };
FE4FE7411492417500A12A34 /* IntersectionUtilities.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IntersectionUtilities.cpp; sourceTree = "<group>"; };
FE7130A014CE0EEB0008E392 /* LineQuadraticIntersection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LineQuadraticIntersection.cpp; sourceTree = "<group>"; };
FE7131C314CF5A960008E392 /* LineQuadraticIntersection_Test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LineQuadraticIntersection_Test.cpp; sourceTree = "<group>"; };
@ -301,6 +305,7 @@
FECAACA614BE1C6100B35E2C /* QuadraticParameterization_TestUtility.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = QuadraticParameterization_TestUtility.cpp; sourceTree = "<group>"; };
FED53C381483CB9400F6359E /* Inline_Tests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Inline_Tests.cpp; sourceTree = "<group>"; };
FED865F815056A79006F4508 /* EdgeWalkerQuadralaterals_Test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EdgeWalkerQuadralaterals_Test.cpp; sourceTree = "<group>"; };
FED866D615066642006F4508 /* EdgeWalkerPolygons_Mismatches.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EdgeWalkerPolygons_Mismatches.cpp; sourceTree = "<group>"; };
FEED723C144DD2250059E97B /* SampleApp.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = SampleApp.xib; path = ../../src/utils/mac/SampleApp.xib; sourceTree = SOURCE_ROOT; };
FEED723D144DD2250059E97B /* SampleAppDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = SampleAppDelegate.mm; path = ../../src/utils/mac/SampleAppDelegate.mm; sourceTree = SOURCE_ROOT; };
FEED723E144DD2250059E97B /* SkEventNotifier.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = SkEventNotifier.mm; path = ../../src/utils/mac/SkEventNotifier.mm; sourceTree = SOURCE_ROOT; };
@ -476,6 +481,8 @@
FE71354F14D305FD0008E392 /* ShapeOps */ = {
isa = PBXGroup;
children = (
FE3DBAFD150E4A680006ADF4 /* junk.htm */,
FE3DB8C9150A48320006ADF4 /* junk.txt */,
FE71358514D309E90008E392 /* EdgeWalker.cpp */,
FE713C6114D9879B0008E392 /* TSearch.h */,
);
@ -539,6 +546,7 @@
FEED764B144F29BD0059E97B /* TestUtilities.cpp */,
FE7413DB14F6926D00056D7B /* EdgeWalker_Test.h */,
FED865F815056A79006F4508 /* EdgeWalkerQuadralaterals_Test.cpp */,
FED866D615066642006F4508 /* EdgeWalkerPolygons_Mismatches.cpp */,
);
name = Tests;
sourceTree = "<group>";
@ -890,6 +898,7 @@
8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */,
1DDD58160DA1D0A300B32029 /* MainMenu.xib in Resources */,
FEED72B0144DD5710059E97B /* SampleApp.xib in Resources */,
FE3DBAFE150E4A680006ADF4 /* junk.htm in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -952,6 +961,7 @@
FE7413D414F6915A00056D7B /* EdgeWalkerPolygons_Test.cpp in Sources */,
FE7413D814F691C200056D7B /* EdgeWalker_TestUtility.cpp in Sources */,
FED865F915056A79006F4508 /* EdgeWalkerQuadralaterals_Test.cpp in Sources */,
FED866D715066642006F4508 /* EdgeWalkerPolygons_Mismatches.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};