-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
check for some special cases: - degenerate or simple cubic - 0/0 Bug: skia: Change-Id: Ie978caf9d862755d9693768695bf84eff9ec80e4 Reviewed-on: https://skia-review.googlesource.com/147112 Commit-Queue: Mike Reed <reed@google.com> Commit-Queue: Florin Malita <fmalita@chromium.org> Reviewed-by: Florin Malita <fmalita@chromium.org> Auto-Submit: Mike Reed <reed@google.com>
- Loading branch information
1 parent
7f25670
commit 0d4a183
Showing
4 changed files
with
120 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright 2018 Google Inc. | ||
* | ||
* Use of this source code is governed by a BSD-style license that can be | ||
* found in the LICENSE file. | ||
*/ | ||
|
||
#include "SkCubicMap.h" | ||
#include "SkRandom.h" | ||
#include "Test.h" | ||
|
||
static bool nearly_le(SkScalar a, SkScalar b) { | ||
return a <= b || SkScalarNearlyZero(a - b); | ||
} | ||
|
||
static void exercise_cubicmap(const SkCubicMap& cmap, skiatest::Reporter* reporter) { | ||
SkScalar prev_y = 0; | ||
for (SkScalar x = 0; x <= 1; x += 1.0f / 512) { | ||
SkScalar y = cmap.computeYFromX(x); | ||
if (y < 0 || y > 1 || !nearly_le(prev_y, y)) { | ||
cmap.computeYFromX(x); | ||
REPORTER_ASSERT(reporter, false); | ||
} | ||
prev_y = y; | ||
} | ||
} | ||
|
||
DEF_TEST(CubicMap, r) { | ||
const SkScalar values[] = { | ||
0, 1, 0.25f, 0.75f, 0.5f, 1.0f/3, 2.0f/3, 0.0000001f, 0.999999f, | ||
}; | ||
|
||
for (SkScalar x0 : values) { | ||
for (SkScalar y0 : values) { | ||
for (SkScalar x1 : values) { | ||
for (SkScalar y1 : values) { | ||
exercise_cubicmap(SkCubicMap({ x0, y0 }, { x1, y1 }), r); | ||
} | ||
} | ||
} | ||
} | ||
} |