Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Typedefs | Functions | Variables
gfx Namespace Reference

Classes

class  Insets
 
class  InsetsF
 
class  Point
 
class  PointF
 
class  Range
 
class  Rect
 
class  RectF
 
class  Size
 
class  SizeF
 
class  Transform
 
class  Vector2d
 
class  Vector2dF
 

Typedefs

typedef struct _UnimplementedNativeViewAccessible UnimplementedNativeViewAccessible
 
typedef UnimplementedNativeViewAccessibleNativeViewAccessible
 
typedef intptr_t NativeViewId
 

Functions

Insets operator+ (Insets lhs, const Insets &rhs)
 
Insets operator- (Insets lhs, const Insets &rhs)
 
InsetsF operator+ (InsetsF lhs, const InsetsF &rhs)
 
InsetsF operator- (InsetsF lhs, const InsetsF &rhs)
 
Point ScaleToCeiledPoint (const Point &point, float x_scale, float y_scale)
 
Point ScaleToCeiledPoint (const Point &point, float scale)
 
Point ScaleToFlooredPoint (const Point &point, float x_scale, float y_scale)
 
Point ScaleToFlooredPoint (const Point &point, float scale)
 
Point ScaleToRoundedPoint (const Point &point, float x_scale, float y_scale)
 
Point ScaleToRoundedPoint (const Point &point, float scale)
 
bool operator== (const Point &lhs, const Point &rhs)
 
bool operator!= (const Point &lhs, const Point &rhs)
 
Point operator+ (const Point &lhs, const Vector2d &rhs)
 
Point operator- (const Point &lhs, const Vector2d &rhs)
 
Vector2d operator- (const Point &lhs, const Point &rhs)
 
Point PointAtOffsetFromOrigin (const Vector2d &offset_from_origin)
 
void PrintTo (const Point &point, ::std::ostream *os)
 
Point ToFlooredPoint (const PointF &point)
 
Point ToCeiledPoint (const PointF &point)
 
Point ToRoundedPoint (const PointF &point)
 
PointF ScalePoint (const PointF &p, float x_scale, float y_scale)
 
bool operator== (const PointF &lhs, const PointF &rhs)
 
bool operator!= (const PointF &lhs, const PointF &rhs)
 
PointF operator+ (const PointF &lhs, const Vector2dF &rhs)
 
PointF operator- (const PointF &lhs, const Vector2dF &rhs)
 
Vector2dF operator- (const PointF &lhs, const PointF &rhs)
 
PointF PointAtOffsetFromOrigin (const Vector2dF &offset_from_origin)
 
PointF ScalePoint (const PointF &p, float scale)
 
void PrintTo (const PointF &point, ::std::ostream *os)
 
 TEST (PointTest, ToPointF)
 
 TEST (PointTest, IsOrigin)
 
 TEST (PointTest, VectorArithmetic)
 
 TEST (PointTest, OffsetFromPoint)
 
 TEST (PointTest, ToRoundedPoint)
 
 TEST (PointTest, Scale)
 
 TEST (PointTest, ClampPoint)
 
 TEST (PointTest, ClampPointF)
 
 TEST (PointTest, Offset)
 
 TEST (PointTest, VectorMath)
 
 TEST (PointTest, IntegerOverflow)
 
void AdjustAlongAxis (int dst_origin, int dst_size, int *origin, int *size)
 
static void SaturatedClampRange (int min, int max, int *origin, int *span)
 
Rect operator+ (const Rect &lhs, const Vector2d &rhs)
 
Rect operator- (const Rect &lhs, const Vector2d &rhs)
 
Rect IntersectRects (const Rect &a, const Rect &b)
 
Rect UnionRects (const Rect &a, const Rect &b)
 
Rect SubtractRects (const Rect &a, const Rect &b)
 
Rect BoundingRect (const Point &p1, const Point &p2)
 
bool operator== (const Rect &lhs, const Rect &rhs)
 
bool operator!= (const Rect &lhs, const Rect &rhs)
 
Rect operator+ (const Vector2d &lhs, const Rect &rhs)
 
Rect ScaleToEnclosingRect (const Rect &rect, float x_scale, float y_scale)
 
Rect ScaleToEnclosingRect (const Rect &rect, float scale)
 
Rect ScaleToEnclosingRectSafe (const Rect &rect, float x_scale, float y_scale)
 
Rect ScaleToEnclosingRectSafe (const Rect &rect, float scale)
 
Rect ScaleToEnclosedRect (const Rect &rect, float x_scale, float y_scale)
 
Rect ScaleToEnclosedRect (const Rect &rect, float scale)
 
Rect ScaleToRoundedRect (const Rect &rect, float x_scale, float y_scale)
 
Rect ScaleToRoundedRect (const Rect &rect, float scale)
 
void PrintTo (const Rect &rect, ::std::ostream *os)
 
Rect ToEnclosingRect (const RectF &r)
 
Rect ToEnclosingRectIgnoringError (const RectF &r, float error)
 
Rect ToEnclosedRect (const RectF &rect)
 
Rect ToEnclosedRectIgnoringError (const RectF &r, float error)
 
Rect ToNearestRect (const RectF &rect)
 
bool IsNearestRectWithinDistance (const gfx::RectF &rect, float distance)
 
gfx::Rect ToRoundedRect (const gfx::RectF &rect)
 
Rect ToFlooredRectDeprecated (const RectF &rect)
 
static void AdjustAlongAxis (float dst_origin, float dst_size, float *origin, float *size)
 
RectF IntersectRects (const RectF &a, const RectF &b)
 
RectF UnionRects (const RectF &a, const RectF &b)
 
RectF SubtractRects (const RectF &a, const RectF &b)
 
RectF BoundingRect (const PointF &p1, const PointF &p2)
 
bool operator== (const RectF &lhs, const RectF &rhs)
 
bool operator!= (const RectF &lhs, const RectF &rhs)
 
RectF operator+ (const RectF &lhs, const Vector2dF &rhs)
 
RectF operator- (const RectF &lhs, const Vector2dF &rhs)
 
RectF operator+ (const Vector2dF &lhs, const RectF &rhs)
 
RectF ScaleRect (const RectF &r, float x_scale, float y_scale)
 
RectF ScaleRect (const RectF &r, float scale)
 
void PrintTo (const RectF &rect, ::std::ostream *os)
 
template<typename T , size_t N>
constexpr size_t size (const T(&array)[N]) noexcept
 
 TEST (RectTest, Contains)
 
 TEST (RectTest, Intersects)
 
 TEST (RectTest, Intersect)
 
 TEST (RectTest, Union)
 
 TEST (RectTest, Equals)
 
 TEST (RectTest, AdjustToFit)
 
 TEST (RectTest, Subtract)
 
 TEST (RectTest, IsEmpty)
 
 TEST (RectTest, SplitVertically)
 
 TEST (RectTest, CenterPoint)
 
 TEST (RectTest, CenterPointF)
 
 TEST (RectTest, SharesEdgeWith)
 
 TEST (RectTest, ScaleRect)
 
 TEST (RectTest, ToEnclosedRect)
 
 TEST (RectTest, ToEnclosingRect)
 
 TEST (RectTest, ToEnclosingRectIgnoringError)
 
 TEST (RectTest, ToNearestRect)
 
 TEST (RectTest, ToFlooredRect)
 
 TEST (RectTest, ScaleToEnclosedRect)
 
 TEST (RectTest, ScaleToEnclosingRect)
 
 TEST (RectTest, ToRectF)
 
 TEST (RectTest, BoundingRect)
 
 TEST (RectTest, IsExpressibleAsRect)
 
 TEST (RectTest, Offset)
 
 TEST (RectTest, Corners)
 
 TEST (RectTest, Centers)
 
 TEST (RectTest, Transpose)
 
 TEST (RectTest, ManhattanDistanceToPoint)
 
 TEST (RectTest, ManhattanInternalDistance)
 
 TEST (RectTest, IntegerOverflow)
 
 TEST (RectTest, ScaleToEnclosingRectSafe)
 
Size ScaleToCeiledSize (const Size &size, float x_scale, float y_scale)
 
Size ScaleToCeiledSize (const Size &size, float scale)
 
Size ScaleToFlooredSize (const Size &size, float x_scale, float y_scale)
 
Size ScaleToFlooredSize (const Size &size, float scale)
 
Size ScaleToRoundedSize (const Size &size, float x_scale, float y_scale)
 
Size ScaleToRoundedSize (const Size &size, float scale)
 
bool operator== (const Size &lhs, const Size &rhs)
 
bool operator!= (const Size &lhs, const Size &rhs)
 
Size operator+ (Size lhs, const Size &rhs)
 
Size operator- (Size lhs, const Size &rhs)
 
void PrintTo (const Size &size, ::std::ostream *os)
 
Size ToFlooredSize (const SizeF &size)
 
Size ToCeiledSize (const SizeF &size)
 
Size ToRoundedSize (const SizeF &size)
 
SizeF ScaleSize (const SizeF &s, float x_scale, float y_scale)
 
bool operator== (const SizeF &lhs, const SizeF &rhs)
 
bool operator!= (const SizeF &lhs, const SizeF &rhs)
 
SizeF ScaleSize (const SizeF &p, float scale)
 
void PrintTo (const SizeF &size, ::std::ostream *os)
 
 TEST (SizeTest, ToSizeF)
 
 TEST (SizeTest, ToFlooredSize)
 
 TEST (SizeTest, ToCeiledSize)
 
 TEST (SizeTest, ToRoundedSize)
 
 TEST (SizeTest, ClampSize)
 
 TEST (SizeTest, ClampSizeF)
 
 TEST (SizeTest, Enlarge)
 
 TEST (SizeTest, IntegerOverflow)
 
 TEST (SizeTest, TrivialDimensionTests)
 
 TEST (SizeTest, ClampsToZero)
 
 TEST (SizeTest, ConsistentClamping)
 
 TEST (SizeTest, StaysSmall)
 
 TEST (SizeTest, OperatorAddSub)
 
 TEST (SizeTest, OperatorAddOverflow)
 
 TEST (SizeTest, OperatorSubClampAtZero)
 
 TEST (SizeTest, OperatorCompare)
 
constexpr Vector2d operator- (const Vector2d &v)
 
Vector2d operator+ (const Vector2d &lhs, const Vector2d &rhs)
 
Vector2d operator- (const Vector2d &lhs, const Vector2d &rhs)
 
void PrintTo (const Vector2d &vector, ::std::ostream *os)
 
Vector2d ToFlooredVector2d (const Vector2dF &vector2d)
 
Vector2d ToCeiledVector2d (const Vector2dF &vector2d)
 
Vector2d ToRoundedVector2d (const Vector2dF &vector2d)
 
double CrossProduct (const Vector2dF &lhs, const Vector2dF &rhs)
 
double DotProduct (const Vector2dF &lhs, const Vector2dF &rhs)
 
Vector2dF ScaleVector2d (const Vector2dF &v, float x_scale, float y_scale)
 
constexpr bool operator== (const Vector2dF &lhs, const Vector2dF &rhs)
 
constexpr bool operator!= (const Vector2dF &lhs, const Vector2dF &rhs)
 
constexpr Vector2dF operator- (const Vector2dF &v)
 
Vector2dF operator+ (const Vector2dF &lhs, const Vector2dF &rhs)
 
Vector2dF operator- (const Vector2dF &lhs, const Vector2dF &rhs)
 
Vector2dF ScaleVector2d (const Vector2dF &v, float scale)
 
void PrintTo (const Vector2dF &vector, ::std::ostream *os)
 
 TEST (Vector2dTest, ConversionToFloat)
 
 TEST (Vector2dTest, IsZero)
 
 TEST (Vector2dTest, Add)
 
 TEST (Vector2dTest, Negative)
 
 TEST (Vector2dTest, Scale)
 
 TEST (Vector2dTest, Length)
 
 TEST (Vector2dTest, ClampVector2d)
 
 TEST (Vector2dTest, ClampVector2dF)
 
 TEST (Vector2dTest, IntegerOverflow)
 
GFX_EXPORT NSRect ScreenRectToNSRect (const Rect &rect)
 
GFX_EXPORT Rect ScreenRectFromNSRect (const NSRect &point)
 
GFX_EXPORT NSPoint ScreenPointToNSPoint (const Point &point)
 
GFX_EXPORT Point ScreenPointFromNSPoint (const NSPoint &point)
 
std::ostream & operator<< (std::ostream &os, const Range &range)
 
::testing::AssertionResult AssertPointFloatEqual (const char *lhs_expr, const char *rhs_expr, const PointF &lhs, const PointF &rhs)
 
::testing::AssertionResult AssertRectFloatEqual (const char *lhs_expr, const char *rhs_expr, const RectF &lhs, const RectF &rhs)
 
::testing::AssertionResult AssertSizeFFloatEqual (const char *lhs_expr, const char *rhs_expr, const SizeF &lhs, const SizeF &rhs)
 
void PrintTo (const Transform &transform, ::std::ostream *os)
 
::testing::AssertionResult AssertAxisTransform2dFloatEqual (const char *lhs_expr, const char *rhs_expr, const AxisTransform2d &lhs, const AxisTransform2d &rhs)
 
::testing::AssertionResult AssertBoxFloatEqual (const char *lhs_expr, const char *rhs_expr, const BoxF &lhs, const BoxF &rhs)
 

Variables

const gfx::NativeCursor kNullCursor = static_cast<gfx::NativeCursor>(nullptr)
 

Typedef Documentation

◆ NativeViewAccessible

Definition at line 225 of file native_widget_types.h.

◆ NativeViewId

typedef intptr_t gfx::NativeViewId

Definition at line 241 of file native_widget_types.h.

◆ UnimplementedNativeViewAccessible

typedef struct _UnimplementedNativeViewAccessible gfx::UnimplementedNativeViewAccessible

Definition at line 224 of file native_widget_types.h.

Function Documentation

◆ AdjustAlongAxis() [1/2]

static void gfx::AdjustAlongAxis ( float  dst_origin,
float  dst_size,
float *  origin,
float *  size 
)
static

Definition at line 24 of file rect_f.cc.

27 {
28 *size = std::min(dst_size, *size);
29 if (*origin < dst_origin)
30 *origin = dst_origin;
31 else
32 *origin = std::min(dst_origin + dst_size, *origin + *size) - *size;
33}

◆ AdjustAlongAxis() [2/2]

void gfx::AdjustAlongAxis ( int  dst_origin,
int  dst_size,
int origin,
int size 
)

Definition at line 49 of file rect.cc.

49 {
50 *size = std::min(dst_size, *size);
51 if (*origin < dst_origin)
52 *origin = dst_origin;
53 else
54 *origin = std::min(dst_origin + dst_size, *origin + *size) - *size;
55}

◆ AssertAxisTransform2dFloatEqual()

::testing::AssertionResult gfx::AssertAxisTransform2dFloatEqual ( const char *  lhs_expr,
const char *  rhs_expr,
const AxisTransform2d &  lhs,
const AxisTransform2d &  rhs 
)

◆ AssertBoxFloatEqual()

::testing::AssertionResult gfx::AssertBoxFloatEqual ( const char *  lhs_expr,
const char *  rhs_expr,
const BoxF &  lhs,
const BoxF &  rhs 
)

◆ AssertPointFloatEqual()

testing::AssertionResult gfx::AssertPointFloatEqual ( const char *  lhs_expr,
const char *  rhs_expr,
const PointF lhs,
const PointF rhs 
)

Definition at line 33 of file gfx_util.cc.

36 {
37 if (FloatAlmostEqual(lhs.x(), rhs.x()) &&
38 FloatAlmostEqual(lhs.y(), rhs.y())) {
39 return ::testing::AssertionSuccess();
40 }
41 return ::testing::AssertionFailure()
42 << "Value of: " << rhs_expr << "\n Actual: " << rhs.ToString()
43 << "\nExpected: " << lhs_expr << "\nWhich is: " << lhs.ToString();
44}
constexpr float x() const
Definition point_f.h:27
std::string ToString() const
Definition point_f.cc:21
constexpr float y() const
Definition point_f.h:28

◆ AssertRectFloatEqual()

testing::AssertionResult gfx::AssertRectFloatEqual ( const char *  lhs_expr,
const char *  rhs_expr,
const RectF lhs,
const RectF rhs 
)

Definition at line 46 of file gfx_util.cc.

49 {
50 if (FloatAlmostEqual(lhs.x(), rhs.x()) &&
51 FloatAlmostEqual(lhs.y(), rhs.y()) &&
52 FloatAlmostEqual(lhs.width(), rhs.width()) &&
53 FloatAlmostEqual(lhs.height(), rhs.height())) {
54 return ::testing::AssertionSuccess();
55 }
56 return ::testing::AssertionFailure()
57 << "Value of: " << rhs_expr << "\n Actual: " << rhs.ToString()
58 << "\nExpected: " << lhs_expr << "\nWhich is: " << lhs.ToString();
59}
constexpr float y() const
Definition rect_f.h:50
constexpr float width() const
Definition rect_f.h:53
std::string ToString() const
Definition rect_f.cc:231
constexpr float height() const
Definition rect_f.h:56
constexpr float x() const
Definition rect_f.h:47

◆ AssertSizeFFloatEqual()

testing::AssertionResult gfx::AssertSizeFFloatEqual ( const char *  lhs_expr,
const char *  rhs_expr,
const SizeF lhs,
const SizeF rhs 
)

Definition at line 61 of file gfx_util.cc.

64 {
65 if (FloatAlmostEqual(lhs.width(), rhs.width()) &&
66 FloatAlmostEqual(lhs.height(), rhs.height())) {
67 return ::testing::AssertionSuccess();
68 }
69 return ::testing::AssertionFailure()
70 << "Value of: " << rhs_expr << "\n Actual: " << rhs.ToString()
71 << "\nExpected: " << lhs_expr << "\nWhich is: " << lhs.ToString();
72}
std::string ToString() const
Definition size_f.cc:29
constexpr float height() const
Definition size_f.h:29
constexpr float width() const
Definition size_f.h:28

◆ BoundingRect() [1/2]

GFX_EXPORT Rect gfx::BoundingRect ( const Point p1,
const Point p2 
)

Definition at line 336 of file rect.cc.

336 {
337 Rect result;
338 result.SetByBounds(std::min(p1.x(), p2.x()), std::min(p1.y(), p2.y()),
339 std::max(p1.x(), p2.x()), std::max(p1.y(), p2.y()));
340 return result;
341}
constexpr int y() const
Definition point.h:49
constexpr int x() const
Definition point.h:48
void SetByBounds(int left, int top, int right, int bottom)
Definition rect.cc:100
GAsyncResult * result

◆ BoundingRect() [2/2]

GFX_EXPORT RectF gfx::BoundingRect ( const PointF p1,
const PointF p2 
)

Definition at line 254 of file rect_f.cc.

254 {
255 float rx = std::min(p1.x(), p2.x());
256 float ry = std::min(p1.y(), p2.y());
257 float rr = std::max(p1.x(), p2.x());
258 float rb = std::max(p1.y(), p2.y());
259 return RectF(rx, ry, rr - rx, rb - ry);
260}

◆ CrossProduct()

GFX_EXPORT double gfx::CrossProduct ( const Vector2dF lhs,
const Vector2dF rhs 
)

Definition at line 44 of file vector2d_f.cc.

44 {
45 return static_cast<double>(lhs.x()) * rhs.y() -
46 static_cast<double>(lhs.y()) * rhs.x();
47}
constexpr float y() const
Definition vector2d_f.h:29
constexpr float x() const
Definition vector2d_f.h:26

◆ DotProduct()

GFX_EXPORT double gfx::DotProduct ( const Vector2dF lhs,
const Vector2dF rhs 
)

Definition at line 49 of file vector2d_f.cc.

49 {
50 return static_cast<double>(lhs.x()) * rhs.x() +
51 static_cast<double>(lhs.y()) * rhs.y();
52}

◆ IntersectRects() [1/2]

GFX_EXPORT Rect gfx::IntersectRects ( const Rect a,
const Rect b 
)

Definition at line 318 of file rect.cc.

