| Flutter Impeller |

geometry_unittests.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "flutter/testing/testing.h"
6 #include "impeller/entity/geometry/geometry.h"
7 #include "impeller/geometry/path_builder.h"
8
9 namespace impeller {
10 namespace testing {
11
12 TEST(EntityGeometryTest, RectGeometryCoversArea) {
13 auto geometry = Geometry::MakeRect(Rect::MakeLTRB(0, 0, 100, 100));
14 ASSERT_TRUE(geometry->CoversArea({}, Rect::MakeLTRB(0, 0, 100, 100)));
15 ASSERT_FALSE(geometry->CoversArea({}, Rect::MakeLTRB(-1, 0, 100, 100)));
16 ASSERT_TRUE(geometry->CoversArea({}, Rect::MakeLTRB(1, 1, 100, 100)));
17 ASSERT_TRUE(geometry->CoversArea({}, Rect()));
18 }
19
20 TEST(EntityGeometryTest, FillPathGeometryCoversArea) {
21 auto path = PathBuilder{}.AddRect(Rect::MakeLTRB(0, 0, 100, 100)).TakePath();
22 auto geometry = Geometry::MakeFillPath(
23 std::move(path), /* inner rect */ Rect::MakeLTRB(0, 0, 100, 100));
24 ASSERT_TRUE(geometry->CoversArea({}, Rect::MakeLTRB(0, 0, 100, 100)));
25 ASSERT_FALSE(geometry->CoversArea({}, Rect::MakeLTRB(-1, 0, 100, 100)));
26 ASSERT_TRUE(geometry->CoversArea({}, Rect::MakeLTRB(1, 1, 100, 100)));
27 ASSERT_TRUE(geometry->CoversArea({}, Rect()));
28 }
29
30 TEST(EntityGeometryTest, FillPathGeometryCoversAreaNoInnerRect) {
31 auto path = PathBuilder{}.AddRect(Rect::MakeLTRB(0, 0, 100, 100)).TakePath();
32 auto geometry = Geometry::MakeFillPath(std::move(path));
33 ASSERT_FALSE(geometry->CoversArea({}, Rect::MakeLTRB(0, 0, 100, 100)));
34 ASSERT_FALSE(geometry->CoversArea({}, Rect::MakeLTRB(-1, 0, 100, 100)));
35 ASSERT_FALSE(geometry->CoversArea({}, Rect::MakeLTRB(1, 1, 100, 100)));
36 ASSERT_FALSE(geometry->CoversArea({}, Rect()));
37 }
38
39 TEST(EntityGeometryTest, LineGeometryCoverage) {
40 {
41 auto geometry = Geometry::MakeLine({10, 10}, {20, 10}, 2, Cap::kButt);
42 EXPECT_EQ(geometry->GetCoverage({}), Rect::MakeLTRB(10, 9, 20, 11));
43 EXPECT_TRUE(geometry->CoversArea({}, Rect::MakeLTRB(10, 9, 20, 11)));
44 }
45
46 {
47 auto geometry = Geometry::MakeLine({10, 10}, {20, 10}, 2, Cap::kSquare);
48 EXPECT_EQ(geometry->GetCoverage({}), Rect::MakeLTRB(9, 9, 21, 11));
49 EXPECT_TRUE(geometry->CoversArea({}, Rect::MakeLTRB(9, 9, 21, 11)));
50 }
51
52 {
53 auto geometry = Geometry::MakeLine({10, 10}, {10, 20}, 2, Cap::kButt);
54 EXPECT_EQ(geometry->GetCoverage({}), Rect::MakeLTRB(9, 10, 11, 20));
55 EXPECT_TRUE(geometry->CoversArea({}, Rect::MakeLTRB(9, 10, 11, 20)));
56 }
57
58 {
59 auto geometry = Geometry::MakeLine({10, 10}, {10, 20}, 2, Cap::kSquare);
60 EXPECT_EQ(geometry->GetCoverage({}), Rect::MakeLTRB(9, 9, 11, 21));
61 EXPECT_TRUE(geometry->CoversArea({}, Rect::MakeLTRB(9, 9, 11, 21)));
62 }
63 }
64
65 TEST(EntityGeometryTest, RoundRectGeometryCoversArea) {
66 auto geometry =
67 Geometry::MakeRoundRect(Rect::MakeLTRB(0, 0, 100, 100), Size(20, 20));
68 EXPECT_FALSE(geometry->CoversArea({}, Rect::MakeLTRB(15, 15, 85, 85)));
69 EXPECT_TRUE(geometry->CoversArea({}, Rect::MakeLTRB(20, 20, 80, 80)));
70 EXPECT_TRUE(geometry->CoversArea({}, Rect::MakeLTRB(30, 1, 70, 99)));
71 EXPECT_TRUE(geometry->CoversArea({}, Rect::MakeLTRB(1, 30, 99, 70)));
72 }
73
74 } // namespace testing
75 } // namespace impeller
impeller::Cap::kSquare
@ kSquare
impeller::Geometry::MakeRoundRect
static std::shared_ptr< Geometry > MakeRoundRect(const Rect &rect, const Size &radii)
Definition: geometry.cc:205
impeller::PathBuilder
Definition: path_builder.h:14
impeller::Size
TSize< Scalar > Size
Definition: size.h:137
impeller::Cap::kButt
@ kButt
impeller::PathBuilder::AddRect
PathBuilder & AddRect(Rect rect)
Definition: path_builder.cc:116
path_builder.h
geometry.h
impeller::testing::TEST
TEST(CanvasRecorder, Save)
Definition: canvas_recorder_unittests.cc:61
impeller::PathBuilder::TakePath
Path TakePath(FillType fill=FillType::kNonZero)
Definition: path_builder.cc:21
impeller::Geometry::MakeFillPath
static std::shared_ptr< Geometry > MakeFillPath(Path path, std::optional< Rect > inner_rect=std::nullopt)
Definition: geometry.cc:150
impeller::Geometry::MakeRect
static std::shared_ptr< Geometry > MakeRect(const Rect &rect)
Definition: geometry.cc:179
impeller::TRect< Scalar >::MakeLTRB
constexpr static TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
Definition: rect.h:27
impeller
Definition: aiks_context.cc:10
impeller::TRect< Scalar >
impeller::Geometry::MakeLine
static std::shared_ptr< Geometry > MakeLine(const Point &p0, const Point &p1, Scalar width, Cap cap)
Definition: geometry.cc:187