Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion impeller/entity/contents/filters/filter_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ std::optional<Rect> FilterContents::GetSourceCoverage(
if (!input_coverage.has_value()) {
return std::nullopt;
}
inputs_coverage = Union(inputs_coverage, input_coverage.value());
inputs_coverage = Rect::Union(inputs_coverage, input_coverage.value());
}
return inputs_coverage;
}
Expand Down
2 changes: 1 addition & 1 deletion impeller/entity/entity_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ EntityPass::EntityResult EntityPass::GetEntityForElement(
return EntityPass::EntityResult::Skip();
}

subpass_coverage = RoundOut(subpass_coverage.value());
subpass_coverage = Rect::RoundOut(subpass_coverage.value());

auto subpass_size = ISize(subpass_coverage->size);
if (subpass_size.IsEmpty()) {
Expand Down
70 changes: 36 additions & 34 deletions impeller/geometry/geometry_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1650,25 +1650,25 @@ TEST(GeometryTest, OptRectUnion) {
Rect c = Rect::MakeLTRB(100, 0, 200, 100);

// NullOpt, NullOpt
EXPECT_FALSE(Union(std::nullopt, std::nullopt).has_value());
EXPECT_EQ(Union(std::nullopt, std::nullopt), std::nullopt);
EXPECT_FALSE(Rect::Union(std::nullopt, std::nullopt).has_value());
EXPECT_EQ(Rect::Union(std::nullopt, std::nullopt), std::nullopt);

auto test1 = [](const Rect& r) {
// Rect, NullOpt
EXPECT_TRUE(Union(r, std::nullopt).has_value());
EXPECT_EQ(Union(r, std::nullopt).value(), r);
EXPECT_TRUE(Rect::Union(r, std::nullopt).has_value());
EXPECT_EQ(Rect::Union(r, std::nullopt).value(), r);

// OptRect, NullOpt
EXPECT_TRUE(Union(std::optional(r), std::nullopt).has_value());
EXPECT_EQ(Union(std::optional(r), std::nullopt).value(), r);
EXPECT_TRUE(Rect::Union(std::optional(r), std::nullopt).has_value());
EXPECT_EQ(Rect::Union(std::optional(r), std::nullopt).value(), r);

// NullOpt, Rect
EXPECT_TRUE(Union(std::nullopt, r).has_value());
EXPECT_EQ(Union(std::nullopt, r).value(), r);
EXPECT_TRUE(Rect::Union(std::nullopt, r).has_value());
EXPECT_EQ(Rect::Union(std::nullopt, r).value(), r);

// NullOpt, OptRect
EXPECT_TRUE(Union(std::nullopt, std::optional(r)).has_value());
EXPECT_EQ(Union(std::nullopt, std::optional(r)).value(), r);
EXPECT_TRUE(Rect::Union(std::nullopt, std::optional(r)).has_value());
EXPECT_EQ(Rect::Union(std::nullopt, std::optional(r)).value(), r);
};

test1(a);
Expand All @@ -1679,16 +1679,16 @@ TEST(GeometryTest, OptRectUnion) {
ASSERT_EQ(a.Union(b), u);

// Rect, OptRect
EXPECT_TRUE(Union(a, std::optional(b)).has_value());
EXPECT_EQ(Union(a, std::optional(b)).value(), u);
EXPECT_TRUE(Rect::Union(a, std::optional(b)).has_value());
EXPECT_EQ(Rect::Union(a, std::optional(b)).value(), u);

// OptRect, Rect
EXPECT_TRUE(Union(std::optional(a), b).has_value());
EXPECT_EQ(Union(std::optional(a), b).value(), u);
EXPECT_TRUE(Rect::Union(std::optional(a), b).has_value());
EXPECT_EQ(Rect::Union(std::optional(a), b).value(), u);

// OptRect, OptRect
EXPECT_TRUE(Union(std::optional(a), std::optional(b)).has_value());
EXPECT_EQ(Union(std::optional(a), std::optional(b)).value(), u);
EXPECT_TRUE(Rect::Union(std::optional(a), std::optional(b)).has_value());
EXPECT_EQ(Rect::Union(std::optional(a), std::optional(b)).value(), u);
};

test2(a, b, Rect::MakeLTRB(0, 0, 200, 200));
Expand Down Expand Up @@ -1751,25 +1751,25 @@ TEST(GeometryTest, OptRectIntersection) {
Rect c = Rect::MakeLTRB(100, 0, 200, 110);

// NullOpt, NullOpt
EXPECT_FALSE(Intersection(std::nullopt, std::nullopt).has_value());
EXPECT_EQ(Intersection(std::nullopt, std::nullopt), std::nullopt);
EXPECT_FALSE(Rect::Intersection(std::nullopt, std::nullopt).has_value());
EXPECT_EQ(Rect::Intersection(std::nullopt, std::nullopt), std::nullopt);

auto test1 = [](const Rect& r) {
// Rect, NullOpt
EXPECT_TRUE(Intersection(r, std::nullopt).has_value());
EXPECT_EQ(Intersection(r, std::nullopt).value(), r);
EXPECT_TRUE(Rect::Intersection(r, std::nullopt).has_value());
EXPECT_EQ(Rect::Intersection(r, std::nullopt).value(), r);

// OptRect, NullOpt
EXPECT_TRUE(Intersection(std::optional(r), std::nullopt).has_value());
EXPECT_EQ(Intersection(std::optional(r), std::nullopt).value(), r);
EXPECT_TRUE(Rect::Intersection(std::optional(r), std::nullopt).has_value());
EXPECT_EQ(Rect::Intersection(std::optional(r), std::nullopt).value(), r);

// NullOpt, Rect
EXPECT_TRUE(Intersection(std::nullopt, r).has_value());
EXPECT_EQ(Intersection(std::nullopt, r).value(), r);
EXPECT_TRUE(Rect::Intersection(std::nullopt, r).has_value());
EXPECT_EQ(Rect::Intersection(std::nullopt, r).value(), r);

// NullOpt, OptRect
EXPECT_TRUE(Intersection(std::nullopt, std::optional(r)).has_value());
EXPECT_EQ(Intersection(std::nullopt, std::optional(r)).value(), r);
EXPECT_TRUE(Rect::Intersection(std::nullopt, std::optional(r)).has_value());
EXPECT_EQ(Rect::Intersection(std::nullopt, std::optional(r)).value(), r);
};

test1(a);
Expand All @@ -1780,16 +1780,18 @@ TEST(GeometryTest, OptRectIntersection) {
ASSERT_EQ(a.Intersection(b), i);

// Rect, OptRect
EXPECT_TRUE(Intersection(a, std::optional(b)).has_value());
EXPECT_EQ(Intersection(a, std::optional(b)).value(), i);
EXPECT_TRUE(Rect::Intersection(a, std::optional(b)).has_value());
EXPECT_EQ(Rect::Intersection(a, std::optional(b)).value(), i);

// OptRect, Rect
EXPECT_TRUE(Intersection(std::optional(a), b).has_value());
EXPECT_EQ(Intersection(std::optional(a), b).value(), i);
EXPECT_TRUE(Rect::Intersection(std::optional(a), b).has_value());
EXPECT_EQ(Rect::Intersection(std::optional(a), b).value(), i);

// OptRect, OptRect
EXPECT_TRUE(Intersection(std::optional(a), std::optional(b)).has_value());
EXPECT_EQ(Intersection(std::optional(a), std::optional(b)).value(), i);
EXPECT_TRUE(
Rect::Intersection(std::optional(a), std::optional(b)).has_value());
EXPECT_EQ(Rect::Intersection(std::optional(a), std::optional(b)).value(),
i);
};

test2(a, b, Rect::MakeLTRB(100, 100, 110, 110));
Expand Down Expand Up @@ -2117,11 +2119,11 @@ TEST(GeometryTest, RectProject) {
TEST(GeometryTest, RectRoundOut) {
{
auto r = Rect::MakeLTRB(-100, -100, 100, 100);
ASSERT_EQ(RoundOut(r), r);
ASSERT_EQ(Rect::RoundOut(r), r);
}
{
auto r = Rect::MakeLTRB(-100.1, -100.1, 100.1, 100.1);
ASSERT_EQ(RoundOut(r), Rect::MakeLTRB(-101, -101, 101, 101));
ASSERT_EQ(Rect::RoundOut(r), Rect::MakeLTRB(-101, -101, 101, 101));
}
}

Expand Down
65 changes: 34 additions & 31 deletions impeller/geometry/rect.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,45 +325,48 @@ struct TRect {
TSize<T>(1.0 / static_cast<Scalar>(size.width),
1.0 / static_cast<Scalar>(size.height)));
}
};

using Rect = TRect<Scalar>;
using IRect = TRect<int64_t>;
constexpr static TRect RoundOut(const TRect& r) {
return TRect::MakeLTRB(floor(r.GetLeft()), floor(r.GetTop()),
ceil(r.GetRight()), ceil(r.GetBottom()));
}

constexpr inline Rect RoundOut(const Rect& r) {
return Rect::MakeLTRB(floor(r.GetLeft()), floor(r.GetTop()),
ceil(r.GetRight()), ceil(r.GetBottom()));
}
constexpr static std::optional<TRect> Union(const TRect& a,
const std::optional<TRect> b) {
return b.has_value() ? a.Union(b.value()) : a;
}

constexpr inline std::optional<Rect> Union(const Rect& a,
const std::optional<Rect> b) {
return b.has_value() ? a.Union(b.value()) : a;
}
constexpr static std::optional<TRect> Union(const std::optional<TRect> a,
const TRect& b) {
return Union(b, a);
}

constexpr inline std::optional<Rect> Union(const std::optional<Rect> a,
const Rect& b) {
return Union(b, a);
}
constexpr static std::optional<TRect> Union(const std::optional<TRect> a,
const std::optional<TRect> b) {
return a.has_value() ? Union(a.value(), b) : b;
}

constexpr inline std::optional<Rect> Union(const std::optional<Rect> a,
const std::optional<Rect> b) {
return a.has_value() ? Union(a.value(), b) : b;
}
constexpr static std::optional<TRect> Intersection(
const TRect& a,
const std::optional<TRect> b) {
return b.has_value() ? a.Intersection(b.value()) : a;
}

constexpr inline std::optional<Rect> Intersection(const Rect& a,
const std::optional<Rect> b) {
return b.has_value() ? a.Intersection(b.value()) : a;
}
constexpr static std::optional<TRect> Intersection(
const std::optional<TRect> a,
const TRect& b) {
return Intersection(b, a);
}

constexpr inline std::optional<Rect> Intersection(const std::optional<Rect> a,
const Rect& b) {
return Intersection(b, a);
}
constexpr static std::optional<TRect> Intersection(
const std::optional<TRect> a,
const std::optional<TRect> b) {
return a.has_value() ? Intersection(a.value(), b) : b;
}
};

constexpr inline std::optional<Rect> Intersection(const std::optional<Rect> a,
const std::optional<Rect> b) {
return a.has_value() ? Intersection(a.value(), b) : b;
}
using Rect = TRect<Scalar>;
using IRect = TRect<int64_t>;

} // namespace impeller

Expand Down