Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit a973154

Browse files
committed
[Impeller] Place Rect statics under the Rect template.
1 parent fe3882e commit a973154

File tree

4 files changed

+72
-67
lines changed

4 files changed

+72
-67
lines changed

impeller/entity/contents/filters/filter_contents.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ std::optional<Rect> FilterContents::GetSourceCoverage(
246246
if (!input_coverage.has_value()) {
247247
return std::nullopt;
248248
}
249-
inputs_coverage = Union(inputs_coverage, input_coverage.value());
249+
inputs_coverage = Rect::Union(inputs_coverage, input_coverage.value());
250250
}
251251
return inputs_coverage;
252252
}

impeller/entity/entity_pass.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ EntityPass::EntityResult EntityPass::GetEntityForElement(
616616
return EntityPass::EntityResult::Skip();
617617
}
618618

619-
subpass_coverage = RoundOut(subpass_coverage.value());
619+
subpass_coverage = Rect::RoundOut(subpass_coverage.value());
620620

621621
auto subpass_size = ISize(subpass_coverage->size);
622622
if (subpass_size.IsEmpty()) {

impeller/geometry/geometry_unittests.cc

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,25 +1650,25 @@ TEST(GeometryTest, OptRectUnion) {
16501650
Rect c = Rect::MakeLTRB(100, 0, 200, 100);
16511651

16521652
// NullOpt, NullOpt
1653-
EXPECT_FALSE(Union(std::nullopt, std::nullopt).has_value());
1654-
EXPECT_EQ(Union(std::nullopt, std::nullopt), std::nullopt);
1653+
EXPECT_FALSE(Rect::Union(std::nullopt, std::nullopt).has_value());
1654+
EXPECT_EQ(Rect::Union(std::nullopt, std::nullopt), std::nullopt);
16551655

16561656
auto test1 = [](const Rect& r) {
16571657
// Rect, NullOpt
1658-
EXPECT_TRUE(Union(r, std::nullopt).has_value());
1659-
EXPECT_EQ(Union(r, std::nullopt).value(), r);
1658+
EXPECT_TRUE(Rect::Union(r, std::nullopt).has_value());
1659+
EXPECT_EQ(Rect::Union(r, std::nullopt).value(), r);
16601660

16611661
// OptRect, NullOpt
1662-
EXPECT_TRUE(Union(std::optional(r), std::nullopt).has_value());
1663-
EXPECT_EQ(Union(std::optional(r), std::nullopt).value(), r);
1662+
EXPECT_TRUE(Rect::Union(std::optional(r), std::nullopt).has_value());
1663+
EXPECT_EQ(Rect::Union(std::optional(r), std::nullopt).value(), r);
16641664

16651665
// NullOpt, Rect
1666-
EXPECT_TRUE(Union(std::nullopt, r).has_value());
1667-
EXPECT_EQ(Union(std::nullopt, r).value(), r);
1666+
EXPECT_TRUE(Rect::Union(std::nullopt, r).has_value());
1667+
EXPECT_EQ(Rect::Union(std::nullopt, r).value(), r);
16681668

16691669
// NullOpt, OptRect
1670-
EXPECT_TRUE(Union(std::nullopt, std::optional(r)).has_value());
1671-
EXPECT_EQ(Union(std::nullopt, std::optional(r)).value(), r);
1670+
EXPECT_TRUE(Rect::Union(std::nullopt, std::optional(r)).has_value());
1671+
EXPECT_EQ(Rect::Union(std::nullopt, std::optional(r)).value(), r);
16721672
};
16731673

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

16811681
// Rect, OptRect
1682-
EXPECT_TRUE(Union(a, std::optional(b)).has_value());
1683-
EXPECT_EQ(Union(a, std::optional(b)).value(), u);
1682+
EXPECT_TRUE(Rect::Union(a, std::optional(b)).has_value());
1683+
EXPECT_EQ(Rect::Union(a, std::optional(b)).value(), u);
16841684

16851685
// OptRect, Rect
1686-
EXPECT_TRUE(Union(std::optional(a), b).has_value());
1687-
EXPECT_EQ(Union(std::optional(a), b).value(), u);
1686+
EXPECT_TRUE(Rect::Union(std::optional(a), b).has_value());
1687+
EXPECT_EQ(Rect::Union(std::optional(a), b).value(), u);
16881688

16891689
// OptRect, OptRect
1690-
EXPECT_TRUE(Union(std::optional(a), std::optional(b)).has_value());
1691-
EXPECT_EQ(Union(std::optional(a), std::optional(b)).value(), u);
1690+
EXPECT_TRUE(Rect::Union(std::optional(a), std::optional(b)).has_value());
1691+
EXPECT_EQ(Rect::Union(std::optional(a), std::optional(b)).value(), u);
16921692
};
16931693

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

17531753
// NullOpt, NullOpt
1754-
EXPECT_FALSE(Intersection(std::nullopt, std::nullopt).has_value());
1755-
EXPECT_EQ(Intersection(std::nullopt, std::nullopt), std::nullopt);
1754+
EXPECT_FALSE(Rect::Intersection(std::nullopt, std::nullopt).has_value());
1755+
EXPECT_EQ(Rect::Intersection(std::nullopt, std::nullopt), std::nullopt);
17561756

17571757
auto test1 = [](const Rect& r) {
17581758
// Rect, NullOpt
1759-
EXPECT_TRUE(Intersection(r, std::nullopt).has_value());
1760-
EXPECT_EQ(Intersection(r, std::nullopt).value(), r);
1759+
EXPECT_TRUE(Rect::Intersection(r, std::nullopt).has_value());
1760+
EXPECT_EQ(Rect::Intersection(r, std::nullopt).value(), r);
17611761

17621762
// OptRect, NullOpt
1763-
EXPECT_TRUE(Intersection(std::optional(r), std::nullopt).has_value());
1764-
EXPECT_EQ(Intersection(std::optional(r), std::nullopt).value(), r);
1763+
EXPECT_TRUE(Rect::Intersection(std::optional(r), std::nullopt).has_value());
1764+
EXPECT_EQ(Rect::Intersection(std::optional(r), std::nullopt).value(), r);
17651765

17661766
// NullOpt, Rect
1767-
EXPECT_TRUE(Intersection(std::nullopt, r).has_value());
1768-
EXPECT_EQ(Intersection(std::nullopt, r).value(), r);
1767+
EXPECT_TRUE(Rect::Intersection(std::nullopt, r).has_value());
1768+
EXPECT_EQ(Rect::Intersection(std::nullopt, r).value(), r);
17691769

17701770
// NullOpt, OptRect
1771-
EXPECT_TRUE(Intersection(std::nullopt, std::optional(r)).has_value());
1772-
EXPECT_EQ(Intersection(std::nullopt, std::optional(r)).value(), r);
1771+
EXPECT_TRUE(Rect::Intersection(std::nullopt, std::optional(r)).has_value());
1772+
EXPECT_EQ(Rect::Intersection(std::nullopt, std::optional(r)).value(), r);
17731773
};
17741774

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

17821782
// Rect, OptRect
1783-
EXPECT_TRUE(Intersection(a, std::optional(b)).has_value());
1784-
EXPECT_EQ(Intersection(a, std::optional(b)).value(), i);
1783+
EXPECT_TRUE(Rect::Intersection(a, std::optional(b)).has_value());
1784+
EXPECT_EQ(Rect::Intersection(a, std::optional(b)).value(), i);
17851785

17861786
// OptRect, Rect
1787-
EXPECT_TRUE(Intersection(std::optional(a), b).has_value());
1788-
EXPECT_EQ(Intersection(std::optional(a), b).value(), i);
1787+
EXPECT_TRUE(Rect::Intersection(std::optional(a), b).has_value());
1788+
EXPECT_EQ(Rect::Intersection(std::optional(a), b).value(), i);
17891789

17901790
// OptRect, OptRect
1791-
EXPECT_TRUE(Intersection(std::optional(a), std::optional(b)).has_value());
1792-
EXPECT_EQ(Intersection(std::optional(a), std::optional(b)).value(), i);
1791+
EXPECT_TRUE(
1792+
Rect::Intersection(std::optional(a), std::optional(b)).has_value());
1793+
EXPECT_EQ(Rect::Intersection(std::optional(a), std::optional(b)).value(),
1794+
i);
17931795
};
17941796

