1ad65a3e5fb1f94699f183551b828efbcc6a133cecaryclark@google.com/* 2ad65a3e5fb1f94699f183551b828efbcc6a133cecaryclark@google.com * Copyright 2013 Google Inc. 3ad65a3e5fb1f94699f183551b828efbcc6a133cecaryclark@google.com * 4ad65a3e5fb1f94699f183551b828efbcc6a133cecaryclark@google.com * Use of this source code is governed by a BSD-style license that can be 5ad65a3e5fb1f94699f183551b828efbcc6a133cecaryclark@google.com * found in the LICENSE file. 6ad65a3e5fb1f94699f183551b828efbcc6a133cecaryclark@google.com */ 78d0a524a4847bc7e1cc63a93b78922739466c201caryclark@google.com#include "PathOpsTestCommon.h" 84431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org#include "SkIntersections.h" 954359294a7c9dc54802d512a5d891a35c1663392caryclark#include "SkOpContour.h" 10ad65a3e5fb1f94699f183551b828efbcc6a133cecaryclark@google.com#include "SkOpSegment.h" 114431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org#include "SkRandom.h" 124431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org#include "SkTSort.h" 13ad65a3e5fb1f94699f183551b828efbcc6a133cecaryclark@google.com#include "Test.h" 14ad65a3e5fb1f94699f183551b828efbcc6a133cecaryclark@google.com 154431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.orgstatic bool gDisableAngleTests = true; 164431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org 174431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.orgstatic float next(float f) 184431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org{ 194431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org int fBits = SkFloatAs2sCompliment(f); 204431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org ++fBits; 214431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org float fNext = Sk2sComplimentAsFloat(fBits); 224431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org return fNext; 23ad65a3e5fb1f94699f183551b828efbcc6a133cecaryclark@google.com} 24ad65a3e5fb1f94699f183551b828efbcc6a133cecaryclark@google.com 254431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.orgstatic float prev(float f) 264431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org{ 274431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org int fBits = SkFloatAs2sCompliment(f); 284431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org --fBits; 294431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org float fNext = Sk2sComplimentAsFloat(fBits); 304431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org return fNext; 314431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org} 324431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org 334431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.orgDEF_TEST(PathOpsAngleFindCrossEpsilon, reporter) { 344431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org if (gDisableAngleTests) { 3507e97fccd2d85076cd22ef411b0773ab92a18abecaryclark@google.com return; 3607e97fccd2d85076cd22ef411b0773ab92a18abecaryclark@google.com } 374431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org SkRandom ran; 384431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org int maxEpsilon = 0; 394431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org for (int index = 0; index < 10000000; ++index) { 404431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org SkDLine line = {{{0, 0}, {ran.nextRangeF(0.0001f, 1000), ran.nextRangeF(0.0001f, 1000)}}}; 414431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org for (int inner = 0; inner < 10; ++inner) { 424431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org float t = ran.nextRangeF(0.0001f, 1); 434431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org SkDPoint dPt = line.ptAtT(t); 444431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org SkPoint pt = dPt.asSkPoint(); 454431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org float xs[3] = { prev(pt.fX), pt.fX, next(pt.fX) }; 464431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org float ys[3] = { prev(pt.fY), pt.fY, next(pt.fY) }; 474431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org for (int xIdx = 0; xIdx < 3; ++xIdx) { 484431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org for (int yIdx = 0; yIdx < 3; ++yIdx) { 494431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org SkPoint test = { xs[xIdx], ys[yIdx] }; 504431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org float p1 = SkDoubleToScalar(line[1].fX * test.fY); 514431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org float p2 = SkDoubleToScalar(line[1].fY * test.fX); 524431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org int p1Bits = SkFloatAs2sCompliment(p1); 534431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org int p2Bits = SkFloatAs2sCompliment(p2); 5460e0fee6d4acff638ccc9670c4055aced529a7a0bungeman int epsilon = SkTAbs(p1Bits - p2Bits); 554431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org if (maxEpsilon < epsilon) { 564431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org SkDebugf("line={{0, 0}, {%1.7g, %1.7g}} t=%1.7g pt={%1.7g, %1.7g}" 574431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org " epsilon=%d\n", 584431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org line[1].fX, line[1].fY, t, test.fX, test.fY, epsilon); 594431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org maxEpsilon = epsilon; 604431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org } 61cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com } 62cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com } 63cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com } 6407e97fccd2d85076cd22ef411b0773ab92a18abecaryclark@google.com } 6507e97fccd2d85076cd22ef411b0773ab92a18abecaryclark@google.com} 6607e97fccd2d85076cd22ef411b0773ab92a18abecaryclark@google.com 674431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.orgDEF_TEST(PathOpsAngleFindQuadEpsilon, reporter) { 684431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org if (gDisableAngleTests) { 694431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org return; 704431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org } 714431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org SkRandom ran; 724431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org int maxEpsilon = 0; 734431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org double maxAngle = 0; 744431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org for (int index = 0; index < 100000; ++index) { 754431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org SkDLine line = {{{0, 0}, {ran.nextRangeF(0.0001f, 1000), ran.nextRangeF(0.0001f, 1000)}}}; 764431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org float t = ran.nextRangeF(0.0001f, 1); 774431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org SkDPoint dPt = line.ptAtT(t); 784431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org float t2 = ran.nextRangeF(0.0001f, 1); 794431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org SkDPoint qPt = line.ptAtT(t2); 804431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org float t3 = ran.nextRangeF(0.0001f, 1); 814431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org SkDPoint qPt2 = line.ptAtT(t3); 824431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org qPt.fX += qPt2.fY; 834431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org qPt.fY -= qPt2.fX; 84a35ab3e6e024d0b548ded26a2e3b8ecd838ead93caryclark QuadPts q = {{line[0], dPt, qPt}}; 85a35ab3e6e024d0b548ded26a2e3b8ecd838ead93caryclark SkDQuad quad; 86a35ab3e6e024d0b548ded26a2e3b8ecd838ead93caryclark quad.debugSet(q.fPts); 874431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org // binary search for maximum movement of quad[1] towards test that still has 1 intersection 884431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org double moveT = 0.5f; 894431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org double deltaT = moveT / 2; 904431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org SkDPoint last; 914431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org do { 924431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org last = quad[1]; 934431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org quad[1].fX = dPt.fX - line[1].fY * moveT; 944431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org quad[1].fY = dPt.fY + line[1].fX * moveT; 954431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org SkIntersections i; 964431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org i.intersect(quad, line); 974431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org REPORTER_ASSERT(reporter, i.used() > 0); 984431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org if (i.used() == 1) { 994431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org moveT += deltaT; 1004431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org } else { 1014431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org moveT -= deltaT; 1024431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org } 1034431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org deltaT /= 2; 1044431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org } while (last.asSkPoint() != quad[1].asSkPoint()); 1054431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org float p1 = SkDoubleToScalar(line[1].fX * last.fY); 1064431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org float p2 = SkDoubleToScalar(line[1].fY * last.fX); 1074431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org int p1Bits = SkFloatAs2sCompliment(p1); 1084431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org int p2Bits = SkFloatAs2sCompliment(p2); 10960e0fee6d4acff638ccc9670c4055aced529a7a0bungeman int epsilon = SkTAbs(p1Bits - p2Bits); 1104431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org if (maxEpsilon < epsilon) { 1114431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org SkDebugf("line={{0, 0}, {%1.7g, %1.7g}} t=%1.7g/%1.7g/%1.7g moveT=%1.7g" 1124431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org " pt={%1.7g, %1.7g} epsilon=%d\n", 1134431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org line[1].fX, line[1].fY, t, t2, t3, moveT, last.fX, last.fY, epsilon); 1144431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org maxEpsilon = epsilon; 1154431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org } 1164431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org double a1 = atan2(line[1].fY, line[1].fX); 1174431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org double a2 = atan2(last.fY, last.fX); 1184431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org double angle = fabs(a1 - a2); 1194431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org if (maxAngle < angle) { 1204431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org SkDebugf("line={{0, 0}, {%1.7g, %1.7g}} t=%1.7g/%1.7g/%1.7g moveT=%1.7g" 1214431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org " pt={%1.7g, %1.7g} angle=%1.7g\n", 1224431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org line[1].fX, line[1].fY, t, t2, t3, moveT, last.fX, last.fY, angle); 1234431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org maxAngle = angle; 1244431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org } 125cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com } 126cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com} 127cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com 128cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.comstatic int find_slop(double x, double y, double rx, double ry) { 129cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com int slopBits = 0; 130cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com bool less1, less2; 131cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com double absX = fabs(x); 132cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com double absY = fabs(y); 133cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com double length = absX < absY ? absX / 2 + absY : absX + absY / 2; 134cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com int exponent; 135cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com (void) frexp(length, &exponent); 136cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com double epsilon = ldexp(FLT_EPSILON, exponent); 137cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com do { 138cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com // get the length as the larger plus half the smaller (both same signs) 139cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com // find the ulps of the length 140cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com // compute the offsets from there 141cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com double xSlop = epsilon * slopBits; 142cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com double ySlop = x * y < 0 ? -xSlop : xSlop; // OPTIMIZATION: use copysign / _copysign ? 143cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com double x1 = x - xSlop; 144cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com double y1 = y + ySlop; 145cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com double x_ry1 = x1 * ry; 146cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com double rx_y1 = rx * y1; 147cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com less1 = x_ry1 < rx_y1; 148cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com double x2 = x + xSlop; 149cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com double y2 = y - ySlop; 150cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com double x_ry2 = x2 * ry; 151cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com double rx_y2 = rx * y2; 152cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com less2 = x_ry2 < rx_y2; 153cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com } while (less1 == less2 && ++slopBits); 154cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com return slopBits; 155cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com} 156cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com 157cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com// from http://stackoverflow.com/questions/1427422/cheap-algorithm-to-find-measure-of-angle-between-vectors 158cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.comstatic double diamond_angle(double y, double x) 159cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com{ 160cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com if (y >= 0) 1618f6ef4010f6835c5ce9ede180e50a6a58512a81eskia.committer@gmail.com return (x >= 0 ? y/(x+y) : 1-x/(-x+y)); 162cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com else 1638f6ef4010f6835c5ce9ede180e50a6a58512a81eskia.committer@gmail.com return (x < 0 ? 2-y/(-x-y) : 3+x/(x-y)); 164cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com} 165cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com 166cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.comstatic const double slopTests[][4] = { 167cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com // x y rx ry 168cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com {-0.058554756452593892, -0.18804585843827226, -0.018568569646021160, -0.059615294434479438}, 169cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com {-0.0013717412948608398, 0.0041152238845825195, -0.00045837944195925573, 0.0013753175735478074}, 170cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com {-2.1033774145221198, -1.4046019261273715e-008, -0.70062688352066704, -1.2706324683777995e-008}, 171cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com}; 172cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com 1734431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.orgDEF_TEST(PathOpsAngleFindSlop, reporter) { 1744431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org if (gDisableAngleTests) { 1754431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org return; 1764431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org } 1774431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org for (int index = 0; index < (int) SK_ARRAY_COUNT(slopTests); ++index) { 178cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com const double* slopTest = slopTests[index]; 179cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com double x = slopTest[0]; 180cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com double y = slopTest[1]; 181cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com double rx = slopTest[2]; 182cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com double ry = slopTest[3]; 1834431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org SkDebugf("%s xy %d=%d\n", __FUNCTION__, index, find_slop(x, y, rx, ry)); 1844431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org SkDebugf("%s rxy %d=%d\n", __FUNCTION__, index, find_slop(rx, ry, x, y)); 185cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com double angle = diamond_angle(y, x); 186cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com double rAngle = diamond_angle(ry, rx); 187cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com double diff = fabs(angle - rAngle); 188cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com SkDebugf("%s diamond xy=%1.9g rxy=%1.9g diff=%1.9g factor=%d\n", __FUNCTION__, 189cffbcc3b9665f2c928544b6fc6b8a0e22a4210fbcaryclark@google.com angle, rAngle, diff, (int) (diff / FLT_EPSILON)); 1904431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org } 1914431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org} 1924431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org 1934431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.orgclass PathOpsAngleTester { 1944431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.orgpublic: 19554359294a7c9dc54802d512a5d891a35c1663392caryclark static int After(SkOpAngle& lh, SkOpAngle& rh) { 1964431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org return lh.after(&rh); 1974431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org } 1984431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org 19955888e44171ffd48b591d19256884a969fe4da17caryclark static int AllOnOneSide(SkOpAngle& lh, SkOpAngle& rh) { 20055888e44171ffd48b591d19256884a969fe4da17caryclark return lh.allOnOneSide(&rh); 20155888e44171ffd48b591d19256884a969fe4da17caryclark } 20255888e44171ffd48b591d19256884a969fe4da17caryclark 20354359294a7c9dc54802d512a5d891a35c1663392caryclark static int ConvexHullOverlaps(SkOpAngle& lh, SkOpAngle& rh) { 20454359294a7c9dc54802d512a5d891a35c1663392caryclark return lh.convexHullOverlaps(&rh); 2054431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org } 2064431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org 20754359294a7c9dc54802d512a5d891a35c1663392caryclark static int Orderable(SkOpAngle& lh, SkOpAngle& rh) { 20854359294a7c9dc54802d512a5d891a35c1663392caryclark return lh.orderable(&rh); 2094431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org } 2104431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org 21154359294a7c9dc54802d512a5d891a35c1663392caryclark static int EndsIntersect(SkOpAngle& lh, SkOpAngle& rh) { 21254359294a7c9dc54802d512a5d891a35c1663392caryclark return lh.endsIntersect(&rh); 2134431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org } 2144431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org 2154431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org static void SetNext(SkOpAngle& lh, SkOpAngle& rh) { 2164431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org lh.fNext = &rh; 2174431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org } 2184431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org}; 2194431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org 2204431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.orgclass PathOpsSegmentTester { 2214431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.orgpublic: 2224431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org static void DebugReset(SkOpSegment* segment) { 2234431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org segment->debugReset(); 2244431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org } 2254431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org}; 2264431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org 2274431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.orgstruct CircleData { 228a35ab3e6e024d0b548ded26a2e3b8ecd838ead93caryclark const CubicPts fPts; 2294431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org const int fPtCount; 2304431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org SkPoint fShortPts[4]; 2314431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org}; 2324431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org 2334431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.orgstatic CircleData circleDataSet[] = { 2344431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{313.0155029296875, 207.90290832519531}, {320.05078125, 227.58743286132812}}}, 2, {} }, 2354431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{313.0155029296875, 207.90290832519531}, {313.98246891063195, 219.33615203830394}, 2364431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org {320.05078125, 227.58743286132812}}}, 3, {} }, 2374431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org}; 2384431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org 2394431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.orgstatic const int circleDataSetSize = (int) SK_ARRAY_COUNT(circleDataSet); 2404431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org 2414431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.orgDEF_TEST(PathOpsAngleCircle, reporter) { 24214a6430b7bcf92bcabf4aef18805969d1335aab1Florin Malita SkSTArenaAlloc<4096> allocator; 243624637cc8ec22c000409704d0b403ac1b81ad4b0caryclark SkOpContourHead contour; 24455888e44171ffd48b591d19256884a969fe4da17caryclark SkOpGlobalState state(&contour, &allocator SkDEBUGPARAMS(false) SkDEBUGPARAMS(nullptr)); 24554359294a7c9dc54802d512a5d891a35c1663392caryclark contour.init(&state, false, false); 2464431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org for (int index = 0; index < circleDataSetSize; ++index) { 2474431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org CircleData& data = circleDataSet[index]; 2484431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org for (int idx2 = 0; idx2 < data.fPtCount; ++idx2) { 2494431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org data.fShortPts[idx2] = data.fPts.fPts[idx2].asSkPoint(); 2504431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org } 2514431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org switch (data.fPtCount) { 2524431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org case 2: 25355888e44171ffd48b591d19256884a969fe4da17caryclark contour.addLine(data.fShortPts); 2544431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org break; 2554431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org case 3: 25655888e44171ffd48b591d19256884a969fe4da17caryclark contour.addQuad(data.fShortPts); 2574431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org break; 2584431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org case 4: 25955888e44171ffd48b591d19256884a969fe4da17caryclark contour.addCubic(data.fShortPts); 2604431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org break; 2614431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org } 2624431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org } 26354359294a7c9dc54802d512a5d891a35c1663392caryclark SkOpSegment* first = contour.first(); 26455888e44171ffd48b591d19256884a969fe4da17caryclark first->debugAddAngle(0, 1); 26554359294a7c9dc54802d512a5d891a35c1663392caryclark SkOpSegment* next = first->next(); 26655888e44171ffd48b591d19256884a969fe4da17caryclark next->debugAddAngle(0, 1); 26754359294a7c9dc54802d512a5d891a35c1663392caryclark PathOpsAngleTester::Orderable(*first->debugLastAngle(), *next->debugLastAngle()); 2684431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org} 2694431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org 2704431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.orgstruct IntersectData { 271a35ab3e6e024d0b548ded26a2e3b8ecd838ead93caryclark const CubicPts fPts; 2724431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org const int fPtCount; 2734431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org double fTStart; 2744431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org double fTEnd; 2754431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org SkPoint fShortPts[4]; 2764431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org}; 2774431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org 2784431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.orgstatic IntersectData intersectDataSet1[] = { 2794431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{322.935669,231.030273}, {312.832214,220.393295}, {312.832214,203.454178}}}, 3, 2804431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org 0.865309956, 0.154740299, {} }, 2814431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{322.12738,233.397751}, {295.718353,159.505829}}}, 2, 2824431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org 0.345028807, 0.0786326511, {} }, 2834431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{322.935669,231.030273}, {312.832214,220.393295}, {312.832214,203.454178}}}, 3, 2844431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org 0.865309956, 1, {} }, 2854431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{322.12738,233.397751}, {295.718353,159.505829}}}, 2, 2864431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org 0.345028807, 1, {} }, 2874431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org}; 2884431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org 2894431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.orgstatic IntersectData intersectDataSet2[] = { 2904431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{364.390686,157.898193}, {375.281769,136.674606}, {396.039917,136.674606}}}, 3, 2914431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org 0.578520747, 1, {} }, 2924431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{364.390686,157.898193}, {375.281769,136.674606}, {396.039917,136.674606}}}, 3, 2934431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org 0.578520747, 0.536512973, {} }, 2944431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{366.608826,151.196014}, {378.803101,136.674606}, {398.164948,136.674606}}}, 3, 2954431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org 0.490456543, 1, {} }, 2964431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org}; 2974431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org 2984431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.orgstatic IntersectData intersectDataSet3[] = { 2994431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{2.000000,0.000000}, {1.33333333,0.66666667}}}, 2, 1, 0, {} }, 3004431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{1.33333333,0.66666667}, {0.000000,2.000000}}}, 2, 0, 0.25, {} }, 3014431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{2.000000,2.000000}, {1.33333333,0.66666667}}}, 2, 1, 0, {} }, 3024431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org}; 3034431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org 3044431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.orgstatic IntersectData intersectDataSet4[] = { 3054431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{1.3333333,0.6666667}, {0.000,2.000}}}, 2, 0.250000006, 0, {} }, 3064431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{1.000,0.000}, {1.000,1.000}}}, 2, 1, 0, {} }, 3074431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{1.000,1.000}, {0.000,0.000}}}, 2, 0, 1, {} }, 3084431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org}; 3094431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org 3104431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.orgstatic IntersectData intersectDataSet5[] = { 3114431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{0.000,0.000}, {1.000,0.000}, {1.000,1.000}}}, 3, 1, 0.666666667, {} }, 3124431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{0.000,0.000}, {2.000,1.000}, {0.000,2.000}}}, 3, 0.5, 1, {} }, 3134431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{0.000,0.000}, {2.000,1.000}, {0.000,2.000}}}, 3, 0.5, 0, {} }, 3144431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org}; 3154431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org 3164431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.orgstatic IntersectData intersectDataSet6[] = { // pathops_visualizer.htm:3658 3174431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{0.000,1.000}, {3.000,4.000}, {1.000,0.000}, {3.000,0.000}}}, 4, 0.0925339054, 0, {} }, // pathops_visualizer.htm:3616 3184431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{0.000,1.000}, {0.000,3.000}, {1.000,0.000}, {4.000,3.000}}}, 4, 0.453872386, 0, {} }, // pathops_visualizer.htm:3616 3194431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{0.000,1.000}, {3.000,4.000}, {1.000,0.000}, {3.000,0.000}}}, 4, 0.0925339054, 0.417096368, {} }, // pathops_visualizer.htm:3616 3204431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org}; 3214431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org 3224431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.orgstatic IntersectData intersectDataSet7[] = { // pathops_visualizer.htm:3748 3234431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{2.000,1.000}, {0.000,1.000}}}, 2, 0.5, 0, {} }, // pathops_visualizer.htm:3706 3244431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{2.000,0.000}, {0.000,2.000}}}, 2, 0.5, 1, {} }, // pathops_visualizer.htm:3706 3254431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{0.000,1.000}, {0.000,2.000}, {2.000,0.000}, {2.000,1.000}}}, 4, 0.5, 1, {} }, // pathops_visualizer.htm:3706 3264431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org}; // 3274431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org 3284431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.orgstatic IntersectData intersectDataSet8[] = { // pathops_visualizer.htm:4194 3294431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{0.000,1.000}, {2.000,3.000}, {5.000,1.000}, {4.000,3.000}}}, 4, 0.311007457, 0.285714286, {} }, // pathops_visualizer.htm:4152 3304431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{1.000,5.000}, {3.000,4.000}, {1.000,0.000}, {3.000,2.000}}}, 4, 0.589885081, 0.999982974, {} }, // pathops_visualizer.htm:4152 3314431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{1.000,5.000}, {3.000,4.000}, {1.000,0.000}, {3.000,2.000}}}, 4, 0.589885081, 0.576935809, {} }, // pathops_visualizer.htm:4152 3324431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org}; // 3334431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org 3344431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.orgstatic IntersectData intersectDataSet9[] = { // pathops_visualizer.htm:4142 3354431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{0.000,1.000}, {2.000,3.000}, {5.000,1.000}, {4.000,3.000}}}, 4, 0.476627072, 0.311007457, {} }, // pathops_visualizer.htm:4100 3364431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{1.000,5.000}, {3.000,4.000}, {1.000,0.000}, {3.000,2.000}}}, 4, 0.999982974, 1, {} }, // pathops_visualizer.htm:4100 3374431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{0.000,1.000}, {2.000,3.000}, {5.000,1.000}, {4.000,3.000}}}, 4, 0.476627072, 1, {} }, // pathops_visualizer.htm:4100 3384431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org}; // 3394431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org 3404431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.orgstatic IntersectData intersectDataSet10[] = { // pathops_visualizer.htm:4186 3414431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{0.000,1.000}, {1.000,6.000}, {1.000,0.000}, {1.000,0.000}}}, 4, 0.788195121, 0.726275769, {} }, // pathops_visualizer.htm:4144 3424431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{0.000,1.000}, {0.000,1.000}, {1.000,0.000}, {6.000,1.000}}}, 4, 0.473378977, 1, {} }, // pathops_visualizer.htm:4144 3434431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{0.000,1.000}, {1.000,6.000}, {1.000,0.000}, {1.000,0.000}}}, 4, 0.788195121, 1, {} }, // pathops_visualizer.htm:4144 3444431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org}; // 3454431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org 3464431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.orgstatic IntersectData intersectDataSet11[] = { // pathops_visualizer.htm:4704 3474431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{979.305,561.000}, {1036.695,291.000}}}, 2, 0.888888874, 0.11111108, {} }, // pathops_visualizer.htm:4662 3484431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{1006.695,291.000}, {1023.264,291.000}, {1033.840,304.431}, {1030.318,321.000}}}, 4, 1, 0, {} }, // pathops_visualizer.htm:4662 3494431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{979.305,561.000}, {1036.695,291.000}}}, 2, 0.888888874, 1, {} }, // pathops_visualizer.htm:4662 3504431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org}; // 3514431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org 3524431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.orgstatic IntersectData intersectDataSet12[] = { // pathops_visualizer.htm:5481 3534431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{67.000,912.000}, {67.000,913.000}}}, 2, 1, 0, {} }, // pathops_visualizer.htm:5439 3544431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{67.000,913.000}, {67.000,917.389}, {67.224,921.726}, {67.662,926.000}}}, 4, 0, 1, {} }, // pathops_visualizer.htm:5439 3554431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{194.000,1041.000}, {123.860,1041.000}, {67.000,983.692}, {67.000,913.000}}}, 4, 1, 0, {} }, // pathops_visualizer.htm:5439 3564431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org}; // 3574431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org 3584431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.orgstatic IntersectData intersectDataSet13[] = { // pathops_visualizer.htm:5735 3594431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{6.000,0.000}, {0.000,4.000}}}, 2, 0.625, 0.25, {} }, // pathops_visualizer.htm:5693 3604431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{0.000,1.000}, {0.000,6.000}, {4.000,0.000}, {6.000,1.000}}}, 4, 0.5, 0.833333333, {} }, // pathops_visualizer.htm:5693 3614431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{0.000,1.000}, {0.000,6.000}, {4.000,0.000}, {6.000,1.000}}}, 4, 0.5, 0.379043969, {} }, // pathops_visualizer.htm:5693 3624431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org}; // 3634431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org 3644431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.orgstatic IntersectData intersectDataSet14[] = { // pathops_visualizer.htm:5875 3654431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{0.000,1.000}, {4.000,6.000}, {2.000,1.000}, {2.000,0.000}}}, 4, 0.0756502183, 0.0594570973, {} }, // pathops_visualizer.htm:5833 3664431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{1.000,2.000}, {0.000,2.000}, {1.000,0.000}, {6.000,4.000}}}, 4, 0.0756502184, 0, {} }, // pathops_visualizer.htm:5833 3674431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{0.000,1.000}, {4.000,6.000}, {2.000,1.000}, {2.000,0.000}}}, 4, 0.0756502183, 0.531917258, {} }, // pathops_visualizer.htm:5833 3684431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org}; // 3694431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org 3704431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.orgstatic IntersectData intersectDataSet15[] = { // pathops_visualizer.htm:6580 3714431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{490.435,879.407}, {405.593,909.436}}}, 2, 0.500554405, 1, {} }, // pathops_visualizer.htm:6538 3724431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{447.967,894.438}, {448.007,894.424}, {448.014,894.422}}}, 3, 0, 1, {} }, // pathops_visualizer.htm:6538 3734431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{490.435,879.407}, {405.593,909.436}}}, 2, 0.500554405, 0.500000273, {} }, // pathops_visualizer.htm:6538 374a1ed7aec95eb8c77d1a39834fea476780007cadeskia.committer@gmail.com}; // 3754431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org 3764431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.orgstatic IntersectData intersectDataSet16[] = { // pathops_visualizer.htm:7419 3774431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{1.000,4.000}, {4.000,5.000}, {3.000,2.000}, {6.000,3.000}}}, 4, 0.5, 0, {} }, // pathops_visualizer.htm:7377 3784431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{2.000,3.000}, {3.000,6.000}, {4.000,1.000}, {5.000,4.000}}}, 4, 0.5, 0.112701665, {} }, // pathops_visualizer.htm:7377 3794431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org { {{{5.000,4.000}, {2.000,3.000}}}, 2, 0.5, 0, {} }, // pathops_visualizer.htm:7377 3804431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org}; // 3814431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org 38254359294a7c9dc54802d512a5d891a35c1663392caryclark// from skpi_gino_com_16 38354359294a7c9dc54802d512a5d891a35c1663392caryclarkstatic IntersectData intersectDataSet17[] = { 38454359294a7c9dc54802d512a5d891a35c1663392caryclark { /*seg=7*/ {{{270.974121f, 770.025879f}, {234.948273f, 734}, {184, 734}}} 38554359294a7c9dc54802d512a5d891a35c1663392caryclark , 3, 0.74590454, 0.547660352, {} }, 38654359294a7c9dc54802d512a5d891a35c1663392caryclark { /*seg=8*/ {{{185, 734}, {252.93103f, 734}, {308, 789.06897f}, {308, 857}}} 38754359294a7c9dc54802d512a5d891a35c1663392caryclark , 4, 0.12052623, 0, {} }, 38854359294a7c9dc54802d512a5d891a35c1663392caryclark { /*seg=7*/ {{{270.974121f, 770.025879f}, {234.948273f, 734}, {184, 734}}} 38954359294a7c9dc54802d512a5d891a35c1663392caryclark , 3, 0.74590454, 1, {} }, 39054359294a7c9dc54802d512a5d891a35c1663392caryclark}; 39154359294a7c9dc54802d512a5d891a35c1663392caryclark 39254359294a7c9dc54802d512a5d891a35c1663392caryclarkstatic IntersectData intersectDataSet18[] = { 39354359294a7c9dc54802d512a5d891a35c1663392caryclark { /*seg=7*/ {{{270.974121f, 770.025879f}, {234.948273f, 734}, {184, 734}}} 39454359294a7c9dc54802d512a5d891a35c1663392caryclark , 3, 0.74590454, 1, {} }, 39554359294a7c9dc54802d512a5d891a35c1663392caryclark { /*seg=8*/ {{{185, 734}, {252.93103f, 734}, {308, 789.06897f}, {308, 857}}} 39654359294a7c9dc54802d512a5d891a35c1663392caryclark , 4, 0.12052623, 0.217351928, {} }, 39754359294a7c9dc54802d512a5d891a35c1663392caryclark { /*seg=7*/ {{{270.974121f, 770.025879f}, {234.948273f, 734}, {184, 734}}} 39854359294a7c9dc54802d512a5d891a35c1663392caryclark , 3, 0.74590454, 0.547660352, {} }, 39954359294a7c9dc54802d512a5d891a35c1663392caryclark}; 40054359294a7c9dc54802d512a5d891a35c1663392caryclark 40154359294a7c9dc54802d512a5d891a35c1663392caryclarkstatic IntersectData intersectDataSet19[] = { 40254359294a7c9dc54802d512a5d891a35c1663392caryclark { /*seg=1*/ {{{0, 1}, {3, 5}, {2, 1}, {3, 1}}} 40354359294a7c9dc54802d512a5d891a35c1663392caryclark , 4, 0.135148995, 0.134791946, {} }, 40454359294a7c9dc54802d512a5d891a35c1663392caryclark { /*seg=3*/ {{{1, 2}, {1, 2.15061641f}, {1, 2.21049166f}, {1.01366711f, 2.21379328f}}} 40554359294a7c9dc54802d512a5d891a35c1663392caryclark , 4, 0.956740456, 0.894913214, {} }, 40654359294a7c9dc54802d512a5d891a35c1663392caryclark { /*seg=1*/ {{{0, 1}, {3, 5}, {2, 1}, {3, 1}}} 40754359294a7c9dc54802d512a5d891a35c1663392caryclark , 4, 0.135148995, 0.551812363, {} }, 40854359294a7c9dc54802d512a5d891a35c1663392caryclark}; 40954359294a7c9dc54802d512a5d891a35c1663392caryclark 4104431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org#define I(x) intersectDataSet##x 4114431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org 4124431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.orgstatic IntersectData* intersectDataSets[] = { 4134431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org I(1), I(2), I(3), I(4), I(5), I(6), I(7), I(8), I(9), I(10), 41454359294a7c9dc54802d512a5d891a35c1663392caryclark I(11), I(12), I(13), I(14), I(15), I(16), I(17), I(18), I(19), 4154431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org}; 4164431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org 4174431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org#undef I 4184431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org#define I(x) (int) SK_ARRAY_COUNT(intersectDataSet##x) 4194431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org 4204431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.orgstatic const int intersectDataSetSizes[] = { 4214431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org I(1), I(2), I(3), I(4), I(5), I(6), I(7), I(8), I(9), I(10), 42254359294a7c9dc54802d512a5d891a35c1663392caryclark I(11), I(12), I(13), I(14), I(15), I(16), I(17), I(18), I(19), 4234431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org}; 4244431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org 4254431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org#undef I 4264431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org 4274431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.orgstatic const int intersectDataSetsSize = (int) SK_ARRAY_COUNT(intersectDataSetSizes); 4284431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org 42954359294a7c9dc54802d512a5d891a35c1663392caryclarkstruct FourPoints { 43054359294a7c9dc54802d512a5d891a35c1663392caryclark SkPoint pts[4]; 43154359294a7c9dc54802d512a5d891a35c1663392caryclark}; 43254359294a7c9dc54802d512a5d891a35c1663392caryclark 4334431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.orgDEF_TEST(PathOpsAngleAfter, reporter) { 43414a6430b7bcf92bcabf4aef18805969d1335aab1Florin Malita SkSTArenaAlloc<4096> allocator; 435624637cc8ec22c000409704d0b403ac1b81ad4b0caryclark SkOpContourHead contour; 43655888e44171ffd48b591d19256884a969fe4da17caryclark SkOpGlobalState state(&contour, &allocator SkDEBUGPARAMS(false) SkDEBUGPARAMS(nullptr)); 43754359294a7c9dc54802d512a5d891a35c1663392caryclark contour.init(&state, false, false); 4384431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org for (int index = intersectDataSetsSize - 1; index >= 0; --index) { 4394431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org IntersectData* dataArray = intersectDataSets[index]; 4404431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org const int dataSize = intersectDataSetSizes[index]; 4414431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org for (int index2 = 0; index2 < dataSize - 2; ++index2) { 44254359294a7c9dc54802d512a5d891a35c1663392caryclark allocator.reset(); 44354359294a7c9dc54802d512a5d891a35c1663392caryclark contour.reset(); 44454359294a7c9dc54802d512a5d891a35c1663392caryclark for (int index3 = 0; index3 < 3; ++index3) { 4454431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org IntersectData& data = dataArray[index2 + index3]; 446ecc364c42691f24b41a672de1636b3a5f181160aHerb Derby SkPoint* temp = (SkPoint*) allocator.make<FourPoints>(); 4474431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org for (int idx2 = 0; idx2 < data.fPtCount; ++idx2) { 4484431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org temp[idx2] = data.fPts.fPts[idx2].asSkPoint(); 4494431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org } 4504431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org switch (data.fPtCount) { 4514431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org case 2: { 45255888e44171ffd48b591d19256884a969fe4da17caryclark contour.addLine(temp); 4534431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org } break; 4544431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org case 3: { 45555888e44171ffd48b591d19256884a969fe4da17caryclark contour.addQuad(temp); 4564431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org } break; 4574431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org case 4: { 45855888e44171ffd48b591d19256884a969fe4da17caryclark contour.addCubic(temp); 4594431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org } break; 4604431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org } 4614431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org } 46254359294a7c9dc54802d512a5d891a35c1663392caryclark SkOpSegment* seg1 = contour.first(); 46355888e44171ffd48b591d19256884a969fe4da17caryclark seg1->debugAddAngle(dataArray[index2 + 0].fTStart, dataArray[index2 + 0].fTEnd); 46454359294a7c9dc54802d512a5d891a35c1663392caryclark SkOpSegment* seg2 = seg1->next(); 46555888e44171ffd48b591d19256884a969fe4da17caryclark seg2->debugAddAngle(dataArray[index2 + 1].fTStart, dataArray[index2 + 1].fTEnd); 46654359294a7c9dc54802d512a5d891a35c1663392caryclark SkOpSegment* seg3 = seg2->next(); 46755888e44171ffd48b591d19256884a969fe4da17caryclark seg3->debugAddAngle(dataArray[index2 + 2].fTStart, dataArray[index2 + 2].fTEnd); 46854359294a7c9dc54802d512a5d891a35c1663392caryclark SkOpAngle& angle1 = *seg1->debugLastAngle(); 46954359294a7c9dc54802d512a5d891a35c1663392caryclark SkOpAngle& angle2 = *seg2->debugLastAngle(); 47054359294a7c9dc54802d512a5d891a35c1663392caryclark SkOpAngle& angle3 = *seg3->debugLastAngle(); 4714431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org PathOpsAngleTester::SetNext(angle1, angle3); 4724431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org // These data sets are seeded when the set itself fails, so likely the dataset does not 4734431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org // match the expected result. The tests above return 1 when first added, but 4744431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org // return 0 after the bug is fixed. 4754431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org SkDEBUGCODE(int result =) PathOpsAngleTester::After(angle2, angle1); 4764431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org SkASSERT(result == 0 || result == 1); 4774431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org } 4784431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org } 4794431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org} 4804431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org 48155888e44171ffd48b591d19256884a969fe4da17caryclarkvoid SkOpSegment::debugAddAngle(double startT, double endT) { 48254359294a7c9dc54802d512a5d891a35c1663392caryclark SkOpPtT* startPtT = startT == 0 ? fHead.ptT() : startT == 1 ? fTail.ptT() 48329b2563afb1677515739f1d24fb27733626eca92caryclark : this->addT(startT); 48454359294a7c9dc54802d512a5d891a35c1663392caryclark SkOpPtT* endPtT = endT == 0 ? fHead.ptT() : endT == 1 ? fTail.ptT() 48529b2563afb1677515739f1d24fb27733626eca92caryclark : this->addT(endT); 486ecc364c42691f24b41a672de1636b3a5f181160aHerb Derby SkOpAngle* angle = this->globalState()->allocator()->make<SkOpAngle>(); 48754359294a7c9dc54802d512a5d891a35c1663392caryclark SkOpSpanBase* startSpan = &fHead; 48854359294a7c9dc54802d512a5d891a35c1663392caryclark while (startSpan->ptT() != startPtT) { 48954359294a7c9dc54802d512a5d891a35c1663392caryclark startSpan = startSpan->upCast()->next(); 49054359294a7c9dc54802d512a5d891a35c1663392caryclark } 49154359294a7c9dc54802d512a5d891a35c1663392caryclark SkOpSpanBase* endSpan = &fHead; 49254359294a7c9dc54802d512a5d891a35c1663392caryclark while (endSpan->ptT() != endPtT) { 49354359294a7c9dc54802d512a5d891a35c1663392caryclark endSpan = endSpan->upCast()->next(); 49454359294a7c9dc54802d512a5d891a35c1663392caryclark } 49554359294a7c9dc54802d512a5d891a35c1663392caryclark angle->set(startSpan, endSpan); 49654359294a7c9dc54802d512a5d891a35c1663392caryclark if (startT < endT) { 49754359294a7c9dc54802d512a5d891a35c1663392caryclark startSpan->upCast()->setToAngle(angle); 49854359294a7c9dc54802d512a5d891a35c1663392caryclark endSpan->setFromAngle(angle); 49954359294a7c9dc54802d512a5d891a35c1663392caryclark } else { 50054359294a7c9dc54802d512a5d891a35c1663392caryclark endSpan->upCast()->setToAngle(angle); 50154359294a7c9dc54802d512a5d891a35c1663392caryclark startSpan->setFromAngle(angle); 50254359294a7c9dc54802d512a5d891a35c1663392caryclark } 5034431e7757cfcb8cfa99535eed0e9f156dabf95c2commit-bot@chromium.org} 50455888e44171ffd48b591d19256884a969fe4da17caryclark 50555888e44171ffd48b591d19256884a969fe4da17caryclarkDEF_TEST(PathOpsAngleAllOnOneSide, reporter) { 50614a6430b7bcf92bcabf4aef18805969d1335aab1Florin Malita SkSTArenaAlloc<4096> allocator; 50755888e44171ffd48b591d19256884a969fe4da17caryclark SkOpContourHead contour; 50855888e44171ffd48b591d19256884a969fe4da17caryclark SkOpGlobalState state(&contour, &allocator SkDEBUGPARAMS(false) SkDEBUGPARAMS(nullptr)); 50955888e44171ffd48b591d19256884a969fe4da17caryclark contour.init(&state, false, false); 51055888e44171ffd48b591d19256884a969fe4da17caryclark SkPoint conicPts[3] = {{494.37100219726562f, 224.66200256347656f}, 51155888e44171ffd48b591d19256884a969fe4da17caryclark {494.37360910682298f, 224.6729026561527f}, 51255888e44171ffd48b591d19256884a969fe4da17caryclark {494.37600708007813f, 224.68400573730469f}}; 51355888e44171ffd48b591d19256884a969fe4da17caryclark SkPoint linePts[2] = {{494.371002f, 224.662003f}, {494.375000f, 224.675995f}}; 51455888e44171ffd48b591d19256884a969fe4da17caryclark for (int i = 10; i >= 0; --i) { 51555888e44171ffd48b591d19256884a969fe4da17caryclark SkPoint modLinePts[2] = { linePts[0], linePts[1] }; 51655888e44171ffd48b591d19256884a969fe4da17caryclark modLinePts[1].fX += i * .1f; 51755888e44171ffd48b591d19256884a969fe4da17caryclark contour.addLine(modLinePts); 51855888e44171ffd48b591d19256884a969fe4da17caryclark contour.addQuad(conicPts); 51955888e44171ffd48b591d19256884a969fe4da17caryclark // contour.addConic(conicPts, 0.999935746f, &allocator); 52055888e44171ffd48b591d19256884a969fe4da17caryclark SkOpSegment* first = contour.first(); 52155888e44171ffd48b591d19256884a969fe4da17caryclark first->debugAddAngle(0, 1); 52255888e44171ffd48b591d19256884a969fe4da17caryclark SkOpSegment* next = first->next(); 52355888e44171ffd48b591d19256884a969fe4da17caryclark next->debugAddAngle(0, 1); 52455888e44171ffd48b591d19256884a969fe4da17caryclark /* int result = */ 52555888e44171ffd48b591d19256884a969fe4da17caryclark PathOpsAngleTester::AllOnOneSide(*first->debugLastAngle(), *next->debugLastAngle()); 52655888e44171ffd48b591d19256884a969fe4da17caryclark // SkDebugf("i=%d result=%d\n", i , result); 52755888e44171ffd48b591d19256884a969fe4da17caryclark // SkDebugf(""); 52855888e44171ffd48b591d19256884a969fe4da17caryclark } 52955888e44171ffd48b591d19256884a969fe4da17caryclark} 530