318 {
319 Rect result = a;
320 result.Intersect(b);
321 return result;
322}
static bool b
struct MyStruct a[10]

◆ IntersectRects() [2/2]

GFX_EXPORT RectF gfx::IntersectRects ( const RectF a,
const RectF b 
)

Definition at line 236 of file rect_f.cc.

236 {
237 RectF result = a;
238 result.Intersect(b);
239 return result;
240}

◆ IsNearestRectWithinDistance()

GFX_EXPORT bool gfx::IsNearestRectWithinDistance ( const gfx::RectF rect,
float  distance 
)

Definition at line 94 of file rect_conversions.cc.

94 {
95 float float_min_x = rect.x();
96 float float_min_y = rect.y();
97 float float_max_x = rect.right();
98 float float_max_y = rect.bottom();
99
100 int min_x = base::ClampRound(float_min_x);
101 int min_y = base::ClampRound(float_min_y);
102 int max_x = base::ClampRound(float_max_x);
103 int max_y = base::ClampRound(float_max_y);
104
105 return (std::abs(min_x - float_min_x) < distance) &&
106 (std::abs(min_y - float_min_y) < distance) &&
107 (std::abs(max_x - float_max_x) < distance) &&
108 (std::abs(max_y - float_max_y) < distance);
109}
Dst ClampRound(Src value)

◆ operator!=() [1/7]

bool gfx::operator!= ( const Point lhs,
const Point rhs 
)
inline

Definition at line 100 of file point.h.

100 {
101 return !(lhs == rhs);
102}

◆ operator!=() [2/7]

bool gfx::operator!= ( const PointF lhs,
const PointF rhs 
)
inline

Definition at line 87 of file point_f.h.

87 {
88 return !(lhs == rhs);
89}

◆ operator!=() [3/7]

bool gfx::operator!= ( const Rect lhs,
const Rect rhs 
)
inline

Definition at line 243 of file rect.h.

243 {
244 return !(lhs == rhs);
245}

◆ operator!=() [4/7]

bool gfx::operator!= ( const RectF lhs,
const RectF rhs 
)
inline

Definition at line 199 of file rect_f.h.

199 {
200 return !(lhs == rhs);
201}

◆ operator!=() [5/7]

bool gfx::operator!= ( const Size lhs,
const Size rhs 
)
inline

Definition at line 83 of file size.h.

83 {
84 return !(lhs == rhs);
85}

◆ operator!=() [6/7]

bool gfx::operator!= ( const SizeF lhs,
const SizeF rhs 
)
inline

Definition at line 69 of file size_f.h.

69 {
70 return !(lhs == rhs);
71}

◆ operator!=() [7/7]

constexpr bool gfx::operator!= ( const Vector2dF lhs,
const Vector2dF rhs 
)
inlineconstexpr

Definition at line 75 of file vector2d_f.h.

75 {
76 return !(lhs == rhs);
77}

◆ operator+() [1/11]

Point gfx::operator+ ( const Point lhs,
const Vector2d rhs 
)
inline

Definition at line 104 of file point.h.

104 {
105 Point result(lhs);
106 result += rhs;
107 return result;
108}

◆ operator+() [2/11]

PointF gfx::operator+ ( const PointF lhs,
const Vector2dF rhs 
)
inline

Definition at line 91 of file point_f.h.

91 {
92 PointF result(lhs);
93 result += rhs;
94 return result;
95}

◆ operator+() [3/11]

GFX_EXPORT Rect gfx::operator+ ( const Rect lhs,
const Vector2d rhs 
)

Definition at line 306 of file rect.cc.

306 {
307 Rect result(lhs);
308 result += rhs;
309 return result;
310}

◆ operator+() [4/11]

RectF gfx::operator+ ( const RectF lhs,
const Vector2dF rhs 
)
inline

Definition at line 203 of file rect_f.h.

203 {
204 return RectF(lhs.x() + rhs.x(), lhs.y() + rhs.y(), lhs.width(), lhs.height());
205}

◆ operator+() [5/11]

Rect gfx::operator+ ( const Vector2d lhs,
const Rect rhs 
)
inline

Definition at line 250 of file rect.h.

250 {
251 return rhs + lhs;
252}

◆ operator+() [6/11]

Vector2d gfx::operator+ ( const Vector2d lhs,
const Vector2d rhs 
)
inline

Definition at line 79 of file vector2d.h.

79 {
80 Vector2d result = lhs;
81 result.Add(rhs);
82 return result;
83}
void Add(const Vector2d &other)
Definition vector2d.cc:18

◆ operator+() [7/11]

RectF gfx::operator+ ( const Vector2dF lhs,
const RectF rhs 
)
inline

Definition at line 211 of file rect_f.h.

211 {
212 return rhs + lhs;
213}

◆ operator+() [8/11]

Vector2dF gfx::operator+ ( const Vector2dF lhs,
const Vector2dF rhs 
)
inline

Definition at line 83 of file vector2d_f.h.

83 {
84 Vector2dF result = lhs;
85 result.Add(rhs);
86 return result;
87}
void Add(const Vector2dF &other)
Definition vector2d_f.cc:21

◆ operator+() [9/11]

Insets gfx::operator+ ( Insets  lhs,
const Insets rhs 
)
inline

Definition at line 175 of file insets.h.

175 {
176 lhs += rhs;
177 return lhs;
178}

◆ operator+() [10/11]

InsetsF gfx::operator+ ( InsetsF  lhs,
const InsetsF rhs 
)
inline

Definition at line 91 of file insets_f.h.

91 {
92 lhs += rhs;
93 return lhs;
94}

◆ operator+() [11/11]

Size gfx::operator+ ( Size  lhs,
const Size rhs 
)
inline

Definition at line 87 of file size.h.

87 {
88 lhs += rhs;
89 return lhs;
90}

◆ operator-() [1/13]

Vector2d gfx::operator- ( const Point lhs,
const Point rhs 
)
inline

Definition at line 116 of file point.h.

116 {
117 return Vector2d(base::ClampSub(lhs.x(), rhs.x()), base::ClampSub(lhs.y(), rhs.y()));
118}

◆ operator-() [2/13]

Point gfx::operator- ( const Point lhs,
const Vector2d rhs 
)
inline

Definition at line 110 of file point.h.

110 {
111 Point result(lhs);
112 result -= rhs;
113 return result;
114}

◆ operator-() [3/13]

Vector2dF gfx::operator- ( const PointF lhs,
const PointF rhs 
)
inline

Definition at line 103 of file point_f.h.

103 {
104 return Vector2dF(lhs.x() - rhs.x(), lhs.y() - rhs.y());
105}

◆ operator-() [4/13]

PointF gfx::operator- ( const PointF lhs,
const Vector2dF rhs 
)
inline

Definition at line 97 of file point_f.h.

97 {
98 PointF result(lhs);
99 result -= rhs;
100 return result;
101}

◆ operator-() [5/13]

GFX_EXPORT Rect gfx::operator- ( const Rect lhs,
const Vector2d rhs 
)

Definition at line 312 of file rect.cc.

312 {
313 Rect result(lhs);
314 result -= rhs;
315 return result;
316}

◆ operator-() [6/13]

RectF gfx::operator- ( const RectF lhs,
const Vector2dF rhs 
)
inline

Definition at line 207 of file rect_f.h.

207 {
208 return RectF(lhs.x() - rhs.x(), lhs.y() - rhs.y(), lhs.width(), lhs.height());
209}

◆ operator-() [7/13]

Vector2d gfx::operator- ( const Vector2d lhs,
const Vector2d rhs 
)
inline

Definition at line 85 of file vector2d.h.

85 {
86 Vector2d result = lhs;
87 result.Add(-rhs);
88 return result;
89}

◆ operator-() [8/13]

constexpr Vector2d gfx::operator- ( const Vector2d v)
inlineconstexpr

Definition at line 75 of file vector2d.h.

75 {
76 return Vector2d(-v.x(), -v.y());
77}
constexpr int x() const
Definition vector2d.h:27
constexpr int y() const
Definition vector2d.h:30

◆ operator-() [9/13]

Vector2dF gfx::operator- ( const Vector2dF lhs,
const Vector2dF rhs 
)
inline

Definition at line 89 of file vector2d_f.h.

89 {
90 Vector2dF result = lhs;
91 result.Add(-rhs);
92 return result;
93}

◆ operator-() [10/13]

constexpr Vector2dF gfx::operator- ( const Vector2dF v)
inlineconstexpr

Definition at line 79 of file vector2d_f.h.

79 {
80 return Vector2dF(-v.x(), -v.y());
81}

◆ operator-() [11/13]

Insets gfx::operator- ( Insets  lhs,
const Insets rhs 
)
inline

Definition at line 180 of file insets.h.

180 {
181 lhs -= rhs;
182 return lhs;
183}

◆ operator-() [12/13]

InsetsF gfx::operator- ( InsetsF  lhs,
const InsetsF rhs 
)
inline

Definition at line 96 of file insets_f.h.

96 {
97 lhs -= rhs;
98 return lhs;
99}

◆ operator-() [13/13]

Size gfx::operator- ( Size  lhs,
const Size rhs 
)
inline

Definition at line 92 of file size.h.

92 {
93 lhs -= rhs;
94 return lhs;
95}

◆ operator<<()

GFX_RANGE_EXPORT std::ostream & gfx::operator<< ( std::ostream &  os,
const Range range 
)

Definition at line 18 of file range.cc.

18 {
19 return os << range.ToString();
20}
std::string ToString() const
Definition range.cc:14

◆ operator==() [1/7]

bool gfx::operator== ( const Point lhs,
const Point rhs 
)
inline

Definition at line 96 of file point.h.

96 {
97 return lhs.x() == rhs.x() && lhs.y() == rhs.y();
98}

◆ operator==() [2/7]

bool gfx::operator== ( const PointF lhs,
const PointF rhs 
)
inline

Definition at line 83 of file point_f.h.

83 {
84 return lhs.x() == rhs.x() && lhs.y() == rhs.y();
85}

◆ operator==() [3/7]

bool gfx::operator== ( const Rect lhs,
const Rect rhs 
)
inline

Definition at line 239 of file rect.h.

239 {
240 return lhs.origin() == rhs.origin() && lhs.size() == rhs.size();
241}
constexpr const Point & origin() const
Definition rect.h:82
constexpr const Size & size() const
Definition rect.h:90

◆ operator==() [4/7]

bool gfx::operator== ( const RectF lhs,
const RectF rhs 
)
inline

Definition at line 195 of file rect_f.h.

195 {
196 return lhs.origin() == rhs.origin() && lhs.size() == rhs.size();
197}
constexpr const PointF & origin() const
Definition rect_f.h:59
constexpr const SizeF & size() const
Definition rect_f.h:62

◆ operator==() [5/7]

bool gfx::operator== ( const Size lhs,
const Size rhs 
)
inline

Definition at line 79 of file size.h.

79 {
80 return lhs.width() == rhs.width() && lhs.height() == rhs.height();
81}
constexpr int height() const
Definition size.h:50
constexpr int width() const
Definition size.h:49

◆ operator==() [6/7]

bool gfx::operator== ( const SizeF lhs,
const SizeF rhs 
)
inline

Definition at line 65 of file size_f.h.

65 {
66 return lhs.width() == rhs.width() && lhs.height() == rhs.height();
67}

◆ operator==() [7/7]

constexpr bool gfx::operator== ( const Vector2dF lhs,
const Vector2dF rhs 
)
inlineconstexpr

Definition at line 71 of file vector2d_f.h.

71 {
72 return lhs.x() == rhs.x() && lhs.y() == rhs.y();
73}

◆ PointAtOffsetFromOrigin() [1/2]

Point gfx::PointAtOffsetFromOrigin ( const Vector2d offset_from_origin)
inline

Definition at line 120 of file point.h.

120 {
121 return Point(offset_from_origin.x(), offset_from_origin.y());
122}

◆ PointAtOffsetFromOrigin() [2/2]

PointF gfx::PointAtOffsetFromOrigin ( const Vector2dF offset_from_origin)
inline

Definition at line 107 of file point_f.h.

107 {
108 return PointF(offset_from_origin.x(), offset_from_origin.y());
109}

◆ PrintTo() [1/9]

void gfx::PrintTo ( const Point point,
::std::ostream *  os 
)

Definition at line 74 of file gfx_util.cc.

74 {
75 *os << point.ToString();
76}
std::string ToString() const
Definition point.cc:63

◆ PrintTo() [2/9]

void gfx::PrintTo ( const PointF point,
::std::ostream *  os 
)

Definition at line 78 of file gfx_util.cc.

78 {
79 *os << point.ToString();
80}

◆ PrintTo() [3/9]

void gfx::PrintTo ( const Rect rect,
::std::ostream *  os 
)

Definition at line 82 of file gfx_util.cc.

82 {
83 *os << rect.ToString();
84}

◆ PrintTo() [4/9]

void gfx::PrintTo ( const RectF rect,
::std::ostream *  os 
)

Definition at line 86 of file gfx_util.cc.

86 {
87 *os << rect.ToString();
88}

◆ PrintTo() [5/9]

void gfx::PrintTo ( const Size size,
::std::ostream *  os 
)

Definition at line 90 of file gfx_util.cc.

90 {
91 *os << size.ToString();
92}

◆ PrintTo() [6/9]

void gfx::PrintTo ( const SizeF size,
::std::ostream *  os 
)

Definition at line 94 of file gfx_util.cc.

94 {
95 *os << size.ToString();
96}

◆ PrintTo() [7/9]

void gfx::PrintTo ( const Transform transform,
::std::ostream *  os 
)

Definition at line 98 of file gfx_util.cc.

98 {
99 *os << transform.ToString();
100}
static SkColor4f transform(SkColor4f c, SkColorSpace *src, SkColorSpace *dst)
Definition p3.cpp:47

◆ PrintTo() [8/9]

void gfx::PrintTo ( const Vector2d vector,
::std::ostream *  os 
)

Definition at line 102 of file gfx_util.cc.

102 {
103 *os << vector.ToString();
104}
std::string ToString() const
Definition vector2d.cc:36

◆ PrintTo() [9/9]

void gfx::PrintTo ( const Vector2dF vector,
::std::ostream *  os 
)

Definition at line 106 of file gfx_util.cc.

106 {
107 *os << vector.ToString();
108}
std::string ToString() const
Definition vector2d_f.cc:13

◆ SaturatedClampRange()

static void gfx::SaturatedClampRange ( int  min,
int  max,
int origin,
int span 
)
static

Definition at line 63 of file rect.cc.

63 {
64 if (max < min) {
65 *span = 0;
66 *origin = min;
67 return;
68 }
69
70 int effective_span = base::ClampSub(max, min);
71 int span_loss = base::ClampSub(max, min + effective_span);
72
73 // If the desired width is within the limits of ints, we can just
74 // use the simple computations to represent the range precisely.
75 if (span_loss == 0) {
76 *span = effective_span;
77 *origin = min;
78 return;
79 }
80
81 // Now we have to approximate. If one of min or max is close enough
82 // to zero we choose to represent that one precisely. The other side is
83 // probably practically "infinite", so we move it.
84 constexpr unsigned kMaxDimension = std::numeric_limits<int>::max() / 2;
85 if (base::SafeUnsignedAbs(max) < kMaxDimension) {
86 // Maintain origin + span == max.
87 *span = effective_span;
88 *origin = max - effective_span;
89 } else if (base::SafeUnsignedAbs(min) < kMaxDimension) {
90 // Maintain origin == min.
91 *span = effective_span;
92 *origin = min;
93 } else {
94 // Both are big, so keep the center.
95 *span = effective_span;
96 *origin = min + span_loss / 2;
97 }
98}
static float max(float r, float g, float b)
Definition hsl.cpp:49
static float min(float r, float g, float b)
Definition hsl.cpp:48

◆ ScalePoint() [1/2]

PointF gfx::ScalePoint ( const PointF p,
float  scale 
)
inline

Definition at line 113 of file point_f.h.

113 {
114 return ScalePoint(p, scale, scale);
115}
PointF ScalePoint(const PointF &p, float x_scale, float y_scale)
Definition point_f.cc:25
const Scalar scale

◆ ScalePoint() [2/2]

GFX_EXPORT PointF gfx::ScalePoint ( const PointF p,
float  x_scale,
float  y_scale 
)

Definition at line 25 of file point_f.cc.

25 {
26 PointF scaled_p(p);
27 scaled_p.Scale(x_scale, y_scale);
28 return scaled_p;
29}

◆ ScaleRect() [1/2]

RectF gfx::ScaleRect ( const RectF r,
float  scale 
)
inline

Definition at line 223 of file rect_f.h.

223 {
224 return ScaleRect(r, scale, scale);
225}
RectF ScaleRect(const RectF &r, float x_scale, float y_scale)
Definition rect_f.h:219

◆ ScaleRect() [2/2]

RectF gfx::ScaleRect ( const RectF r,
float  x_scale,
float  y_scale 
)
inline

Definition at line 219 of file rect_f.h.

219 {
220 return RectF(r.x() * x_scale, r.y() * y_scale, r.width() * x_scale, r.height() * y_scale);
221}

◆ ScaleSize() [1/2]

SizeF gfx::ScaleSize ( const SizeF p,
float  scale 
)
inline

Definition at line 75 of file size_f.h.

75 {
76 return ScaleSize(p, scale, scale);
77}
SizeF ScaleSize(const SizeF &s, float x_scale, float y_scale)
Definition size_f.cc:33

◆ ScaleSize() [2/2]

GFX_EXPORT SizeF gfx::ScaleSize ( const SizeF s,
float  x_scale,
float  y_scale 
)

Definition at line 33 of file size_f.cc.

33 {
34 SizeF scaled_s(s);
35 scaled_s.Scale(x_scale, y_scale);
36 return scaled_s;
37}
struct MyStruct s

◆ ScaleToCeiledPoint() [1/2]

GFX_EXPORT Point gfx::ScaleToCeiledPoint ( const Point point,
float  scale 
)

Definition at line 73 of file point.cc.

73 {
74 if (scale == 1.f)
75 return point;
77}
Point ToCeiledPoint(const PointF &point)

◆ ScaleToCeiledPoint() [2/2]

GFX_EXPORT Point gfx::ScaleToCeiledPoint ( const Point point,
float  x_scale,
float  y_scale 
)

Definition at line 67 of file point.cc.

67 {
68 if (x_scale == 1.f && y_scale == 1.f)
69 return point;
70 return ToCeiledPoint(ScalePoint(gfx::PointF(point), x_scale, y_scale));
71}

◆ ScaleToCeiledSize() [1/2]

GFX_EXPORT Size gfx::ScaleToCeiledSize ( const Size size,
float  scale 
)

Definition at line 90 of file size.cc.

90 {
91 if (scale == 1.f)
92 return size;
94}
Size ToCeiledSize(const SizeF &size)

◆ ScaleToCeiledSize() [2/2]

GFX_EXPORT Size gfx::ScaleToCeiledSize ( const Size size,
float  x_scale,
float  y_scale 
)

Definition at line 84 of file size.cc.

84 {
85 if (x_scale == 1.f && y_scale == 1.f)
86 return size;
87 return ToCeiledSize(ScaleSize(gfx::SizeF(size), x_scale, y_scale));
88}

◆ ScaleToEnclosedRect() [1/2]

Rect gfx::ScaleToEnclosedRect ( const Rect rect,
float  scale 
)
inline

Definition at line 323 of file rect.h.

323 {
324 return ScaleToEnclosedRect(rect, scale, scale);
325}
Rect ScaleToEnclosedRect(const Rect &rect, float x_scale, float y_scale)
Definition rect.h:309

◆ ScaleToEnclosedRect() [2/2]

Rect gfx::ScaleToEnclosedRect ( const Rect rect,
float  x_scale,
float  y_scale 
)
inline

Definition at line 309 of file rect.h.

