10 #include "third_party/googletest/googletest/include/gtest/gtest.h"
17 return std::clamp(
x, 0.f, 1.f);
21 float CalculateLine(
const LineVertexShader::PerVertexData& per_vertex,
23 Vector3 pos = Vector3(position.x, position.y, 1.0);
24 Scalar d[4] = {pos.Dot(per_vertex.e0), pos.Dot(per_vertex.e1),
25 pos.Dot(per_vertex.e2), pos.Dot(per_vertex.e3)};
27 for (
int i = 0; i < 4; ++i) {
33 return lookup(std::min(d[0], d[2])) * lookup(std::min(d[1], d[3]));
39 auto geometry = std::make_unique<LineGeometry>(
46 std::unique_ptr<LineContents> contents =
48 EXPECT_TRUE(contents);
50 std::optional<Rect> coverage = contents->
GetCoverage(entity);
51 EXPECT_TRUE(coverage.has_value());
52 if (coverage.has_value()) {
53 Scalar lip = sqrt((width * width) / 2.f);
60 LineVertexShader::PerVertexData per_vertex[4];
61 auto geometry = std::make_unique<LineGeometry>(
70 fml::StatusOr<LineContents::EffectiveLineParameters> status =
74 ASSERT_TRUE(status.ok());
75 EXPECT_EQ(status.value().width, 5.f);
86 for (
int i = 1; i < 4; ++i) {
93 EXPECT_EQ(CalculateLine(per_vertex[0],
Point(0, 0)), 0.f);
94 EXPECT_NEAR(CalculateLine(per_vertex[0],
Point(150, 100 + offset)), 0.f,
96 EXPECT_NEAR(CalculateLine(per_vertex[0],
Point(150, 100 + offset * 0.5)),
98 EXPECT_NEAR(CalculateLine(per_vertex[0],
Point(150, 100)), 1.f,
106 EXPECT_EQ(
data.size(), 32u);
108 EXPECT_NEAR(
data[1] / 255.f, 0.5f, 0.02);
117 EXPECT_EQ(
data.size(), 32u);
119 EXPECT_NEAR(
data[1] / 255.f, 0.5f, 0.02);
126 LineVertexShader::PerVertexData per_vertex[4];
128 auto geometry = std::make_unique<LineGeometry>(
139 fml::StatusOr<LineContents::EffectiveLineParameters> status =
144 Scalar one_px_size = 1.f / scale;
145 Scalar offset = one_px_size / 2.f + one_radius_size;
146 ASSERT_TRUE(status.ok());
151 Point(100 - one_radius_size, 100 + offset));
153 Point(200 + one_radius_size, 100 + offset));
155 Point(100 - one_radius_size, 100 - offset));
157 Point(200 + one_radius_size, 100 - offset));
159 EXPECT_NEAR(CalculateLine(per_vertex[0],
Point(150, 100)), 1.f,
std::optional< Rect > GetCoverage() const
static std::unique_ptr< LineContents > Make(std::unique_ptr< LineGeometry > geometry, Color color)
static std::vector< uint8_t > CreateCurveData(Scalar width, Scalar radius, Scalar scale)
static const Scalar kSampleRadius
static fml::StatusOr< EffectiveLineParameters > CalculatePerVertex(LineVertexShader::PerVertexData *per_vertex, const LineGeometry *geometry, const Matrix &entity_transform)
#define EXPECT_VECTOR3_NEAR(a, b)
#define EXPECT_POINT_NEAR(a, b)
ScopedObject< Object > Create(CtorArgs &&... args)
TEST(AllocationSizeTest, CanCreateTypedAllocations)
constexpr float kEhCloseEnough
A 4x4 matrix using column-major storage.
static constexpr Matrix MakeTranslation(const Vector3 &t)
static constexpr Matrix MakeScale(const Vector3 &s)
A structure to store all of the parameters related to stroking a path or basic geometry object.
constexpr static TRect MakeXYWH(Type x, Type y, Type width, Type height)
std::shared_ptr< const fml::Mapping > data