mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Add assignment operators to point (flutter/engine#26)
This commit is contained in:
parent
f22879f695
commit
55b7b49549
@ -393,6 +393,66 @@ TEST(GeometryTest, SizeCoercesToPoint) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST(GeometryTest, CanUsePointAssignmentOperators) {
|
||||
// Point on RHS
|
||||
{
|
||||
IPoint p(1, 2);
|
||||
p += IPoint(1, 2);
|
||||
ASSERT_EQ(p.x, 2u);
|
||||
ASSERT_EQ(p.y, 4u);
|
||||
}
|
||||
|
||||
{
|
||||
IPoint p(3, 6);
|
||||
p -= IPoint(1, 2);
|
||||
ASSERT_EQ(p.x, 2u);
|
||||
ASSERT_EQ(p.y, 4u);
|
||||
}
|
||||
|
||||
{
|
||||
IPoint p(1, 2);
|
||||
p *= IPoint(2, 3);
|
||||
ASSERT_EQ(p.x, 2u);
|
||||
ASSERT_EQ(p.y, 6u);
|
||||
}
|
||||
|
||||
{
|
||||
IPoint p(2, 6);
|
||||
p /= IPoint(2, 3);
|
||||
ASSERT_EQ(p.x, 1u);
|
||||
ASSERT_EQ(p.y, 2u);
|
||||
}
|
||||
|
||||
// Size on RHS
|
||||
{
|
||||
IPoint p(1, 2);
|
||||
p += ISize(1, 2);
|
||||
ASSERT_EQ(p.x, 2u);
|
||||
ASSERT_EQ(p.y, 4u);
|
||||
}
|
||||
|
||||
{
|
||||
IPoint p(3, 6);
|
||||
p -= ISize(1, 2);
|
||||
ASSERT_EQ(p.x, 2u);
|
||||
ASSERT_EQ(p.y, 4u);
|
||||
}
|
||||
|
||||
{
|
||||
IPoint p(1, 2);
|
||||
p *= ISize(2, 3);
|
||||
ASSERT_EQ(p.x, 2u);
|
||||
ASSERT_EQ(p.y, 6u);
|
||||
}
|
||||
|
||||
{
|
||||
IPoint p(2, 6);
|
||||
p /= ISize(2, 3);
|
||||
ASSERT_EQ(p.x, 1u);
|
||||
ASSERT_EQ(p.y, 2u);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(GeometryTest, CanConvertBetweenDegressAndRadians) {
|
||||
{
|
||||
auto deg = Degrees{90.0};
|
||||
|
||||
@ -45,6 +45,62 @@ struct TPoint {
|
||||
return p.x != x || p.y != y;
|
||||
}
|
||||
|
||||
template <class U>
|
||||
inline TPoint operator+=(const TPoint<U>& p) {
|
||||
x += static_cast<Type>(p.x);
|
||||
y += static_cast<Type>(p.y);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class U>
|
||||
inline TPoint operator+=(const TSize<U>& s) {
|
||||
x += static_cast<Type>(s.width);
|
||||
y += static_cast<Type>(s.height);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class U>
|
||||
inline TPoint operator-=(const TPoint<U>& p) {
|
||||
x -= static_cast<Type>(p.x);
|
||||
y -= static_cast<Type>(p.y);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class U>
|
||||
inline TPoint operator-=(const TSize<U>& s) {
|
||||
x -= static_cast<Type>(s.width);
|
||||
y -= static_cast<Type>(s.height);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class U>
|
||||
inline TPoint operator*=(const TPoint<U>& p) {
|
||||
x *= static_cast<Type>(p.x);
|
||||
y *= static_cast<Type>(p.y);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class U>
|
||||
inline TPoint operator*=(const TSize<U>& s) {
|
||||
x *= static_cast<Type>(s.width);
|
||||
y *= static_cast<Type>(s.height);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class U>
|
||||
inline TPoint operator/=(const TPoint<U>& p) {
|
||||
x /= static_cast<Type>(p.x);
|
||||
y /= static_cast<Type>(p.y);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class U>
|
||||
inline TPoint operator/=(const TSize<U>& s) {
|
||||
x /= static_cast<Type>(s.width);
|
||||
y /= static_cast<Type>(s.height);
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr TPoint operator-() const { return {-x, -y}; }
|
||||
|
||||
constexpr TPoint operator+(const TPoint& p) const {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user