309 {
310 if (x_scale == 1.f && y_scale == 1.f)
311 return rect;
312 BASE_DCHECK(base::IsValueInRangeForNumericType<int>(std::ceil(rect.x() * x_scale)));
313 BASE_DCHECK(base::IsValueInRangeForNumericType<int>(std::ceil(rect.y() * y_scale)));
314 BASE_DCHECK(base::IsValueInRangeForNumericType<int>(std::floor(rect.right() * x_scale)));
315 BASE_DCHECK(base::IsValueInRangeForNumericType<int>(std::floor(rect.bottom() * y_scale)));
316 int x = static_cast<int>(std::ceil(rect.x() * x_scale));
317 int y = static_cast<int>(std::ceil(rect.y() * y_scale));
318 int r = rect.width() == 0 ? x : static_cast<int>(std::floor(rect.right() * x_scale));
319 int b = rect.height() == 0 ? y : static_cast<int>(std::floor(rect.bottom() * y_scale));
320 return Rect(x, y, r - x, b - y);
321}
double y
double x
#define BASE_DCHECK(condition)
Definition logging.h:63

◆ ScaleToEnclosingRect() [1/2]

Rect gfx::ScaleToEnclosingRect ( const Rect rect,
float  scale 
)
inline

Definition at line 287 of file rect.h.

287 {
288 return ScaleToEnclosingRect(rect, scale, scale);
289}
Rect ScaleToEnclosingRect(const Rect &rect, float x_scale, float y_scale)
Definition rect.h:269

◆ ScaleToEnclosingRect() [2/2]

Rect gfx::ScaleToEnclosingRect ( const Rect rect,
float  x_scale,
float  y_scale 
)
inline

Definition at line 269 of file rect.h.

269 {
270 if (x_scale == 1.f && y_scale == 1.f)
271 return rect;
272 // These next functions cast instead of using e.g. base::ClampFloor() because
273 // we haven't checked to ensure that the clamping behavior of the helper
274 // functions doesn't degrade performance, and callers shouldn't be passing
275 // values that cause overflow anyway.
276 BASE_DCHECK(base::IsValueInRangeForNumericType<int>(std::floor(rect.x() * x_scale)));
277 BASE_DCHECK(base::IsValueInRangeForNumericType<int>(std::floor(rect.y() * y_scale)));
278 BASE_DCHECK(base::IsValueInRangeForNumericType<int>(std::ceil(rect.right() * x_scale)));
279 BASE_DCHECK(base::IsValueInRangeForNumericType<int>(std::ceil(rect.bottom() * y_scale)));
280 int x = static_cast<int>(std::floor(rect.x() * x_scale));
281 int y = static_cast<int>(std::floor(rect.y() * y_scale));
282 int r = rect.width() == 0 ? x : static_cast<int>(std::ceil(rect.right() * x_scale));
283 int b = rect.height() == 0 ? y : static_cast<int>(std::ceil(rect.bottom() * y_scale));
284 return Rect(x, y, r - x, b - y);
285}

◆ ScaleToEnclosingRectSafe() [1/2]

Rect gfx::ScaleToEnclosingRectSafe ( const Rect rect,
float  scale 
)
inline

Definition at line 305 of file rect.h.

305 {
306 return ScaleToEnclosingRectSafe(rect, scale, scale);
307}
Rect ScaleToEnclosingRectSafe(const Rect &rect, float x_scale, float y_scale)
Definition rect.h:295

◆ ScaleToEnclosingRectSafe() [2/2]

Rect gfx::ScaleToEnclosingRectSafe ( const Rect rect,
float  x_scale,
float  y_scale 
)
inline

Definition at line 295 of file rect.h.

295 {
296 if (x_scale == 1.f && y_scale == 1.f)
297 return rect;
298 int x = base::ClampFloor(rect.x() * x_scale);
299 int y = base::ClampFloor(rect.y() * y_scale);
300 int w = base::ClampCeil(rect.width() * x_scale);
301 int h = base::ClampCeil(rect.height() * y_scale);
302 return Rect(x, y, w, h);
303}
Dst ClampFloor(Src value)
Dst ClampCeil(Src value)
SkScalar w
SkScalar h

◆ ScaleToFlooredPoint() [1/2]

GFX_EXPORT Point gfx::ScaleToFlooredPoint ( const Point point,
float  scale 
)

Definition at line 85 of file point.cc.

85 {
86 if (scale == 1.f)
87 return point;
89}
Point ToFlooredPoint(const PointF &point)

◆ ScaleToFlooredPoint() [2/2]

GFX_EXPORT Point gfx::ScaleToFlooredPoint ( const Point point,
float  x_scale,
float  y_scale 
)

Definition at line 79 of file point.cc.

79 {
80 if (x_scale == 1.f && y_scale == 1.f)
81 return point;
82 return ToFlooredPoint(ScalePoint(gfx::PointF(point), x_scale, y_scale));
83}

◆ ScaleToFlooredSize() [1/2]

GFX_EXPORT Size gfx::ScaleToFlooredSize ( const Size size,
float  scale 
)

Definition at line 102 of file size.cc.

102 {
103 if (scale == 1.f)
104 return size;
106}
Size ToFlooredSize(const SizeF &size)

◆ ScaleToFlooredSize() [2/2]

GFX_EXPORT Size gfx::ScaleToFlooredSize ( const Size size,
float  x_scale,
float  y_scale 
)

Definition at line 96 of file size.cc.

96 {
97 if (x_scale == 1.f && y_scale == 1.f)
98 return size;
99 return ToFlooredSize(ScaleSize(gfx::SizeF(size), x_scale, y_scale));
100}

◆ ScaleToRoundedPoint() [1/2]

GFX_EXPORT Point gfx::ScaleToRoundedPoint ( const Point point,
float  scale 
)

Definition at line 97 of file point.cc.

97 {
98 if (scale == 1.f)
99 return point;
101}
Point ToRoundedPoint(const PointF &point)

◆ ScaleToRoundedPoint() [2/2]

GFX_EXPORT Point gfx::ScaleToRoundedPoint ( const Point point,
float  x_scale,
float  y_scale 
)

Definition at line 91 of file point.cc.

91 {
92 if (x_scale == 1.f && y_scale == 1.f)
93 return point;
94 return ToRoundedPoint(ScalePoint(gfx::PointF(point), x_scale, y_scale));
95}

◆ ScaleToRoundedRect() [1/2]

Rect gfx::ScaleToRoundedRect ( const Rect rect,
float  scale 
)
inline

Definition at line 350 of file rect.h.

350 {
351 return ScaleToRoundedRect(rect, scale, scale);
352}
Rect ScaleToRoundedRect(const Rect &rect, float x_scale, float y_scale)
Definition rect.h:333

◆ ScaleToRoundedRect() [2/2]

Rect gfx::ScaleToRoundedRect ( const Rect rect,
float  x_scale,
float  y_scale 
)
inline

Definition at line 333 of file rect.h.

333 {
334 if (x_scale == 1.f && y_scale == 1.f)
335 return rect;
336
337 BASE_DCHECK(base::IsValueInRangeForNumericType<int>(std::round(rect.x() * x_scale)));
338 BASE_DCHECK(base::IsValueInRangeForNumericType<int>(std::round(rect.y() * y_scale)));
339 BASE_DCHECK(base::IsValueInRangeForNumericType<int>(std::round(rect.right() * x_scale)));
340 BASE_DCHECK(base::IsValueInRangeForNumericType<int>(std::round(rect.bottom() * y_scale)));
341
342 int x = static_cast<int>(std::round(rect.x() * x_scale));
343 int y = static_cast<int>(std::round(rect.y() * y_scale));
344 int r = rect.width() == 0 ? x : static_cast<int>(std::round(rect.right() * x_scale));
345 int b = rect.height() == 0 ? y : static_cast<int>(std::round(rect.bottom() * y_scale));
346
347 return Rect(x, y, r - x, b - y);
348}

◆ ScaleToRoundedSize() [1/2]

GFX_EXPORT Size gfx::ScaleToRoundedSize ( const Size size,
float  scale 
)

Definition at line 114 of file size.cc.

114 {
115 if (scale == 1.f)
116 return size;
118}
Size ToRoundedSize(const SizeF &size)

◆ ScaleToRoundedSize() [2/2]

GFX_EXPORT Size gfx::ScaleToRoundedSize ( const Size size,
float  x_scale,
float  y_scale 
)

Definition at line 108 of file size.cc.

108 {
109 if (x_scale == 1.f && y_scale == 1.f)
110 return size;
111 return ToRoundedSize(ScaleSize(gfx::SizeF(size), x_scale, y_scale));
112}

◆ ScaleVector2d() [1/2]

Vector2dF gfx::ScaleVector2d ( const Vector2dF v,
float  scale 
)
inline

Definition at line 108 of file vector2d_f.h.

108 {
109 return ScaleVector2d(v, scale, scale);
110}
Vector2dF ScaleVector2d(const Vector2dF &v, float x_scale, float y_scale)
Definition vector2d_f.cc:54

◆ ScaleVector2d() [2/2]

GFX_EXPORT Vector2dF gfx::ScaleVector2d ( const Vector2dF v,
float  x_scale,
float  y_scale 
)

Definition at line 54 of file vector2d_f.cc.

54 {
55 Vector2dF scaled_v(v);
56 scaled_v.Scale(x_scale, y_scale);
57 return scaled_v;
58}

◆ ScreenPointFromNSPoint()

Point gfx::ScreenPointFromNSPoint ( const NSPoint &  point)

Definition at line 38 of file coordinate_conversion.mm.

38 {
39 return Point(point.x, PrimaryDisplayHeight() - point.y);
40}

◆ ScreenPointToNSPoint()

NSPoint gfx::ScreenPointToNSPoint ( const Point point)

Definition at line 34 of file coordinate_conversion.mm.

34 {
35 return NSMakePoint(point.x(), PrimaryDisplayHeight() - point.y());
36}

◆ ScreenRectFromNSRect()

Rect gfx::ScreenRectFromNSRect ( const NSRect &  point)

Definition at line 29 of file coordinate_conversion.mm.

29 {
30 return Rect(rect.origin.x, PrimaryDisplayHeight() - rect.origin.y - rect.size.height,
31 rect.size.width, rect.size.height);
32}

◆ ScreenRectToNSRect()

NSRect gfx::ScreenRectToNSRect ( const Rect rect)

Definition at line 24 of file coordinate_conversion.mm.

24 {
25 return NSMakeRect(rect.x(), PrimaryDisplayHeight() - rect.y() - rect.height(), rect.width(),
26 rect.height());
27}

◆ size()

template<typename T , size_t N>
constexpr size_t gfx::size ( const T(&)  array[N])
constexprnoexcept

Definition at line 21 of file rect_unittest.cc.

21 {
22 return N;
23}
#define N
Definition beziers.cpp:19

◆ SubtractRects() [1/2]

GFX_EXPORT Rect gfx::SubtractRects ( const Rect a,
const Rect b 
)

Definition at line 330 of file rect.cc.

330 {
331 Rect result = a;
332 result.Subtract(b);
333 return result;
334}

◆ SubtractRects() [2/2]

GFX_EXPORT RectF gfx::SubtractRects ( const RectF a,
const RectF b 
)

Definition at line 248 of file rect_f.cc.

248 {
249 RectF result = a;
250 result.Subtract(b);
251 return result;
252}

◆ TEST() [1/67]

gfx::TEST ( PointTest  ,
ClampPoint   
)

Definition at line 108 of file point_unittest.cc.

108 {
109 Point a;
110
111 a = Point(3, 5);
112 EXPECT_EQ(Point(3, 5).ToString(), a.ToString());
113 a.SetToMax(Point(2, 4));
114 EXPECT_EQ(Point(3, 5).ToString(), a.ToString());
115 a.SetToMax(Point(3, 5));
116 EXPECT_EQ(Point(3, 5).ToString(), a.ToString());
117 a.SetToMax(Point(4, 2));
118 EXPECT_EQ(Point(4, 5).ToString(), a.ToString());
119 a.SetToMax(Point(8, 10));
120 EXPECT_EQ(Point(8, 10).ToString(), a.ToString());
121
122 a.SetToMin(Point(9, 11));
123 EXPECT_EQ(Point(8, 10).ToString(), a.ToString());
124 a.SetToMin(Point(8, 10));
125 EXPECT_EQ(Point(8, 10).ToString(), a.ToString());
126 a.SetToMin(Point(11, 9));
127 EXPECT_EQ(Point(8, 9).ToString(), a.ToString());
128 a.SetToMin(Point(7, 11));
129 EXPECT_EQ(Point(7, 9).ToString(), a.ToString());
130 a.SetToMin(Point(3, 5));
131 EXPECT_EQ(Point(3, 5).ToString(), a.ToString());
132}

◆ TEST() [2/67]

gfx::TEST ( PointTest  ,
ClampPointF   
)

Definition at line 134 of file point_unittest.cc.

134 {
135 PointF a;
136
137 a = PointF(3.5f, 5.5f);
138 EXPECT_EQ(PointF(3.5f, 5.5f).ToString(), a.ToString());
139 a.SetToMax(PointF(2.5f, 4.5f));
140 EXPECT_EQ(PointF(3.5f, 5.5f).ToString(), a.ToString());
141 a.SetToMax(PointF(3.5f, 5.5f));
142 EXPECT_EQ(PointF(3.5f, 5.5f).ToString(), a.ToString());
143 a.SetToMax(PointF(4.5f, 2.5f));
144 EXPECT_EQ(PointF(4.5f, 5.5f).ToString(), a.ToString());
145 a.SetToMax(PointF(8.5f, 10.5f));
146 EXPECT_EQ(PointF(8.5f, 10.5f).ToString(), a.ToString());
147
148 a.SetToMin(PointF(9.5f, 11.5f));
149 EXPECT_EQ(PointF(8.5f, 10.5f).ToString(), a.ToString());
150 a.SetToMin(PointF(8.5f, 10.5f));
151 EXPECT_EQ(PointF(8.5f, 10.5f).ToString(), a.ToString());
152 a.SetToMin(PointF(11.5f, 9.5f));
153 EXPECT_EQ(PointF(8.5f, 9.5f).ToString(), a.ToString());
154 a.SetToMin(PointF(7.5f, 11.5f));
155 EXPECT_EQ(PointF(7.5f, 9.5f).ToString(), a.ToString());
156 a.SetToMin(PointF(3.5f, 5.5f));
157 EXPECT_EQ(PointF(3.5f, 5.5f).ToString(), a.ToString());
158}

◆ TEST() [3/67]

gfx::TEST ( PointTest  ,
IntegerOverflow   
)

Definition at line 176 of file point_unittest.cc.

176 {
177 int int_max = std::numeric_limits<int>::max();
178 int int_min = std::numeric_limits<int>::min();
179
180 Point max_point(int_max, int_max);
181 Point min_point(int_min, int_min);
182 Point test;
183
184 test = Point();
185 test.Offset(int_max, int_max);
186 EXPECT_EQ(test, max_point);
187
188 test = Point();
189 test.Offset(int_min, int_min);
190 EXPECT_EQ(test, min_point);
191
192 test = Point(10, 20);
193 test.Offset(int_max, int_max);
194 EXPECT_EQ(test, max_point);
195
196 test = Point(-10, -20);
197 test.Offset(int_min, int_min);
198 EXPECT_EQ(test, min_point);
199
200 test = Point();
201 test += Vector2d(int_max, int_max);
202 EXPECT_EQ(test, max_point);
203
204 test = Point();
205 test += Vector2d(int_min, int_min);
206 EXPECT_EQ(test, min_point);
207
208 test = Point(10, 20);
209 test += Vector2d(int_max, int_max);
210 EXPECT_EQ(test, max_point);
211
212 test = Point(-10, -20);
213 test += Vector2d(int_min, int_min);
214 EXPECT_EQ(test, min_point);
215
216 test = Point();
217 test -= Vector2d(int_max, int_max);
218 EXPECT_EQ(test, Point(-int_max, -int_max));
219
220 test = Point();
221 test -= Vector2d(int_min, int_min);
222 EXPECT_EQ(test, max_point);
223
224 test = Point(10, 20);
225 test -= Vector2d(int_min, int_min);
226 EXPECT_EQ(test, max_point);
227
228 test = Point(-10, -20);
229 test -= Vector2d(int_max, int_max);
230 EXPECT_EQ(test, min_point);
231}
#define test(name)

◆ TEST() [4/67]

gfx::TEST ( PointTest  ,
IsOrigin   
)

Definition at line 23 of file point_unittest.cc.

23 {
24 EXPECT_FALSE(Point(1, 0).IsOrigin());
25 EXPECT_FALSE(Point(0, 1).IsOrigin());
26 EXPECT_FALSE(Point(1, 2).IsOrigin());
27 EXPECT_FALSE(Point(-1, 0).IsOrigin());
28 EXPECT_FALSE(Point(0, -1).IsOrigin());
29 EXPECT_FALSE(Point(-1, -2).IsOrigin());
30 EXPECT_TRUE(Point(0, 0).IsOrigin());
31
32 EXPECT_FALSE(PointF(0.1f, 0).IsOrigin());
33 EXPECT_FALSE(PointF(0, 0.1f).IsOrigin());
34 EXPECT_FALSE(PointF(0.1f, 2).IsOrigin());
35 EXPECT_FALSE(PointF(-0.1f, 0).IsOrigin());
36 EXPECT_FALSE(PointF(0, -0.1f).IsOrigin());
37 EXPECT_FALSE(PointF(-0.1f, -2).IsOrigin());
38 EXPECT_TRUE(PointF(0, 0).IsOrigin());
39}
#define EXPECT_TRUE(handle)
Definition unit_test.h:685

◆ TEST() [5/67]

gfx::TEST ( PointTest  ,
Offset   
)

Definition at line 160 of file point_unittest.cc.

160 {
161 Point test(3, 4);
162 test.Offset(5, -8);
163 EXPECT_EQ(test, Point(8, -4));
164}

◆ TEST() [6/67]

gfx::TEST ( PointTest  ,
OffsetFromPoint   
)

Definition at line 61 of file point_unittest.cc.

61 {
62 Point a(1, 5);
63 Point b(-20, 8);
64 EXPECT_EQ(Vector2d(-20 - 1, 8 - 5).ToString(), (b - a).ToString());
65}

◆ TEST() [7/67]

gfx::TEST ( PointTest  ,
Scale   
)

Definition at line 87 of file point_unittest.cc.

87 {
88 EXPECT_EQ(PointF().ToString(), ScalePoint(PointF(), 2).ToString());
89 EXPECT_EQ(PointF().ToString(), ScalePoint(PointF(), 2, 2).ToString());
90
91 EXPECT_EQ(PointF(2, -2).ToString(), ScalePoint(PointF(1, -1), 2).ToString());
92 EXPECT_EQ(PointF(2, -2).ToString(),
93 ScalePoint(PointF(1, -1), 2, 2).ToString());
94
95 PointF zero;
96 PointF one(1, -1);
97
98 zero.Scale(2);
99 zero.Scale(3, 1.5);
100
101 one.Scale(2);
102 one.Scale(3, 1.5);
103
104 EXPECT_EQ(PointF().ToString(), zero.ToString());
105 EXPECT_EQ(PointF(6, -3).ToString(), one.ToString());
106}
void Scale(float scale)
Definition point_f.h:69

◆ TEST() [8/67]

gfx::TEST ( PointTest  ,
ToPointF   
)

Definition at line 14 of file point_unittest.cc.

14 {
15 // Check that explicit conversion from integer to float compiles.
16 Point a(10, 20);
17 PointF b = PointF(a);
18
19 EXPECT_EQ(static_cast<float>(a.x()), b.x());
20 EXPECT_EQ(static_cast<float>(a.y()), b.y());
21}

◆ TEST() [9/67]

gfx::TEST ( PointTest  ,
ToRoundedPoint   
)

Definition at line 67 of file point_unittest.cc.

