1cb93a386Sopenharmony_ci/* 2cb93a386Sopenharmony_ci * Copyright 2013 Google Inc. 3cb93a386Sopenharmony_ci * 4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be 5cb93a386Sopenharmony_ci * found in the LICENSE file. 6cb93a386Sopenharmony_ci */ 7cb93a386Sopenharmony_ci#include "src/pathops/SkPathOpsBounds.h" 8cb93a386Sopenharmony_ci#include "src/pathops/SkPathOpsCurve.h" 9cb93a386Sopenharmony_ci#include "tests/PathOpsTestCommon.h" 10cb93a386Sopenharmony_ci#include "tests/Test.h" 11cb93a386Sopenharmony_ci 12cb93a386Sopenharmony_cistatic const SkRect sectTests[][2] = { 13cb93a386Sopenharmony_ci {{2, 0, 4, 1}, {4, 0, 6, 1}}, 14cb93a386Sopenharmony_ci {{2, 0, 4, 1}, {3, 0, 5, 1}}, 15cb93a386Sopenharmony_ci {{2, 0, 4, 1}, {3, 0, 5, 0}}, 16cb93a386Sopenharmony_ci {{2, 0, 4, 1}, {3, 1, 5, 2}}, 17cb93a386Sopenharmony_ci {{2, 1, 4, 2}, {1, 0, 5, 3}}, 18cb93a386Sopenharmony_ci {{2, 1, 5, 3}, {3, 1, 4, 2}}, 19cb93a386Sopenharmony_ci {{2, 0, 4, 1}, {3, 0, 3, 0}}, // intersecting an empty bounds is OK 20cb93a386Sopenharmony_ci {{2, 0, 4, 1}, {4, 1, 5, 2}}, // touching just on a corner is OK 21cb93a386Sopenharmony_ci}; 22cb93a386Sopenharmony_ci 23cb93a386Sopenharmony_cistatic const size_t sectTestsCount = SK_ARRAY_COUNT(sectTests); 24cb93a386Sopenharmony_ci 25cb93a386Sopenharmony_cistatic const SkRect noSectTests[][2] = { 26cb93a386Sopenharmony_ci {{2, 0, 4, 1}, {5, 0, 6, 1}}, 27cb93a386Sopenharmony_ci {{2, 0, 4, 1}, {3, 2, 5, 2}}, 28cb93a386Sopenharmony_ci}; 29cb93a386Sopenharmony_ci 30cb93a386Sopenharmony_cistatic const size_t noSectTestsCount = SK_ARRAY_COUNT(noSectTests); 31cb93a386Sopenharmony_ci 32cb93a386Sopenharmony_ciDEF_TEST(PathOpsBounds, reporter) { 33cb93a386Sopenharmony_ci for (size_t index = 0; index < sectTestsCount; ++index) { 34cb93a386Sopenharmony_ci const SkPathOpsBounds& bounds1 = static_cast<const SkPathOpsBounds&>(sectTests[index][0]); 35cb93a386Sopenharmony_ci SkASSERT(ValidBounds(bounds1)); 36cb93a386Sopenharmony_ci const SkPathOpsBounds& bounds2 = static_cast<const SkPathOpsBounds&>(sectTests[index][1]); 37cb93a386Sopenharmony_ci SkASSERT(ValidBounds(bounds2)); 38cb93a386Sopenharmony_ci bool touches = SkPathOpsBounds::Intersects(bounds1, bounds2); 39cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, touches); 40cb93a386Sopenharmony_ci } 41cb93a386Sopenharmony_ci for (size_t index = 0; index < noSectTestsCount; ++index) { 42cb93a386Sopenharmony_ci const SkPathOpsBounds& bounds1 = static_cast<const SkPathOpsBounds&>(noSectTests[index][0]); 43cb93a386Sopenharmony_ci SkASSERT(ValidBounds(bounds1)); 44cb93a386Sopenharmony_ci const SkPathOpsBounds& bounds2 = static_cast<const SkPathOpsBounds&>(noSectTests[index][1]); 45cb93a386Sopenharmony_ci SkASSERT(ValidBounds(bounds2)); 46cb93a386Sopenharmony_ci bool touches = SkPathOpsBounds::Intersects(bounds1, bounds2); 47cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, !touches); 48cb93a386Sopenharmony_ci } 49cb93a386Sopenharmony_ci SkPathOpsBounds bounds; 50cb93a386Sopenharmony_ci bounds.setEmpty(); 51cb93a386Sopenharmony_ci bounds.add(1, 2, 3, 4); 52cb93a386Sopenharmony_ci SkPathOpsBounds expected; 53cb93a386Sopenharmony_ci expected.setLTRB(0, 0, 3, 4); 54cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, bounds == expected); 55cb93a386Sopenharmony_ci bounds.setEmpty(); 56cb93a386Sopenharmony_ci SkPathOpsBounds ordinal; 57cb93a386Sopenharmony_ci ordinal.setLTRB(1, 2, 3, 4); 58cb93a386Sopenharmony_ci bounds.add(ordinal); 59cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, bounds == expected); 60cb93a386Sopenharmony_ci bounds.setEmpty(); 61cb93a386Sopenharmony_ci SkDPoint botRight = {3, 4}; 62cb93a386Sopenharmony_ci bounds.add(botRight); 63cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, bounds == expected); 64cb93a386Sopenharmony_ci const SkPoint curvePts[] = {{0, 0}, {1, 2}, {3, 4}, {5, 6}}; 65cb93a386Sopenharmony_ci SkDCurve curve; 66cb93a386Sopenharmony_ci curve.fQuad.set(curvePts); 67cb93a386Sopenharmony_ci curve.setQuadBounds(curvePts, 1, 0, 1, &bounds); 68cb93a386Sopenharmony_ci expected.setLTRB(0, 0, 3, 4); 69cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, bounds == expected); 70cb93a386Sopenharmony_ci curve.fCubic.set(curvePts); 71cb93a386Sopenharmony_ci curve.setCubicBounds(curvePts, 1, 0, 1, &bounds); 72cb93a386Sopenharmony_ci expected.setLTRB(0, 0, 5, 6); 73cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, bounds == expected); 74cb93a386Sopenharmony_ci} 75