diff --git a/engine/src/flutter/impeller/geometry/geometry_unittests.cc b/engine/src/flutter/impeller/geometry/geometry_unittests.cc index aa0b66b197..927f8536a3 100644 --- a/engine/src/flutter/impeller/geometry/geometry_unittests.cc +++ b/engine/src/flutter/impeller/geometry/geometry_unittests.cc @@ -1059,6 +1059,111 @@ TEST(GeometryTest, PointAngleTo) { } } +TEST(GeometryTest, PointMin) { + Point p(1, 2); + Point result = p.Min({0, 10}); + Point expected(0, 2); + ASSERT_POINT_NEAR(result, expected); +} + +TEST(GeometryTest, Vector3Min) { + Vector3 p(1, 2, 3); + Vector3 result = p.Min({0, 10, 2}); + Vector3 expected(0, 2, 2); + ASSERT_VECTOR3_NEAR(result, expected); +} + +TEST(GeometryTest, Vector4Min) { + Vector4 p(1, 2, 3, 4); + Vector4 result = p.Min({0, 10, 2, 1}); + Vector4 expected(0, 2, 2, 1); + ASSERT_VECTOR4_NEAR(result, expected); +} + +TEST(GeometryTest, PointMax) { + Point p(1, 2); + Point result = p.Max({0, 10}); + Point expected(1, 10); + ASSERT_POINT_NEAR(result, expected); +} + +TEST(GeometryTest, Vector3Max) { + Vector3 p(1, 2, 3); + Vector3 result = p.Max({0, 10, 2}); + Vector3 expected(1, 10, 3); + ASSERT_VECTOR3_NEAR(result, expected); +} + +TEST(GeometryTest, Vector4Max) { + Vector4 p(1, 2, 3, 4); + Vector4 result = p.Max({0, 10, 2, 1}); + Vector4 expected(1, 10, 3, 4); + ASSERT_VECTOR4_NEAR(result, expected); +} + +TEST(GeometryTest, PointFloor) { + Point p(1.5, 2.3); + Point result = p.Floor(); + Point expected(1, 2); + ASSERT_POINT_NEAR(result, expected); +} + +TEST(GeometryTest, Vector3Floor) { + Vector3 p(1.5, 2.3, 3.9); + Vector3 result = p.Floor(); + Vector3 expected(1, 2, 3); + ASSERT_VECTOR3_NEAR(result, expected); +} + +TEST(GeometryTest, Vector4Floor) { + Vector4 p(1.5, 2.3, 3.9, 4.0); + Vector4 result = p.Floor(); + Vector4 expected(1, 2, 3, 4); + ASSERT_VECTOR4_NEAR(result, expected); +} + +TEST(GeometryTest, PointCeil) { + Point p(1.5, 2.3); + Point result = p.Ceil(); + Point expected(2, 3); + ASSERT_POINT_NEAR(result, expected); +} + +TEST(GeometryTest, Vector3Ceil) { + Vector3 p(1.5, 2.3, 3.9); + Vector3 result = p.Ceil(); + Vector3 expected(2, 3, 4); + ASSERT_VECTOR3_NEAR(result, expected); +} + +TEST(GeometryTest, Vector4Ceil) { + Vector4 p(1.5, 2.3, 3.9, 4.0); + Vector4 result = p.Ceil(); + Vector4 expected(2, 3, 4, 4); + ASSERT_VECTOR4_NEAR(result, expected); +} + +TEST(GeometryTest, PointRound) { + Point p(1.5, 2.3); + Point result = p.Round(); + Point expected(2, 2); + ASSERT_POINT_NEAR(result, expected); +} + +TEST(GeometryTest, Vector3Round) { + Vector3 p(1.5, 2.3, 3.9); + Vector3 result = p.Round(); + Vector3 expected(2, 2, 4); + ASSERT_VECTOR3_NEAR(result, expected); +} + +TEST(GeometryTest, Vector4Round) { + Vector4 p(1.5, 2.3, 3.9, 4.0); + Vector4 result = p.Round(); + Vector4 expected(2, 2, 4, 4); + ASSERT_VECTOR4_NEAR(result, expected); +} + TEST(GeometryTest, PointLerp) { Point p(1, 2); Point result = p.Lerp({5, 10}, 0.75); diff --git a/engine/src/flutter/impeller/geometry/path.cc b/engine/src/flutter/impeller/geometry/path.cc index e018b0ff38..8aaa366067 100644 --- a/engine/src/flutter/impeller/geometry/path.cc +++ b/engine/src/flutter/impeller/geometry/path.cc @@ -351,15 +351,13 @@ std::optional> Path::GetMinMaxCoveragePoints() const { auto clamp = [&min, &max](const Point& point) { if (min.has_value()) { - min->x = std::min(min->x, point.x); - min->y = std::min(min->y, point.y); + min = min->Min(point); } else { min = point; } if (max.has_value()) { - max->x = std::max(max->x, point.x); - max->y = std::max(max->y, point.y); + max = max->Max(point); } else { max = point; } diff --git a/engine/src/flutter/impeller/geometry/point.h b/engine/src/flutter/impeller/geometry/point.h index d5ca7eb6a6..6434fe5a28 100644 --- a/engine/src/flutter/impeller/geometry/point.h +++ b/engine/src/flutter/impeller/geometry/point.h @@ -184,6 +184,12 @@ struct TPoint { return {std::max(x, p.x), std::max(y, p.y)}; } + constexpr TPoint Floor() const { return {std::floor(x), std::floor(y)}; } + + constexpr TPoint Ceil() const { return {std::ceil(x), std::ceil(y)}; } + + constexpr TPoint Round() const { return {std::round(x), std::round(y)}; } + constexpr Type GetDistance(const TPoint& p) const { return sqrt(GetDistanceSquared(p)); } diff --git a/engine/src/flutter/impeller/geometry/size.h b/engine/src/flutter/impeller/geometry/size.h index dc6abd4126..f0b3a815da 100644 --- a/engine/src/flutter/impeller/geometry/size.h +++ b/engine/src/flutter/impeller/geometry/size.h @@ -82,6 +82,16 @@ struct TSize { }; } + constexpr TSize Floor() const { + return {std::floor(width), std::floor(height)}; + } + + constexpr TSize Ceil() const { return {std::ceil(width), std::ceil(height)}; } + + constexpr TSize Round() const { + return {std::round(width), std::round(height)}; + } + constexpr Type Area() const { return width * height; } constexpr bool IsPositive() const { return width > 0 && height > 0; } diff --git a/engine/src/flutter/impeller/geometry/vector.h b/engine/src/flutter/impeller/geometry/vector.h index e87c22f61e..705a88ca05 100644 --- a/engine/src/flutter/impeller/geometry/vector.h +++ b/engine/src/flutter/impeller/geometry/vector.h @@ -60,6 +60,26 @@ struct Vector3 { }; } + constexpr Vector3 Min(const Vector3& p) const { + return {std::min(x, p.x), std::min(y, p.y), std::min(z, p.z)}; + } + + constexpr Vector3 Max(const Vector3& p) const { + return {std::max(x, p.x), std::max(y, p.y), std::max(z, p.z)}; + } + + constexpr Vector3 Floor() const { + return {std::floor(x), std::floor(y), std::floor(z)}; + } + + constexpr Vector3 Ceil() const { + return {std::ceil(x), std::ceil(y), std::ceil(z)}; + } + + constexpr Vector3 Round() const { + return {std::round(x), std::round(y), std::round(z)}; + } + constexpr bool operator==(const Vector3& v) const { return v.x == x && v.y == y && v.z == z; } @@ -236,6 +256,28 @@ struct Vector4 { return Vector4(x * v.x, y * v.y, z * v.z, w * v.w); } + constexpr Vector4 Min(const Vector4& p) const { + return {std::min(x, p.x), std::min(y, p.y), std::min(z, p.z), + std::min(w, p.w)}; + } + + constexpr Vector4 Max(const Vector4& p) const { + return {std::max(x, p.x), std::max(y, p.y), std::max(z, p.z), + std::max(w, p.w)}; + } + + constexpr Vector4 Floor() const { + return {std::floor(x), std::floor(y), std::floor(z), std::floor(w)}; + } + + constexpr Vector4 Ceil() const { + return {std::ceil(x), std::ceil(y), std::ceil(z), std::ceil(w)}; + } + + constexpr Vector4 Round() const { + return {std::round(x), std::round(y), std::round(z), std::round(w)}; + } + constexpr Vector4 Lerp(const Vector4& v, Scalar t) const { return *this + (v - *this) * t; } diff --git a/engine/src/flutter/impeller/playground/playground.cc b/engine/src/flutter/impeller/playground/playground.cc index a102d44ac2..85042638b8 100644 --- a/engine/src/flutter/impeller/playground/playground.cc +++ b/engine/src/flutter/impeller/playground/playground.cc @@ -214,8 +214,7 @@ bool Playground::OpenPlaygroundHere( if (!playground) { return; } - playground->SetWindowSize( - ISize{std::max(width, 0), std::max(height, 0)}); + playground->SetWindowSize(ISize{width, height}.Max({})); }); ::glfwSetKeyCallback(window, &PlaygroundKeyCallback); ::glfwSetCursorPosCallback(window, [](GLFWwindow* window, double x, diff --git a/engine/src/flutter/impeller/typographer/backends/skia/text_frame_skia.cc b/engine/src/flutter/impeller/typographer/backends/skia/text_frame_skia.cc index 87aa408d25..534bab00bd 100644 --- a/engine/src/flutter/impeller/typographer/backends/skia/text_frame_skia.cc +++ b/engine/src/flutter/impeller/typographer/backends/skia/text_frame_skia.cc @@ -75,9 +75,8 @@ TextFrame TextFrameFromTextBlob(const sk_sp& blob, Scalar scale) { ? Glyph::Type::kBitmap : Glyph::Type::kPath; - text_run.AddGlyph( - Glyph{glyphs[i], type, ToRect(glyph_bounds[i])}, - Point{std::round(point->x()), std::round(point->y())}); + text_run.AddGlyph(Glyph{glyphs[i], type, ToRect(glyph_bounds[i])}, + Point{point->x(), point->y()}.Round()); } break; }