67 {
68 EXPECT_EQ(Point(0, 0), ToRoundedPoint(PointF(0, 0)));
69 EXPECT_EQ(Point(0, 0), ToRoundedPoint(PointF(0.0001f, 0.0001f)));
70 EXPECT_EQ(Point(0, 0), ToRoundedPoint(PointF(0.4999f, 0.4999f)));
71 EXPECT_EQ(Point(1, 1), ToRoundedPoint(PointF(0.5f, 0.5f)));
72 EXPECT_EQ(Point(1, 1), ToRoundedPoint(PointF(0.9999f, 0.9999f)));
73
74 EXPECT_EQ(Point(10, 10), ToRoundedPoint(PointF(10, 10)));
75 EXPECT_EQ(Point(10, 10), ToRoundedPoint(PointF(10.0001f, 10.0001f)));
76 EXPECT_EQ(Point(10, 10), ToRoundedPoint(PointF(10.4999f, 10.4999f)));
77 EXPECT_EQ(Point(11, 11), ToRoundedPoint(PointF(10.5f, 10.5f)));
78 EXPECT_EQ(Point(11, 11), ToRoundedPoint(PointF(10.9999f, 10.9999f)));
79
80 EXPECT_EQ(Point(-10, -10), ToRoundedPoint(PointF(-10, -10)));
81 EXPECT_EQ(Point(-10, -10), ToRoundedPoint(PointF(-10.0001f, -10.0001f)));
82 EXPECT_EQ(Point(-10, -10), ToRoundedPoint(PointF(-10.4999f, -10.4999f)));
83 EXPECT_EQ(Point(-11, -11), ToRoundedPoint(PointF(-10.5f, -10.5f)));
84 EXPECT_EQ(Point(-11, -11), ToRoundedPoint(PointF(-10.9999f, -10.9999f)));
85}

◆ TEST() [10/67]

gfx::TEST ( PointTest  ,
VectorArithmetic   
)

Definition at line 41 of file point_unittest.cc.

41 {
42 Point a(1, 5);
43 Vector2d v1(3, -3);
44 Vector2d v2(-8, 1);
45
46 static const struct {
47 Point expected;
48 Point actual;
49 } tests[] = {{Point(4, 2), a + v1},
50 {Point(-2, 8), a - v1},
51 {a, a - v1 + v1},
52 {a, a + v1 - v1},
53 {a, a + Vector2d()},
54 {Point(12, 1), a + v1 - v2},
55 {Point(-10, 9), a - v1 + v2}};
56
57 for (size_t i = 0; i < 7; ++i)
58 EXPECT_EQ(tests[i].expected.ToString(), tests[i].actual.ToString());
59}
static BlurTest tests[]
Definition BlurTest.cpp:84
Vec2Value v2
TPoint< Scalar > Point
Definition point.h:316

◆ TEST() [11/67]

gfx::TEST ( PointTest  ,
VectorMath   
)

Definition at line 166 of file point_unittest.cc.

166 {
167 Point test = Point(3, 4);
168 test += Vector2d(5, -8);
169 EXPECT_EQ(test, Point(8, -4));
170
171 Point test2 = Point(3, 4);
172 test2 -= Vector2d(5, -8);
173 EXPECT_EQ(test2, Point(-2, 12));
174}

◆ TEST() [12/67]

gfx::TEST ( RectTest  ,
AdjustToFit   
)

Definition at line 164 of file rect_unittest.cc.

164 {
165 static const struct Test {
166 int x1; // source
167 int y1;
168 int w1;
169 int h1;
170 int x2; // target
171 int y2;
172 int w2;
173 int h2;
174 int x3; // rect 3: results of invoking AdjustToFit
175 int y3;
176 int w3;
177 int h3;
178 } tests[] = {{0, 0, 2, 2, 0, 0, 2, 2, 0, 0, 2, 2},
179 {2, 2, 3, 3, 0, 0, 4, 4, 1, 1, 3, 3},
180 {-1, -1, 5, 5, 0, 0, 4, 4, 0, 0, 4, 4},
181 {2, 2, 4, 4, 0, 0, 3, 3, 0, 0, 3, 3},
182 {2, 2, 1, 1, 0, 0, 3, 3, 2, 2, 1, 1}};
183 for (size_t i = 0; i < size(tests); ++i) {
184 Rect r1(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1);
185 Rect r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2);
186 Rect r3(tests[i].x3, tests[i].y3, tests[i].w3, tests[i].h3);
187 Rect u = r1;
188 u.AdjustToFit(r2);
189 EXPECT_EQ(r3.x(), u.x());
190 EXPECT_EQ(r3.y(), u.y());
191 EXPECT_EQ(r3.width(), u.width());
192 EXPECT_EQ(r3.height(), u.height());
193 }
194}
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition switches.h:259
TRect< Scalar > Rect
Definition rect.h:746

◆ TEST() [13/67]

gfx::TEST ( RectTest  ,
BoundingRect   
)

Definition at line 760 of file rect_unittest.cc.

760 {
761 struct {
762 Point a;
763 Point b;
764 Rect expected;
765 } int_tests[] = {
766 // If point B dominates A, then A should be the origin.
767 {Point(4, 6), Point(4, 6), Rect(4, 6, 0, 0)},
768 {Point(4, 6), Point(8, 6), Rect(4, 6, 4, 0)},
769 {Point(4, 6), Point(4, 9), Rect(4, 6, 0, 3)},
770 {Point(4, 6), Point(8, 9), Rect(4, 6, 4, 3)},
771 // If point A dominates B, then B should be the origin.
772 {Point(4, 6), Point(4, 6), Rect(4, 6, 0, 0)},
773 {Point(8, 6), Point(4, 6), Rect(4, 6, 4, 0)},
774 {Point(4, 9), Point(4, 6), Rect(4, 6, 0, 3)},
775 {Point(8, 9), Point(4, 6), Rect(4, 6, 4, 3)},
776 // If neither point dominates, then the origin is a combination of the
777 // two.
778 {Point(4, 6), Point(6, 4), Rect(4, 4, 2, 2)},
779 {Point(-4, -6), Point(-6, -4), Rect(-6, -6, 2, 2)},
780 {Point(-4, 6), Point(6, -4), Rect(-4, -4, 10, 10)},
781 };
782
783 for (size_t i = 0; i < size(int_tests); ++i) {
784 Rect actual = BoundingRect(int_tests[i].a, int_tests[i].b);
785 EXPECT_EQ(int_tests[i].expected, actual);
786 }
787
788 struct {
789 PointF a;
790 PointF b;
791 RectF expected;
792 } float_tests[] = {
793 // If point B dominates A, then A should be the origin.
794 {PointF(4.2f, 6.8f), PointF(4.2f, 6.8f), RectF(4.2f, 6.8f, 0, 0)},
795 {PointF(4.2f, 6.8f), PointF(8.5f, 6.8f), RectF(4.2f, 6.8f, 4.3f, 0)},
796 {PointF(4.2f, 6.8f), PointF(4.2f, 9.3f), RectF(4.2f, 6.8f, 0, 2.5f)},
797 {PointF(4.2f, 6.8f), PointF(8.5f, 9.3f), RectF(4.2f, 6.8f, 4.3f, 2.5f)},
798 // If point A dominates B, then B should be the origin.
799 {PointF(4.2f, 6.8f), PointF(4.2f, 6.8f), RectF(4.2f, 6.8f, 0, 0)},
800 {PointF(8.5f, 6.8f), PointF(4.2f, 6.8f), RectF(4.2f, 6.8f, 4.3f, 0)},
801 {PointF(4.2f, 9.3f), PointF(4.2f, 6.8f), RectF(4.2f, 6.8f, 0, 2.5f)},
802 {PointF(8.5f, 9.3f), PointF(4.2f, 6.8f), RectF(4.2f, 6.8f, 4.3f, 2.5f)},
803 // If neither point dominates, then the origin is a combination of the
804 // two.
805 {PointF(4.2f, 6.8f), PointF(6.8f, 4.2f), RectF(4.2f, 4.2f, 2.6f, 2.6f)},
806 {PointF(-4.2f, -6.8f), PointF(-6.8f, -4.2f),
807 RectF(-6.8f, -6.8f, 2.6f, 2.6f)},
808 {PointF(-4.2f, 6.8f), PointF(6.8f, -4.2f),
809 RectF(-4.2f, -4.2f, 11.0f, 11.0f)}};
810
811 for (size_t i = 0; i < size(float_tests); ++i) {
812 RectF actual = BoundingRect(float_tests[i].a, float_tests[i].b);
813 EXPECT_RECTF_EQ(float_tests[i].expected, actual);
814 }
815}
#define EXPECT_RECTF_EQ(a, b)
Definition gfx_util.h:46
Rect BoundingRect(const Point &p1, const Point &p2)
Definition rect.cc:336

◆ TEST() [14/67]

gfx::TEST ( RectTest  ,
CenterPoint   
)

Definition at line 297 of file rect_unittest.cc.

297 {
299
300 // When origin is (0, 0).
301 center = Rect(0, 0, 20, 20).CenterPoint();
302 EXPECT_TRUE(center == Point(10, 10));
303
304 // When origin is even.
305 center = Rect(10, 10, 20, 20).CenterPoint();
306 EXPECT_TRUE(center == Point(20, 20));
307
308 // When origin is odd.
309 center = Rect(11, 11, 20, 20).CenterPoint();
310 EXPECT_TRUE(center == Point(21, 21));
311
312 // When 0 width or height.
313 center = Rect(10, 10, 0, 20).CenterPoint();
314 EXPECT_TRUE(center == Point(10, 20));
315 center = Rect(10, 10, 20, 0).CenterPoint();
316 EXPECT_TRUE(center == Point(20, 10));
317
318 // When an odd size.
319 center = Rect(10, 10, 21, 21).CenterPoint();
320 EXPECT_TRUE(center == Point(20, 20));
321
322 // When an odd size and position.
323 center = Rect(11, 11, 21, 21).CenterPoint();
324 EXPECT_TRUE(center == Point(21, 21));
325}
static SkScalar center(float pos0, float pos1)
Point CenterPoint() const
Definition rect.cc:244

◆ TEST() [15/67]

gfx::TEST ( RectTest  ,
CenterPointF   
)

Definition at line 327 of file rect_unittest.cc.

327 {
329
330 // When origin is (0, 0).
331 center = RectF(0, 0, 20, 20).CenterPoint();
332 EXPECT_TRUE(center == PointF(10, 10));
333
334 // When origin is even.
335 center = RectF(10, 10, 20, 20).CenterPoint();
336 EXPECT_TRUE(center == PointF(20, 20));
337
338 // When origin is odd.
339 center = RectF(11, 11, 20, 20).CenterPoint();
340 EXPECT_TRUE(center == PointF(21, 21));
341
342 // When 0 width or height.
343 center = RectF(10, 10, 0, 20).CenterPoint();
344 EXPECT_TRUE(center == PointF(10, 20));
345 center = RectF(10, 10, 20, 0).CenterPoint();
346 EXPECT_TRUE(center == PointF(20, 10));
347
348 // When an odd size.
349 center = RectF(10, 10, 21, 21).CenterPoint();
350 EXPECT_TRUE(center == PointF(20.5f, 20.5f));
351
352 // When an odd size and position.
353 center = RectF(11, 11, 21, 21).CenterPoint();
354 EXPECT_TRUE(center == PointF(21.5f, 21.5f));
355}
PointF CenterPoint() const
Definition rect_f.cc:171

◆ TEST() [16/67]

gfx::TEST ( RectTest  ,
Centers   
)

Definition at line 883 of file rect_unittest.cc.

883 {
884 Rect i(10, 20, 30, 40);
885 EXPECT_EQ(Point(10, 40), i.left_center());
886 EXPECT_EQ(Point(25, 20), i.top_center());
887 EXPECT_EQ(Point(40, 40), i.right_center());
888 EXPECT_EQ(Point(25, 60), i.bottom_center());
889
890 RectF f(10.1f, 20.2f, 30.3f, 40.4f);
891 EXPECT_EQ(PointF(10.1f, 40.4f), f.left_center());
892 EXPECT_EQ(PointF(25.25f, 20.2f), f.top_center());
893 EXPECT_EQ(PointF(40.4f, 40.4f), f.right_center());
894 EXPECT_EQ(25.25f, f.bottom_center().x());
895 EXPECT_NEAR(60.6f, f.bottom_center().y(), 0.001f);
896}

◆ TEST() [17/67]

gfx::TEST ( RectTest  ,
Contains   
)

Definition at line 25 of file rect_unittest.cc.

25 {
26 static const struct ContainsCase {
27 int rect_x;
28 int rect_y;
29 int rect_width;
30 int rect_height;
31 int point_x;
32 int point_y;
33 bool contained;
34 } contains_cases[] = {
35 {0, 0, 10, 10, 0, 0, true},
36 {0, 0, 10, 10, 5, 5, true},
37 {0, 0, 10, 10, 9, 9, true},
38 {0, 0, 10, 10, 5, 10, false},
39 {0, 0, 10, 10, 10, 5, false},
40 {0, 0, 10, 10, -1, -1, false},
41 {0, 0, 10, 10, 50, 50, false},
42#if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
43 {0, 0, -10, -10, 0, 0, false},
44#endif
45 };
46 for (size_t i = 0; i < size(contains_cases); ++i) {
47 const ContainsCase& value = contains_cases[i];
48 Rect rect(value.rect_x, value.rect_y, value.rect_width, value.rect_height);
49 EXPECT_EQ(value.contained, rect.Contains(value.point_x, value.point_y));
50 }
51}
uint8_t value
sk_sp< SkBlender > blender SkRect rect
Definition SkRecords.h:350

◆ TEST() [18/67]

gfx::TEST ( RectTest  ,
Corners   
)

Definition at line 868 of file rect_unittest.cc.

868 {
869 Rect i(1, 2, 3, 4);
870 RectF f(1.1f, 2.1f, 3.1f, 4.1f);
871
872 EXPECT_EQ(Point(1, 2), i.origin());
873 EXPECT_EQ(Point(4, 2), i.top_right());
874 EXPECT_EQ(Point(1, 6), i.bottom_left());
875 EXPECT_EQ(Point(4, 6), i.bottom_right());
876
877 EXPECT_EQ(PointF(1.1f, 2.1f), f.origin());
878 EXPECT_EQ(PointF(4.2f, 2.1f), f.top_right());
879 EXPECT_EQ(PointF(1.1f, 6.2f), f.bottom_left());
880 EXPECT_EQ(PointF(4.2f, 6.2f), f.bottom_right());
881}

◆ TEST() [19/67]

gfx::TEST ( RectTest  ,
Equals   
)

Definition at line 155 of file rect_unittest.cc.

155 {
156 ASSERT_TRUE(Rect(0, 0, 0, 0) == Rect(0, 0, 0, 0));
157 ASSERT_TRUE(Rect(1, 2, 3, 4) == Rect(1, 2, 3, 4));
158 ASSERT_FALSE(Rect(0, 0, 0, 0) == Rect(0, 0, 0, 1));
159 ASSERT_FALSE(Rect(0, 0, 0, 0) == Rect(0, 0, 1, 0));
160 ASSERT_FALSE(Rect(0, 0, 0, 0) == Rect(0, 1, 0, 0));
161 ASSERT_FALSE(Rect(0, 0, 0, 0) == Rect(1, 0, 0, 0));
162}

◆ TEST() [20/67]

gfx::TEST ( RectTest  ,
IntegerOverflow   
)

Definition at line 971 of file rect_unittest.cc.

971 {
972 int limit = std::numeric_limits<int>::max();
973 int min_limit = std::numeric_limits<int>::min();
974 int expected = 10;
975 int large_number = limit - expected;
976
977 Rect height_overflow(0, large_number, 100, 100);
978 EXPECT_EQ(large_number, height_overflow.y());
979 EXPECT_EQ(expected, height_overflow.height());
980
981 Rect width_overflow(large_number, 0, 100, 100);
982 EXPECT_EQ(large_number, width_overflow.x());
983 EXPECT_EQ(expected, width_overflow.width());
984
985 Rect size_height_overflow(Point(0, large_number), Size(100, 100));
986 EXPECT_EQ(large_number, size_height_overflow.y());
987 EXPECT_EQ(expected, size_height_overflow.height());
988
989 Rect size_width_overflow(Point(large_number, 0), Size(100, 100));
990 EXPECT_EQ(large_number, size_width_overflow.x());
991 EXPECT_EQ(expected, size_width_overflow.width());
992
993 Rect set_height_overflow(0, large_number, 100, 5);
994 EXPECT_EQ(5, set_height_overflow.height());
995 set_height_overflow.set_height(100);
996 EXPECT_EQ(expected, set_height_overflow.height());
997
998 Rect set_y_overflow(100, 100, 100, 100);
999 EXPECT_EQ(100, set_y_overflow.height());
1000 set_y_overflow.set_y(large_number);
1001 EXPECT_EQ(expected, set_y_overflow.height());
1002
1003 Rect set_width_overflow(large_number, 0, 5, 100);
1004 EXPECT_EQ(5, set_width_overflow.width());
1005 set_width_overflow.set_width(100);
1006 EXPECT_EQ(expected, set_width_overflow.width());
1007
1008 Rect set_x_overflow(100, 100, 100, 100);
1009 EXPECT_EQ(100, set_x_overflow.width());
1010 set_x_overflow.set_x(large_number);
1011 EXPECT_EQ(expected, set_x_overflow.width());
1012
1013 Point large_offset(large_number, large_number);
1014 Size size(100, 100);
1015 Size expected_size(10, 10);
1016
1017 Rect set_origin_overflow(100, 100, 100, 100);
1018 EXPECT_EQ(size, set_origin_overflow.size());
1019 set_origin_overflow.set_origin(large_offset);
1020 EXPECT_EQ(large_offset, set_origin_overflow.origin());
1021 EXPECT_EQ(expected_size, set_origin_overflow.size());
1022
1023 Rect set_size_overflow(large_number, large_number, 5, 5);
1024 EXPECT_EQ(Size(5, 5), set_size_overflow.size());
1025 set_size_overflow.set_size(size);
1026 EXPECT_EQ(large_offset, set_size_overflow.origin());
1027 EXPECT_EQ(expected_size, set_size_overflow.size());
1028
1029 Rect set_rect_overflow;
1030 set_rect_overflow.SetRect(large_number, large_number, 100, 100);
1031 EXPECT_EQ(large_offset, set_rect_overflow.origin());
1032 EXPECT_EQ(expected_size, set_rect_overflow.size());
1033
1034 // Insetting an empty rect, but the total inset (left + right) could overflow.
1035 Rect inset_overflow;
1036 inset_overflow.Inset(large_number, large_number, 100, 100);
1037 EXPECT_EQ(large_offset, inset_overflow.origin());
1038 EXPECT_EQ(gfx::Size(), inset_overflow.size());
1039
1040 // Insetting where the total inset (width - left - right) could overflow.
1041 // Also, this insetting by the min limit in all directions cannot
1042 // represent width() without overflow, so that will also clamp.
1043 Rect inset_overflow2;
1044 inset_overflow2.Inset(min_limit, min_limit, min_limit, min_limit);
1045 EXPECT_EQ(inset_overflow2, gfx::Rect(min_limit, min_limit, limit, limit));
1046
1047 // Insetting where the width shouldn't change, but if the insets operations
1048 // clamped in the wrong order, e.g. ((width - left) - right) vs (width - (left
1049 // + right)) then this will not work properly. This is the proper order,
1050 // as if left + right overflows, the width cannot be decreased by more than
1051 // max int anyway. Additionally, if left + right underflows, it cannot be
1052 // increased by more then max int.
1053 Rect inset_overflow3(0, 0, limit, limit);
1054 inset_overflow3.Inset(-100, -100, 100, 100);
1055 EXPECT_EQ(inset_overflow3, gfx::Rect(-100, -100, limit, limit));
1056
1057 Rect inset_overflow4(-1000, -1000, limit, limit);
1058 inset_overflow4.Inset(100, 100, -100, -100);
1059 EXPECT_EQ(inset_overflow4, gfx::Rect(-900, -900, limit, limit));
1060
1061 Rect offset_overflow(0, 0, 100, 100);
1062 offset_overflow.Offset(large_number, large_number);
1063 EXPECT_EQ(large_offset, offset_overflow.origin());
1064 EXPECT_EQ(expected_size, offset_overflow.size());
1065
1066 Rect operator_overflow(0, 0, 100, 100);
1067 operator_overflow += Vector2d(large_number, large_number);
1068 EXPECT_EQ(large_offset, operator_overflow.origin());
1069 EXPECT_EQ(expected_size, operator_overflow.size());
1070
1071 Rect origin_maxint(limit, limit, limit, limit);
1072 EXPECT_EQ(origin_maxint, Rect(gfx::Point(limit, limit), gfx::Size()));
1073
1074 // Expect a rect at the origin and a rect whose right/bottom is maxint
1075 // create a rect that extends from 0..maxint in both extents.
1076 {
1077 Rect origin_small(0, 0, 100, 100);
1078 Rect big_clamped(50, 50, limit, limit);
1079 EXPECT_EQ(big_clamped.right(), limit);
1080
1081 Rect unioned = UnionRects(origin_small, big_clamped);
1082 Rect rect_limit(0, 0, limit, limit);
1083 EXPECT_EQ(unioned, rect_limit);
1084 }
1085
1086 // Expect a rect that would overflow width (but not right) to be clamped
1087 // and to have maxint extents after unioning.
1088 {
1089 Rect small(-500, -400, 100, 100);
1090 Rect big(-400, -500, limit, limit);
1091 // Technically, this should be limit + 100 width, but will clamp to maxint.
1092 EXPECT_EQ(UnionRects(small, big), Rect(-500, -500, limit, limit));
1093 }
1094
1095 // Expect a rect that would overflow right *and* width to be clamped.
1096 {
1097 Rect clamped(500, 500, limit, limit);
1098 Rect positive_origin(100, 100, 500, 500);
1099
1100 // Ideally, this should be (100, 100, limit + 400, limit + 400).
1101 // However, width overflows and would be clamped to limit, but right
1102 // overflows too and so will be clamped to limit - 100.
1103 Rect expected(100, 100, limit - 100, limit - 100);
1104 EXPECT_EQ(UnionRects(clamped, positive_origin), expected);
1105 }
1106
1107 // Unioning a left=minint rect with a right=maxint rect.
1108 // We can't represent both ends of the spectrum in the same rect.
1109 // Make sure we keep the most useful area.
1110 {
1111 int part_limit = min_limit / 3;
1112 Rect left_minint(min_limit, min_limit, 1, 1);
1113 Rect right_maxint(limit - 1, limit - 1, limit, limit);
1114 Rect expected(part_limit, part_limit, 2 * part_limit, 2 * part_limit);
1115 Rect result = UnionRects(left_minint, right_maxint);
1116
1117 // The result should be maximally big.
1118 EXPECT_EQ(limit, result.height());
1119 EXPECT_EQ(limit, result.width());
1120
1121 // The result should include the area near the origin.
1122 EXPECT_GT(-part_limit, result.x());
1123 EXPECT_LT(part_limit, result.right());
1124 EXPECT_GT(-part_limit, result.y());
1125 EXPECT_LT(part_limit, result.bottom());
1126
1127 // More succinctly, but harder to read in the results.
1128 EXPECT_TRUE(UnionRects(left_minint, right_maxint).Contains(expected));
1129 }
1130}
void Inset(int horizontal, int vertical)
Definition rect.h:123
void SetRect(int x, int y, int width, int height)
Definition rect.h:110
bool Contains(const Container &container, const Value &value)
Rect UnionRects(const Rect &a, const Rect &b)
Definition rect.cc:324

