skia2/docs/examples/Rect_equal_operator.cpp
John Stiles 7bf799956d Reland "Add format-specifier warnings to SkDebugf."
This is a reland of e58831cd95

Original change's description:
> Add format-specifier warnings to SkDebugf.
>
> This CL fixes up many existing format-specifier violations in Skia.
> Note that GCC has a warning for formatting nothing, so existing calls to
> `SkDebugf("")` have been removed, or replaced with `SkDebugf("%s", "")`.
> These were apparently meant to be used as a place to set a breakpoint.
>
> Some of our clients also use SkDebug with bad format specifiers, so this
> check is currently only enabled when SKIA_IMPLEMENTATION is true.
>
> Change-Id: I8177a1298a624c6936adc24e0d8f481362a356d0
> Bug: skia:12143
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/420902
> Auto-Submit: John Stiles <johnstiles@google.com>
> Commit-Queue: Brian Osman <brianosman@google.com>
> Reviewed-by: Brian Osman <brianosman@google.com>

Bug: skia:12143
Change-Id: Id3c0c21436ebd13899908d5ed5d44c42a0e23921
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/421918
Commit-Queue: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2021-06-25 17:57:43 +00:00

24 lines
1.1 KiB
C++

// Copyright 2019 Google LLC.
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
#include "tools/fiddle/examples.h"
// HASH=c6c5b40cad7c3a839fdf576b380391a6
REG_FIDDLE(Rect_equal_operator, 256, 256, true, 0) {
void draw(SkCanvas* canvas) {
auto debugster = [](const SkRect& test) -> void {
SkRect negZero = {-0.0f, -0.0f, 2, 2};
SkDebugf("{%g, %g, %g, %g} %c= {%g, %g, %g, %g} %s numerically equal\n",
test.fLeft, test.fTop, test.fRight, test.fBottom,
test == negZero ? '=' : '!',
negZero.fLeft, negZero.fTop, negZero.fRight, negZero.fBottom,
(test.fLeft == negZero.fLeft && test.fTop == negZero.fTop &&
test.fRight == negZero.fRight && test.fBottom == negZero.fBottom) ?
"and are" : "yet are not");
};
SkRect tests[] = {{0, 0, 2, 2}, {-0, -0, 2, 2}, {0.0f, 0.0f, 2, 2}};
SkDebugf("tests are %s" "equal\n", tests[0] == tests[1] && tests[1] == tests[2] ? "" : "not ");
for (auto rect : tests) {
debugster(rect);
}
}
} // END FIDDLE