mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
[Impeller] Add lerps (flutter/engine#36430)
This commit is contained in:
parent
410c81f785
commit
516d2f21d7
@ -965,6 +965,27 @@ TEST(GeometryTest, PointAngleTo) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST(GeometryTest, PointLerp) {
|
||||
Point p(1, 2);
|
||||
Point result = p.Lerp({5, 10}, 0.75);
|
||||
Point expected(4, 8);
|
||||
ASSERT_POINT_NEAR(result, expected);
|
||||
}
|
||||
|
||||
TEST(GeometryTest, Vector3Lerp) {
|
||||
Vector3 p(1, 2, 3);
|
||||
Vector3 result = p.Lerp({5, 10, 15}, 0.75);
|
||||
Vector3 expected(4, 8, 12);
|
||||
ASSERT_VECTOR3_NEAR(result, expected);
|
||||
}
|
||||
|
||||
TEST(GeometryTest, Vector4Lerp) {
|
||||
Vector4 p(1, 2, 3, 4);
|
||||
Vector4 result = p.Lerp({5, 10, 15, 20}, 0.75);
|
||||
Vector4 expected(4, 8, 12, 16);
|
||||
ASSERT_VECTOR4_NEAR(result, expected);
|
||||
}
|
||||
|
||||
TEST(GeometryTest, CanUseVector3AssignmentOperators) {
|
||||
{
|
||||
Vector3 p(1, 2, 4);
|
||||
|
||||
@ -208,6 +208,10 @@ struct TPoint {
|
||||
return Radians{std::atan2(this->Cross(p), this->Dot(p))};
|
||||
}
|
||||
|
||||
constexpr TPoint Lerp(const TPoint& p, Scalar t) const {
|
||||
return *this + (p - *this) * t;
|
||||
}
|
||||
|
||||
constexpr bool IsZero() const { return x == 0 && y == 0; }
|
||||
};
|
||||
|
||||
|
||||
@ -140,6 +140,10 @@ struct Vector3 {
|
||||
return Vector3(x / scale, y / scale, z / scale);
|
||||
}
|
||||
|
||||
constexpr Vector3 Lerp(const Vector3& v, Scalar t) const {
|
||||
return *this + (v - *this) * t;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a linear combination of two vectors and return the result.
|
||||
*
|
||||
@ -224,10 +228,14 @@ struct Vector4 {
|
||||
return Vector4(x - v.x, y - v.y, z - v.z, w - v.w);
|
||||
}
|
||||
|
||||
constexpr Vector4 operator*(float f) const {
|
||||
constexpr Vector4 operator*(Scalar f) const {
|
||||
return Vector4(x * f, y * f, z * f, w * f);
|
||||
}
|
||||
|
||||
constexpr Vector4 Lerp(const Vector4& v, Scalar t) const {
|
||||
return *this + (v - *this) * t;
|
||||
}
|
||||
|
||||
std::string ToString() const;
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user