◆ TEST() [21/67]

gfx::TEST ( RectTest  ,
Intersect   
)

Definition at line 82 of file rect_unittest.cc.

82 {
83 static const struct {
84 int x1; // rect 1
85 int y1;
86 int w1;
87 int h1;
88 int x2; // rect 2
89 int y2;
90 int w2;
91 int h2;
92 int x3; // rect 3: the union of rects 1 and 2
93 int y3;
94 int w3;
95 int h3;
96 } tests[] = {{0, 0, 0, 0, // zeros
97 0, 0, 0, 0, 0, 0, 0, 0},
98 {0, 0, 4, 4, // equal
99 0, 0, 4, 4, 0, 0, 4, 4},
100 {0, 0, 4, 4, // neighboring
101 4, 4, 4, 4, 0, 0, 0, 0},
102 {0, 0, 4, 4, // overlapping corners
103 2, 2, 4, 4, 2, 2, 2, 2},
104 {0, 0, 4, 4, // T junction
105 3, 1, 4, 2, 3, 1, 1, 2},
106 {3, 0, 2, 2, // gap
107 0, 0, 2, 2, 0, 0, 0, 0}};
108 for (size_t i = 0; i < size(tests); ++i) {
109 Rect r1(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1);
110 Rect r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2);
111 Rect r3(tests[i].x3, tests[i].y3, tests[i].w3, tests[i].h3);
112 Rect ir = IntersectRects(r1, r2);
113 EXPECT_EQ(r3.x(), ir.x());
114 EXPECT_EQ(r3.y(), ir.y());
115 EXPECT_EQ(r3.width(), ir.width());
116 EXPECT_EQ(r3.height(), ir.height());
117 }
118}
Rect IntersectRects(const Rect &a, const Rect &b)
Definition rect.cc:318

◆ TEST() [22/67]

gfx::TEST ( RectTest  ,
Intersects   
)

Definition at line 53 of file rect_unittest.cc.

53 {
54 static const struct {
55 int x1; // rect 1
56 int y1;
57 int w1;
58 int h1;
59 int x2; // rect 2
60 int y2;
61 int w2;
62 int h2;
63 bool intersects;
64 } tests[] = {{0, 0, 0, 0, 0, 0, 0, 0, false},
65 {0, 0, 0, 0, -10, -10, 20, 20, false},
66 {-10, 0, 0, 20, 0, -10, 20, 0, false},
67 {0, 0, 10, 10, 0, 0, 10, 10, true},
68 {0, 0, 10, 10, 10, 10, 10, 10, false},
69 {10, 10, 10, 10, 0, 0, 10, 10, false},
70 {10, 10, 10, 10, 5, 5, 10, 10, true},
71 {10, 10, 10, 10, 15, 15, 10, 10, true},
72 {10, 10, 10, 10, 20, 15, 10, 10, false},
73 {10, 10, 10, 10, 21, 15, 10, 10, false}};
74 for (size_t i = 0; i < size(tests); ++i) {
75 Rect r1(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1);
76 Rect r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2);
77 EXPECT_EQ(tests[i].intersects, r1.Intersects(r2));
78 EXPECT_EQ(tests[i].intersects, r2.Intersects(r1));
79 }
80}

◆ TEST() [23/67]

gfx::TEST ( RectTest  ,
IsEmpty   
)

Definition at line 262 of file rect_unittest.cc.

262 {
263 EXPECT_TRUE(Rect(0, 0, 0, 0).IsEmpty());
264 EXPECT_TRUE(Rect(0, 0, 0, 0).size().IsEmpty());
265 EXPECT_TRUE(Rect(0, 0, 10, 0).IsEmpty());
266 EXPECT_TRUE(Rect(0, 0, 10, 0).size().IsEmpty());
267 EXPECT_TRUE(Rect(0, 0, 0, 10).IsEmpty());
268 EXPECT_TRUE(Rect(0, 0, 0, 10).size().IsEmpty());
269 EXPECT_FALSE(Rect(0, 0, 10, 10).IsEmpty());
270 EXPECT_FALSE(Rect(0, 0, 10, 10).size().IsEmpty());
271}

◆ TEST() [24/67]

gfx::TEST ( RectTest  ,
IsExpressibleAsRect   
)

Definition at line 817 of file rect_unittest.cc.

817 {
818 EXPECT_TRUE(RectF().IsExpressibleAsRect());
819
820 float min = static_cast<float>(std::numeric_limits<int>::min());
821 float max = static_cast<float>(std::numeric_limits<int>::max());
822 float infinity = std::numeric_limits<float>::infinity();
823
825 RectF(min + 200, min + 200, max - 200, max - 200).IsExpressibleAsRect());
826 EXPECT_FALSE(
827 RectF(min - 200, min + 200, max + 200, max + 200).IsExpressibleAsRect());
828 EXPECT_FALSE(
829 RectF(min + 200, min - 200, max + 200, max + 200).IsExpressibleAsRect());
830 EXPECT_FALSE(
831 RectF(min + 200, min + 200, max + 200, max - 200).IsExpressibleAsRect());
832 EXPECT_FALSE(
833 RectF(min + 200, min + 200, max - 200, max + 200).IsExpressibleAsRect());
834
835 EXPECT_TRUE(RectF(0, 0, max - 200, max - 200).IsExpressibleAsRect());
836 EXPECT_FALSE(RectF(200, 0, max + 200, max - 200).IsExpressibleAsRect());
837 EXPECT_FALSE(RectF(0, 200, max - 200, max + 200).IsExpressibleAsRect());
838 EXPECT_FALSE(RectF(0, 0, max + 200, max - 200).IsExpressibleAsRect());
839 EXPECT_FALSE(RectF(0, 0, max - 200, max + 200).IsExpressibleAsRect());
840
841 EXPECT_FALSE(RectF(infinity, 0, 1, 1).IsExpressibleAsRect());
842 EXPECT_FALSE(RectF(0, infinity, 1, 1).IsExpressibleAsRect());
843 EXPECT_FALSE(RectF(0, 0, infinity, 1).IsExpressibleAsRect());
844 EXPECT_FALSE(RectF(0, 0, 1, infinity).IsExpressibleAsRect());
845}

◆ TEST() [25/67]

gfx::TEST ( RectTest  ,
ManhattanDistanceToPoint   
)

Definition at line 908 of file rect_unittest.cc.

908 {
909 Rect i(1, 2, 3, 4);
910 EXPECT_EQ(0, i.ManhattanDistanceToPoint(Point(1, 2)));
911 EXPECT_EQ(0, i.ManhattanDistanceToPoint(Point(4, 6)));
912 EXPECT_EQ(0, i.ManhattanDistanceToPoint(Point(2, 4)));
913 EXPECT_EQ(3, i.ManhattanDistanceToPoint(Point(0, 0)));
914 EXPECT_EQ(2, i.ManhattanDistanceToPoint(Point(2, 0)));
915 EXPECT_EQ(3, i.ManhattanDistanceToPoint(Point(5, 0)));
916 EXPECT_EQ(1, i.ManhattanDistanceToPoint(Point(5, 4)));
917 EXPECT_EQ(3, i.ManhattanDistanceToPoint(Point(5, 8)));
918 EXPECT_EQ(2, i.ManhattanDistanceToPoint(Point(3, 8)));
919 EXPECT_EQ(2, i.ManhattanDistanceToPoint(Point(0, 7)));
920 EXPECT_EQ(1, i.ManhattanDistanceToPoint(Point(0, 3)));
921
922 RectF f(1.1f, 2.1f, 3.1f, 4.1f);
923 EXPECT_FLOAT_EQ(0.f, f.ManhattanDistanceToPoint(PointF(1.1f, 2.1f)));
924 EXPECT_FLOAT_EQ(0.f, f.ManhattanDistanceToPoint(PointF(4.2f, 6.f)));
925 EXPECT_FLOAT_EQ(0.f, f.ManhattanDistanceToPoint(PointF(2.f, 4.f)));
926 EXPECT_FLOAT_EQ(3.2f, f.ManhattanDistanceToPoint(PointF(0.f, 0.f)));
927 EXPECT_FLOAT_EQ(2.1f, f.ManhattanDistanceToPoint(PointF(2.f, 0.f)));
928 EXPECT_FLOAT_EQ(2.9f, f.ManhattanDistanceToPoint(PointF(5.f, 0.f)));
929 EXPECT_FLOAT_EQ(.8f, f.ManhattanDistanceToPoint(PointF(5.f, 4.f)));
930 EXPECT_FLOAT_EQ(2.6f, f.ManhattanDistanceToPoint(PointF(5.f, 8.f)));
931 EXPECT_FLOAT_EQ(1.8f, f.ManhattanDistanceToPoint(PointF(3.f, 8.f)));
932 EXPECT_FLOAT_EQ(1.9f, f.ManhattanDistanceToPoint(PointF(0.f, 7.f)));
933 EXPECT_FLOAT_EQ(1.1f, f.ManhattanDistanceToPoint(PointF(0.f, 3.f)));
934}

◆ TEST() [26/67]

gfx::TEST ( RectTest  ,
ManhattanInternalDistance   
)

Definition at line 936 of file rect_unittest.cc.

936 {
937 Rect i(0, 0, 400, 400);
938 EXPECT_EQ(0, i.ManhattanInternalDistance(gfx::Rect(-1, 0, 2, 1)));
939 EXPECT_EQ(1, i.ManhattanInternalDistance(gfx::Rect(400, 0, 1, 400)));
940 EXPECT_EQ(2, i.ManhattanInternalDistance(gfx::Rect(-100, -100, 100, 100)));
941 EXPECT_EQ(2, i.ManhattanInternalDistance(gfx::Rect(-101, 100, 100, 100)));
942 EXPECT_EQ(4, i.ManhattanInternalDistance(gfx::Rect(-101, -101, 100, 100)));
943 EXPECT_EQ(435, i.ManhattanInternalDistance(gfx::Rect(630, 603, 100, 100)));
944
945 RectF f(0.0f, 0.0f, 400.0f, 400.0f);
946 static const float kEpsilon = std::numeric_limits<float>::epsilon();
947
948 EXPECT_FLOAT_EQ(
949 0.0f, f.ManhattanInternalDistance(gfx::RectF(-1.0f, 0.0f, 2.0f, 1.0f)));
950 EXPECT_FLOAT_EQ(kEpsilon, f.ManhattanInternalDistance(
951 gfx::RectF(400.0f, 0.0f, 1.0f, 400.0f)));
952 EXPECT_FLOAT_EQ(2.0f * kEpsilon, f.ManhattanInternalDistance(gfx::RectF(
953 -100.0f, -100.0f, 100.0f, 100.0f)));
954 EXPECT_FLOAT_EQ(1.0f + kEpsilon, f.ManhattanInternalDistance(gfx::RectF(
955 -101.0f, 100.0f, 100.0f, 100.0f)));
956 EXPECT_FLOAT_EQ(2.0f + 2.0f * kEpsilon,
957 f.ManhattanInternalDistance(
958 gfx::RectF(-101.0f, -101.0f, 100.0f, 100.0f)));
959 EXPECT_FLOAT_EQ(
960 433.0f + 2.0f * kEpsilon,
961 f.ManhattanInternalDistance(gfx::RectF(630.0f, 603.0f, 100.0f, 100.0f)));
962
963 EXPECT_FLOAT_EQ(
964 0.0f, f.ManhattanInternalDistance(gfx::RectF(-1.0f, 0.0f, 1.1f, 1.0f)));
965 EXPECT_FLOAT_EQ(0.1f + kEpsilon, f.ManhattanInternalDistance(
966 gfx::RectF(-1.5f, 0.0f, 1.4f, 1.0f)));
967 EXPECT_FLOAT_EQ(kEpsilon, f.ManhattanInternalDistance(
968 gfx::RectF(-1.5f, 0.0f, 1.5f, 1.0f)));
969}
static constexpr double kEpsilon

◆ TEST() [27/67]

gfx::TEST ( RectTest  ,
Offset   
)

Definition at line 847 of file rect_unittest.cc.

847 {
848 Rect i(1, 2, 3, 4);
849
850 EXPECT_EQ(Rect(2, 1, 3, 4), (i + Vector2d(1, -1)));
851 EXPECT_EQ(Rect(2, 1, 3, 4), (Vector2d(1, -1) + i));
852 i += Vector2d(1, -1);
853 EXPECT_EQ(Rect(2, 1, 3, 4), i);
854 EXPECT_EQ(Rect(1, 2, 3, 4), (i - Vector2d(1, -1)));
855 i -= Vector2d(1, -1);
856 EXPECT_EQ(Rect(1, 2, 3, 4), i);
857
858 RectF f(1.1f, 2.2f, 3.3f, 4.4f);
859 EXPECT_EQ(RectF(2.2f, 1.1f, 3.3f, 4.4f), (f + Vector2dF(1.1f, -1.1f)));
860 EXPECT_EQ(RectF(2.2f, 1.1f, 3.3f, 4.4f), (Vector2dF(1.1f, -1.1f) + f));
861 f += Vector2dF(1.1f, -1.1f);
862 EXPECT_EQ(RectF(2.2f, 1.1f, 3.3f, 4.4f), f);
863 EXPECT_EQ(RectF(1.1f, 2.2f, 3.3f, 4.4f), (f - Vector2dF(1.1f, -1.1f)));
864 f -= Vector2dF(1.1f, -1.1f);
865 EXPECT_EQ(RectF(1.1f, 2.2f, 3.3f, 4.4f), f);
866}

◆ TEST() [28/67]

gfx::TEST ( RectTest  ,
ScaleRect   
)

Definition at line 399 of file rect_unittest.cc.

399 {
400 static const struct Test {
401 int x1; // source
402 int y1;
403 int w1;
404 int h1;
405 float scale;
406 float x2; // target
407 float y2;
408 float w2;
409 float h2;
410 } tests[] = {
411 {3, 3, 3, 3, 1.5f, 4.5f, 4.5f, 4.5f, 4.5f},
412 {3, 3, 3, 3, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f},
413 {3, 3, 3, 3, std::numeric_limits<float>::quiet_NaN(),
414 std::numeric_limits<float>::quiet_NaN(),
415 std::numeric_limits<float>::quiet_NaN(),
416 std::numeric_limits<float>::quiet_NaN(),
417 std::numeric_limits<float>::quiet_NaN()},
418 {3, 3, 3, 3, std::numeric_limits<float>::max(),
419 std::numeric_limits<float>::max(), std::numeric_limits<float>::max(),
420 std::numeric_limits<float>::max(), std::numeric_limits<float>::max()}};
421
422 for (size_t i = 0; i < size(tests); ++i) {
423 RectF r1(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1);
424 RectF r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2);
425
426 RectF scaled = ScaleRect(r1, tests[i].scale);
427 EXPECT_FLOAT_AND_NAN_EQ(r2.x(), scaled.x());
428 EXPECT_FLOAT_AND_NAN_EQ(r2.y(), scaled.y());
429 EXPECT_FLOAT_AND_NAN_EQ(r2.width(), scaled.width());
430 EXPECT_FLOAT_AND_NAN_EQ(r2.height(), scaled.height());
431 }
432}
#define EXPECT_FLOAT_AND_NAN_EQ(a, b)

◆ TEST() [29/67]

gfx::TEST ( RectTest  ,
ScaleToEnclosedRect   
)

Definition at line 643 of file rect_unittest.cc.

643 {
644 static const struct Test {
645 Rect input_rect;
646 float input_scale;
647 Rect expected_rect;
648 } tests[] = {{
649 Rect(),
650 5.f,
651 Rect(),
652 },
653 {
654 Rect(1, 1, 1, 1),
655 5.f,
656 Rect(5, 5, 5, 5),
657 },
658 {
659 Rect(-1, -1, 0, 0),
660 5.f,
661 Rect(-5, -5, 0, 0),
662 },
663 {
664 Rect(1, -1, 0, 1),
665 5.f,
666 Rect(5, -5, 0, 5),
667 },
668 {
669 Rect(-1, 1, 1, 0),
670 5.f,
671 Rect(-5, 5, 5, 0),
672 },
673 {
674 Rect(1, 2, 3, 4),
675 1.5f,
676 Rect(2, 3, 4, 6),
677 },
678 {
679 Rect(-1, -2, 0, 0),
680 1.5f,
681 Rect(-1, -3, 0, 0),
682 }};
683
684 for (size_t i = 0; i < size(tests); ++i) {
685 Rect result =
686 ScaleToEnclosedRect(tests[i].input_rect, tests[i].input_scale);
687 EXPECT_EQ(tests[i].expected_rect, result);
688 }
689}

◆ TEST() [30/67]

gfx::TEST ( RectTest  ,
ScaleToEnclosingRect   
)

Definition at line 691 of file rect_unittest.cc.

