259 {
260 auto assertRectsNearlyEqual = [&](
const SkRect& actual,
const SkRect& expected,
263 "Expected %g == %g", actual.
fLeft, expected.fLeft);
265 "Expected %g == %g", actual.
fTop, expected.fTop);
267 "Expected %g == %g", actual.
fRight, expected.fRight);
269 "Expected %g == %g", actual.
fBottom, expected.fBottom);
270 };
272 SkRect epsilon = {1e-5f, 1e-5f, 1e-5f, 1e-5f};
273
276
277 if (expected) {
278 assertRectsNearlyEqual(actual, *expected, epsilon);
279 }
280
281 SkV4 corners[4] = {{
src.fLeft,
src.fTop, 0.f, 1.f},
282 {
src.fRight,
src.fTop, 0.f, 1.f},
283 {
src.fRight,
src.fBottom, 0.f, 1.f},
284 {
src.fLeft,
src.fBottom, 0.f, 1.f}};
285 bool leftFound = false;
286 bool topFound = false;
287 bool rightFound = false;
288 bool bottomFound = false;
289 bool clipped = false;
290 for (
int i = 0;
i < 4; ++
i) {
291 SkV4 mapped =
m * corners[
i];
292 if (mapped.
w > 0.f) {
293
294 float x = mapped.
x / mapped.
w;
295 float y = mapped.
y / mapped.
w;
296
297
299 "Expected %g contained in [%g, %g]",
302 "Expected %g contained in [%g, %g]",
304
309 } else {
310
311
312 clipped = true;
313 }
314 }
315
316 if (clipped) {
317
319
320
321
322
323
324
325
326 if (!leftFound) { epsilon.
fLeft = .01f * actual.
fLeft; }
327 if (!topFound) { epsilon.
fTop = .01f * actual.
fTop; }
328 if (!rightFound) { epsilon.
fRight = .01f * actual.
fRight; }
330 } else {
331
333 }
334
337 assertRectsNearlyEqual(actual,
path.getBounds(), epsilon);
338 };
339
340
342
343
345
347 10.f + 2.f *
src.fRight, 8.f + 4.f *
src.fBottom);
348 assertMapRect(
SkM44::Scale(2.f, 4.f).postTranslate(10.f, 8.f),
src, &st);
349
351 .preTranslate(-
src.centerX(), -
src.centerY())
354
355
357 p.preTranslate(0.f, 5.f, -0.1f);
359 assertMapRect(
p,
src,
nullptr);
360
361
363 p.setRow(3, {-.2f, -.6f, 0.f, 8.f});
364 assertMapRect(
p,
src,
nullptr);
365}
@ kYes
Do pre-clip the geometry before applying the (perspective) matrix.
static bool SkScalarNearlyEqual(SkScalar x, SkScalar y, SkScalar tolerance=SK_ScalarNearlyZero)
SkM44 & postTranslate(SkScalar x, SkScalar y, SkScalar z=0)
static SkM44 Rotate(SkV3 axis, SkScalar radians)
static SkM44 Perspective(float near, float far, float angle)
static SkM44 Scale(SkScalar x, SkScalar y, SkScalar z=1)
static SkRect MapRect(const SkM44 &m, const SkRect &r)
static SkPath Rect(const SkRect &, SkPathDirection=SkPathDirection::kCW, unsigned startIndex=0)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
SkScalar fBottom
larger y-axis bounds
SkScalar fLeft
smaller x-axis bounds
SkScalar fRight
larger x-axis bounds
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
SkScalar fTop
smaller y-axis bounds