17951797
test2(a, b, Rect::MakeLTRB(100, 100, 110, 110));
@@ -2117,11 +2119,11 @@ TEST(GeometryTest, RectProject) {
21172119
TEST(GeometryTest, RectRoundOut) {
21182120
{
21192121
auto r = Rect::MakeLTRB(-100, -100, 100, 100);
2120-
ASSERT_EQ(RoundOut(r), r);
2122+
ASSERT_EQ(Rect::RoundOut(r), r);
21212123
}
21222124
{
21232125
auto r = Rect::MakeLTRB(-100.1, -100.1, 100.1, 100.1);
2124-
ASSERT_EQ(RoundOut(r), Rect::MakeLTRB(-101, -101, 101, 101));
2126+
ASSERT_EQ(Rect::RoundOut(r), Rect::MakeLTRB(-101, -101, 101, 101));
21252127
}
21262128
}
21272129

impeller/geometry/rect.h

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -325,45 +325,48 @@ struct TRect {
325325
TSize<T>(1.0 / static_cast<Scalar>(size.width),
326326
1.0 / static_cast<Scalar>(size.height)));
327327
}
328-
};
329328

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

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

338-
constexpr inline std::optional<Rect> Union(const Rect& a,
339-
const std::optional<Rect> b) {
340-
return b.has_value() ? a.Union(b.value()) : a;
341-
}
339+
constexpr static std::optional<TRect> Union(const std::optional<TRect> a,
340+
const TRect& b) {
341+
return Union(b, a);
342+
}
342343