691 {
692 static const struct Test {
693 Rect input_rect;
694 float input_scale;
695 Rect expected_rect;
696 } tests[] = {{
697 Rect(),
698 5.f,
699 Rect(),
700 },
701 {
702 Rect(1, 1, 1, 1),
703 5.f,
704 Rect(5, 5, 5, 5),
705 },
706 {
707 Rect(-1, -1, 0, 0),
708 5.f,
709 Rect(-5, -5, 0, 0),
710 },
711 {
712 Rect(1, -1, 0, 1),
713 5.f,
714 Rect(5, -5, 0, 5),
715 },
716 {
717 Rect(-1, 1, 1, 0),
718 5.f,
719 Rect(-5, 5, 5, 0),
720 },
721 {
722 Rect(1, 2, 3, 4),
723 1.5f,
724 Rect(1, 3, 5, 6),
725 },
726 {
727 Rect(-1, -2, 0, 0),
728 1.5f,
729 Rect(-2, -3, 0, 0),
730 }};
731
732 for (size_t i = 0; i < size(tests); ++i) {
733 Rect result =
734 ScaleToEnclosingRect(tests[i].input_rect, tests[i].input_scale);
735 EXPECT_EQ(tests[i].expected_rect, result);
736 Rect result_safe =
737 ScaleToEnclosingRectSafe(tests[i].input_rect, tests[i].input_scale);
738 EXPECT_EQ(tests[i].expected_rect, result_safe);
739 }
740}

◆ TEST() [31/67]

gfx::TEST ( RectTest  ,
ScaleToEnclosingRectSafe   
)

Definition at line 1132 of file rect_unittest.cc.

1132 {
1133 const int max_int = std::numeric_limits<int>::max();
1134 const int min_int = std::numeric_limits<int>::min();
1135 const float max_float = std::numeric_limits<float>::max();
1136
1137 Rect xy_underflow(-100000, -123456, 10, 20);
1138 EXPECT_EQ(ScaleToEnclosingRectSafe(xy_underflow, 100000, 100000),
1139 Rect(min_int, min_int, 1000000, 2000000));
1140
1141 // A location overflow means that width/right and bottom/top also
1142 // overflow so need to be clamped.
1143 Rect xy_overflow(100000, 123456, 10, 20);
1144 EXPECT_EQ(ScaleToEnclosingRectSafe(xy_overflow, 100000, 100000),
1145 Rect(max_int, max_int, 0, 0));
1146
1147 // In practice all rects are clamped to 0 width / 0 height so
1148 // negative sizes don't matter, but try this for the sake of testing.
1149 Rect size_underflow(-1, -2, 100000, 100000);
1150 EXPECT_EQ(ScaleToEnclosingRectSafe(size_underflow, -100000, -100000),
1151 Rect(100000, 200000, 0, 0));
1152
1153 Rect size_overflow(-1, -2, 123456, 234567);
1154 EXPECT_EQ(ScaleToEnclosingRectSafe(size_overflow, 100000, 100000),
1155 Rect(-100000, -200000, max_int, max_int));
1156 // Verify width/right gets clamped properly too if x/y positive.
1157 Rect size_overflow2(1, 2, 123456, 234567);
1158 EXPECT_EQ(ScaleToEnclosingRectSafe(size_overflow2, 100000, 100000),
1159 Rect(100000, 200000, max_int - 100000, max_int - 200000));
1160
1161 Rect max_rect(max_int, max_int, max_int, max_int);
1162 EXPECT_EQ(ScaleToEnclosingRectSafe(max_rect, max_float, max_float),
1163 Rect(max_int, max_int, 0, 0));
1164
1165 Rect min_rect(min_int, min_int, max_int, max_int);
1166 // Min rect can't be scaled up any further in any dimension.
1167 EXPECT_EQ(ScaleToEnclosingRectSafe(min_rect, 2, 3.5), min_rect);
1168 EXPECT_EQ(ScaleToEnclosingRectSafe(min_rect, max_float, max_float), min_rect);
1169 // Min rect scaled by min is an empty rect at (max, max)
1170 EXPECT_EQ(ScaleToEnclosingRectSafe(min_rect, min_int, min_int), max_rect);
1171}

◆ TEST() [32/67]

gfx::TEST ( RectTest  ,
SharesEdgeWith   
)

Definition at line 357 of file rect_unittest.cc.

357 {
358 Rect r(2, 3, 4, 5);
359
360 // Must be non-overlapping
361 EXPECT_FALSE(r.SharesEdgeWith(r));
362
363 Rect just_above(2, 1, 4, 2);
364 Rect just_below(2, 8, 4, 2);
365 Rect just_left(0, 3, 2, 5);
366 Rect just_right(6, 3, 2, 5);
367
368 EXPECT_TRUE(r.SharesEdgeWith(just_above));
369 EXPECT_TRUE(r.SharesEdgeWith(just_below));
370 EXPECT_TRUE(r.SharesEdgeWith(just_left));
371 EXPECT_TRUE(r.SharesEdgeWith(just_right));
372
373 // Wrong placement
374 Rect same_height_no_edge(0, 0, 1, 5);
375 Rect same_width_no_edge(0, 0, 4, 1);
376
377 EXPECT_FALSE(r.SharesEdgeWith(same_height_no_edge));
378 EXPECT_FALSE(r.SharesEdgeWith(same_width_no_edge));
379
380 Rect just_above_no_edge(2, 1, 5, 2); // too wide
381 Rect just_below_no_edge(2, 8, 3, 2); // too narrow
382 Rect just_left_no_edge(0, 3, 2, 6); // too tall
383 Rect just_right_no_edge(6, 3, 2, 4); // too short
384
385 EXPECT_FALSE(r.SharesEdgeWith(just_above_no_edge));
386 EXPECT_FALSE(r.SharesEdgeWith(just_below_no_edge));
387 EXPECT_FALSE(r.SharesEdgeWith(just_left_no_edge));
388 EXPECT_FALSE(r.SharesEdgeWith(just_right_no_edge));
389}

◆ TEST() [33/67]

gfx::TEST ( RectTest  ,
SplitVertically   
)

Definition at line 273 of file rect_unittest.cc.

273 {
274 Rect left_half, right_half;
275
276 // Splitting when origin is (0, 0).
277 Rect(0, 0, 20, 20).SplitVertically(&left_half, &right_half);
278 EXPECT_TRUE(left_half == Rect(0, 0, 10, 20));
279 EXPECT_TRUE(right_half == Rect(10, 0, 10, 20));
280
281 // Splitting when origin is arbitrary.
282 Rect(10, 10, 20, 10).SplitVertically(&left_half, &right_half);
283 EXPECT_TRUE(left_half == Rect(10, 10, 10, 10));
284 EXPECT_TRUE(right_half == Rect(20, 10, 10, 10));
285
286 // Splitting a rectangle of zero width.
287 Rect(10, 10, 0, 10).SplitVertically(&left_half, &right_half);
288 EXPECT_TRUE(left_half == Rect(10, 10, 0, 10));
289 EXPECT_TRUE(right_half == Rect(10, 10, 0, 10));
290
291 // Splitting a rectangle of odd width.
292 Rect(10, 10, 5, 10).SplitVertically(&left_half, &right_half);
293 EXPECT_TRUE(left_half == Rect(10, 10, 2, 10));
294 EXPECT_TRUE(right_half == Rect(12, 10, 3, 10));
295}
void SplitVertically(Rect *left_half, Rect *right_half) const
Definition rect.cc:260

◆ TEST() [34/67]

gfx::TEST ( RectTest  ,
Subtract   
)

Definition at line 196 of file rect_unittest.cc.

196 {
197 Rect result;
198
199 // Matching
200 result = Rect(10, 10, 20, 20);
201 result.Subtract(Rect(10, 10, 20, 20));
202 EXPECT_EQ(Rect(0, 0, 0, 0), result);
203
204 // Contains
205 result = Rect(10, 10, 20, 20);
206 result.Subtract(Rect(5, 5, 30, 30));
207 EXPECT_EQ(Rect(0, 0, 0, 0), result);
208
209 // No intersection
210 result = Rect(10, 10, 20, 20);
211 result.Subtract(Rect(30, 30, 30, 30));
212 EXPECT_EQ(Rect(10, 10, 20, 20), result);
213
214 // Not a complete intersection in either direction
215 result = Rect(10, 10, 20, 20);
216 result.Subtract(Rect(15, 15, 20, 20));
217 EXPECT_EQ(Rect(10, 10, 20, 20), result);
218
219 // Complete intersection in the x-direction, top edge is fully covered.
220 result = Rect(10, 10, 20, 20);
221 result.Subtract(Rect(10, 15, 20, 20));
222 EXPECT_EQ(Rect(10, 10, 20, 5), result);
223
224 // Complete intersection in the x-direction, top edge is fully covered.
225 result = Rect(10, 10, 20, 20);
226 result.Subtract(Rect(5, 15, 30, 20));
227 EXPECT_EQ(Rect(10, 10, 20, 5), result);
228
229 // Complete intersection in the x-direction, bottom edge is fully covered.
230 result = Rect(10, 10, 20, 20);
231 result.Subtract(Rect(5, 5, 30, 20));
232 EXPECT_EQ(Rect(10, 25, 20, 5), result);
233
234 // Complete intersection in the x-direction, none of the edges is fully
235 // covered.
236 result = Rect(10, 10, 20, 20);
237 result.Subtract(Rect(5, 15, 30, 1));
238 EXPECT_EQ(Rect(10, 10, 20, 20), result);
239
240 // Complete intersection in the y-direction, left edge is fully covered.
241 result = Rect(10, 10, 20, 20);
242 result.Subtract(Rect(10, 10, 10, 30));
243 EXPECT_EQ(Rect(20, 10, 10, 20), result);
244
245 // Complete intersection in the y-direction, left edge is fully covered.
246 result = Rect(10, 10, 20, 20);
247 result.Subtract(Rect(5, 5, 20, 30));
248 EXPECT_EQ(Rect(25, 10, 5, 20), result);
249
250 // Complete intersection in the y-direction, right edge is fully covered.
251 result = Rect(10, 10, 20, 20);
252 result.Subtract(Rect(20, 5, 20, 30));
253 EXPECT_EQ(Rect(10, 10, 10, 20), result);
254
255 // Complete intersection in the y-direction, none of the edges is fully
256 // covered.
257 result = Rect(10, 10, 20, 20);
258 result.Subtract(Rect(15, 5, 1, 30));
259 EXPECT_EQ(Rect(10, 10, 20, 20), result);
260}

◆ TEST() [35/67]

gfx::TEST ( RectTest  ,
ToEnclosedRect   
)

Definition at line 434 of file rect_unittest.cc.

434 {
435 static const int max_int = std::numeric_limits<int>::max();
436 static const int min_int = std::numeric_limits<int>::min();
437 static const float max_float = std::numeric_limits<float>::max();
438 static const float max_int_f = static_cast<float>(max_int);
439 static const float min_int_f = static_cast<float>(min_int);
440
441 static const struct Test {
442 struct {
443 float x;
444 float y;
445 float width;
446 float height;
447 } in;
448 struct {
449 int x;
450 int y;
451 int width;
452 int height;
453 } expected;
454 } tests[] = {
455 {{0.0f, 0.0f, 0.0f, 0.0f}, {0, 0, 0, 0}},
456 {{-1.5f, -1.5f, 3.0f, 3.0f}, {-1, -1, 2, 2}},
457 {{-1.5f, -1.5f, 3.5f, 3.5f}, {-1, -1, 3, 3}},
458 {{max_float, max_float, 2.0f, 2.0f}, {max_int, max_int, 0, 0}},
459 {{0.0f, 0.0f, max_float, max_float}, {0, 0, max_int, max_int}},
460 {{20000.5f, 20000.5f, 0.5f, 0.5f}, {20001, 20001, 0, 0}},
461 {{max_int_f, max_int_f, max_int_f, max_int_f}, {max_int, max_int, 0, 0}},
462 {{1.9999f, 2.0002f, 5.9998f, 6.0001f}, {2, 3, 5, 5}},
463 {{1.9999f, 2.0001f, 6.0002f, 5.9998f}, {2, 3, 6, 4}},
464 {{1.9998f, 2.0002f, 6.0001f, 5.9999f}, {2, 3, 5, 5}}};
465
466 for (size_t i = 0; i < size(tests); ++i) {
467 RectF source(tests[i].in.x, tests[i].in.y, tests[i].in.width,
468 tests[i].in.height);
469 Rect enclosed = ToEnclosedRect(source);
470
471 EXPECT_EQ(tests[i].expected.x, enclosed.x());
472 EXPECT_EQ(tests[i].expected.y, enclosed.y());
473 EXPECT_EQ(tests[i].expected.width, enclosed.width());
474 EXPECT_EQ(tests[i].expected.height, enclosed.height());
475 }
476
477 {
478 RectF source(min_int_f, min_int_f, max_int_f * 3.f, max_int_f * 3.f);
479 Rect enclosed = ToEnclosedRect(source);
480
481 // That rect can't be represented, but it should be big.
482 EXPECT_EQ(max_int, enclosed.width());
483 EXPECT_EQ(max_int, enclosed.height());
484 // It should include some axis near the global origin.
485 EXPECT_GT(1, enclosed.x());
486 EXPECT_GT(1, enclosed.y());
487 // And it should not cause computation issues for itself.
488 EXPECT_LT(0, enclosed.right());
489 EXPECT_LT(0, enclosed.bottom());
490 }
491}
SkBitmap source
Definition examples.cpp:28
Rect ToEnclosedRect(const RectF &rect)
int32_t height
int32_t width

◆ TEST() [36/67]

gfx::TEST ( RectTest  ,
ToEnclosingRect   
)

Definition at line 493 of file rect_unittest.cc.

493 {
494 static const int max_int = std::numeric_limits<int>::max();
495 static const int min_int = std::numeric_limits<int>::min();
496 static const float max_float = std::numeric_limits<float>::max();
497 static const float epsilon_float = std::numeric_limits<float>::epsilon();
498 static const float max_int_f = static_cast<float>(max_int);
499 static const float min_int_f = static_cast<float>(min_int);
500 static const struct Test {
501 struct {
502 float x;
503 float y;
504 float width;
505 float height;
506 } in;
507 struct {
508 int x;
509 int y;
510 int width;
511 int height;
512 } expected;
513 } tests[] = {
514 {{0.0f, 0.0f, 0.0f, 0.0f}, {0, 0, 0, 0}},
515 {{5.5f, 5.5f, 0.0f, 0.0f}, {5, 5, 0, 0}},
516 {{3.5f, 2.5f, epsilon_float, -0.0f}, {3, 2, 0, 0}},
517 {{3.5f, 2.5f, 0.f, 0.001f}, {3, 2, 0, 1}},
518 {{-1.5f, -1.5f, 3.0f, 3.0f}, {-2, -2, 4, 4}},
519 {{-1.5f, -1.5f, 3.5f, 3.5f}, {-2, -2, 4, 4}},
520 {{max_float, max_float, 2.0f, 2.0f}, {max_int, max_int, 0, 0}},
521 {{0.0f, 0.0f, max_float, max_float}, {0, 0, max_int, max_int}},
522 {{20000.5f, 20000.5f, 0.5f, 0.5f}, {20000, 20000, 1, 1}},
523 {{max_int_f, max_int_f, max_int_f, max_int_f}, {max_int, max_int, 0, 0}},
524 {{-0.5f, -0.5f, 22777712.f, 1.f}, {-1, -1, 22777713, 2}},
525 {{1.9999f, 2.0002f, 5.9998f, 6.0001f}, {1, 2, 7, 7}},
526 {{1.9999f, 2.0001f, 6.0002f, 5.9998f}, {1, 2, 8, 6}},
527 {{1.9998f, 2.0002f, 6.0001f, 5.9999f}, {1, 2, 7, 7}}};
528
529 for (size_t i = 0; i < size(tests); ++i) {
530 RectF source(tests[i].in.x, tests[i].in.y, tests[i].in.width,
531 tests[i].in.height);
532
533 Rect enclosing = ToEnclosingRect(source);
534 EXPECT_EQ(tests[i].expected.x, enclosing.x());
535 EXPECT_EQ(tests[i].expected.y, enclosing.y());
536 EXPECT_EQ(tests[i].expected.width, enclosing.width());
537 EXPECT_EQ(tests[i].expected.height, enclosing.height());
538 }
539
540 {
541 RectF source(min_int_f, min_int_f, max_int_f * 3.f, max_int_f * 3.f);
542 Rect enclosing = ToEnclosingRect(source);
543
544 // That rect can't be represented, but it should be big.
545 EXPECT_EQ(max_int, enclosing.width());
546 EXPECT_EQ(max_int, enclosing.height());
547 // It should include some axis near the global origin.
548 EXPECT_GT(1, enclosing.x());
549 EXPECT_GT(1, enclosing.y());
550 // And it should cause computation issues for itself.
551 EXPECT_LT(0, enclosing.right());
552 EXPECT_LT(0, enclosing.bottom());
553 }
554}
Rect ToEnclosingRect(const RectF &r)

◆ TEST() [37/67]

gfx::TEST ( RectTest  ,
ToEnclosingRectIgnoringError   
)

Definition at line 556 of file rect_unittest.cc.

556 {
557 static const int max_int = std::numeric_limits<int>::max();
558 static const float max_float = std::numeric_limits<float>::max();
559 static const float epsilon_float = std::numeric_limits<float>::epsilon();
560 static const float max_int_f = static_cast<float>(max_int);
561 static const float error = 0.001f;
562 static const struct Test {
563 struct {
564 float x;
565 float y;
566 float width;
567 float height;
568 } in;
569 struct {
570 int x;
571 int y;
572 int width;
573 int height;
574 } expected;
575 } tests[] = {
576 {{0.0f, 0.0f, 0.0f, 0.0f}, {0, 0, 0, 0}},
577 {{5.5f, 5.5f, 0.0f, 0.0f}, {5, 5, 0, 0}},
578 {{3.5f, 2.5f, epsilon_float, -0.0f}, {3, 2, 0, 0}},
579 {{3.5f, 2.5f, 0.f, 0.001f}, {3, 2, 0, 1}},
580 {{-1.5f, -1.5f, 3.0f, 3.0f}, {-2, -2, 4, 4}},
581 {{-1.5f, -1.5f, 3.5f, 3.5f}, {-2, -2, 4, 4}},
582 {{max_float, max_float, 2.0f, 2.0f}, {max_int, max_int, 0, 0}},
583 {{0.0f, 0.0f, max_float, max_float}, {0, 0, max_int, max_int}},
584 {{20000.5f, 20000.5f, 0.5f, 0.5f}, {20000, 20000, 1, 1}},
585 {{max_int_f, max_int_f, max_int_f, max_int_f}, {max_int, max_int, 0, 0}},
586 {{-0.5f, -0.5f, 22777712.f, 1.f}, {-1, -1, 22777713, 2}},
587 {{1.9999f, 2.0002f, 5.9998f, 6.0001f}, {2, 2, 6, 6}},
588 {{1.9999f, 2.0001f, 6.0002f, 5.9998f}, {2, 2, 6, 6}},
589 {{1.9998f, 2.0002f, 6.0001f, 5.9999f}, {2, 2, 6, 6}}};
590
591 for (size_t i = 0; i < size(tests); ++i) {
592 RectF source(tests[i].in.x, tests[i].in.y, tests[i].in.width,
593 tests[i].in.height);
594
596 EXPECT_EQ(tests[i].expected.x, enclosing.x());
597 EXPECT_EQ(tests[i].expected.y, enclosing.y());
598 EXPECT_EQ(tests[i].expected.width, enclosing.width());
599 EXPECT_EQ(tests[i].expected.height, enclosing.height());
600 }
601}
const uint8_t uint32_t uint32_t GError ** error
Rect ToEnclosingRectIgnoringError(const RectF &r, float error)

◆ TEST() [38/67]

gfx::TEST ( RectTest  ,
ToFlooredRect   
)

Definition at line 614 of file rect_unittest.cc.

