From b4977cb51a7ad3ec6334a7675a1bf35ea751eaad Mon Sep 17 00:00:00 2001 From: Chun-Heng Tai Date: Mon, 21 Dec 2020 11:38:42 -0800 Subject: [PATCH] format forked chromium accessibility code --- .../base/numerics/checked_math.h | 22 +- .../base/numerics/clamped_math.h | 16 +- .../base/numerics/safe_conversions.h | 16 +- .../base/numerics/safe_conversions_arm_impl.h | 18 +- .../base/numerics/safe_conversions_impl.h | 26 +- .../base/numerics/safe_math_arm_impl.h | 8 +- .../base/numerics/safe_math_shared_impl.h | 10 +- .../accessibility/gfx/geometry/insets.cc | 2 +- .../accessibility/gfx/geometry/insets.h | 4 +- .../accessibility/gfx/geometry/insets_f.cc | 2 +- .../accessibility/gfx/geometry/insets_f.h | 4 +- .../gfx/geometry/insets_unittest.cc | 2 +- .../accessibility/gfx/geometry/point.cc | 6 +- .../accessibility/gfx/geometry/point.h | 19 +- .../gfx/geometry/point_conversions.cc | 1 - .../accessibility/gfx/geometry/point_f.cc | 1 - .../accessibility/gfx/geometry/point_f.h | 4 +- .../gfx/geometry/point_unittest.cc | 16 +- .../accessibility/gfx/geometry/rect.cc | 19 +- .../accessibility/gfx/geometry/rect.h | 98 ++-- .../accessibility/gfx/geometry/rect_f.cc | 14 +- .../accessibility/gfx/geometry/rect_f.h | 32 +- .../gfx/geometry/rect_unittest.cc | 422 ++++++++---------- .../accessibility/gfx/geometry/size.cc | 4 +- .../accessibility/gfx/geometry/size.h | 12 +- .../gfx/geometry/size_conversions.cc | 1 - .../accessibility/gfx/geometry/size_f.h | 4 +- .../gfx/geometry/size_unittest.cc | 2 +- .../accessibility/gfx/geometry/vector2d.h | 2 +- .../gfx/geometry/vector2d_conversions.cc | 1 - .../accessibility/gfx/geometry/vector2d_f.cc | 4 +- .../accessibility/gfx/geometry/vector2d_f.h | 2 +- .../gfx/geometry/vector2d_unittest.cc | 115 ++--- .../gfx/mac/coordinate_conversion.mm | 7 +- .../accessibility/gfx/transform.cc | 92 ++-- .../third_party/accessibility/gfx/transform.h | 11 +- 36 files changed, 404 insertions(+), 615 deletions(-) diff --git a/engine/src/flutter/third_party/accessibility/base/numerics/checked_math.h b/engine/src/flutter/third_party/accessibility/base/numerics/checked_math.h index 50be2f0ea2d..2ea2eba873d 100644 --- a/engine/src/flutter/third_party/accessibility/base/numerics/checked_math.h +++ b/engine/src/flutter/third_party/accessibility/base/numerics/checked_math.h @@ -370,23 +370,23 @@ L* operator-(L* lhs, const StrictNumeric rhs) { } // namespace internal +using internal::CheckAdd; +using internal::CheckAnd; +using internal::CheckDiv; using internal::CheckedNumeric; -using internal::IsValidForType; -using internal::ValueOrDieForType; -using internal::ValueOrDefaultForType; -using internal::MakeCheckedNum; +using internal::CheckLsh; using internal::CheckMax; using internal::CheckMin; -using internal::CheckAdd; -using internal::CheckSub; -using internal::CheckMul; -using internal::CheckDiv; using internal::CheckMod; -using internal::CheckLsh; -using internal::CheckRsh; -using internal::CheckAnd; +using internal::CheckMul; using internal::CheckOr; +using internal::CheckRsh; +using internal::CheckSub; using internal::CheckXor; +using internal::IsValidForType; +using internal::MakeCheckedNum; +using internal::ValueOrDefaultForType; +using internal::ValueOrDieForType; } // namespace base diff --git a/engine/src/flutter/third_party/accessibility/base/numerics/clamped_math.h b/engine/src/flutter/third_party/accessibility/base/numerics/clamped_math.h index 37a4cfd22a8..e32ef1c7a7e 100644 --- a/engine/src/flutter/third_party/accessibility/base/numerics/clamped_math.h +++ b/engine/src/flutter/third_party/accessibility/base/numerics/clamped_math.h @@ -244,20 +244,20 @@ BASE_NUMERIC_COMPARISON_OPERATORS(Clamped, IsNotEqual, !=) } // namespace internal +using internal::ClampAdd; +using internal::ClampAnd; +using internal::ClampDiv; using internal::ClampedNumeric; -using internal::MakeClampedNum; +using internal::ClampLsh; using internal::ClampMax; using internal::ClampMin; -using internal::ClampAdd; -using internal::ClampSub; -using internal::ClampMul; -using internal::ClampDiv; using internal::ClampMod; -using internal::ClampLsh; -using internal::ClampRsh; -using internal::ClampAnd; +using internal::ClampMul; using internal::ClampOr; +using internal::ClampRsh; +using internal::ClampSub; using internal::ClampXor; +using internal::MakeClampedNum; } // namespace base diff --git a/engine/src/flutter/third_party/accessibility/base/numerics/safe_conversions.h b/engine/src/flutter/third_party/accessibility/base/numerics/safe_conversions.h index 7c1c265d5bc..46466b2bc6e 100644 --- a/engine/src/flutter/third_party/accessibility/base/numerics/safe_conversions.h +++ b/engine/src/flutter/third_party/accessibility/base/numerics/safe_conversions.h @@ -171,7 +171,9 @@ struct SaturateFastOp< std::is_integral::value && SaturateFastAsmOp::is_supported>::type> { static constexpr bool is_supported = true; - static constexpr Dst Do(Src value) { return SaturateFastAsmOp::Do(value); } + static constexpr Dst Do(Src value) { + return SaturateFastAsmOp::Do(value); + } }; template @@ -343,14 +345,14 @@ BASE_NUMERIC_COMPARISON_OPERATORS(Strict, IsNotEqual, !=) using internal::as_signed; using internal::as_unsigned; using internal::checked_cast; -using internal::strict_cast; -using internal::saturated_cast; -using internal::SafeUnsignedAbs; -using internal::StrictNumeric; -using internal::MakeStrictNum; -using internal::IsValueInRangeForNumericType; using internal::IsTypeInRangeForNumericType; +using internal::IsValueInRangeForNumericType; using internal::IsValueNegative; +using internal::MakeStrictNum; +using internal::SafeUnsignedAbs; +using internal::saturated_cast; +using internal::strict_cast; +using internal::StrictNumeric; // Explicitly make a shorter size_t alias for convenience. using SizeT = StrictNumeric; diff --git a/engine/src/flutter/third_party/accessibility/base/numerics/safe_conversions_arm_impl.h b/engine/src/flutter/third_party/accessibility/base/numerics/safe_conversions_arm_impl.h index cf31072b9b8..c94947d42d9 100644 --- a/engine/src/flutter/third_party/accessibility/base/numerics/safe_conversions_arm_impl.h +++ b/engine/src/flutter/third_party/accessibility/base/numerics/safe_conversions_arm_impl.h @@ -30,16 +30,18 @@ struct SaturateFastAsmOp { uint32_t>::type result; if (std::is_signed::value) { asm("ssat %[dst], %[shift], %[src]" - : [dst] "=r"(result) - : [src] "r"(src), [shift] "n"(IntegerBitsPlusSign::value <= 32 - ? IntegerBitsPlusSign::value - : 32)); + : [ dst ] "=r"(result) + : + [ src ] "r"(src), [ shift ] "n"(IntegerBitsPlusSign::value <= 32 + ? IntegerBitsPlusSign::value + : 32)); } else { asm("usat %[dst], %[shift], %[src]" - : [dst] "=r"(result) - : [src] "r"(src), [shift] "n"(IntegerBitsPlusSign::value < 32 - ? IntegerBitsPlusSign::value - : 31)); + : [ dst ] "=r"(result) + : + [ src ] "r"(src), [ shift ] "n"(IntegerBitsPlusSign::value < 32 + ? IntegerBitsPlusSign::value + : 31)); } return static_cast(result); } diff --git a/engine/src/flutter/third_party/accessibility/base/numerics/safe_conversions_impl.h b/engine/src/flutter/third_party/accessibility/base/numerics/safe_conversions_impl.h index 7c5ca68c3bb..96471057185 100644 --- a/engine/src/flutter/third_party/accessibility/base/numerics/safe_conversions_impl.h +++ b/engine/src/flutter/third_party/accessibility/base/numerics/safe_conversions_impl.h @@ -276,7 +276,8 @@ struct NarrowingRange { template class Bounds, + template + class Bounds, IntegerRepresentation DstSign = std::is_signed::value ? INTEGER_REPRESENTATION_SIGNED : INTEGER_REPRESENTATION_UNSIGNED, @@ -294,7 +295,8 @@ struct DstRangeRelationToSrcRangeImpl; // Same sign narrowing: The range is contained for normal limits. template class Bounds, + template + class Bounds, IntegerRepresentation DstSign, IntegerRepresentation SrcSign> struct DstRangeRelationToSrcRangeImpl(lhs) < - static_cast(rhs)); + (l_range == r_range && static_cast(lhs) < + static_cast(rhs)); } template @@ -713,9 +714,8 @@ constexpr bool IsLessOrEqualImpl(const L lhs, const RangeCheck l_range, const RangeCheck r_range) { return l_range.IsUnderflow() || r_range.IsOverflow() || - (l_range == r_range && - static_cast(lhs) <= - static_cast(rhs)); + (l_range == r_range && static_cast(lhs) <= + static_cast(rhs)); } template @@ -734,9 +734,8 @@ constexpr bool IsGreaterImpl(const L lhs, const RangeCheck l_range, const RangeCheck r_range) { return l_range.IsOverflow() || r_range.IsUnderflow() || - (l_range == r_range && - static_cast(lhs) > - static_cast(rhs)); + (l_range == r_range && static_cast(lhs) > + static_cast(rhs)); } template @@ -755,9 +754,8 @@ constexpr bool IsGreaterOrEqualImpl(const L lhs, const RangeCheck l_range, const RangeCheck r_range) { return l_range.IsOverflow() || r_range.IsUnderflow() || - (l_range == r_range && - static_cast(lhs) >= - static_cast(rhs)); + (l_range == r_range && static_cast(lhs) >= + static_cast(rhs)); } template diff --git a/engine/src/flutter/third_party/accessibility/base/numerics/safe_math_arm_impl.h b/engine/src/flutter/third_party/accessibility/base/numerics/safe_math_arm_impl.h index ff86bd0b73b..f8abca7f4f9 100644 --- a/engine/src/flutter/third_party/accessibility/base/numerics/safe_math_arm_impl.h +++ b/engine/src/flutter/third_party/accessibility/base/numerics/safe_math_arm_impl.h @@ -61,8 +61,8 @@ struct ClampedAddFastAsmOp { int32_t y_i32 = checked_cast(y); asm("qadd %[result], %[first], %[second]" - : [result] "=r"(result) - : [first] "r"(x_i32), [second] "r"(y_i32)); + : [ result ] "=r"(result) + : [ first ] "r"(x_i32), [ second ] "r"(y_i32)); return saturated_cast(result); } }; @@ -87,8 +87,8 @@ struct ClampedSubFastAsmOp { int32_t y_i32 = checked_cast(y); asm("qsub %[result], %[first], %[second]" - : [result] "=r"(result) - : [first] "r"(x_i32), [second] "r"(y_i32)); + : [ result ] "=r"(result) + : [ first ] "r"(x_i32), [ second ] "r"(y_i32)); return saturated_cast(result); } }; diff --git a/engine/src/flutter/third_party/accessibility/base/numerics/safe_math_shared_impl.h b/engine/src/flutter/third_party/accessibility/base/numerics/safe_math_shared_impl.h index 17c61d68996..80a23146d22 100644 --- a/engine/src/flutter/third_party/accessibility/base/numerics/safe_math_shared_impl.h +++ b/engine/src/flutter/third_party/accessibility/base/numerics/safe_math_shared_impl.h @@ -22,11 +22,11 @@ // Optimized safe math instructions are incompatible with asmjs. #define BASE_HAS_OPTIMIZED_SAFE_MATH (0) // Where available use builtin math overflow support on Clang and GCC. -#elif !defined(__native_client__) && \ - ((defined(__clang__) && \ - ((__clang_major__ > 3) || \ - (__clang_major__ == 3 && __clang_minor__ >= 4))) || \ - (defined(__GNUC__) && __GNUC__ >= 5)) +#elif !defined(__native_client__) && \ + ((defined(__clang__) && \ + ((__clang_major__ > 3) || \ + (__clang_major__ == 3 && __clang_minor__ >= 4))) || \ + (defined(__GNUC__) && __GNUC__ >= 5)) #include "base/numerics/safe_math_clang_gcc_impl.h" #define BASE_HAS_OPTIMIZED_SAFE_MATH (1) #else diff --git a/engine/src/flutter/third_party/accessibility/gfx/geometry/insets.cc b/engine/src/flutter/third_party/accessibility/gfx/geometry/insets.cc index 88b563bda86..75a216caa3c 100644 --- a/engine/src/flutter/third_party/accessibility/gfx/geometry/insets.cc +++ b/engine/src/flutter/third_party/accessibility/gfx/geometry/insets.cc @@ -11,7 +11,7 @@ namespace gfx { std::string Insets::ToString() const { // Print members in the same order of the constructor parameters. - return base::StringPrintf("%d,%d,%d,%d", top(), left(), bottom(), right()); + return base::StringPrintf("%d,%d,%d,%d", top(), left(), bottom(), right()); } Insets Insets::Offset(const gfx::Vector2d& vector) const { diff --git a/engine/src/flutter/third_party/accessibility/gfx/geometry/insets.h b/engine/src/flutter/third_party/accessibility/gfx/geometry/insets.h index 598e0d38ff2..58ab1b77993 100644 --- a/engine/src/flutter/third_party/accessibility/gfx/geometry/insets.h +++ b/engine/src/flutter/third_party/accessibility/gfx/geometry/insets.h @@ -85,9 +85,7 @@ class GEOMETRY_EXPORT Insets { bottom_ == insets.bottom_ && right_ == insets.right_; } - bool operator!=(const Insets& insets) const { - return !(*this == insets); - } + bool operator!=(const Insets& insets) const { return !(*this == insets); } void operator+=(const Insets& insets) { top_ = base::ClampAdd(top_, insets.top_); diff --git a/engine/src/flutter/third_party/accessibility/gfx/geometry/insets_f.cc b/engine/src/flutter/third_party/accessibility/gfx/geometry/insets_f.cc index c1bc27ec524..efaebc3674d 100644 --- a/engine/src/flutter/third_party/accessibility/gfx/geometry/insets_f.cc +++ b/engine/src/flutter/third_party/accessibility/gfx/geometry/insets_f.cc @@ -10,7 +10,7 @@ namespace gfx { std::string InsetsF::ToString() const { // Print members in the same order of the constructor parameters. - return base::StringPrintf("%f,%f,%f,%f", top(), left(), bottom(), right()); + return base::StringPrintf("%f,%f,%f,%f", top(), left(), bottom(), right()); } } // namespace gfx diff --git a/engine/src/flutter/third_party/accessibility/gfx/geometry/insets_f.h b/engine/src/flutter/third_party/accessibility/gfx/geometry/insets_f.h index 281a599b97d..bae68dde406 100644 --- a/engine/src/flutter/third_party/accessibility/gfx/geometry/insets_f.h +++ b/engine/src/flutter/third_party/accessibility/gfx/geometry/insets_f.h @@ -53,9 +53,7 @@ class GEOMETRY_EXPORT InsetsF { bottom_ == insets.bottom_ && right_ == insets.right_; } - bool operator!=(const InsetsF& insets) const { - return !(*this == insets); - } + bool operator!=(const InsetsF& insets) const { return !(*this == insets); } void operator+=(const InsetsF& insets) { top_ += insets.top_; diff --git a/engine/src/flutter/third_party/accessibility/gfx/geometry/insets_unittest.cc b/engine/src/flutter/third_party/accessibility/gfx/geometry/insets_unittest.cc index ac22c834560..eb49c173746 100644 --- a/engine/src/flutter/third_party/accessibility/gfx/geometry/insets_unittest.cc +++ b/engine/src/flutter/third_party/accessibility/gfx/geometry/insets_unittest.cc @@ -27,7 +27,7 @@ TEST(InsetsTest, Insets) { EXPECT_EQ(2, insets.left()); EXPECT_EQ(3, insets.bottom()); EXPECT_EQ(4, insets.right()); - EXPECT_EQ(6, insets.width()); // Left + right. + EXPECT_EQ(6, insets.width()); // Left + right. EXPECT_EQ(4, insets.height()); // Top + bottom. EXPECT_FALSE(insets.IsEmpty()); } diff --git a/engine/src/flutter/third_party/accessibility/gfx/geometry/point.cc b/engine/src/flutter/third_party/accessibility/gfx/geometry/point.cc index 0307b2fa885..522bbfdee86 100644 --- a/engine/src/flutter/third_party/accessibility/gfx/geometry/point.cc +++ b/engine/src/flutter/third_party/accessibility/gfx/geometry/point.cc @@ -26,8 +26,7 @@ Point::Point(DWORD point) { y_ = points.y; } -Point::Point(const POINT& point) : x_(point.x), y_(point.y) { -} +Point::Point(const POINT& point) : x_(point.x), y_(point.y) {} Point& Point::operator=(const POINT& point) { x_ = point.x; @@ -35,8 +34,7 @@ Point& Point::operator=(const POINT& point) { return *this; } #elif defined(OS_APPLE) -Point::Point(const CGPoint& point) : x_(point.x), y_(point.y) { -} +Point::Point(const CGPoint& point) : x_(point.x), y_(point.y) {} #endif #if defined(OS_WIN) diff --git a/engine/src/flutter/third_party/accessibility/gfx/geometry/point.h b/engine/src/flutter/third_party/accessibility/gfx/geometry/point.h index 71c5a5b949b..06cb71bcb48 100644 --- a/engine/src/flutter/third_party/accessibility/gfx/geometry/point.h +++ b/engine/src/flutter/third_party/accessibility/gfx/geometry/point.h @@ -83,9 +83,7 @@ class GEOMETRY_EXPORT Point { // other. // This comparison is required to use Point in sets, or sorted // vectors. - bool operator<(const Point& rhs) const { - return std::tie(y_, x_) < std::tie(rhs.y_, rhs.x_); - } + bool operator<(const Point& rhs) const { return std::tie(y_, x_) < std::tie(rhs.y_, rhs.x_); } // Returns a string representation of point. std::string ToString() const; @@ -116,8 +114,7 @@ inline Point operator-(const Point& lhs, const Vector2d& rhs) { } inline Vector2d operator-(const Point& lhs, const Point& rhs) { - return Vector2d(base::ClampSub(lhs.x(), rhs.x()), - base::ClampSub(lhs.y(), rhs.y())); + return Vector2d(base::ClampSub(lhs.x(), rhs.x()), base::ClampSub(lhs.y(), rhs.y())); } inline Point PointAtOffsetFromOrigin(const Vector2d& offset_from_origin) { @@ -130,17 +127,11 @@ inline Point PointAtOffsetFromOrigin(const Vector2d& offset_from_origin) { void PrintTo(const Point& point, ::std::ostream* os); // Helper methods to scale a gfx::Point to a new gfx::Point. -GEOMETRY_EXPORT Point ScaleToCeiledPoint(const Point& point, - float x_scale, - float y_scale); +GEOMETRY_EXPORT Point ScaleToCeiledPoint(const Point& point, float x_scale, float y_scale); GEOMETRY_EXPORT Point ScaleToCeiledPoint(const Point& point, float x_scale); -GEOMETRY_EXPORT Point ScaleToFlooredPoint(const Point& point, - float x_scale, - float y_scale); +GEOMETRY_EXPORT Point ScaleToFlooredPoint(const Point& point, float x_scale, float y_scale); GEOMETRY_EXPORT Point ScaleToFlooredPoint(const Point& point, float x_scale); -GEOMETRY_EXPORT Point ScaleToRoundedPoint(const Point& point, - float x_scale, - float y_scale); +GEOMETRY_EXPORT Point ScaleToRoundedPoint(const Point& point, float x_scale, float y_scale); GEOMETRY_EXPORT Point ScaleToRoundedPoint(const Point& point, float x_scale); } // namespace gfx diff --git a/engine/src/flutter/third_party/accessibility/gfx/geometry/point_conversions.cc b/engine/src/flutter/third_party/accessibility/gfx/geometry/point_conversions.cc index bf800da0289..42fb2f6eb64 100644 --- a/engine/src/flutter/third_party/accessibility/gfx/geometry/point_conversions.cc +++ b/engine/src/flutter/third_party/accessibility/gfx/geometry/point_conversions.cc @@ -21,4 +21,3 @@ Point ToRoundedPoint(const PointF& point) { } } // namespace gfx - diff --git a/engine/src/flutter/third_party/accessibility/gfx/geometry/point_f.cc b/engine/src/flutter/third_party/accessibility/gfx/geometry/point_f.cc index 0d153945936..211fd7df2b1 100644 --- a/engine/src/flutter/third_party/accessibility/gfx/geometry/point_f.cc +++ b/engine/src/flutter/third_party/accessibility/gfx/geometry/point_f.cc @@ -28,5 +28,4 @@ PointF ScalePoint(const PointF& p, float x_scale, float y_scale) { return scaled_p; } - } // namespace gfx diff --git a/engine/src/flutter/third_party/accessibility/gfx/geometry/point_f.h b/engine/src/flutter/third_party/accessibility/gfx/geometry/point_f.h index a3823bcb0f5..e2bff3375a9 100644 --- a/engine/src/flutter/third_party/accessibility/gfx/geometry/point_f.h +++ b/engine/src/flutter/third_party/accessibility/gfx/geometry/point_f.h @@ -66,9 +66,7 @@ class GEOMETRY_EXPORT PointF { return std::tie(y_, x_) < std::tie(rhs.y_, rhs.x_); } - void Scale(float scale) { - Scale(scale, scale); - } + void Scale(float scale) { Scale(scale, scale); } void Scale(float x_scale, float y_scale) { SetPoint(x() * x_scale, y() * y_scale); diff --git a/engine/src/flutter/third_party/accessibility/gfx/geometry/point_unittest.cc b/engine/src/flutter/third_party/accessibility/gfx/geometry/point_unittest.cc index 33f7f3b91b1..b60800f2712 100644 --- a/engine/src/flutter/third_party/accessibility/gfx/geometry/point_unittest.cc +++ b/engine/src/flutter/third_party/accessibility/gfx/geometry/point_unittest.cc @@ -47,15 +47,13 @@ TEST(PointTest, VectorArithmetic) { static const struct { Point expected; Point actual; - } tests[] = { - { Point(4, 2), a + v1 }, - { Point(-2, 8), a - v1 }, - { a, a - v1 + v1 }, - { a, a + v1 - v1 }, - { a, a + Vector2d() }, - { Point(12, 1), a + v1 - v2 }, - { Point(-10, 9), a - v1 + v2 } - }; + } tests[] = {{Point(4, 2), a + v1}, + {Point(-2, 8), a - v1}, + {a, a - v1 + v1}, + {a, a + v1 - v1}, + {a, a + Vector2d()}, + {Point(12, 1), a + v1 - v2}, + {Point(-10, 9), a - v1 + v2}}; for (size_t i = 0; i < base::size(tests); ++i) EXPECT_EQ(tests[i].expected.ToString(), tests[i].actual.ToString()); diff --git a/engine/src/flutter/third_party/accessibility/gfx/geometry/rect.cc b/engine/src/flutter/third_party/accessibility/gfx/geometry/rect.cc index 370fe34565e..f4e190a411a 100644 --- a/engine/src/flutter/third_party/accessibility/gfx/geometry/rect.cc +++ b/engine/src/flutter/third_party/accessibility/gfx/geometry/rect.cc @@ -25,12 +25,10 @@ namespace gfx { #if defined(OS_WIN) Rect::Rect(const RECT& r) : origin_(r.left, r.top), - size_(std::abs(r.right - r.left), std::abs(r.bottom - r.top)) { -} + size_(std::abs(r.right - r.left), std::abs(r.bottom - r.top)) {} #elif defined(OS_APPLE) Rect::Rect(const CGRect& r) - : origin_(r.origin.x, r.origin.y), size_(r.size.width, r.size.height) { -} + : origin_(r.origin.x, r.origin.y), size_(r.size.width, r.size.height) {} #endif #if defined(OS_WIN) @@ -56,7 +54,7 @@ void AdjustAlongAxis(int dst_origin, int dst_size, int* origin, int* size) { *origin = std::min(dst_origin + dst_size, *origin + *size) - *size; } -} // namespace +} // namespace gfx namespace gfx { @@ -139,9 +137,7 @@ void Rect::operator-=(const Vector2d& offset) { } Insets Rect::InsetsFrom(const Rect& inner) const { - return Insets(inner.y() - y(), - inner.x() - x(), - bottom() - inner.bottom(), + return Insets(inner.y() - y(), inner.x() - x(), bottom() - inner.bottom(), right() - inner.right()); } @@ -266,8 +262,8 @@ void Rect::SplitVertically(Rect* left_half, Rect* right_half) const { DCHECK(right_half); left_half->SetRect(x(), y(), width() / 2, height()); - right_half->SetRect( - left_half->right(), y(), width() - left_half->width(), height()); + right_half->SetRect(left_half->right(), y(), width() - left_half->width(), + height()); } bool Rect::SharesEdgeWith(const Rect& rect) const { @@ -296,8 +292,7 @@ int Rect::ManhattanInternalDistance(const Rect& rect) const { } std::string Rect::ToString() const { - return base::StringPrintf("%s %s", - origin().ToString().c_str(), + return base::StringPrintf("%s %s", origin().ToString().c_str(), size().ToString().c_str()); } diff --git a/engine/src/flutter/third_party/accessibility/gfx/geometry/rect.h b/engine/src/flutter/third_party/accessibility/gfx/geometry/rect.h index 13aa771ffe2..5d600ade7c9 100644 --- a/engine/src/flutter/third_party/accessibility/gfx/geometry/rect.h +++ b/engine/src/flutter/third_party/accessibility/gfx/geometry/rect.h @@ -38,8 +38,7 @@ class GEOMETRY_EXPORT Rect { constexpr Rect() = default; constexpr Rect(int width, int height) : size_(width, height) {} constexpr Rect(int x, int y, int width, int height) - : origin_(x, y), - size_(GetClampedValue(x, width), GetClampedValue(y, height)) {} + : origin_(x, y), size_(GetClampedValue(x, width), GetClampedValue(y, height)) {} constexpr explicit Rect(const Size& size) : size_(size) {} constexpr Rect(const Point& origin, const Size& size) : origin_(origin), @@ -78,9 +77,7 @@ class GEOMETRY_EXPORT Rect { void set_width(int width) { size_.set_width(GetClampedValue(x(), width)); } constexpr int height() const { return size_.height(); } - void set_height(int height) { - size_.set_height(GetClampedValue(y(), height)); - } + void set_height(int height) { size_.set_height(GetClampedValue(y(), height)); } constexpr const Point& origin() const { return origin_; } void set_origin(const Point& origin) { @@ -105,12 +102,8 @@ class GEOMETRY_EXPORT Rect { constexpr Point left_center() const { return Point(x(), y() + height() / 2); } constexpr Point top_center() const { return Point(x() + width() / 2, y()); } - constexpr Point right_center() const { - return Point(right(), y() + height() / 2); - } - constexpr Point bottom_center() const { - return Point(x() + width() / 2, bottom()); - } + constexpr Point right_center() const { return Point(right(), y() + height() / 2); } + constexpr Point bottom_center() const { return Point(x() + width() / 2, bottom()); } Vector2d OffsetFromOrigin() const { return Vector2d(x(), y()); } @@ -127,9 +120,7 @@ class GEOMETRY_EXPORT Rect { void SetByBounds(int left, int top, int right, int bottom); // Shrink the rectangle by a horizontal and vertical distance on all sides. - void Inset(int horizontal, int vertical) { - Inset(horizontal, vertical, horizontal, vertical); - } + void Inset(int horizontal, int vertical) { Inset(horizontal, vertical, horizontal, vertical); } // Shrink the rectangle by the given insets. void Inset(const Insets& insets); @@ -162,9 +153,7 @@ class GEOMETRY_EXPORT Rect { bool Contains(int point_x, int point_y) const; // Returns true if the specified point is contained by this rectangle. - bool Contains(const Point& point) const { - return Contains(point.x(), point.y()); - } + bool Contains(const Point& point) const { return Contains(point.x(), point.y()); } // Returns true if this rectangle contains the specified rectangle. bool Contains(const Rect& rect) const; @@ -235,8 +224,7 @@ class GEOMETRY_EXPORT Rect { // // This is intended to be: a > 0 && max - a < b return a > 0 && b > 0 && - static_cast(std::numeric_limits::max() - a) < - static_cast(b); + static_cast(std::numeric_limits::max() - a) < static_cast(b); } // Clamp the size to avoid integer overflow in bottom() and right(). @@ -244,9 +232,7 @@ class GEOMETRY_EXPORT Rect { // TODO(enne): this should probably use base::ClampAdd, but that // function is not a constexpr. static constexpr int GetClampedValue(int origin, int size) { - return AddWouldOverflow(origin, size) - ? std::numeric_limits::max() - origin - : size; + return AddWouldOverflow(origin, size) ? std::numeric_limits::max() - origin : size; } }; @@ -280,29 +266,21 @@ GEOMETRY_EXPORT Rect BoundingRect(const Point& p1, const Point& p2); // Scales the rect and returns the enclosing rect. Use this only the inputs are // known to not overflow. Use ScaleToEnclosingRectSafe if the inputs are // unknown and need to use saturated math. -inline Rect ScaleToEnclosingRect(const Rect& rect, - float x_scale, - float y_scale) { +inline Rect ScaleToEnclosingRect(const Rect& rect, float x_scale, float y_scale) { if (x_scale == 1.f && y_scale == 1.f) return rect; // These next functions cast instead of using e.g. base::ClampFloor() because // we haven't checked to ensure that the clamping behavior of the helper // functions doesn't degrade performance, and callers shouldn't be passing // values that cause overflow anyway. - DCHECK(base::IsValueInRangeForNumericType( - std::floor(rect.x() * x_scale))); - DCHECK(base::IsValueInRangeForNumericType( - std::floor(rect.y() * y_scale))); - DCHECK(base::IsValueInRangeForNumericType( - std::ceil(rect.right() * x_scale))); - DCHECK(base::IsValueInRangeForNumericType( - std::ceil(rect.bottom() * y_scale))); + DCHECK(base::IsValueInRangeForNumericType(std::floor(rect.x() * x_scale))); + DCHECK(base::IsValueInRangeForNumericType(std::floor(rect.y() * y_scale))); + DCHECK(base::IsValueInRangeForNumericType(std::ceil(rect.right() * x_scale))); + DCHECK(base::IsValueInRangeForNumericType(std::ceil(rect.bottom() * y_scale))); int x = static_cast(std::floor(rect.x() * x_scale)); int y = static_cast(std::floor(rect.y() * y_scale)); - int r = rect.width() == 0 ? - x : static_cast(std::ceil(rect.right() * x_scale)); - int b = rect.height() == 0 ? - y : static_cast(std::ceil(rect.bottom() * y_scale)); + int r = rect.width() == 0 ? x : static_cast(std::ceil(rect.right() * x_scale)); + int b = rect.height() == 0 ? y : static_cast(std::ceil(rect.bottom() * y_scale)); return Rect(x, y, r - x, b - y); } @@ -314,9 +292,7 @@ inline Rect ScaleToEnclosingRect(const Rect& rect, float scale) { // would overflow. // TODO(pkasting): Attempt to switch ScaleTo...Rect() to this construction and // check performance. -inline Rect ScaleToEnclosingRectSafe(const Rect& rect, - float x_scale, - float y_scale) { +inline Rect ScaleToEnclosingRectSafe(const Rect& rect, float x_scale, float y_scale) { if (x_scale == 1.f && y_scale == 1.f) return rect; int x = base::ClampFloor(rect.x() * x_scale); @@ -330,25 +306,17 @@ inline Rect ScaleToEnclosingRectSafe(const Rect& rect, float scale) { return ScaleToEnclosingRectSafe(rect, scale, scale); } -inline Rect ScaleToEnclosedRect(const Rect& rect, - float x_scale, - float y_scale) { +inline Rect ScaleToEnclosedRect(const Rect& rect, float x_scale, float y_scale) { if (x_scale == 1.f && y_scale == 1.f) return rect; - DCHECK(base::IsValueInRangeForNumericType( - std::ceil(rect.x() * x_scale))); - DCHECK(base::IsValueInRangeForNumericType( - std::ceil(rect.y() * y_scale))); - DCHECK(base::IsValueInRangeForNumericType( - std::floor(rect.right() * x_scale))); - DCHECK(base::IsValueInRangeForNumericType( - std::floor(rect.bottom() * y_scale))); + DCHECK(base::IsValueInRangeForNumericType(std::ceil(rect.x() * x_scale))); + DCHECK(base::IsValueInRangeForNumericType(std::ceil(rect.y() * y_scale))); + DCHECK(base::IsValueInRangeForNumericType(std::floor(rect.right() * x_scale))); + DCHECK(base::IsValueInRangeForNumericType(std::floor(rect.bottom() * y_scale))); int x = static_cast(std::ceil(rect.x() * x_scale)); int y = static_cast(std::ceil(rect.y() * y_scale)); - int r = rect.width() == 0 ? - x : static_cast(std::floor(rect.right() * x_scale)); - int b = rect.height() == 0 ? - y : static_cast(std::floor(rect.bottom() * y_scale)); + int r = rect.width() == 0 ? x : static_cast(std::floor(rect.right() * x_scale)); + int b = rect.height() == 0 ? y : static_cast(std::floor(rect.bottom() * y_scale)); return Rect(x, y, r - x, b - y); } @@ -366,23 +334,15 @@ inline Rect ScaleToRoundedRect(const Rect& rect, float x_scale, float y_scale) { if (x_scale == 1.f && y_scale == 1.f) return rect; - DCHECK( - base::IsValueInRangeForNumericType(std::round(rect.x() * x_scale))); - DCHECK( - base::IsValueInRangeForNumericType(std::round(rect.y() * y_scale))); - DCHECK(base::IsValueInRangeForNumericType( - std::round(rect.right() * x_scale))); - DCHECK(base::IsValueInRangeForNumericType( - std::round(rect.bottom() * y_scale))); + DCHECK(base::IsValueInRangeForNumericType(std::round(rect.x() * x_scale))); + DCHECK(base::IsValueInRangeForNumericType(std::round(rect.y() * y_scale))); + DCHECK(base::IsValueInRangeForNumericType(std::round(rect.right() * x_scale))); + DCHECK(base::IsValueInRangeForNumericType(std::round(rect.bottom() * y_scale))); int x = static_cast(std::round(rect.x() * x_scale)); int y = static_cast(std::round(rect.y() * y_scale)); - int r = rect.width() == 0 - ? x - : static_cast(std::round(rect.right() * x_scale)); - int b = rect.height() == 0 - ? y - : static_cast(std::round(rect.bottom() * y_scale)); + int r = rect.width() == 0 ? x : static_cast(std::round(rect.right() * x_scale)); + int b = rect.height() == 0 ? y : static_cast(std::round(rect.bottom() * y_scale)); return Rect(x, y, r - x, b - y); } diff --git a/engine/src/flutter/third_party/accessibility/gfx/geometry/rect_f.cc b/engine/src/flutter/third_party/accessibility/gfx/geometry/rect_f.cc index 0250709923a..fc26eeab888 100644 --- a/engine/src/flutter/third_party/accessibility/gfx/geometry/rect_f.cc +++ b/engine/src/flutter/third_party/accessibility/gfx/geometry/rect_f.cc @@ -34,8 +34,7 @@ static void AdjustAlongAxis(float dst_origin, #if defined(OS_APPLE) RectF::RectF(const CGRect& r) - : origin_(r.origin.x, r.origin.y), size_(r.size.width, r.size.height) { -} + : origin_(r.origin.x, r.origin.y), size_(r.size.width, r.size.height) {} CGRect RectF::ToCGRect() const { return CGRectMake(x(), y(), width(), height()); @@ -65,9 +64,7 @@ void RectF::operator-=(const Vector2dF& offset) { } InsetsF RectF::InsetsFrom(const RectF& inner) const { - return InsetsF(inner.y() - y(), - inner.x() - x(), - bottom() - inner.bottom(), + return InsetsF(inner.y() - y(), inner.x() - x(), bottom() - inner.bottom(), right() - inner.right()); } @@ -192,8 +189,8 @@ void RectF::SplitVertically(RectF* left_half, RectF* right_half) const { DCHECK(right_half); left_half->SetRect(x(), y(), width() / 2, height()); - right_half->SetRect( - left_half->right(), y(), width() - left_half->width(), height()); + right_half->SetRect(left_half->right(), y(), width() - left_half->width(), + height()); } bool RectF::SharesEdgeWith(const RectF& rect) const { @@ -232,8 +229,7 @@ bool RectF::IsExpressibleAsRect() const { } std::string RectF::ToString() const { - return base::StringPrintf("%s %s", - origin().ToString().c_str(), + return base::StringPrintf("%s %s", origin().ToString().c_str(), size().ToString().c_str()); } diff --git a/engine/src/flutter/third_party/accessibility/gfx/geometry/rect_f.h b/engine/src/flutter/third_party/accessibility/gfx/geometry/rect_f.h index 2a5571fd896..cf41fc4b13c 100644 --- a/engine/src/flutter/third_party/accessibility/gfx/geometry/rect_f.h +++ b/engine/src/flutter/third_party/accessibility/gfx/geometry/rect_f.h @@ -30,8 +30,7 @@ class GEOMETRY_EXPORT RectF { constexpr RectF(float x, float y, float width, float height) : origin_(x, y), size_(width, height) {} constexpr explicit RectF(const SizeF& size) : size_(size) {} - constexpr RectF(const PointF& origin, const SizeF& size) - : origin_(origin), size_(size) {} + constexpr RectF(const PointF& origin, const SizeF& size) : origin_(origin), size_(size) {} constexpr explicit RectF(const Rect& r) : RectF(static_cast(r.x()), @@ -70,16 +69,10 @@ class GEOMETRY_EXPORT RectF { constexpr PointF bottom_left() const { return PointF(x(), bottom()); } constexpr PointF bottom_right() const { return PointF(right(), bottom()); } - constexpr PointF left_center() const { - return PointF(x(), y() + height() / 2); - } + constexpr PointF left_center() const { return PointF(x(), y() + height() / 2); } constexpr PointF top_center() const { return PointF(x() + width() / 2, y()); } - constexpr PointF right_center() const { - return PointF(right(), y() + height() / 2); - } - constexpr PointF bottom_center() const { - return PointF(x() + width() / 2, bottom()); - } + constexpr PointF right_center() const { return PointF(right(), y() + height() / 2); } + constexpr PointF bottom_center() const { return PointF(x() + width() / 2, bottom()); } Vector2dF OffsetFromOrigin() const { return Vector2dF(x(), y()); } @@ -124,9 +117,7 @@ class GEOMETRY_EXPORT RectF { bool Contains(float point_x, float point_y) const; // Returns true if the specified point is contained by this rectangle. - bool Contains(const PointF& point) const { - return Contains(point.x(), point.y()); - } + bool Contains(const PointF& point) const { return Contains(point.x(), point.y()); } // Returns true if this rectangle contains the specified rectangle. bool Contains(const RectF& rect) const; @@ -181,9 +172,7 @@ class GEOMETRY_EXPORT RectF { float ManhattanInternalDistance(const RectF& rect) const; // Scales the rectangle by |scale|. - void Scale(float scale) { - Scale(scale, scale); - } + void Scale(float scale) { Scale(scale, scale); } void Scale(float x_scale, float y_scale) { set_origin(ScalePoint(origin(), x_scale, y_scale)); @@ -212,13 +201,11 @@ inline bool operator!=(const RectF& lhs, const RectF& rhs) { } inline RectF operator+(const RectF& lhs, const Vector2dF& rhs) { - return RectF(lhs.x() + rhs.x(), lhs.y() + rhs.y(), - lhs.width(), lhs.height()); + return RectF(lhs.x() + rhs.x(), lhs.y() + rhs.y(), lhs.width(), lhs.height()); } inline RectF operator-(const RectF& lhs, const Vector2dF& rhs) { - return RectF(lhs.x() - rhs.x(), lhs.y() - rhs.y(), - lhs.width(), lhs.height()); + return RectF(lhs.x() - rhs.x(), lhs.y() - rhs.y(), lhs.width(), lhs.height()); } inline RectF operator+(const Vector2dF& lhs, const RectF& rhs) { @@ -230,8 +217,7 @@ GEOMETRY_EXPORT RectF UnionRects(const RectF& a, const RectF& b); GEOMETRY_EXPORT RectF SubtractRects(const RectF& a, const RectF& b); inline RectF ScaleRect(const RectF& r, float x_scale, float y_scale) { - return RectF(r.x() * x_scale, r.y() * y_scale, - r.width() * x_scale, r.height() * y_scale); + return RectF(r.x() * x_scale, r.y() * y_scale, r.width() * x_scale, r.height() * y_scale); } inline RectF ScaleRect(const RectF& r, float scale) { diff --git a/engine/src/flutter/third_party/accessibility/gfx/geometry/rect_unittest.cc b/engine/src/flutter/third_party/accessibility/gfx/geometry/rect_unittest.cc index 1f6d576b9e4..699d4d19ef7 100644 --- a/engine/src/flutter/third_party/accessibility/gfx/geometry/rect_unittest.cc +++ b/engine/src/flutter/third_party/accessibility/gfx/geometry/rect_unittest.cc @@ -36,9 +36,9 @@ TEST(RectTest, Contains) { {0, 0, 10, 10, 10, 5, false}, {0, 0, 10, 10, -1, -1, false}, {0, 0, 10, 10, 50, 50, false}, - #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) +#if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) {0, 0, -10, -10, 0, 0, false}, - #endif +#endif }; for (size_t i = 0; i < base::size(contains_cases); ++i) { const ContainsCase& value = contains_cases[i]; @@ -58,18 +58,16 @@ TEST(RectTest, Intersects) { int w2; int h2; bool intersects; - } tests[] = { - { 0, 0, 0, 0, 0, 0, 0, 0, false }, - { 0, 0, 0, 0, -10, -10, 20, 20, false }, - { -10, 0, 0, 20, 0, -10, 20, 0, false }, - { 0, 0, 10, 10, 0, 0, 10, 10, true }, - { 0, 0, 10, 10, 10, 10, 10, 10, false }, - { 10, 10, 10, 10, 0, 0, 10, 10, false }, - { 10, 10, 10, 10, 5, 5, 10, 10, true }, - { 10, 10, 10, 10, 15, 15, 10, 10, true }, - { 10, 10, 10, 10, 20, 15, 10, 10, false }, - { 10, 10, 10, 10, 21, 15, 10, 10, false } - }; + } tests[] = {{0, 0, 0, 0, 0, 0, 0, 0, false}, + {0, 0, 0, 0, -10, -10, 20, 20, false}, + {-10, 0, 0, 20, 0, -10, 20, 0, false}, + {0, 0, 10, 10, 0, 0, 10, 10, true}, + {0, 0, 10, 10, 10, 10, 10, 10, false}, + {10, 10, 10, 10, 0, 0, 10, 10, false}, + {10, 10, 10, 10, 5, 5, 10, 10, true}, + {10, 10, 10, 10, 15, 15, 10, 10, true}, + {10, 10, 10, 10, 20, 15, 10, 10, false}, + {10, 10, 10, 10, 21, 15, 10, 10, false}}; for (size_t i = 0; i < base::size(tests); ++i) { Rect r1(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1); Rect r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2); @@ -92,26 +90,18 @@ TEST(RectTest, Intersect) { int y3; int w3; int h3; - } tests[] = { - { 0, 0, 0, 0, // zeros - 0, 0, 0, 0, - 0, 0, 0, 0 }, - { 0, 0, 4, 4, // equal - 0, 0, 4, 4, - 0, 0, 4, 4 }, - { 0, 0, 4, 4, // neighboring - 4, 4, 4, 4, - 0, 0, 0, 0 }, - { 0, 0, 4, 4, // overlapping corners - 2, 2, 4, 4, - 2, 2, 2, 2 }, - { 0, 0, 4, 4, // T junction - 3, 1, 4, 2, - 3, 1, 1, 2 }, - { 3, 0, 2, 2, // gap - 0, 0, 2, 2, - 0, 0, 0, 0 } - }; + } tests[] = {{0, 0, 0, 0, // zeros + 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 4, 4, // equal + 0, 0, 4, 4, 0, 0, 4, 4}, + {0, 0, 4, 4, // neighboring + 4, 4, 4, 4, 0, 0, 0, 0}, + {0, 0, 4, 4, // overlapping corners + 2, 2, 4, 4, 2, 2, 2, 2}, + {0, 0, 4, 4, // T junction + 3, 1, 4, 2, 3, 1, 1, 2}, + {3, 0, 2, 2, // gap + 0, 0, 2, 2, 0, 0, 0, 0}}; for (size_t i = 0; i < base::size(tests); ++i) { Rect r1(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1); Rect r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2); @@ -138,29 +128,15 @@ TEST(RectTest, Union) { int y3; int w3; int h3; - } tests[] = { - { 0, 0, 0, 0, - 0, 0, 0, 0, - 0, 0, 0, 0 }, - { 0, 0, 4, 4, - 0, 0, 4, 4, - 0, 0, 4, 4 }, - { 0, 0, 4, 4, - 4, 4, 4, 4, - 0, 0, 8, 8 }, - { 0, 0, 4, 4, - 0, 5, 4, 4, - 0, 0, 4, 9 }, - { 0, 0, 2, 2, - 3, 3, 2, 2, - 0, 0, 5, 5 }, - { 3, 3, 2, 2, // reverse r1 and r2 from previous test - 0, 0, 2, 2, - 0, 0, 5, 5 }, - { 0, 0, 0, 0, // union with empty rect - 2, 2, 2, 2, - 2, 2, 2, 2 } - }; + } tests[] = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 4, 4, 0, 0, 4, 4, 0, 0, 4, 4}, + {0, 0, 4, 4, 4, 4, 4, 4, 0, 0, 8, 8}, + {0, 0, 4, 4, 0, 5, 4, 4, 0, 0, 4, 9}, + {0, 0, 2, 2, 3, 3, 2, 2, 0, 0, 5, 5}, + {3, 3, 2, 2, // reverse r1 and r2 from previous test + 0, 0, 2, 2, 0, 0, 5, 5}, + {0, 0, 0, 0, // union with empty rect + 2, 2, 2, 2, 2, 2, 2, 2}}; for (size_t i = 0; i < base::size(tests); ++i) { Rect r1(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1); Rect r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2); @@ -196,23 +172,11 @@ TEST(RectTest, AdjustToFit) { int y3; int w3; int h3; - } tests[] = { - { 0, 0, 2, 2, - 0, 0, 2, 2, - 0, 0, 2, 2 }, - { 2, 2, 3, 3, - 0, 0, 4, 4, - 1, 1, 3, 3 }, - { -1, -1, 5, 5, - 0, 0, 4, 4, - 0, 0, 4, 4 }, - { 2, 2, 4, 4, - 0, 0, 3, 3, - 0, 0, 3, 3 }, - { 2, 2, 1, 1, - 0, 0, 3, 3, - 2, 2, 1, 1 } - }; + } tests[] = {{0, 0, 2, 2, 0, 0, 2, 2, 0, 0, 2, 2}, + {2, 2, 3, 3, 0, 0, 4, 4, 1, 1, 3, 3}, + {-1, -1, 5, 5, 0, 0, 4, 4, 0, 0, 4, 4}, + {2, 2, 4, 4, 0, 0, 3, 3, 0, 0, 3, 3}, + {2, 2, 1, 1, 0, 0, 3, 3, 2, 2, 1, 1}}; for (size_t i = 0; i < base::size(tests); ++i) { Rect r1(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1); Rect r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2); @@ -423,7 +387,11 @@ TEST(RectTest, SharesEdgeWith) { // Similar to EXPECT_FLOAT_EQ, but lets NaN equal NaN #define EXPECT_FLOAT_AND_NAN_EQ(a, b) \ - { if (a == a || b == b) { EXPECT_FLOAT_EQ(a, b); } } + { \ + if (a == a || b == b) { \ + EXPECT_FLOAT_EQ(a, b); \ + } \ + } TEST(RectTest, ScaleRect) { static const struct Test { @@ -437,25 +405,16 @@ TEST(RectTest, ScaleRect) { float w2; float h2; } tests[] = { - { 3, 3, 3, 3, - 1.5f, - 4.5f, 4.5f, 4.5f, 4.5f }, - { 3, 3, 3, 3, - 0.0f, - 0.0f, 0.0f, 0.0f, 0.0f }, - { 3, 3, 3, 3, - std::numeric_limits::quiet_NaN(), - std::numeric_limits::quiet_NaN(), - std::numeric_limits::quiet_NaN(), - std::numeric_limits::quiet_NaN(), - std::numeric_limits::quiet_NaN() }, - { 3, 3, 3, 3, - std::numeric_limits::max(), - std::numeric_limits::max(), - std::numeric_limits::max(), - std::numeric_limits::max(), - std::numeric_limits::max() } - }; + {3, 3, 3, 3, 1.5f, 4.5f, 4.5f, 4.5f, 4.5f}, + {3, 3, 3, 3, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, + {3, 3, 3, 3, std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN()}, + {3, 3, 3, 3, std::numeric_limits::max(), + std::numeric_limits::max(), std::numeric_limits::max(), + std::numeric_limits::max(), std::numeric_limits::max()}}; for (size_t i = 0; i < base::size(tests); ++i) { RectF r1(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1); @@ -651,23 +610,19 @@ TEST(RectTest, ToNearestRect) { TEST(RectTest, ToFlooredRect) { static const struct Test { - float x1; // source + float x1; // source float y1; float w1; float h1; - int x2; // target + int x2; // target int y2; int w2; int h2; - } tests [] = { - { 0.0f, 0.0f, 0.0f, 0.0f, - 0, 0, 0, 0 }, - { -1.5f, -1.5f, 3.0f, 3.0f, - -2, -2, 3, 3 }, - { -1.5f, -1.5f, 3.5f, 3.5f, - -2, -2, 3, 3 }, - { 20000.5f, 20000.5f, 0.5f, 0.5f, - 20000, 20000, 0, 0 }, + } tests[] = { + {0.0f, 0.0f, 0.0f, 0.0f, 0, 0, 0, 0}, + {-1.5f, -1.5f, 3.0f, 3.0f, -2, -2, 3, 3}, + {-1.5f, -1.5f, 3.5f, 3.5f, -2, -2, 3, 3}, + {20000.5f, 20000.5f, 0.5f, 0.5f, 20000, 20000, 0, 0}, }; for (size_t i = 0; i < base::size(tests); ++i) { @@ -687,41 +642,45 @@ TEST(RectTest, ScaleToEnclosedRect) { Rect input_rect; float input_scale; Rect expected_rect; - } tests[] = { - { - Rect(), - 5.f, - Rect(), - }, { - Rect(1, 1, 1, 1), - 5.f, - Rect(5, 5, 5, 5), - }, { - Rect(-1, -1, 0, 0), - 5.f, - Rect(-5, -5, 0, 0), - }, { - Rect(1, -1, 0, 1), - 5.f, - Rect(5, -5, 0, 5), - }, { - Rect(-1, 1, 1, 0), - 5.f, - Rect(-5, 5, 5, 0), - }, { - Rect(1, 2, 3, 4), - 1.5f, - Rect(2, 3, 4, 6), - }, { - Rect(-1, -2, 0, 0), - 1.5f, - Rect(-1, -3, 0, 0), - } - }; + } tests[] = {{ + Rect(), + 5.f, + Rect(), + }, + { + Rect(1, 1, 1, 1), + 5.f, + Rect(5, 5, 5, 5), + }, + { + Rect(-1, -1, 0, 0), + 5.f, + Rect(-5, -5, 0, 0), + }, + { + Rect(1, -1, 0, 1), + 5.f, + Rect(5, -5, 0, 5), + }, + { + Rect(-1, 1, 1, 0), + 5.f, + Rect(-5, 5, 5, 0), + }, + { + Rect(1, 2, 3, 4), + 1.5f, + Rect(2, 3, 4, 6), + }, + { + Rect(-1, -2, 0, 0), + 1.5f, + Rect(-1, -3, 0, 0), + }}; for (size_t i = 0; i < base::size(tests); ++i) { - Rect result = ScaleToEnclosedRect(tests[i].input_rect, - tests[i].input_scale); + Rect result = + ScaleToEnclosedRect(tests[i].input_rect, tests[i].input_scale); EXPECT_EQ(tests[i].expected_rect, result); } } @@ -731,37 +690,41 @@ TEST(RectTest, ScaleToEnclosingRect) { Rect input_rect; float input_scale; Rect expected_rect; - } tests[] = { - { - Rect(), - 5.f, - Rect(), - }, { - Rect(1, 1, 1, 1), - 5.f, - Rect(5, 5, 5, 5), - }, { - Rect(-1, -1, 0, 0), - 5.f, - Rect(-5, -5, 0, 0), - }, { - Rect(1, -1, 0, 1), - 5.f, - Rect(5, -5, 0, 5), - }, { - Rect(-1, 1, 1, 0), - 5.f, - Rect(-5, 5, 5, 0), - }, { - Rect(1, 2, 3, 4), - 1.5f, - Rect(1, 3, 5, 6), - }, { - Rect(-1, -2, 0, 0), - 1.5f, - Rect(-2, -3, 0, 0), - } - }; + } tests[] = {{ + Rect(), + 5.f, + Rect(), + }, + { + Rect(1, 1, 1, 1), + 5.f, + Rect(5, 5, 5, 5), + }, + { + Rect(-1, -1, 0, 0), + 5.f, + Rect(-5, -5, 0, 0), + }, + { + Rect(1, -1, 0, 1), + 5.f, + Rect(5, -5, 0, 5), + }, + { + Rect(-1, 1, 1, 0), + 5.f, + Rect(-5, 5, 5, 0), + }, + { + Rect(1, 2, 3, 4), + 1.5f, + Rect(1, 3, 5, 6), + }, + { + Rect(-1, -2, 0, 0), + 1.5f, + Rect(-2, -3, 0, 0), + }}; for (size_t i = 0; i < base::size(tests); ++i) { Rect result = @@ -775,8 +738,8 @@ TEST(RectTest, ScaleToEnclosingRect) { #if defined(OS_WIN) TEST(RectTest, ConstructAndAssign) { - const RECT rect_1 = { 0, 0, 10, 10 }; - const RECT rect_2 = { 0, 0, -10, -10 }; + const RECT rect_1 = {0, 0, 10, 10}; + const RECT rect_2 = {0, 0, -10, -10}; Rect test1(rect_1); Rect test2(rect_2); } @@ -797,20 +760,21 @@ TEST(RectTest, BoundingRect) { Point b; Rect expected; } int_tests[] = { - // If point B dominates A, then A should be the origin. - { Point(4, 6), Point(4, 6), Rect(4, 6, 0, 0) }, - { Point(4, 6), Point(8, 6), Rect(4, 6, 4, 0) }, - { Point(4, 6), Point(4, 9), Rect(4, 6, 0, 3) }, - { Point(4, 6), Point(8, 9), Rect(4, 6, 4, 3) }, - // If point A dominates B, then B should be the origin. - { Point(4, 6), Point(4, 6), Rect(4, 6, 0, 0) }, - { Point(8, 6), Point(4, 6), Rect(4, 6, 4, 0) }, - { Point(4, 9), Point(4, 6), Rect(4, 6, 0, 3) }, - { Point(8, 9), Point(4, 6), Rect(4, 6, 4, 3) }, - // If neither point dominates, then the origin is a combination of the two. - { Point(4, 6), Point(6, 4), Rect(4, 4, 2, 2) }, - { Point(-4, -6), Point(-6, -4), Rect(-6, -6, 2, 2) }, - { Point(-4, 6), Point(6, -4), Rect(-4, -4, 10, 10) }, + // If point B dominates A, then A should be the origin. + {Point(4, 6), Point(4, 6), Rect(4, 6, 0, 0)}, + {Point(4, 6), Point(8, 6), Rect(4, 6, 4, 0)}, + {Point(4, 6), Point(4, 9), Rect(4, 6, 0, 3)}, + {Point(4, 6), Point(8, 9), Rect(4, 6, 4, 3)}, + // If point A dominates B, then B should be the origin. + {Point(4, 6), Point(4, 6), Rect(4, 6, 0, 0)}, + {Point(8, 6), Point(4, 6), Rect(4, 6, 4, 0)}, + {Point(4, 9), Point(4, 6), Rect(4, 6, 0, 3)}, + {Point(8, 9), Point(4, 6), Rect(4, 6, 4, 3)}, + // If neither point dominates, then the origin is a combination of the + // two. + {Point(4, 6), Point(6, 4), Rect(4, 4, 2, 2)}, + {Point(-4, -6), Point(-6, -4), Rect(-6, -6, 2, 2)}, + {Point(-4, 6), Point(6, -4), Rect(-4, -4, 10, 10)}, }; for (size_t i = 0; i < base::size(int_tests); ++i) { @@ -823,32 +787,23 @@ TEST(RectTest, BoundingRect) { PointF b; RectF expected; } float_tests[] = { - // If point B dominates A, then A should be the origin. - { PointF(4.2f, 6.8f), PointF(4.2f, 6.8f), - RectF(4.2f, 6.8f, 0, 0) }, - { PointF(4.2f, 6.8f), PointF(8.5f, 6.8f), - RectF(4.2f, 6.8f, 4.3f, 0) }, - { PointF(4.2f, 6.8f), PointF(4.2f, 9.3f), - RectF(4.2f, 6.8f, 0, 2.5f) }, - { PointF(4.2f, 6.8f), PointF(8.5f, 9.3f), - RectF(4.2f, 6.8f, 4.3f, 2.5f) }, - // If point A dominates B, then B should be the origin. - { PointF(4.2f, 6.8f), PointF(4.2f, 6.8f), - RectF(4.2f, 6.8f, 0, 0) }, - { PointF(8.5f, 6.8f), PointF(4.2f, 6.8f), - RectF(4.2f, 6.8f, 4.3f, 0) }, - { PointF(4.2f, 9.3f), PointF(4.2f, 6.8f), - RectF(4.2f, 6.8f, 0, 2.5f) }, - { PointF(8.5f, 9.3f), PointF(4.2f, 6.8f), - RectF(4.2f, 6.8f, 4.3f, 2.5f) }, - // If neither point dominates, then the origin is a combination of the two. - { PointF(4.2f, 6.8f), PointF(6.8f, 4.2f), - RectF(4.2f, 4.2f, 2.6f, 2.6f) }, - { PointF(-4.2f, -6.8f), PointF(-6.8f, -4.2f), - RectF(-6.8f, -6.8f, 2.6f, 2.6f) }, - { PointF(-4.2f, 6.8f), PointF(6.8f, -4.2f), - RectF(-4.2f, -4.2f, 11.0f, 11.0f) } - }; + // If point B dominates A, then A should be the origin. + {PointF(4.2f, 6.8f), PointF(4.2f, 6.8f), RectF(4.2f, 6.8f, 0, 0)}, + {PointF(4.2f, 6.8f), PointF(8.5f, 6.8f), RectF(4.2f, 6.8f, 4.3f, 0)}, + {PointF(4.2f, 6.8f), PointF(4.2f, 9.3f), RectF(4.2f, 6.8f, 0, 2.5f)}, + {PointF(4.2f, 6.8f), PointF(8.5f, 9.3f), RectF(4.2f, 6.8f, 4.3f, 2.5f)}, + // If point A dominates B, then B should be the origin. + {PointF(4.2f, 6.8f), PointF(4.2f, 6.8f), RectF(4.2f, 6.8f, 0, 0)}, + {PointF(8.5f, 6.8f), PointF(4.2f, 6.8f), RectF(4.2f, 6.8f, 4.3f, 0)}, + {PointF(4.2f, 9.3f), PointF(4.2f, 6.8f), RectF(4.2f, 6.8f, 0, 2.5f)}, + {PointF(8.5f, 9.3f), PointF(4.2f, 6.8f), RectF(4.2f, 6.8f, 4.3f, 2.5f)}, + // If neither point dominates, then the origin is a combination of the + // two. + {PointF(4.2f, 6.8f), PointF(6.8f, 4.2f), RectF(4.2f, 4.2f, 2.6f, 2.6f)}, + {PointF(-4.2f, -6.8f), PointF(-6.8f, -4.2f), + RectF(-6.8f, -6.8f, 2.6f, 2.6f)}, + {PointF(-4.2f, 6.8f), PointF(6.8f, -4.2f), + RectF(-4.2f, -4.2f, 11.0f, 11.0f)}}; for (size_t i = 0; i < base::size(float_tests); ++i) { RectF actual = BoundingRect(float_tests[i].a, float_tests[i].b); @@ -863,16 +818,16 @@ TEST(RectTest, IsExpressibleAsRect) { float max = std::numeric_limits::max(); float infinity = std::numeric_limits::infinity(); - EXPECT_TRUE(RectF( - min + 200, min + 200, max - 200, max - 200).IsExpressibleAsRect()); - EXPECT_FALSE(RectF( - min - 200, min + 200, max + 200, max + 200).IsExpressibleAsRect()); - EXPECT_FALSE(RectF( - min + 200 , min - 200, max + 200, max + 200).IsExpressibleAsRect()); - EXPECT_FALSE(RectF( - min + 200, min + 200, max + 200, max - 200).IsExpressibleAsRect()); - EXPECT_FALSE(RectF( - min + 200, min + 200, max - 200, max + 200).IsExpressibleAsRect()); + EXPECT_TRUE( + RectF(min + 200, min + 200, max - 200, max - 200).IsExpressibleAsRect()); + EXPECT_FALSE( + RectF(min - 200, min + 200, max + 200, max + 200).IsExpressibleAsRect()); + EXPECT_FALSE( + RectF(min + 200, min - 200, max + 200, max + 200).IsExpressibleAsRect()); + EXPECT_FALSE( + RectF(min + 200, min + 200, max + 200, max - 200).IsExpressibleAsRect()); + EXPECT_FALSE( + RectF(min + 200, min + 200, max - 200, max + 200).IsExpressibleAsRect()); EXPECT_TRUE(RectF(0, 0, max - 200, max - 200).IsExpressibleAsRect()); EXPECT_FALSE(RectF(200, 0, max + 200, max - 200).IsExpressibleAsRect()); @@ -989,15 +944,12 @@ TEST(RectTest, ManhattanInternalDistance) { EXPECT_FLOAT_EQ( 0.0f, f.ManhattanInternalDistance(gfx::RectF(-1.0f, 0.0f, 2.0f, 1.0f))); - EXPECT_FLOAT_EQ( - kEpsilon, - f.ManhattanInternalDistance(gfx::RectF(400.0f, 0.0f, 1.0f, 400.0f))); - EXPECT_FLOAT_EQ(2.0f * kEpsilon, - f.ManhattanInternalDistance( - gfx::RectF(-100.0f, -100.0f, 100.0f, 100.0f))); - EXPECT_FLOAT_EQ( - 1.0f + kEpsilon, - f.ManhattanInternalDistance(gfx::RectF(-101.0f, 100.0f, 100.0f, 100.0f))); + EXPECT_FLOAT_EQ(kEpsilon, f.ManhattanInternalDistance( + gfx::RectF(400.0f, 0.0f, 1.0f, 400.0f))); + EXPECT_FLOAT_EQ(2.0f * kEpsilon, f.ManhattanInternalDistance(gfx::RectF( + -100.0f, -100.0f, 100.0f, 100.0f))); + EXPECT_FLOAT_EQ(1.0f + kEpsilon, f.ManhattanInternalDistance(gfx::RectF( + -101.0f, 100.0f, 100.0f, 100.0f))); EXPECT_FLOAT_EQ(2.0f + 2.0f * kEpsilon, f.ManhattanInternalDistance( gfx::RectF(-101.0f, -101.0f, 100.0f, 100.0f))); @@ -1007,12 +959,10 @@ TEST(RectTest, ManhattanInternalDistance) { EXPECT_FLOAT_EQ( 0.0f, f.ManhattanInternalDistance(gfx::RectF(-1.0f, 0.0f, 1.1f, 1.0f))); - EXPECT_FLOAT_EQ( - 0.1f + kEpsilon, - f.ManhattanInternalDistance(gfx::RectF(-1.5f, 0.0f, 1.4f, 1.0f))); - EXPECT_FLOAT_EQ( - kEpsilon, - f.ManhattanInternalDistance(gfx::RectF(-1.5f, 0.0f, 1.5f, 1.0f))); + EXPECT_FLOAT_EQ(0.1f + kEpsilon, f.ManhattanInternalDistance( + gfx::RectF(-1.5f, 0.0f, 1.4f, 1.0f))); + EXPECT_FLOAT_EQ(kEpsilon, f.ManhattanInternalDistance( + gfx::RectF(-1.5f, 0.0f, 1.5f, 1.0f))); } TEST(RectTest, IntegerOverflow) { diff --git a/engine/src/flutter/third_party/accessibility/gfx/geometry/size.cc b/engine/src/flutter/third_party/accessibility/gfx/geometry/size.cc index bebcd33eedd..761b246dc33 100644 --- a/engine/src/flutter/third_party/accessibility/gfx/geometry/size.cc +++ b/engine/src/flutter/third_party/accessibility/gfx/geometry/size.cc @@ -22,9 +22,7 @@ namespace gfx { #if defined(OS_APPLE) Size::Size(const CGSize& s) - : width_(s.width < 0 ? 0 : s.width), - height_(s.height < 0 ? 0 : s.height) { -} + : width_(s.width < 0 ? 0 : s.width), height_(s.height < 0 ? 0 : s.height) {} Size& Size::operator=(const CGSize& s) { set_width(s.width); diff --git a/engine/src/flutter/third_party/accessibility/gfx/geometry/size.h b/engine/src/flutter/third_party/accessibility/gfx/geometry/size.h index 3472dacf24b..7866834aab5 100644 --- a/engine/src/flutter/third_party/accessibility/gfx/geometry/size.h +++ b/engine/src/flutter/third_party/accessibility/gfx/geometry/size.h @@ -100,17 +100,11 @@ inline Size operator-(Size lhs, const Size& rhs) { void PrintTo(const Size& size, ::std::ostream* os); // Helper methods to scale a gfx::Size to a new gfx::Size. -GEOMETRY_EXPORT Size ScaleToCeiledSize(const Size& size, - float x_scale, - float y_scale); +GEOMETRY_EXPORT Size ScaleToCeiledSize(const Size& size, float x_scale, float y_scale); GEOMETRY_EXPORT Size ScaleToCeiledSize(const Size& size, float scale); -GEOMETRY_EXPORT Size ScaleToFlooredSize(const Size& size, - float x_scale, - float y_scale); +GEOMETRY_EXPORT Size ScaleToFlooredSize(const Size& size, float x_scale, float y_scale); GEOMETRY_EXPORT Size ScaleToFlooredSize(const Size& size, float scale); -GEOMETRY_EXPORT Size ScaleToRoundedSize(const Size& size, - float x_scale, - float y_scale); +GEOMETRY_EXPORT Size ScaleToRoundedSize(const Size& size, float x_scale, float y_scale); GEOMETRY_EXPORT Size ScaleToRoundedSize(const Size& size, float scale); } // namespace gfx diff --git a/engine/src/flutter/third_party/accessibility/gfx/geometry/size_conversions.cc b/engine/src/flutter/third_party/accessibility/gfx/geometry/size_conversions.cc index 18dab3340a6..0c995ca7c64 100644 --- a/engine/src/flutter/third_party/accessibility/gfx/geometry/size_conversions.cc +++ b/engine/src/flutter/third_party/accessibility/gfx/geometry/size_conversions.cc @@ -21,4 +21,3 @@ Size ToRoundedSize(const SizeF& size) { } } // namespace gfx - diff --git a/engine/src/flutter/third_party/accessibility/gfx/geometry/size_f.h b/engine/src/flutter/third_party/accessibility/gfx/geometry/size_f.h index ceda9edfc44..21e5950caf3 100644 --- a/engine/src/flutter/third_party/accessibility/gfx/geometry/size_f.h +++ b/engine/src/flutter/third_party/accessibility/gfx/geometry/size_f.h @@ -50,9 +50,7 @@ class GEOMETRY_EXPORT SizeF { bool IsEmpty() const { return !width() || !height(); } - void Scale(float scale) { - Scale(scale, scale); - } + void Scale(float scale) { Scale(scale, scale); } void Scale(float x_scale, float y_scale) { SetSize(width() * x_scale, height() * y_scale); diff --git a/engine/src/flutter/third_party/accessibility/gfx/geometry/size_unittest.cc b/engine/src/flutter/third_party/accessibility/gfx/geometry/size_unittest.cc index b3ec2ec07b0..46958dbe864 100644 --- a/engine/src/flutter/third_party/accessibility/gfx/geometry/size_unittest.cc +++ b/engine/src/flutter/third_party/accessibility/gfx/geometry/size_unittest.cc @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "testing/gtest/include/gtest/gtest.h" #include "ui/gfx/geometry/size.h" +#include "testing/gtest/include/gtest/gtest.h" #include "ui/gfx/geometry/size_conversions.h" #include "ui/gfx/geometry/size_f.h" diff --git a/engine/src/flutter/third_party/accessibility/gfx/geometry/vector2d.h b/engine/src/flutter/third_party/accessibility/gfx/geometry/vector2d.h index 11d55bf0e82..3d9c60d018e 100644 --- a/engine/src/flutter/third_party/accessibility/gfx/geometry/vector2d.h +++ b/engine/src/flutter/third_party/accessibility/gfx/geometry/vector2d.h @@ -96,4 +96,4 @@ void PrintTo(const Vector2d& vector, ::std::ostream* os); } // namespace gfx -#endif // UI_GFX_GEOMETRY_VECTOR2D_H_ +#endif // UI_GFX_GEOMETRY_VECTOR2D_H_ diff --git a/engine/src/flutter/third_party/accessibility/gfx/geometry/vector2d_conversions.cc b/engine/src/flutter/third_party/accessibility/gfx/geometry/vector2d_conversions.cc index c33199bf966..a7c5b423db8 100644 --- a/engine/src/flutter/third_party/accessibility/gfx/geometry/vector2d_conversions.cc +++ b/engine/src/flutter/third_party/accessibility/gfx/geometry/vector2d_conversions.cc @@ -23,4 +23,3 @@ Vector2d ToRoundedVector2d(const Vector2dF& vector2d) { } } // namespace gfx - diff --git a/engine/src/flutter/third_party/accessibility/gfx/geometry/vector2d_f.cc b/engine/src/flutter/third_party/accessibility/gfx/geometry/vector2d_f.cc index ccb15ae0c4c..f59cdd57a4d 100644 --- a/engine/src/flutter/third_party/accessibility/gfx/geometry/vector2d_f.cc +++ b/engine/src/flutter/third_party/accessibility/gfx/geometry/vector2d_f.cc @@ -43,12 +43,12 @@ void Vector2dF::Scale(float x_scale, float y_scale) { double CrossProduct(const Vector2dF& lhs, const Vector2dF& rhs) { return static_cast(lhs.x()) * rhs.y() - - static_cast(lhs.y()) * rhs.x(); + static_cast(lhs.y()) * rhs.x(); } double DotProduct(const Vector2dF& lhs, const Vector2dF& rhs) { return static_cast(lhs.x()) * rhs.x() + - static_cast(lhs.y()) * rhs.y(); + static_cast(lhs.y()) * rhs.y(); } Vector2dF ScaleVector2d(const Vector2dF& v, float x_scale, float y_scale) { diff --git a/engine/src/flutter/third_party/accessibility/gfx/geometry/vector2d_f.h b/engine/src/flutter/third_party/accessibility/gfx/geometry/vector2d_f.h index 938e45aeacc..28128bd7c28 100644 --- a/engine/src/flutter/third_party/accessibility/gfx/geometry/vector2d_f.h +++ b/engine/src/flutter/third_party/accessibility/gfx/geometry/vector2d_f.h @@ -115,4 +115,4 @@ void PrintTo(const Vector2dF& vector, ::std::ostream* os); } // namespace gfx -#endif // UI_GFX_GEOMETRY_VECTOR2D_F_H_ +#endif // UI_GFX_GEOMETRY_VECTOR2D_F_H_ diff --git a/engine/src/flutter/third_party/accessibility/gfx/geometry/vector2d_unittest.cc b/engine/src/flutter/third_party/accessibility/gfx/geometry/vector2d_unittest.cc index 8f49a8b52db..286ec358d95 100644 --- a/engine/src/flutter/third_party/accessibility/gfx/geometry/vector2d_unittest.cc +++ b/engine/src/flutter/third_party/accessibility/gfx/geometry/vector2d_unittest.cc @@ -39,15 +39,12 @@ TEST(Vector2dTest, Add) { const struct { Vector2d expected; Vector2d actual; - } int_tests[] = { - { Vector2d(3, 5), i1 + Vector2d() }, - { Vector2d(3 + 4, 5 - 1), i1 + i2 }, - { Vector2d(3 - 4, 5 + 1), i1 - i2 } - }; + } int_tests[] = {{Vector2d(3, 5), i1 + Vector2d()}, + {Vector2d(3 + 4, 5 - 1), i1 + i2}, + {Vector2d(3 - 4, 5 + 1), i1 - i2}}; for (size_t i = 0; i < base::size(int_tests); ++i) - EXPECT_EQ(int_tests[i].expected.ToString(), - int_tests[i].actual.ToString()); + EXPECT_EQ(int_tests[i].expected.ToString(), int_tests[i].actual.ToString()); Vector2dF f1(3.1f, 5.1f); Vector2dF f2(4.3f, -1.3f); @@ -55,12 +52,10 @@ TEST(Vector2dTest, Add) { const struct { Vector2dF expected; Vector2dF actual; - } float_tests[] = { - { Vector2dF(3.1F, 5.1F), f1 + Vector2d() }, - { Vector2dF(3.1F, 5.1F), f1 + Vector2dF() }, - { Vector2dF(3.1f + 4.3f, 5.1f - 1.3f), f1 + f2 }, - { Vector2dF(3.1f - 4.3f, 5.1f + 1.3f), f1 - f2 } - }; + } float_tests[] = {{Vector2dF(3.1F, 5.1F), f1 + Vector2d()}, + {Vector2dF(3.1F, 5.1F), f1 + Vector2dF()}, + {Vector2dF(3.1f + 4.3f, 5.1f - 1.3f), f1 + f2}, + {Vector2dF(3.1f - 4.3f, 5.1f + 1.3f), f1 - f2}}; for (size_t i = 0; i < base::size(float_tests); ++i) EXPECT_EQ(float_tests[i].expected.ToString(), @@ -71,28 +66,23 @@ TEST(Vector2dTest, Negative) { const struct { Vector2d expected; Vector2d actual; - } int_tests[] = { - { Vector2d(0, 0), -Vector2d(0, 0) }, - { Vector2d(-3, -3), -Vector2d(3, 3) }, - { Vector2d(3, 3), -Vector2d(-3, -3) }, - { Vector2d(-3, 3), -Vector2d(3, -3) }, - { Vector2d(3, -3), -Vector2d(-3, 3) } - }; + } int_tests[] = {{Vector2d(0, 0), -Vector2d(0, 0)}, + {Vector2d(-3, -3), -Vector2d(3, 3)}, + {Vector2d(3, 3), -Vector2d(-3, -3)}, + {Vector2d(-3, 3), -Vector2d(3, -3)}, + {Vector2d(3, -3), -Vector2d(-3, 3)}}; for (size_t i = 0; i < base::size(int_tests); ++i) - EXPECT_EQ(int_tests[i].expected.ToString(), - int_tests[i].actual.ToString()); + EXPECT_EQ(int_tests[i].expected.ToString(), int_tests[i].actual.ToString()); const struct { Vector2dF expected; Vector2dF actual; - } float_tests[] = { - { Vector2dF(0, 0), -Vector2d(0, 0) }, - { Vector2dF(-0.3f, -0.3f), -Vector2dF(0.3f, 0.3f) }, - { Vector2dF(0.3f, 0.3f), -Vector2dF(-0.3f, -0.3f) }, - { Vector2dF(-0.3f, 0.3f), -Vector2dF(0.3f, -0.3f) }, - { Vector2dF(0.3f, -0.3f), -Vector2dF(-0.3f, 0.3f) } - }; + } float_tests[] = {{Vector2dF(0, 0), -Vector2d(0, 0)}, + {Vector2dF(-0.3f, -0.3f), -Vector2dF(0.3f, 0.3f)}, + {Vector2dF(0.3f, 0.3f), -Vector2dF(-0.3f, -0.3f)}, + {Vector2dF(-0.3f, 0.3f), -Vector2dF(0.3f, -0.3f)}, + {Vector2dF(0.3f, -0.3f), -Vector2dF(-0.3f, 0.3f)}}; for (size_t i = 0; i < base::size(float_tests); ++i) EXPECT_EQ(float_tests[i].expected.ToString(), @@ -101,16 +91,11 @@ TEST(Vector2dTest, Negative) { TEST(Vector2dTest, Scale) { float double_values[][4] = { - { 4.5f, 1.2f, 3.3f, 5.6f }, - { 4.5f, -1.2f, 3.3f, 5.6f }, - { 4.5f, 1.2f, 3.3f, -5.6f }, - { 4.5f, 1.2f, -3.3f, -5.6f }, - { -4.5f, 1.2f, 3.3f, 5.6f }, - { -4.5f, 1.2f, 0, 5.6f }, - { -4.5f, 1.2f, 3.3f, 0 }, - { 4.5f, 0, 3.3f, 5.6f }, - { 0, 1.2f, 3.3f, 5.6f } - }; + {4.5f, 1.2f, 3.3f, 5.6f}, {4.5f, -1.2f, 3.3f, 5.6f}, + {4.5f, 1.2f, 3.3f, -5.6f}, {4.5f, 1.2f, -3.3f, -5.6f}, + {-4.5f, 1.2f, 3.3f, 5.6f}, {-4.5f, 1.2f, 0, 5.6f}, + {-4.5f, 1.2f, 3.3f, 0}, {4.5f, 0, 3.3f, 5.6f}, + {0, 1.2f, 3.3f, 5.6f}}; for (size_t i = 0; i < base::size(double_values); ++i) { Vector2dF v(double_values[i][0], double_values[i][1]); @@ -118,24 +103,17 @@ TEST(Vector2dTest, Scale) { EXPECT_EQ(v.x(), double_values[i][0] * double_values[i][2]); EXPECT_EQ(v.y(), double_values[i][1] * double_values[i][3]); - Vector2dF v2 = ScaleVector2d( - gfx::Vector2dF(double_values[i][0], double_values[i][1]), - double_values[i][2], double_values[i][3]); + Vector2dF v2 = + ScaleVector2d(gfx::Vector2dF(double_values[i][0], double_values[i][1]), + double_values[i][2], double_values[i][3]); EXPECT_EQ(double_values[i][0] * double_values[i][2], v2.x()); EXPECT_EQ(double_values[i][1] * double_values[i][3], v2.y()); } float single_values[][3] = { - { 4.5f, 1.2f, 3.3f }, - { 4.5f, -1.2f, 3.3f }, - { 4.5f, 1.2f, 3.3f }, - { 4.5f, 1.2f, -3.3f }, - { -4.5f, 1.2f, 3.3f }, - { -4.5f, 1.2f, 0 }, - { -4.5f, 1.2f, 3.3f }, - { 4.5f, 0, 3.3f }, - { 0, 1.2f, 3.3f } - }; + {4.5f, 1.2f, 3.3f}, {4.5f, -1.2f, 3.3f}, {4.5f, 1.2f, 3.3f}, + {4.5f, 1.2f, -3.3f}, {-4.5f, 1.2f, 3.3f}, {-4.5f, 1.2f, 0}, + {-4.5f, 1.2f, 3.3f}, {4.5f, 0, 3.3f}, {0, 1.2f, 3.3f}}; for (size_t i = 0; i < base::size(single_values); ++i) { Vector2dF v(single_values[i][0], single_values[i][1]); @@ -143,9 +121,9 @@ TEST(Vector2dTest, Scale) { EXPECT_EQ(v.x(), single_values[i][0] * single_values[i][2]); EXPECT_EQ(v.y(), single_values[i][1] * single_values[i][2]); - Vector2dF v2 = ScaleVector2d( - gfx::Vector2dF(double_values[i][0], double_values[i][1]), - double_values[i][2]); + Vector2dF v2 = + ScaleVector2d(gfx::Vector2dF(double_values[i][0], double_values[i][1]), + double_values[i][2]); EXPECT_EQ(single_values[i][0] * single_values[i][2], v2.x()); EXPECT_EQ(single_values[i][1] * single_values[i][2], v2.y()); } @@ -153,12 +131,7 @@ TEST(Vector2dTest, Scale) { TEST(Vector2dTest, Length) { int int_values[][2] = { - { 0, 0 }, - { 10, 20 }, - { 20, 10 }, - { -10, -20 }, - { -20, 10 }, - { 10, -20 }, + {0, 0}, {10, 20}, {20, 10}, {-10, -20}, {-20, 10}, {10, -20}, }; for (size_t i = 0; i < base::size(int_values); ++i) { @@ -173,16 +146,16 @@ TEST(Vector2dTest, Length) { } float float_values[][2] = { - { 0, 0 }, - { 10.5f, 20.5f }, - { 20.5f, 10.5f }, - { -10.5f, -20.5f }, - { -20.5f, 10.5f }, - { 10.5f, -20.5f }, - // A large vector that fails if the Length function doesn't use - // double precision internally. - { 1236278317862780234892374893213178027.12122348904204230f, - 335890352589839028212313231225425134332.38123f }, + {0, 0}, + {10.5f, 20.5f}, + {20.5f, 10.5f}, + {-10.5f, -20.5f}, + {-20.5f, 10.5f}, + {10.5f, -20.5f}, + // A large vector that fails if the Length function doesn't use + // double precision internally. + {1236278317862780234892374893213178027.12122348904204230f, + 335890352589839028212313231225425134332.38123f}, }; for (size_t i = 0; i < base::size(float_values); ++i) { diff --git a/engine/src/flutter/third_party/accessibility/gfx/mac/coordinate_conversion.mm b/engine/src/flutter/third_party/accessibility/gfx/mac/coordinate_conversion.mm index b31ce9e1451..916bb5d53af 100644 --- a/engine/src/flutter/third_party/accessibility/gfx/mac/coordinate_conversion.mm +++ b/engine/src/flutter/third_party/accessibility/gfx/mac/coordinate_conversion.mm @@ -22,15 +22,12 @@ CGFloat PrimaryDisplayHeight() { } // namespace NSRect ScreenRectToNSRect(const Rect& rect) { - return NSMakeRect(rect.x(), - PrimaryDisplayHeight() - rect.y() - rect.height(), - rect.width(), + return NSMakeRect(rect.x(), PrimaryDisplayHeight() - rect.y() - rect.height(), rect.width(), rect.height()); } Rect ScreenRectFromNSRect(const NSRect& rect) { - return Rect(rect.origin.x, - PrimaryDisplayHeight() - rect.origin.y - rect.size.height, + return Rect(rect.origin.x, PrimaryDisplayHeight() - rect.origin.y - rect.size.height, rect.size.width, rect.size.height); } diff --git a/engine/src/flutter/third_party/accessibility/gfx/transform.cc b/engine/src/flutter/third_party/accessibility/gfx/transform.cc index 0184c6a3e57..2ca5fff7526 100644 --- a/engine/src/flutter/third_party/accessibility/gfx/transform.cc +++ b/engine/src/flutter/third_party/accessibility/gfx/transform.cc @@ -98,14 +98,10 @@ void Transform::RotateAboutXAxis(double degrees) { SkScalar cosTheta = SkDoubleToScalar(std::cos(radians)); SkScalar sinTheta = SkDoubleToScalar(std::sin(radians)); if (matrix_.isIdentity()) { - matrix_.set3x3(1, 0, 0, - 0, cosTheta, sinTheta, - 0, -sinTheta, cosTheta); + matrix_.set3x3(1, 0, 0, 0, cosTheta, sinTheta, 0, -sinTheta, cosTheta); } else { SkMatrix44 rot(SkMatrix44::kUninitialized_Constructor); - rot.set3x3(1, 0, 0, - 0, cosTheta, sinTheta, - 0, -sinTheta, cosTheta); + rot.set3x3(1, 0, 0, 0, cosTheta, sinTheta, 0, -sinTheta, cosTheta); matrix_.preConcat(rot); } } @@ -115,16 +111,12 @@ void Transform::RotateAboutYAxis(double degrees) { SkScalar cosTheta = SkDoubleToScalar(std::cos(radians)); SkScalar sinTheta = SkDoubleToScalar(std::sin(radians)); if (matrix_.isIdentity()) { - // Note carefully the placement of the -sinTheta for rotation about - // y-axis is different than rotation about x-axis or z-axis. - matrix_.set3x3(cosTheta, 0, -sinTheta, - 0, 1, 0, - sinTheta, 0, cosTheta); + // Note carefully the placement of the -sinTheta for rotation about + // y-axis is different than rotation about x-axis or z-axis. + matrix_.set3x3(cosTheta, 0, -sinTheta, 0, 1, 0, sinTheta, 0, cosTheta); } else { SkMatrix44 rot(SkMatrix44::kUninitialized_Constructor); - rot.set3x3(cosTheta, 0, -sinTheta, - 0, 1, 0, - sinTheta, 0, cosTheta); + rot.set3x3(cosTheta, 0, -sinTheta, 0, 1, 0, sinTheta, 0, cosTheta); matrix_.preConcat(rot); } } @@ -134,14 +126,10 @@ void Transform::RotateAboutZAxis(double degrees) { SkScalar cosTheta = SkDoubleToScalar(std::cos(radians)); SkScalar sinTheta = SkDoubleToScalar(std::sin(radians)); if (matrix_.isIdentity()) { - matrix_.set3x3(cosTheta, sinTheta, 0, - -sinTheta, cosTheta, 0, - 0, 0, 1); + matrix_.set3x3(cosTheta, sinTheta, 0, -sinTheta, cosTheta, 0, 0, 0, 1); } else { SkMatrix44 rot(SkMatrix44::kUninitialized_Constructor); - rot.set3x3(cosTheta, sinTheta, 0, - -sinTheta, cosTheta, 0, - 0, 0, 1); + rot.set3x3(cosTheta, sinTheta, 0, -sinTheta, cosTheta, 0, 0, 0, 1); matrix_.preConcat(rot); } } @@ -228,20 +216,18 @@ void Transform::ConcatTransform(const Transform& transform) { bool Transform::IsApproximatelyIdentityOrTranslation(SkScalar tolerance) const { DCHECK_GE(tolerance, 0); - return - ApproximatelyOne(matrix_.get(0, 0), tolerance) && - ApproximatelyZero(matrix_.get(1, 0), tolerance) && - ApproximatelyZero(matrix_.get(2, 0), tolerance) && - matrix_.get(3, 0) == 0 && - ApproximatelyZero(matrix_.get(0, 1), tolerance) && - ApproximatelyOne(matrix_.get(1, 1), tolerance) && - ApproximatelyZero(matrix_.get(2, 1), tolerance) && - matrix_.get(3, 1) == 0 && - ApproximatelyZero(matrix_.get(0, 2), tolerance) && - ApproximatelyZero(matrix_.get(1, 2), tolerance) && - ApproximatelyOne(matrix_.get(2, 2), tolerance) && - matrix_.get(3, 2) == 0 && - matrix_.get(3, 3) == 1; + return ApproximatelyOne(matrix_.get(0, 0), tolerance) && + ApproximatelyZero(matrix_.get(1, 0), tolerance) && + ApproximatelyZero(matrix_.get(2, 0), tolerance) && + matrix_.get(3, 0) == 0 && + ApproximatelyZero(matrix_.get(0, 1), tolerance) && + ApproximatelyOne(matrix_.get(1, 1), tolerance) && + ApproximatelyZero(matrix_.get(2, 1), tolerance) && + matrix_.get(3, 1) == 0 && + ApproximatelyZero(matrix_.get(0, 2), tolerance) && + ApproximatelyZero(matrix_.get(1, 2), tolerance) && + ApproximatelyOne(matrix_.get(2, 2), tolerance) && + matrix_.get(3, 2) == 0 && matrix_.get(3, 3) == 1; } bool Transform::IsApproximatelyIdentityOrIntegerTranslation( @@ -313,13 +299,8 @@ bool Transform::IsBackFaceVisible() const { double cofactor_part_6 = matrix_.get(0, 3) * matrix_.get(1, 1) * matrix_.get(3, 0); - double cofactor33 = - cofactor_part_1 + - cofactor_part_2 + - cofactor_part_3 - - cofactor_part_4 - - cofactor_part_5 - - cofactor_part_6; + double cofactor33 = cofactor_part_1 + cofactor_part_2 + cofactor_part_3 - + cofactor_part_4 - cofactor_part_5 - cofactor_part_6; // Technically the transformed z component is cofactor33 / determinant. But // we can avoid the costly division because we only care about the resulting @@ -385,12 +366,9 @@ bool Transform::Preserves2dAxisAlignment() const { num_non_zero_in_col_1++; } - return - num_non_zero_in_row_0 <= 1 && - num_non_zero_in_row_1 <= 1 && - num_non_zero_in_col_0 <= 1 && - num_non_zero_in_col_1 <= 1 && - !has_x_or_y_perspective; + return num_non_zero_in_row_0 <= 1 && num_non_zero_in_row_1 <= 1 && + num_non_zero_in_col_0 <= 1 && num_non_zero_in_col_1 <= 1 && + !has_x_or_y_perspective; } void Transform::Transpose() { @@ -619,21 +597,11 @@ std::string Transform::ToString() const { " %+0.4f %+0.4f %+0.4f %+0.4f \n" " %+0.4f %+0.4f %+0.4f %+0.4f \n" " %+0.4f %+0.4f %+0.4f %+0.4f ]\n", - matrix_.get(0, 0), - matrix_.get(0, 1), - matrix_.get(0, 2), - matrix_.get(0, 3), - matrix_.get(1, 0), - matrix_.get(1, 1), - matrix_.get(1, 2), - matrix_.get(1, 3), - matrix_.get(2, 0), - matrix_.get(2, 1), - matrix_.get(2, 2), - matrix_.get(2, 3), - matrix_.get(3, 0), - matrix_.get(3, 1), - matrix_.get(3, 2), + matrix_.get(0, 0), matrix_.get(0, 1), matrix_.get(0, 2), + matrix_.get(0, 3), matrix_.get(1, 0), matrix_.get(1, 1), + matrix_.get(1, 2), matrix_.get(1, 3), matrix_.get(2, 0), + matrix_.get(2, 1), matrix_.get(2, 2), matrix_.get(2, 3), + matrix_.get(3, 0), matrix_.get(3, 1), matrix_.get(3, 2), matrix_.get(3, 3)); } diff --git a/engine/src/flutter/third_party/accessibility/gfx/transform.h b/engine/src/flutter/third_party/accessibility/gfx/transform.h index c056ab0f854..4e8b5dabac4 100644 --- a/engine/src/flutter/third_party/accessibility/gfx/transform.h +++ b/engine/src/flutter/third_party/accessibility/gfx/transform.h @@ -28,10 +28,7 @@ class Vector3dF; // copy/assign. class GEOMETRY_SKIA_EXPORT Transform { public: - - enum SkipInitialization { - kSkipInitialization - }; + enum SkipInitialization { kSkipInitialization }; constexpr Transform() : matrix_(SkMatrix44::kIdentity_Constructor) {} @@ -291,13 +288,11 @@ class GEOMETRY_SKIA_EXPORT Transform { std::string ToString() const; private: - void TransformPointInternal(const SkMatrix44& xform, - Point* point) const; + void TransformPointInternal(const SkMatrix44& xform, Point* point) const; void TransformPointInternal(const SkMatrix44& xform, PointF* point) const; - void TransformPointInternal(const SkMatrix44& xform, - Point3F* point) const; + void TransformPointInternal(const SkMatrix44& xform, Point3F* point) const; void TransformVectorInternal(const SkMatrix44& xform, Vector3dF* vector) const;