343-
constexpr inline std::optional<Rect> Union(const std::optional<Rect> a,
344-
const Rect& b) {
345-
return Union(b, a);
346-
}
344+
constexpr static std::optional<TRect> Union(const std::optional<TRect> a,
345+
const std::optional<TRect> b) {
346+
return a.has_value() ? Union(a.value(), b) : b;
347+
}
347348

348-
constexpr inline std::optional<Rect> Union(const std::optional<Rect> a,
349-
const std::optional<Rect> b) {
350-
return a.has_value() ? Union(a.value(), b) : b;
351-
}
349+
constexpr static std::optional<TRect> Intersection(
350+
const TRect& a,
351+
const std::optional<TRect> b) {
352+
return b.has_value() ? a.Intersection(b.value()) : a;
353+
}
352354

353-
constexpr inline std::optional<Rect> Intersection(const Rect& a,
354-
const std::optional<Rect> b) {
355-
return b.has_value() ? a.Intersection(b.value()) : a;
356-
}
355+
constexpr static std::optional<TRect> Intersection(
356+
const std::optional<TRect> a,
357+
const TRect& b) {
358+
return Intersection(b, a);
359+
}
357360

358-
constexpr inline std::optional<Rect> Intersection(const std::optional<Rect> a,
359-
const Rect& b) {
360-
return Intersection(b, a);
361-
}
361+
constexpr static std::optional<TRect> Intersection(
362+
const std::optional<TRect> a,
363+
const std::optional<TRect> b) {
364+
return a.has_value() ? Intersection(a.value(), b) : b;
365+
}
366+
};
362367

363-
constexpr inline std::optional<Rect> Intersection(const std::optional<Rect> a,
364-
const std::optional<Rect> b) {
365-
return a.has_value() ? Intersection(a.value(), b) : b;
366-
}
368+
using Rect = TRect<Scalar>;
369+
using IRect = TRect<int64_t>;
367370

368371
} // namespace impeller
369372

0 commit comments

Comments
 (0)