614 {
615 static const struct Test {
616 float x1; // source
617 float y1;
618 float w1;
619 float h1;
620 int x2; // target
621 int y2;
622 int w2;
623 int h2;
624 } tests[] = {
625 {0.0f, 0.0f, 0.0f, 0.0f, 0, 0, 0, 0},
626 {-1.5f, -1.5f, 3.0f, 3.0f, -2, -2, 3, 3},
627 {-1.5f, -1.5f, 3.5f, 3.5f, -2, -2, 3, 3},
628 {20000.5f, 20000.5f, 0.5f, 0.5f, 20000, 20000, 0, 0},
629 };
630
631 for (size_t i = 0; i < size(tests); ++i) {
632 RectF r1(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1);
633 Rect r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2);
634
635 Rect floored = ToFlooredRectDeprecated(r1);
636 EXPECT_FLOAT_EQ(r2.x(), floored.x());
637 EXPECT_FLOAT_EQ(r2.y(), floored.y());
638 EXPECT_FLOAT_EQ(r2.width(), floored.width());
639 EXPECT_FLOAT_EQ(r2.height(), floored.height());
640 }
641}
Rect ToFlooredRectDeprecated(const RectF &rect)

◆ TEST() [39/67]

gfx::TEST ( RectTest  ,
ToNearestRect   
)

Definition at line 603 of file rect_unittest.cc.

603 {
604 Rect rect;
605 EXPECT_EQ(rect, ToNearestRect(RectF(rect)));
606
607 rect = Rect(-1, -1, 3, 3);
608 EXPECT_EQ(rect, ToNearestRect(RectF(rect)));
609
610 RectF rectf(-1.00001f, -0.999999f, 3.0000001f, 2.999999f);
611 EXPECT_EQ(rect, ToNearestRect(rectf));
612}
Rect ToNearestRect(const RectF &rect)

◆ TEST() [40/67]

gfx::TEST ( RectTest  ,
ToRectF   
)

Definition at line 751 of file rect_unittest.cc.

751 {
752 // Check that explicit conversion from integer to float compiles.
753 Rect a(10, 20, 30, 40);
754 RectF b(10, 20, 30, 40);
755
756 RectF c = RectF(a);
757 EXPECT_EQ(b, c);
758}

◆ TEST() [41/67]

gfx::TEST ( RectTest  ,
Transpose   
)

Definition at line 898 of file rect_unittest.cc.

898 {
899 Rect i(10, 20, 30, 40);
900 i.Transpose();
901 EXPECT_EQ(Rect(20, 10, 40, 30), i);
902
903 RectF f(10.1f, 20.2f, 30.3f, 40.4f);
904 f.Transpose();
905 EXPECT_EQ(RectF(20.2f, 10.1f, 40.4f, 30.3f), f);
906}

◆ TEST() [42/67]

gfx::TEST ( RectTest  ,
Union   
)

Definition at line 120 of file rect_unittest.cc.

120 {
121 static const struct Test {
122 int x1; // rect 1
123 int y1;
124 int w1;
125 int h1;
126 int x2; // rect 2
127 int y2;
128 int w2;
129 int h2;
130 int x3; // rect 3: the union of rects 1 and 2
131 int y3;
132 int w3;
133 int h3;
134 } tests[] = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
135 {0, 0, 4, 4, 0, 0, 4, 4, 0, 0, 4, 4},
136 {0, 0, 4, 4, 4, 4, 4, 4, 0, 0, 8, 8},
137 {0, 0, 4, 4, 0, 5, 4, 4, 0, 0, 4, 9},
138 {0, 0, 2, 2, 3, 3, 2, 2, 0, 0, 5, 5},
139 {3, 3, 2, 2, // reverse r1 and r2 from previous test
140 0, 0, 2, 2, 0, 0, 5, 5},
141 {0, 0, 0, 0, // union with empty rect
142 2, 2, 2, 2, 2, 2, 2, 2}};
143 for (size_t i = 0; i < size(tests); ++i) {
144 Rect r1(tests[i].x1, tests[i].y1, tests[i].w1, tests[i].h1);
145 Rect r2(tests[i].x2, tests[i].y2, tests[i].w2, tests[i].h2);
146 Rect r3(tests[i].x3, tests[i].y3, tests[i].w3, tests[i].h3);
147 Rect u = UnionRects(r1, r2);
148 EXPECT_EQ(r3.x(), u.x());
149 EXPECT_EQ(r3.y(), u.y());
150 EXPECT_EQ(r3.width(), u.width());
151 EXPECT_EQ(r3.height(), u.height());
152 }
153}

◆ TEST() [43/67]

gfx::TEST ( SizeTest  ,
ClampSize   
)

Definition at line 75 of file size_unittest.cc.

75 {
76 Size a;
77
78 a = Size(3, 5);
79 EXPECT_EQ(Size(3, 5).ToString(), a.ToString());
80 a.SetToMax(Size(2, 4));
81 EXPECT_EQ(Size(3, 5).ToString(), a.ToString());
82 a.SetToMax(Size(3, 5));
83 EXPECT_EQ(Size(3, 5).ToString(), a.ToString());
84 a.SetToMax(Size(4, 2));
85 EXPECT_EQ(Size(4, 5).ToString(), a.ToString());
86 a.SetToMax(Size(8, 10));
87 EXPECT_EQ(Size(8, 10).ToString(), a.ToString());
88
89 a.SetToMin(Size(9, 11));
90 EXPECT_EQ(Size(8, 10).ToString(), a.ToString());
91 a.SetToMin(Size(8, 10));
92 EXPECT_EQ(Size(8, 10).ToString(), a.ToString());
93 a.SetToMin(Size(11, 9));
94 EXPECT_EQ(Size(8, 9).ToString(), a.ToString());
95 a.SetToMin(Size(7, 11));
96 EXPECT_EQ(Size(7, 9).ToString(), a.ToString());
97 a.SetToMin(Size(3, 5));
98 EXPECT_EQ(Size(3, 5).ToString(), a.ToString());
99}

◆ TEST() [44/67]

gfx::TEST ( SizeTest  ,
ClampSizeF   
)

Definition at line 101 of file size_unittest.cc.

101 {
102 SizeF a;
103
104 a = SizeF(3.5f, 5.5f);
105 EXPECT_EQ(SizeF(3.5f, 5.5f).ToString(), a.ToString());
106 a.SetToMax(SizeF(2.5f, 4.5f));
107 EXPECT_EQ(SizeF(3.5f, 5.5f).ToString(), a.ToString());
108 a.SetToMax(SizeF(3.5f, 5.5f));
109 EXPECT_EQ(SizeF(3.5f, 5.5f).ToString(), a.ToString());
110 a.SetToMax(SizeF(4.5f, 2.5f));
111 EXPECT_EQ(SizeF(4.5f, 5.5f).ToString(), a.ToString());
112 a.SetToMax(SizeF(8.5f, 10.5f));
113 EXPECT_EQ(SizeF(8.5f, 10.5f).ToString(), a.ToString());
114
115 a.SetToMin(SizeF(9.5f, 11.5f));
116 EXPECT_EQ(SizeF(8.5f, 10.5f).ToString(), a.ToString());
117 a.SetToMin(SizeF(8.5f, 10.5f));
118 EXPECT_EQ(SizeF(8.5f, 10.5f).ToString(), a.ToString());
119 a.SetToMin(SizeF(11.5f, 9.5f));
120 EXPECT_EQ(SizeF(8.5f, 9.5f).ToString(), a.ToString());
121 a.SetToMin(SizeF(7.5f, 11.5f));
122 EXPECT_EQ(SizeF(7.5f, 9.5f).ToString(), a.ToString());
123 a.SetToMin(SizeF(3.5f, 5.5f));
124 EXPECT_EQ(SizeF(3.5f, 5.5f).ToString(), a.ToString());
125}

◆ TEST() [45/67]

gfx::TEST ( SizeTest  ,
ClampsToZero   
)

Definition at line 203 of file size_unittest.cc.

203 {
204 const float clearly_trivial = kTrivial / 2.f;
205 const float nearly_trivial = kTrivial * 1.5f;
206
207 SizeF test(clearly_trivial, 1.f);
208
209 EXPECT_FLOAT_EQ(0.f, test.width());
210 EXPECT_FLOAT_EQ(1.f, test.height());
211
212 test.SetSize(.01f, clearly_trivial);
213
214 EXPECT_FLOAT_EQ(.01f, test.width());
215 EXPECT_FLOAT_EQ(0.f, test.height());
216
217 test.SetSize(nearly_trivial, nearly_trivial);
218
219 EXPECT_FLOAT_EQ(nearly_trivial, test.width());
220 EXPECT_FLOAT_EQ(nearly_trivial, test.height());
221
222 test.Scale(0.5f);
223
224 EXPECT_FLOAT_EQ(0.f, test.width());
225 EXPECT_FLOAT_EQ(0.f, test.height());
226
227 test.SetSize(0.f, 0.f);
228 test.Enlarge(clearly_trivial, clearly_trivial);
229 test.Enlarge(clearly_trivial, clearly_trivial);
230 test.Enlarge(clearly_trivial, clearly_trivial);
231
232 EXPECT_EQ(SizeF(0.f, 0.f), test);
233}

◆ TEST() [46/67]

gfx::TEST ( SizeTest  ,
ConsistentClamping   
)

Definition at line 237 of file size_unittest.cc.

237 {
238 SizeF resized;
239
240 resized.SetSize(kTrivial, 0.f);
241 EXPECT_EQ(SizeF(kTrivial, 0.f), resized);
242
243 resized.SetSize(0.f, kTrivial);
244 EXPECT_EQ(SizeF(0.f, kTrivial), resized);
245}
void SetSize(float width, float height)
Definition size_f.h:36

◆ TEST() [47/67]

gfx::TEST ( SizeTest  ,
Enlarge   
)

Definition at line 127 of file size_unittest.cc.

127 {
128 Size test(3, 4);
129 test.Enlarge(5, -8);
130 EXPECT_EQ(test, Size(8, -4));
131}

◆ TEST() [48/67]

gfx::TEST ( SizeTest  ,
IntegerOverflow   
)

Definition at line 133 of file size_unittest.cc.

133 {
134 int int_max = std::numeric_limits<int>::max();
135 int int_min = std::numeric_limits<int>::min();
136
137 Size max_size(int_max, int_max);
138 Size min_size(int_min, int_min);
139 Size test;
140
141 test = Size();
142 test.Enlarge(int_max, int_max);
143 EXPECT_EQ(test, max_size);
144
145 test = Size();
146 test.Enlarge(int_min, int_min);
147 EXPECT_EQ(test, min_size);
148
149 test = Size(10, 20);
150 test.Enlarge(int_max, int_max);
151 EXPECT_EQ(test, max_size);
152
153 test = Size(-10, -20);
154 test.Enlarge(int_min, int_min);
155 EXPECT_EQ(test, min_size);
156}

◆ TEST() [49/67]

gfx::TEST ( SizeTest  ,
OperatorAddOverflow   
)

Definition at line 271 of file size_unittest.cc.

271 {
272 int int_max = std::numeric_limits<int>::max();
273
274 Size lhs(int_max, int_max);
275 Size rhs(int_max, int_max);
276 EXPECT_EQ(Size(int_max, int_max), lhs + rhs);
277}

◆ TEST() [50/67]

gfx::TEST ( SizeTest  ,
OperatorAddSub   
)

Definition at line 253 of file size_unittest.cc.

253 {
254 Size lhs(100, 20);
255 Size rhs(50, 10);
256
257 lhs += rhs;
258 EXPECT_EQ(Size(150, 30), lhs);
259
260 lhs = Size(100, 20);
261 EXPECT_EQ(Size(150, 30), lhs + rhs);
262
263 lhs = Size(100, 20);
264 lhs -= rhs;
265 EXPECT_EQ(Size(50, 10), lhs);
266
267 lhs = Size(100, 20);
268 EXPECT_EQ(Size(50, 10), lhs - rhs);
269}

◆ TEST() [51/67]

gfx::TEST ( SizeTest  ,
OperatorCompare   
)

Definition at line 290 of file size_unittest.cc.

290 {
291 Size lhs(100, 20);
292 Size rhs(50, 10);
293
294 EXPECT_TRUE(lhs != rhs);
295 EXPECT_FALSE(lhs == rhs);
296
297 rhs = Size(100, 20);
298 EXPECT_TRUE(lhs == rhs);
299 EXPECT_FALSE(lhs != rhs);
300}

◆ TEST() [52/67]

gfx::TEST ( SizeTest  ,
OperatorSubClampAtZero   
)

Definition at line 279 of file size_unittest.cc.

279 {
280 Size lhs(10, 10);
281 Size rhs(100, 100);
282 EXPECT_EQ(Size(0, 0), lhs - rhs);
283
284 lhs = Size(10, 10);
285 rhs = Size(100, 100);
286 lhs -= rhs;
287 EXPECT_EQ(Size(0, 0), lhs);
288}

◆ TEST() [53/67]

gfx::TEST ( SizeTest  ,
StaysSmall   
)

Definition at line 249 of file size_unittest.cc.

249 {
250 EXPECT_EQ(2 * sizeof(float), sizeof(SizeF));
251}

◆ TEST() [54/67]

gfx::TEST ( SizeTest  ,
ToCeiledSize   
)

Definition at line 47 of file size_unittest.cc.

47 {
48 EXPECT_EQ(Size(0, 0), ToCeiledSize(SizeF(0, 0)));
49 EXPECT_EQ(Size(1, 1), ToCeiledSize(SizeF(0.0001f, 0.0001f)));
50 EXPECT_EQ(Size(1, 1), ToCeiledSize(SizeF(0.4999f, 0.4999f)));
51 EXPECT_EQ(Size(1, 1), ToCeiledSize(SizeF(0.5f, 0.5f)));
52 EXPECT_EQ(Size(1, 1), ToCeiledSize(SizeF(0.9999f, 0.9999f)));
53
54 EXPECT_EQ(Size(10, 10), ToCeiledSize(SizeF(10, 10)));
55 EXPECT_EQ(Size(11, 11), ToCeiledSize(SizeF(10.0001f, 10.0001f)));
56 EXPECT_EQ(Size(11, 11), ToCeiledSize(SizeF(10.4999f, 10.4999f)));
57 EXPECT_EQ(Size(11, 11), ToCeiledSize(SizeF(10.5f, 10.5f)));
58 EXPECT_EQ(Size(11, 11), ToCeiledSize(SizeF(10.9999f, 10.9999f)));
59}

◆ TEST() [55/67]

gfx::TEST ( SizeTest  ,
ToFlooredSize   
)

Definition at line 33 of file size_unittest.cc.

33 {
34 EXPECT_EQ(Size(0, 0), ToFlooredSize(SizeF(0, 0)));
35 EXPECT_EQ(Size(0, 0), ToFlooredSize(SizeF(0.0001f, 0.0001f)));
36 EXPECT_EQ(Size(0, 0), ToFlooredSize(SizeF(0.4999f, 0.4999f)));
37 EXPECT_EQ(Size(0, 0), ToFlooredSize(SizeF(0.5f, 0.5f)));
38 EXPECT_EQ(Size(0, 0), ToFlooredSize(SizeF(0.9999f, 0.9999f)));
39
40 EXPECT_EQ(Size(10, 10), ToFlooredSize(SizeF(10, 10)));
41 EXPECT_EQ(Size(10, 10), ToFlooredSize(SizeF(10.0001f, 10.0001f)));
42 EXPECT_EQ(Size(10, 10), ToFlooredSize(SizeF(10.4999f, 10.4999f)));
43 EXPECT_EQ(Size(10, 10), ToFlooredSize(SizeF(10.5f, 10.5f)));
44 EXPECT_EQ(Size(10, 10), ToFlooredSize(SizeF(10.9999f, 10.9999f)));
45}

◆ TEST() [56/67]

gfx::TEST ( SizeTest  ,
ToRoundedSize   
)

Definition at line 61 of file size_unittest.cc.

61 {
62 EXPECT_EQ(Size(0, 0), ToRoundedSize(SizeF(0, 0)));
63 EXPECT_EQ(Size(0, 0), ToRoundedSize(SizeF(0.0001f, 0.0001f)));
64 EXPECT_EQ(Size(0, 0), ToRoundedSize(SizeF(0.4999f, 0.4999f)));
65 EXPECT_EQ(Size(1, 1), ToRoundedSize(SizeF(0.5f, 0.5f)));
66 EXPECT_EQ(Size(1, 1), ToRoundedSize(SizeF(0.9999f, 0.9999f)));
67
68 EXPECT_EQ(Size(10, 10), ToRoundedSize(SizeF(10, 10)));
69 EXPECT_EQ(Size(10, 10), ToRoundedSize(SizeF(10.0001f, 10.0001f)));
70 EXPECT_EQ(Size(10, 10), ToRoundedSize(SizeF(10.4999f, 10.4999f)));
71 EXPECT_EQ(Size(11, 11), ToRoundedSize(SizeF(10.5f, 10.5f)));
72 EXPECT_EQ(Size(11, 11), ToRoundedSize(SizeF(10.9999f, 10.9999f)));
73}

◆ TEST() [57/67]

gfx::TEST ( SizeTest  ,
ToSizeF   
)

Definition at line 22 of file size_unittest.cc.

22 {
23 // Check that explicit conversion from integer to float compiles.
24 Size a(10, 20);
25 float width = TestSizeF(gfx::SizeF(a));
26 EXPECT_EQ(width, a.width());
27
28 SizeF b(10, 20);
29
30 EXPECT_EQ(b, gfx::SizeF(a));
31}

◆ TEST() [58/67]

gfx::TEST ( SizeTest  ,
TrivialDimensionTests   
)

Definition at line 159 of file size_unittest.cc.

159 {
160 const float clearly_trivial = kTrivial / 2.f;
161 const float massize_dimension = 4e13f;
162
163 // First, using the constructor.
164 EXPECT_TRUE(SizeF(clearly_trivial, 1.f).IsEmpty());
165 EXPECT_TRUE(SizeF(.01f, clearly_trivial).IsEmpty());
166 EXPECT_TRUE(SizeF(0.f, 0.f).IsEmpty());
167 EXPECT_FALSE(SizeF(.01f, .01f).IsEmpty());
168
169 // Then use the setter.
170 SizeF test(2.f, 1.f);
171 EXPECT_FALSE(test.IsEmpty());
172
173 test.SetSize(clearly_trivial, 1.f);
174 EXPECT_TRUE(test.IsEmpty());
175
176 test.SetSize(.01f, clearly_trivial);
177 EXPECT_TRUE(test.IsEmpty());
178
179 test.SetSize(0.f, 0.f);
180 EXPECT_TRUE(test.IsEmpty());
181
182 test.SetSize(.01f, .01f);
183 EXPECT_FALSE(test.IsEmpty());
184
185 // Now just one dimension at a time.
186 test.set_width(clearly_trivial);
187 EXPECT_TRUE(test.IsEmpty());
188
189 test.set_width(massize_dimension);
190 test.set_height(clearly_trivial);
191 EXPECT_TRUE(test.IsEmpty());
192
193 test.set_width(clearly_trivial);
194 test.set_height(massize_dimension);
195 EXPECT_TRUE(test.IsEmpty());
196
197 test.set_width(2.f);
198 EXPECT_FALSE(test.IsEmpty());
199}

◆ TEST() [59/67]

gfx::TEST ( Vector2dTest  ,
Add   
)

Definition at line 38 of file vector2d_unittest.cc.

38 {
39 Vector2d i1(3, 5);
40 Vector2d i2(4, -1);
41
42 const struct {
43 Vector2d expected;
44 Vector2d actual;
45 } int_tests[] = {{Vector2d(3, 5), i1 + Vector2d()},
46 {Vector2d(3 + 4, 5 - 1), i1 + i2},
47 {Vector2d(3 - 4, 5 + 1), i1 - i2}};
48
49 for (size_t i = 0; i < size(int_tests); ++i)
50 EXPECT_EQ(int_tests[i].expected.ToString(), int_tests[i].actual.ToString());
51
52 Vector2dF f1(3.1f, 5.1f);
53 Vector2dF f2(4.3f, -1.3f);
54
55 const struct {
56 Vector2dF expected;
57 Vector2dF actual;
58 } float_tests[] = {{Vector2dF(3.1F, 5.1F), f1 + Vector2d()},
59 {Vector2dF(3.1F, 5.1F), f1 + Vector2dF()},
60 {Vector2dF(3.1f + 4.3f, 5.1f - 1.3f), f1 + f2},
61 {Vector2dF(3.1f - 4.3f, 5.1f + 1.3f), f1 - f2}};
62
63 for (size_t i = 0; i < size(float_tests); ++i)
64 EXPECT_EQ(float_tests[i].expected.ToString(),
65 float_tests[i].actual.ToString());
66}

◆ TEST() [60/67]

gfx::TEST ( Vector2dTest  ,
ClampVector2d   
)

Definition at line 176 of file vector2d_unittest.cc.

176 {
177 Vector2d a;
178
179 a = Vector2d(3, 5);
180 EXPECT_EQ(Vector2d(3, 5).ToString(), a.ToString());
181 a.SetToMax(Vector2d(2, 4));
182 EXPECT_EQ(Vector2d(3, 5).ToString(), a.ToString());
183 a.SetToMax(Vector2d(3, 5));
184 EXPECT_EQ(Vector2d(3, 5).ToString(), a.ToString());
185 a.SetToMax(Vector2d(4, 2));
186 EXPECT_EQ(Vector2d(4, 5).ToString(), a.ToString());
187 a.SetToMax(Vector2d(8, 10));
188 EXPECT_EQ(Vector2d(8, 10).ToString(), a.ToString());
189
190 a.SetToMin(Vector2d(9, 11));
191 EXPECT_EQ(Vector2d(8, 10).ToString(), a.ToString());
192 a.SetToMin(Vector2d(8, 10));
193 EXPECT_EQ(Vector2d(8, 10).ToString(), a.ToString());
194 a.SetToMin(Vector2d(11, 9));
195 EXPECT_EQ(Vector2d(8, 9).ToString(), a.ToString());
196 a.SetToMin(Vector2d(7, 11));
197 EXPECT_EQ(Vector2d(7, 9).ToString(), a.ToString());
198 a.SetToMin(Vector2d(3, 5));
199 EXPECT_EQ(Vector2d(3, 5).ToString(), a.ToString());
200}

◆ TEST() [61/67]

gfx::TEST ( Vector2dTest  ,
ClampVector2dF   
)

Definition at line 202 of file vector2d_unittest.cc.

202 {
203 Vector2dF a;
204
205 a = Vector2dF(3.5f, 5.5f);
206 EXPECT_EQ(Vector2dF(3.5f, 5.5f).ToString(), a.ToString());
207 a.SetToMax(Vector2dF(2.5f, 4.5f));
208 EXPECT_EQ(Vector2dF(3.5f, 5.5f).ToString(), a.ToString());
209 a.SetToMax(Vector2dF(3.5f, 5.5f));
210 EXPECT_EQ(Vector2dF(3.5f, 5.5f).ToString(), a.ToString());
211 a.SetToMax(Vector2dF(4.5f, 2.5f));
212 EXPECT_EQ(Vector2dF(4.5f, 5.5f).ToString(), a.ToString());
213 a.SetToMax(Vector2dF(8.5f, 10.5f));
214 EXPECT_EQ(Vector2dF(8.5f, 10.5f).ToString(), a.ToString());
215
216 a.SetToMin(Vector2dF(9.5f, 11.5f));
217 EXPECT_EQ(Vector2dF(8.5f, 10.5f).ToString(), a.ToString());
218 a.SetToMin(Vector2dF(8.5f, 10.5f));
219 EXPECT_EQ(Vector2dF(8.5f, 10.5f).ToString(), a.ToString());
220 a.SetToMin(Vector2dF(11.5f, 9.5f));
221 EXPECT_EQ(Vector2dF(8.5f, 9.5f).ToString(), a.ToString());
222 a.SetToMin(Vector2dF(7.5f, 11.5f));
223 EXPECT_EQ(Vector2dF(7.5f, 9.5f).ToString(), a.ToString());
224 a.SetToMin(Vector2dF(3.5f, 5.5f));
225 EXPECT_EQ(Vector2dF(3.5f, 5.5f).ToString(), a.ToString());
226}

◆ TEST() [62/67]

gfx::TEST ( Vector2dTest  ,
ConversionToFloat   
)

Definition at line 20 of file vector2d_unittest.cc.

20 {
21 Vector2d i(3, 4);
22 Vector2dF f = i;
23 EXPECT_EQ(i, f);
24}

◆ TEST() [63/67]

gfx::TEST ( Vector2dTest  ,
IntegerOverflow   
)

Definition at line 228 of file vector2d_unittest.cc.

228 {
229 int int_max = std::numeric_limits<int>::max();
230 int int_min = std::numeric_limits<int>::min();
231
232 Vector2d max_vector(int_max, int_max);
233 Vector2d min_vector(int_min, int_min);
235
236 test = Vector2d();
237 test += Vector2d(int_max, int_max);
238 EXPECT_EQ(test, max_vector);
239
240 test = Vector2d();
241 test += Vector2d(int_min, int_min);
242 EXPECT_EQ(test, min_vector);
243
244 test = Vector2d(10, 20);
245 test += Vector2d(int_max, int_max);
246 EXPECT_EQ(test, max_vector);
247
248 test = Vector2d(-10, -20);
249 test += Vector2d(int_min, int_min);
250 EXPECT_EQ(test, min_vector);
251
252 test = Vector2d();
253 test -= Vector2d(int_max, int_max);
254 EXPECT_EQ(test, Vector2d(-int_max, -int_max));
255
256 test = Vector2d();
257 test -= Vector2d(int_min, int_min);
258 EXPECT_EQ(test, max_vector);
259
260 test = Vector2d(10, 20);
261 test -= Vector2d(int_min, int_min);
262 EXPECT_EQ(test, max_vector);
263
264 test = Vector2d(-10, -20);
265 test -= Vector2d(int_max, int_max);
266 EXPECT_EQ(test, min_vector);
267}

◆ TEST() [64/67]

gfx::TEST ( Vector2dTest  ,
IsZero   
)

Definition at line 26 of file vector2d_unittest.cc.

26 {
27 Vector2d int_zero(0, 0);
28 Vector2d int_nonzero(2, -2);
29 Vector2dF float_zero(0, 0);
30 Vector2dF float_nonzero(0.1f, -0.1f);
31
32 EXPECT_TRUE(int_zero.IsZero());
33 EXPECT_FALSE(int_nonzero.IsZero());
34 EXPECT_TRUE(float_zero.IsZero());
35 EXPECT_FALSE(float_nonzero.IsZero());
36}

◆ TEST() [65/67]

gfx::TEST ( Vector2dTest  ,
Length   
)

Definition at line 135 of file vector2d_unittest.cc.

135 {
136 int int_values[][2] = {
137 {0, 0}, {10, 20}, {20, 10}, {-10, -20}, {-20, 10}, {10, -20},
138 };
139
140 for (size_t i = 0; i < size(int_values); ++i) {
141 int v0 = int_values[i][0];
142 int v1 = int_values[i][1];
143 double length_squared =
144 static_cast<double>(v0) * v0 + static_cast<double>(v1) * v1;
145 double length = std::sqrt(length_squared);
146 Vector2d vector(v0, v1);
147 EXPECT_EQ(static_cast<float>(length_squared), vector.LengthSquared());
148 EXPECT_EQ(static_cast<float>(length), vector.Length());
149 }
150
151 float float_values[][2] = {
152 {0, 0},
153 {10.5f, 20.5f},
154 {20.5f, 10.5f},
155 {-10.5f, -20.5f},
156 {-20.5f, 10.5f},
157 {10.5f, -20.5f},
158 // A large vector that fails if the Length function doesn't use
159 // double precision internally.
160 {1236278317862780234892374893213178027.12122348904204230f,
161 335890352589839028212313231225425134332.38123f},
162 };
163
164 for (size_t i = 0; i < size(float_values); ++i) {
165 double v0 = float_values[i][0];
166 double v1 = float_values[i][1];
167 double length_squared =
168 static_cast<double>(v0) * v0 + static_cast<double>(v1) * v1;
169 double length = std::sqrt(length_squared);
170 Vector2dF vector(v0, v1);
171 EXPECT_DOUBLE_EQ(length_squared, vector.LengthSquared());
172 EXPECT_FLOAT_EQ(static_cast<float>(length), vector.Length());
173 }
174}
size_t length

◆ TEST() [66/67]

gfx::TEST ( Vector2dTest  ,
Negative   
)

Definition at line 68 of file vector2d_unittest.cc.

68 {
69 const struct {
70 Vector2d expected;
71 Vector2d actual;
72 } int_tests[] = {{Vector2d(0, 0), -Vector2d(0, 0)},
73 {Vector2d(-3, -3), -Vector2d(3, 3)},
74 {Vector2d(3, 3), -Vector2d(-3, -3)},
75 {Vector2d(-3, 3), -Vector2d(3, -3)},
76 {Vector2d(3, -3), -Vector2d(-3, 3)}};
77
78 for (size_t i = 0; i < size(int_tests); ++i)
79 EXPECT_EQ(int_tests[i].expected.ToString(), int_tests[i].actual.ToString());
80
81 const struct {
82 Vector2dF expected;
83 Vector2dF actual;
84 } float_tests[] = {{Vector2dF(0, 0), -Vector2d(0, 0)},
85 {Vector2dF(-0.3f, -0.3f), -Vector2dF(0.3f, 0.3f)},
86 {Vector2dF(0.3f, 0.3f), -Vector2dF(-0.3f, -0.3f)},
87 {Vector2dF(-0.3f, 0.3f), -Vector2dF(0.3f, -0.3f)},
88 {Vector2dF(0.3f, -0.3f), -Vector2dF(-0.3f, 0.3f)}};
89
90 for (size_t i = 0; i < size(float_tests); ++i)
91 EXPECT_EQ(float_tests[i].expected.ToString(),
92 float_tests[i].actual.ToString());
93}

◆ TEST() [67/67]

gfx::TEST ( Vector2dTest  ,
Scale   
)

Definition at line 95 of file vector2d_unittest.cc.

95 {
96 float double_values[][4] = {
97 {4.5f, 1.2f, 3.3f, 5.6f}, {4.5f, -1.2f, 3.3f, 5.6f},
98 {4.5f, 1.2f, 3.3f, -5.6f}, {4.5f, 1.2f, -3.3f, -5.6f},
99 {-4.5f, 1.2f, 3.3f, 5.6f}, {-4.5f, 1.2f, 0, 5.6f},
100 {-4.5f, 1.2f, 3.3f, 0}, {4.5f, 0, 3.3f, 5.6f},
101 {0, 1.2f, 3.3f, 5.6f}};
102
103 for (size_t i = 0; i < size(double_values); ++i) {
104 Vector2dF v(double_values[i][0], double_values[i][1]);
105 v.Scale(double_values[i][2], double_values[i][3]);
106 EXPECT_EQ(v.x(), double_values[i][0] * double_values[i][2]);
107 EXPECT_EQ(v.y(), double_values[i][1] * double_values[i][3]);
108
109 Vector2dF v2 =
110 ScaleVector2d(gfx::Vector2dF(double_values[i][0], double_values[i][1]),
111 double_values[i][2], double_values[i][3]);
112 EXPECT_EQ(double_values[i][0] * double_values[i][2], v2.x());
113 EXPECT_EQ(double_values[i][1] * double_values[i][3], v2.y());
114 }
115
116 float single_values[][3] = {
117 {4.5f, 1.2f, 3.3f}, {4.5f, -1.2f, 3.3f}, {4.5f, 1.2f, 3.3f},
118 {4.5f, 1.2f, -3.3f}, {-4.5f, 1.2f, 3.3f}, {-4.5f, 1.2f, 0},
119 {-4.5f, 1.2f, 3.3f}, {4.5f, 0, 3.3f}, {0, 1.2f, 3.3f}};
120
121 for (size_t i = 0; i < size(single_values); ++i) {
122 Vector2dF v(single_values[i][0], single_values[i][1]);
123 v.Scale(single_values[i][2]);
124 EXPECT_EQ(v.x(), single_values[i][0] * single_values[i][2]);
125 EXPECT_EQ(v.y(), single_values[i][1] * single_values[i][2]);
126
127 Vector2dF v2 =
128 ScaleVector2d(gfx::Vector2dF(double_values[i][0], double_values[i][1]),
129 double_values[i][2]);
130 EXPECT_EQ(single_values[i][0] * single_values[i][2], v2.x());
131 EXPECT_EQ(single_values[i][1] * single_values[i][2], v2.y());
132 }
133}

◆ ToCeiledPoint()

GFX_EXPORT Point gfx::ToCeiledPoint ( const PointF point)

Definition at line 15 of file point_conversions.cc.

15 {
16 return Point(base::ClampCeil(point.x()), base::ClampCeil(point.y()));
17}

◆ ToCeiledSize()

GFX_EXPORT Size gfx::ToCeiledSize ( const SizeF size)

Definition at line 15 of file size_conversions.cc.

15 {
16 return Size(base::ClampCeil(size.width()), base::ClampCeil(size.height()));
17}

◆ ToCeiledVector2d()

GFX_EXPORT Vector2d gfx::ToCeiledVector2d ( const Vector2dF vector2d)

Definition at line 16 of file vector2d_conversions.cc.

16 {
17 return Vector2d(base::ClampCeil(vector2d.x()), base::ClampCeil(vector2d.y()));
18}

◆ ToEnclosedRect()

GFX_EXPORT Rect gfx::ToEnclosedRect ( const RectF rect)

Definition at line 51 of file rect_conversions.cc.

51 {
54 base::ClampFloor(rect.right()),
55 base::ClampFloor(rect.bottom()));
56 return result;
57}

◆ ToEnclosedRectIgnoringError()

GFX_EXPORT Rect gfx::ToEnclosedRectIgnoringError ( const RectF r,
float  error 
)

Definition at line 59 of file rect_conversions.cc.

59 {
60 int left = CeilIgnoringError(r.x(), error);
61 int right = r.width() ? FloorIgnoringError(r.right(), error) : left;
62 int top = CeilIgnoringError(r.y(), error);
63 int bottom = r.height() ? FloorIgnoringError(r.bottom(), error) : top;
64
66 result.SetByBounds(left, top, right, bottom);
67 return result;
68}
static bool left(const SkPoint &p0, const SkPoint &p1)
static bool right(const SkPoint &p0, const SkPoint &p1)
constexpr float right() const
Definition rect_f.h:65
constexpr float bottom() const
Definition rect_f.h:66

◆ ToEnclosingRect()

GFX_EXPORT Rect gfx::ToEnclosingRect ( const RectF r)

Definition at line 29 of file rect_conversions.cc.

29 {
30 int left = base::ClampFloor(r.x());
31 int right = r.width() ? base::ClampCeil(r.right()) : left;
32 int top = base::ClampFloor(r.y());
33 int bottom = r.height() ? base::ClampCeil(r.bottom()) : top;
34
36 result.SetByBounds(left, top, right, bottom);
37 return result;
38}

◆ ToEnclosingRectIgnoringError()

GFX_EXPORT Rect gfx::ToEnclosingRectIgnoringError ( const RectF r,
float  error 
)

Definition at line 40 of file rect_conversions.cc.

40 {
41 int left = FloorIgnoringError(r.x(), error);
42 int right = r.width() ? CeilIgnoringError(r.right(), error) : left;
43 int top = FloorIgnoringError(r.y(), error);
44 int bottom = r.height() ? CeilIgnoringError(r.bottom(), error) : top;
45
47 result.SetByBounds(left, top, right, bottom);
48 return result;
49}

◆ ToFlooredPoint()

GFX_EXPORT Point gfx::ToFlooredPoint ( const PointF point)

Definition at line 11 of file point_conversions.cc.

11 {
12 return Point(base::ClampFloor(point.x()), base::ClampFloor(point.y()));
13}

◆ ToFlooredRectDeprecated()

GFX_EXPORT Rect gfx::ToFlooredRectDeprecated ( const RectF rect)

Definition at line 121 of file rect_conversions.cc.

121 {
122 return Rect(base::ClampFloor(rect.x()), base::ClampFloor(rect.y()),
123 base::ClampFloor(rect.width()), base::ClampFloor(rect.height()));
124}

◆ ToFlooredSize()

GFX_EXPORT Size gfx::ToFlooredSize ( const SizeF size)

Definition at line 11 of file size_conversions.cc.

11 {
12 return Size(base::ClampFloor(size.width()), base::ClampFloor(size.height()));
13}

◆ ToFlooredVector2d()

GFX_EXPORT Vector2d gfx::ToFlooredVector2d ( const Vector2dF vector2d)

Definition at line 11 of file vector2d_conversions.cc.

11 {
12 return Vector2d(base::ClampFloor(vector2d.x()),
13 base::ClampFloor(vector2d.y()));
14}

◆ ToNearestRect()

GFX_EXPORT Rect gfx::ToNearestRect ( const RectF rect)

Definition at line 70 of file rect_conversions.cc.

70 {
71 float float_min_x = rect.x();
72 float float_min_y = rect.y();
73 float float_max_x = rect.right();
74 float float_max_y = rect.bottom();
75
76 int min_x = base::ClampRound(float_min_x);
77 int min_y = base::ClampRound(float_min_y);
78 int max_x = base::ClampRound(float_max_x);
79 int max_y = base::ClampRound(float_max_y);
80
81 // If these DCHECKs fail, you're using the wrong method, consider using
82 // ToEnclosingRect or ToEnclosedRect instead.
83 BASE_DCHECK(std::abs(min_x - float_min_x) < 0.01f);
84 BASE_DCHECK(std::abs(min_y - float_min_y) < 0.01f);
85 BASE_DCHECK(std::abs(max_x - float_max_x) < 0.01f);
86 BASE_DCHECK(std::abs(max_y - float_max_y) < 0.01f);
87
89 result.SetByBounds(min_x, min_y, max_x, max_y);
90
91 return result;
92}

◆ ToRoundedPoint()

GFX_EXPORT Point gfx::ToRoundedPoint ( const PointF point)

Definition at line 19 of file point_conversions.cc.

19 {
20 return Point(base::ClampRound(point.x()), base::ClampRound(point.y()));
21}

◆ ToRoundedRect()

GFX_EXPORT gfx::Rect gfx::ToRoundedRect ( const gfx::RectF rect)

Definition at line 111 of file rect_conversions.cc.

111 {
112 int left = base::ClampRound(rect.x());
113 int top = base::ClampRound(rect.y());
114 int right = base::ClampRound(rect.right());
115 int bottom = base::ClampRound(rect.bottom());
117 result.SetByBounds(left, top, right, bottom);
118 return result;
119}

◆ ToRoundedSize()

GFX_EXPORT Size gfx::ToRoundedSize ( const SizeF size)

Definition at line 19 of file size_conversions.cc.

19 {
20 return Size(base::ClampRound(size.width()), base::ClampRound(size.height()));
21}

◆ ToRoundedVector2d()

GFX_EXPORT Vector2d gfx::ToRoundedVector2d ( const Vector2dF vector2d)

Definition at line 20 of file vector2d_conversions.cc.

20 {
21 return Vector2d(base::ClampRound(vector2d.x()),
22 base::ClampRound(vector2d.y()));
23}

◆ UnionRects() [1/2]

GFX_EXPORT Rect gfx::UnionRects ( const Rect a,
const Rect b 
)

Definition at line 324 of file rect.cc.

324 {
325 Rect result = a;
326 result.Union(b);
327 return result;
328}

◆ UnionRects() [2/2]

GFX_EXPORT RectF gfx::UnionRects ( const RectF a,
const RectF b 
)

Definition at line 242 of file rect_f.cc.

242 {
243 RectF result = a;
244 result.Union(b);
245 return result;
246}

Variable Documentation

◆ kNullCursor

const gfx::NativeCursor gfx::kNullCursor = static_cast<gfx::NativeCursor>(nullptr)

Definition at line 233 of file native_widget_types.h.