Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1 | #Topic Rect |
| 2 | #Alias Rects |
| 3 | #Alias Rect_Reference |
| 4 | |
| 5 | #Struct SkRect |
| 6 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 7 | SkRect holds four SkScalar coordinates describing the upper and |
| 8 | lower bounds of a rectangle. SkRect may be created from outer bounds or |
| 9 | from position, width, and height. SkRect describes an area; if its right |
| 10 | is less than or equal to its left, or if its bottom is less than or equal to |
| 11 | its top, it is considered empty. |
| 12 | |
| 13 | # move to topic about MakeIWH and friends |
| 14 | SkRect can be constructed from int values to avoid compiler warnings that |
| 15 | integer input cannot convert to SkScalar without loss of precision. |
| 16 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 17 | #Topic Overview |
| 18 | |
| 19 | #Subtopic Subtopics |
| 20 | #ToDo manually add subtopics ## |
| 21 | #Table |
| 22 | #Legend |
| 23 | # topics # description ## |
| 24 | #Legend ## |
| 25 | #Table ## |
| 26 | ## |
| 27 | |
| 28 | #Subtopic Operators |
| 29 | #Table |
| 30 | #Legend |
| 31 | # description # function ## |
| 32 | #Legend ## |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 33 | # friend bool operator!=(const SkRect& a, const SkRect& b) # Returns true if member bits are unequal. ## |
| 34 | # friend bool operator==(const SkRect& a, const SkRect& b) # Returns true if member bits are equal. ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 35 | #Table ## |
| 36 | #Subtopic ## |
| 37 | |
| 38 | #Subtopic Member_Functions |
| 39 | #Table |
| 40 | #Legend |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 41 | # description # function ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 42 | #Legend ## |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 43 | # Intersects # Returns true if areas overlap. ## |
| 44 | # Make # Constructs from ISize returning (0, 0, width, height). ## |
| 45 | # MakeEmpty # Constructs from bounds of (0, 0, 0, 0). ## |
| 46 | # MakeFromIRect # Deprecated. ## |
| 47 | # MakeIWH # Constructs from int input returning (0, 0, width, height). ## |
| 48 | # MakeLTRB # Constructs from SkScalar left, top, right, bottom. ## |
| 49 | # MakeLargest # Constructs (SK_ScalarMin, SK_ScalarMin, SK_ScalarMax, SK_ScalarMax). ## |
| 50 | # MakeSize # Constructs from Size returning (0, 0, width, height). ## |
| 51 | # MakeWH # Constructs from SkScalar input returning (0, 0, width, height). ## |
| 52 | # MakeXYWH # Constructs from SkScalar input returning (x, y, width, height). ## |
| 53 | # asScalars # Returns pointer to members as array. ## |
| 54 | # bottom() # Returns larger bounds in y, if sorted. ## |
| 55 | # centerX # Returns midpoint in x. ## |
| 56 | # centerY # Returns midpoint in y. ## |
| 57 | # contains() # Returns true if points are equal or inside. ## |
| 58 | # dump() # Sends text representation using floats to standard output. ## |
| 59 | # dumpHex # Sends text representation using hexadecimal to standard output. ## |
| 60 | # growToInclude # Sets to union of bounds and one or more Points. ## |
| 61 | # height # Returns span in y. ## |
| 62 | # inset() # Moves the sides symmetrically about the center. ## |
| 63 | # intersect() # Sets to shared area; returns true if not empty. ## |
| 64 | # intersects() # Returns true if areas overlap. ## |
| 65 | # isEmpty # Returns true if width or height are zero or negative. ## |
| 66 | # isFinite # Returns true if no member is infinite or NaN. ## |
| 67 | # isLargest # Returns equal to (SK_ScalarMin, SK_ScalarMin, SK_ScalarMax, SK_ScalarMax). ## |
| 68 | # isSorted # Returns true if width or height are zero or positive. ## |
| 69 | # iset() # Sets to int input (left, top, right, bottom). ## |
| 70 | # isetWH # Sets to int input (0, 0, width, height). ## |
| 71 | # join() # Sets to union of bounds. ## |
| 72 | # joinNonEmptyArg # Sets to union of bounds, asserting that argument is not empty. ## |
| 73 | # joinPossiblyEmptyRect # Sets to union of bounds. Skips empty check for both. ## |
| 74 | # left() # Returns smaller bounds in x, if sorted. ## |
| 75 | # makeInset # Constructs from sides moved symmetrically about the center. ## |
| 76 | # makeOffset # Constructs from translated sides. ## |
| 77 | # makeOutset # Constructs from sides moved symmetrically about the center. ## |
| 78 | # makeSorted # Constructs, ordering sides from smaller to larger. ## |
| 79 | # offset() # Translates sides without changing width and height. ## |
| 80 | # offsetTo # Translates to (x, y) without changing width and height. ## |
| 81 | # outset() # Moves the sides symmetrically about the center. ## |
| 82 | # right() # Returns larger bounds in x, if sorted. ## |
| 83 | # round() # Sets members to nearest integer value. ## |
| 84 | # roundIn # Sets members to nearest integer value towards opposite. ## |
| 85 | # roundOut # Sets members to nearest integer value away from opposite. ## |
| 86 | # set() # Sets to SkScalar input (left, top, right, bottom) and others. ## |
| 87 | # setBounds # Sets to upper and lower limits of Point array. ## |
| 88 | # setBoundsCheck # Sets to upper and lower limits of Point array. ## |
| 89 | # setEmpty # Sets to (0, 0, 0, 0). ## |
| 90 | # setLTRB # Sets to SkScalar input (left, top, right, bottom). ## |
| 91 | # setLargest # Sets to (SK_ScalarMin, SK_ScalarMin, SK_ScalarMax, SK_ScalarMax). ## |
| 92 | # setLargestInverted # Sets to (SK_ScalarMax, SK_ScalarMax, SK_ScalarMin, SK_ScalarMin). ## |
| 93 | # setWH # Sets to SkScalar input (0, 0, width, height). ## |
| 94 | # setXYWH # Sets to SkScalar input (x, y, width, height). ## |
| 95 | # sort() # Orders sides from smaller to larger. ## |
| 96 | # toQuad # Returns four corners as Point. ## |
| 97 | # top() # Returns smaller bounds in y, if sorted. ## |
| 98 | # width() # Returns span in x. ## |
| 99 | # x() # Returns bounds left. ## |
| 100 | # y() # Returns bounds top. ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 101 | #Table ## |
| 102 | #Subtopic ## |
| 103 | |
| 104 | #Topic ## |
| 105 | |
| 106 | #Member SkScalar fLeft |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 107 | May contain any value, including infinities and NaN. The smaller of the |
| 108 | horizontal values when sorted. When equal to or greater than fRight, Rect is empty. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 109 | ## |
| 110 | |
| 111 | #Member SkScalar fTop |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 112 | May contain any value, including infinities and NaN. The smaller of the |
| 113 | vertical values when sorted. When equal to or greater than fBottom, Rect is empty. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 114 | ## |
| 115 | |
| 116 | #Member SkScalar fRight |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 117 | May contain any value, including infinities and NaN. The larger of the |
| 118 | horizontal values when sorted. When equal to or less than fLeft, Rect is empty. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 119 | ## |
| 120 | |
| 121 | #Member SkScalar fBottom |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 122 | May contain any value, including infinities and NaN. The larger of the |
| 123 | vertical values when sorted. When equal to or less than fTop, Rect is empty. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 124 | ## |
| 125 | |
| 126 | # ------------------------------------------------------------------------------ |
| 127 | |
| 128 | #Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeEmpty() |
| 129 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 130 | Returns constructed Rect set to (0, 0, 0, 0). |
| 131 | Many other rectangles are empty; if left is equal to or greater than right, |
| 132 | or if top is equal to or greater than bottom. Setting all members to zero |
| 133 | is a convenience, but does not designate a special empty rectangle. |
| 134 | |
| 135 | #Return bounds (0, 0, 0, 0) ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 136 | |
| 137 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 138 | SkRect rect = SkRect::MakeEmpty();
|
| 139 | SkDebugf("MakeEmpty isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
|
| 140 | rect.offset(10, 10);
|
| 141 | SkDebugf("offset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
|
| 142 | rect.inset(10, 10);
|
| 143 | SkDebugf("inset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
|
| 144 | rect.outset(20, 20);
|
| 145 | SkDebugf("outset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
|
| 146 | #StdOut
|
| 147 | MakeEmpty isEmpty: true
|
| 148 | offset rect isEmpty: true
|
| 149 | inset rect isEmpty: true
|
| 150 | outset rect isEmpty: false
|
| 151 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 152 | ## |
| 153 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 154 | #SeeAlso isEmpty setEmpty setLargestInverted SkIRect::MakeEmpty |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 155 | |
| 156 | ## |
| 157 | |
| 158 | # ------------------------------------------------------------------------------ |
| 159 | |
| 160 | #Method static SkRect SK_WARN_UNUSED_RESULT MakeLargest() |
| 161 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 162 | Returns constructed Rect setting left and top to most negative finite value, and |
| 163 | setting right and bottom to most positive finite value. |
| 164 | |
| 165 | #Return bounds (SK_ScalarMin, SK_ScalarMin, SK_ScalarMax, SK_ScalarMax) ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 166 | |
| 167 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 168 | SkRect rect = SkRect::MakeLargest();
|
| 169 | SkDebugf("MakeLargest isLargest: %s\n", rect.isLargest() ? "true" : "false");
|
| 170 | SkDebugf("MakeLargest isFinite: %s\n", rect.isFinite() ? "true" : "false");
|
| 171 | rect.outset(1e31, 1e31);
|
| 172 | SkDebugf("outset a little isLargest: %s\n", rect.isLargest() ? "true" : "false");
|
| 173 | SkDebugf("outset a little isFinite: %s\n", rect.isFinite() ? "true" : "false");
|
| 174 | rect.outset(1e32, 1e32);
|
| 175 | SkDebugf("outset a little more isLargest: %s\n", rect.isLargest() ? "true" : "false");
|
| 176 | SkDebugf("outset a little more isFinite: %s\n", rect.isFinite() ? "true" : "false");
|
| 177 | #StdOut
|
| 178 | MakeLargest isLargest: true
|
| 179 | MakeLargest isFinite: true
|
| 180 | outset a little isLargest: true
|
| 181 | outset a little isFinite: true
|
| 182 | outset a little more isLargest: false
|
| 183 | outset a little more isFinite: false
|
| 184 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 185 | ## |
| 186 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 187 | #SeeAlso isLargest setLargest SkIRect::MakeLargest |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 188 | |
| 189 | ## |
| 190 | |
| 191 | # ------------------------------------------------------------------------------ |
| 192 | |
| 193 | #Method static SkRect SK_WARN_UNUSED_RESULT MakeWH(SkScalar w, SkScalar h) |
| 194 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 195 | Returns constructed Rect set to SkScalar values (0, 0, w, h). Does not |
| 196 | validate input; w or h may be negative. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 197 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 198 | Passing integer values may generate a compiler warning since Rect cannot |
| 199 | represent 32-bit integers exactly. Use SkIRect for an exact integer rectangle. |
| 200 | |
| 201 | #Param w SkScalar width of constructed Rect ## |
| 202 | #Param h SkScalar height of constructed Rect ## |
| 203 | |
| 204 | #Return bounds (0, 0, w, h) ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 205 | |
| 206 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 207 | SkRect rect1 = SkRect::MakeWH(25, 35);
|
| 208 | SkRect rect2 = SkRect::MakeIWH(25, 35);
|
| 209 | SkRect rect3 = SkRect::MakeXYWH(0, 0, 25, 35);
|
| 210 | SkRect rect4 = SkRect::MakeLTRB(0, 0, 25, 35);
|
| 211 | SkDebugf("all %s" "equal\n", rect1 == rect2 && rect2 == rect3 && rect3 == rect4 ?
|
| 212 | "" : "not "); |
| 213 | #StdOut |
| 214 | all equal |
| 215 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 216 | ## |
| 217 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 218 | #SeeAlso MakeSize MakeXYWH MakeIWH setWH SkIRect::MakeWH |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 219 | |
| 220 | ## |
| 221 | |
| 222 | # ------------------------------------------------------------------------------ |
| 223 | |
| 224 | #Method static SkRect SK_WARN_UNUSED_RESULT MakeIWH(int w, int h) |
| 225 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 226 | Returns constructed Rect set to integer values (0, 0, w, h). Does not validate |
| 227 | input; w or h may be negative. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 228 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 229 | Use to avoid a compiler warning that input may lose precision when stored. |
| 230 | Use SkIRect for an exact integer rectangle. |
| 231 | |
| 232 | #Param w integer width of constructed Rect ## |
| 233 | #Param h integer height of constructed Rect ## |
| 234 | |
| 235 | #Return bounds (0, 0, w, h) ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 236 | |
| 237 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 238 | SkIRect i_rect = SkIRect::MakeWH(25, 35);
|
| 239 | SkRect f_rect = SkRect::MakeIWH(25, 35);
|
| 240 | SkDebugf("i_rect width: %d f_rect width:%g\n", i_rect.width(), f_rect.width());
|
| 241 | i_rect = SkIRect::MakeWH(125000111, 0);
|
| 242 | f_rect = SkRect::MakeIWH(125000111, 0);
|
| 243 | SkDebugf("i_rect width: %d f_rect width:%.0f\n", i_rect.width(), f_rect.width());
|
| 244 | #StdOut |
| 245 | i_rect width: 25 f_rect width:25
|
| 246 | i_rect width: 125000111 f_rect width:125000112 |
| 247 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 248 | ## |
| 249 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 250 | #SeeAlso MakeXYWH MakeWH isetWH SkIRect::MakeWH |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 251 | |
| 252 | ## |
| 253 | |
| 254 | # ------------------------------------------------------------------------------ |
| 255 | |
| 256 | #Method static SkRect SK_WARN_UNUSED_RESULT MakeSize(const SkSize& size) |
| 257 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 258 | Returns constructed Rect set to (0, 0, size.width(), size.height()). Does not |
| 259 | validate input; size.width() or size.height() may be negative. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 260 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 261 | #Param size SkScalar values for Rect width and height ## |
| 262 | |
| 263 | #Return bounds (0, 0, size.width(), size.height()) ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 264 | |
| 265 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 266 | SkSize size = {25.5f, 35.5f};
|
| 267 | SkRect rect = SkRect::MakeSize(size);
|
| 268 | SkDebugf("rect width: %g height: %g\n", rect.width(), rect.height());
|
| 269 | SkISize floor = size.toFloor();
|
| 270 | rect = SkRect::MakeSize(SkSize::Make(floor));
|
| 271 | SkDebugf("floor width: %g height: %g\n", rect.width(), rect.height());
|
| 272 | #StdOut |
| 273 | rect width: 25.5 height: 35.5
|
| 274 | floor width: 25 height: 35 |
| 275 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 276 | ## |
| 277 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 278 | #SeeAlso MakeWH MakeXYWH MakeIWH setWH SkIRect::MakeWH |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 279 | |
| 280 | ## |
| 281 | |
| 282 | # ------------------------------------------------------------------------------ |
| 283 | |
| 284 | #Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeLTRB(SkScalar l, SkScalar t, SkScalar r, |
| 285 | SkScalar b) |
| 286 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 287 | Returns constructed Rect set to (l, t, r, b). Does not sort input; Rect may |
| 288 | result in fLeft greater than fRight, or fTop greater than fBottom. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 289 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 290 | #Param l SkScalar stored in fLeft ## |
| 291 | #Param t SkScalar stored in fTop ## |
| 292 | #Param r SkScalar stored in fRight ## |
| 293 | #Param b SkScalar stored in fBottom ## |
| 294 | |
| 295 | #Return bounds (l, t, r, b) ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 296 | |
| 297 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 298 | SkRect rect = SkRect::MakeLTRB(5, 35, 15, 25);
|
| 299 | SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
|
| 300 | rect.bottom(), rect.isEmpty() ? "true" : "false");
|
| 301 | rect.sort();
|
| 302 | SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
|
| 303 | rect.bottom(), rect.isEmpty() ? "true" : "false");
|
| 304 | #StdOut |
| 305 | rect: 5, 35, 15, 25 isEmpty: true
|
| 306 | rect: 5, 25, 15, 35 isEmpty: false |
| 307 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 308 | ## |
| 309 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 310 | #SeeAlso MakeXYWH SkIRect::MakeLTRB |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 311 | |
| 312 | ## |
| 313 | |
| 314 | # ------------------------------------------------------------------------------ |
| 315 | |
| 316 | #Method static SkRect SK_WARN_UNUSED_RESULT MakeXYWH(SkScalar x, SkScalar y, SkScalar w, SkScalar h) |
| 317 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 318 | Returns constructed Rect set to |
| 319 | #Formula |
| 320 | (x, y, x + w, y + h) |
| 321 | ## |
| 322 | . Does not validate input; |
| 323 | w or h may be negative. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 324 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 325 | #Param x stored in fLeft ## |
| 326 | #Param y stored in fTop ## |
| 327 | #Param w added to x and stored in fRight ## |
| 328 | #Param h added to y and stored in fBottom ## |
| 329 | |
| 330 | #Return bounds (x, y, x + w, y + h) ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 331 | |
| 332 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 333 | SkRect rect = SkRect::MakeXYWH(5, 35, -15, 25);
|
| 334 | SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
|
| 335 | rect.bottom(), rect.isEmpty() ? "true" : "false");
|
| 336 | rect.sort();
|
| 337 | SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
|
| 338 | rect.bottom(), rect.isEmpty() ? "true" : "false");
|
| 339 | #StdOut |
| 340 | rect: 5, 35, -10, 60 isEmpty: true
|
| 341 | rect: -10, 35, 5, 60 isEmpty: false |
| 342 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 343 | ## |
| 344 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 345 | #SeeAlso MakeLTRB SkIRect::MakeXYWH |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 346 | |
| 347 | ## |
| 348 | |
| 349 | # ------------------------------------------------------------------------------ |
| 350 | |
| 351 | #Method static SkRect SK_WARN_UNUSED_RESULT MakeFromIRect(const SkIRect& irect) |
| 352 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 353 | Deprecated. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 354 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 355 | #Deprecated |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 356 | ## |
| 357 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 358 | #Param irect integer rect ## |
| 359 | |
| 360 | #Return irect as SkRect ## |
| 361 | |
| 362 | #NoExample |
| 363 | ## |
| 364 | |
| 365 | #SeeAlso Make |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 366 | |
| 367 | ## |
| 368 | |
| 369 | # ------------------------------------------------------------------------------ |
| 370 | |
| 371 | #Method static SkRect Make(const SkISize& size) |
| 372 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 373 | Returns constructed IRect set to (0, 0, size.width(), size.height()). |
| 374 | Does not validate input; size.width() or size.height() may be negative. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 375 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 376 | #Param size integer values for Rect width and height ## |
| 377 | |
| 378 | #Return bounds (0, 0, size.width(), size.height()) ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 379 | |
| 380 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 381 | SkRect rect1 = SkRect::MakeSize({2, 35});
|
| 382 | SkRect rect2 = SkRect::MakeIWH(2, 35);
|
| 383 | SkDebugf("rect1 %c= rect2\n", rect1 == rect2 ? '=' : '!');
|
| 384 | #StdOut |
| 385 | rect1 == rect2 |
| 386 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 387 | ## |
| 388 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 389 | #SeeAlso MakeWH MakeXYWH SkRect::MakeIWH SkIRect::MakeSize |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 390 | |
| 391 | ## |
| 392 | |
| 393 | # ------------------------------------------------------------------------------ |
| 394 | |
| 395 | #Method static SkRect SK_WARN_UNUSED_RESULT Make(const SkIRect& irect) |
| 396 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 397 | Returns constructed IRect set to irect, promoting integers to Scalar. |
| 398 | Does not validate input; fLeft may be greater than fRight, fTop may be greater |
| 399 | than fBottom. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 400 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 401 | #Param irect integer unsorted bounds ## |
| 402 | |
| 403 | #Return irect members converted to SkScalar ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 404 | |
| 405 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 406 | SkIRect i_rect1 = {2, 35, 22, 53};
|
| 407 | SkRect f_rect = SkRect::Make(i_rect1);
|
| 408 | f_rect.offset(0.49f, 0.49f);
|
| 409 | SkIRect i_rect2;
|
| 410 | f_rect.round(&i_rect2);
|
| 411 | SkDebugf("i_rect1 %c= i_rect2\n", i_rect1 == i_rect2? '=' : '!');
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 412 | ## |
| 413 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 414 | #SeeAlso MakeLTRB |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 415 | |
| 416 | ## |
| 417 | |
| 418 | # ------------------------------------------------------------------------------ |
| 419 | |
| 420 | #Method bool isEmpty() const |
| 421 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 422 | Returns true if fLeft is equal to or greater than fRight, or if fTop is equal |
| 423 | to or greater than fBottom. Call sort() to reverse rectangles with negative |
| 424 | width() or height(). |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 425 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 426 | #Return true if width() or height() are zero or negative ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 427 | |
| 428 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 429 | SkRect tests[] = {{20, 40, 10, 50}, {20, 40, 20, 50}};
|
| 430 | for (auto rect : tests) {
|
| 431 | SkDebugf("rect: {%g, %g, %g, %g} is" "%s empty\n", rect.left(), rect.top(), rect.right(),
|
| 432 | rect.bottom(), rect.isEmpty() ? "" : " not");
|
| 433 | rect.sort();
|
| 434 | SkDebugf("sorted: {%g, %g, %g, %g} is" "%s empty\n", rect.left(), rect.top(), rect.right(),
|
| 435 | rect.bottom(), rect.isEmpty() ? "" : " not");
|
| 436 | }
|
| 437 | #StdOut
|
| 438 | rect: {20, 40, 10, 50} is empty
|
| 439 | sorted: {10, 40, 20, 50} is not empty
|
| 440 | rect: {20, 40, 20, 50} is empty
|
| 441 | sorted: {20, 40, 20, 50} is empty
|
| 442 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 443 | ## |
| 444 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 445 | #SeeAlso MakeEmpty sort SkIRect::isEmpty |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 446 | |
| 447 | ## |
| 448 | |
| 449 | # ------------------------------------------------------------------------------ |
| 450 | |
| 451 | #Method bool isSorted() const |
| 452 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 453 | Returns true if fLeft is equal to or less than fRight, or if fTop is equal |
| 454 | to or less than fBottom. Call sort() to reverse rectangles with negative |
| 455 | width() or height(). |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 456 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 457 | #Return true if width() or height() are zero or positive ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 458 | |
| 459 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 460 | SkRect tests[] = {{20, 40, 10, 50}, {20, 40, 20, 50}};
|
| 461 | for (auto rect : tests) {
|
| 462 | SkDebugf("rect: {%g, %g, %g, %g} is" "%s sorted\n", rect.left(), rect.top(), rect.right(),
|
| 463 | rect.bottom(), rect.isSorted() ? "" : " not");
|
| 464 | rect.sort();
|
| 465 | SkDebugf("sorted: {%g, %g, %g, %g} is" "%s sorted\n", rect.left(), rect.top(), rect.right(),
|
| 466 | rect.bottom(), rect.isSorted() ? "" : " not");
|
| 467 | }
|
| 468 | #StdOut
|
| 469 | rect: {20, 40, 10, 50} is not sorted
|
| 470 | sorted: {10, 40, 20, 50} is sorted
|
| 471 | rect: {20, 40, 20, 50} is sorted
|
| 472 | sorted: {20, 40, 20, 50} is sorted
|
| 473 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 474 | ## |
| 475 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 476 | #SeeAlso sort makeSorted isEmpty |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 477 | |
| 478 | ## |
| 479 | |
| 480 | # ------------------------------------------------------------------------------ |
| 481 | |
| 482 | #Method bool isLargest() const |
| 483 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 484 | Returns true if Rect encloses largest possible area. |
| 485 | |
| 486 | #Return true if equal to (SK_ScalarMin, SK_ScalarMin, SK_ScalarMax, SK_ScalarMax) ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 487 | |
| 488 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 489 | #Description |
| 490 | Note that the width cannot be represented as a 32-bit finite value. |
| 491 | ## |
| 492 | SkRect large = SkRect::MakeLargest();
|
| 493 | SkDebugf("large is largest: %s\n" ,large.isLargest() ? "true" : "false");
|
| 494 | SkDebugf("large width %g\n", large.width());
|
| 495 | SkDebugf("large is empty: %s\n", large.isEmpty() ? "true" : "false");
|
| 496 | SkDebugf("large is sorted: %s\n", large.isSorted() ? "true" : "false"); |
| 497 | SkDebugf("large is finite: %s\n", large.isFinite() ? "true" : "false");
|
| 498 | #StdOut
|
| 499 | large is largest: true
|
| 500 | large width inf
|
| 501 | large is empty: false
|
| 502 | large is sorted: true |
| 503 | large is finite: true |
| 504 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 505 | ## |
| 506 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 507 | #SeeAlso MakeLargest SkIRect::isLargest |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 508 | |
| 509 | ## |
| 510 | |
| 511 | # ------------------------------------------------------------------------------ |
| 512 | |
| 513 | #Method bool isFinite() const |
| 514 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 515 | Returns true if all values in the rectangle are finite: SK_ScalarMin or larger, |
| 516 | and SK_ScalarMax or smaller. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 517 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 518 | #Return true if no member is infinite or NaN ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 519 | |
| 520 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 521 | SkRect largest = SkRect::MakeLargest();
|
| 522 | SkDebugf("largest is finite: %s\n", largest.isFinite() ? "true" : "false");
|
| 523 | SkDebugf("large width %g\n", largest.width());
|
| 524 | SkRect widest = SkRect::MakeWH(largest.width(), largest.height());
|
| 525 | SkDebugf("widest is finite: %s\n", widest.isFinite() ? "true" : "false");
|
| 526 | #StdOut
|
| 527 | largest is finite: true
|
| 528 | large width inf
|
| 529 | widest is finite: false |
| 530 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 531 | ## |
| 532 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 533 | #SeeAlso SkScalarIsFinite SkScalarIsNaN |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 534 | |
| 535 | ## |
| 536 | |
| 537 | # ------------------------------------------------------------------------------ |
| 538 | |
| 539 | #Method SkScalar x() const |
| 540 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 541 | Returns left edge of Rect, if sorted. Call isSorted to see if Rect is valid. |
| 542 | Call sort() to reverse fLeft and fRight if needed. |
| 543 | |
| 544 | #Return fLeft ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 545 | |
| 546 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 547 | SkRect unsorted = { 15, 5, 10, 25 };
|
| 548 | SkDebugf("unsorted.fLeft: %g unsorted.x(): %g\n", unsorted.fLeft, unsorted.x());
|
| 549 | SkRect sorted = unsorted.makeSorted();
|
| 550 | SkDebugf("sorted.fLeft: %g sorted.x(): %g\n", sorted.fLeft, sorted.x());
|
| 551 | #StdOut |
| 552 | unsorted.fLeft: 15 unsorted.x(): 15
|
| 553 | sorted.fLeft: 10 sorted.x(): 10 |
| 554 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 555 | ## |
| 556 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 557 | #SeeAlso fLeft left() y() SkIRect::x() |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 558 | |
| 559 | ## |
| 560 | |
| 561 | # ------------------------------------------------------------------------------ |
| 562 | |
| 563 | #Method SkScalar y() const |
| 564 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 565 | Returns top edge of Rect, if sorted. Call isEmpty to see if Rect may be invalid, |
| 566 | and sort() to reverse fTop and fBottom if needed. |
| 567 | |
| 568 | #Return fTop ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 569 | |
| 570 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 571 | SkRect unsorted = { 15, 25, 10, 5 };
|
| 572 | SkDebugf("unsorted.fTop: %g unsorted.y(): %g\n", unsorted.fTop, unsorted.y());
|
| 573 | SkRect sorted = unsorted.makeSorted();
|
| 574 | SkDebugf("sorted.fTop: %g sorted.y(): %g\n", sorted.fTop, sorted.y()); |
| 575 | #StdOut |
| 576 | unsorted.fTop: 25 unsorted.y(): 25
|
| 577 | sorted.fTop: 5 sorted.y(): 5 |
| 578 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 579 | ## |
| 580 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 581 | #SeeAlso fTop top() x() SkIRect::y() |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 582 | |
| 583 | ## |
| 584 | |
| 585 | # ------------------------------------------------------------------------------ |
| 586 | |
| 587 | #Method SkScalar left() const |
| 588 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 589 | Returns left edge of Rect, if sorted. Call isSorted to see if Rect is valid. |
| 590 | Call sort() to reverse fLeft and fRight if needed. |
| 591 | |
| 592 | #Return fLeft ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 593 | |
| 594 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 595 | SkRect unsorted = { 15, 5, 10, 25 };
|
| 596 | SkDebugf("unsorted.fLeft: %g unsorted.left(): %g\n", unsorted.fLeft, unsorted.left());
|
| 597 | SkRect sorted = unsorted.makeSorted();
|
| 598 | SkDebugf("sorted.fLeft: %g sorted.left(): %g\n", sorted.fLeft, sorted.left());
|
| 599 | #StdOut |
| 600 | unsorted.fLeft: 15 unsorted.left(): 15
|
| 601 | sorted.fLeft: 10 sorted.left(): 10 |
| 602 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 603 | ## |
| 604 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 605 | #SeeAlso fLeft x() SkIRect::left() |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 606 | |
| 607 | ## |
| 608 | |
| 609 | # ------------------------------------------------------------------------------ |
| 610 | |
| 611 | #Method SkScalar top() const |
| 612 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 613 | Returns top edge of Rect, if sorted. Call isEmpty to see if Rect may be invalid, |
| 614 | and sort() to reverse fTop and fBottom if needed. |
| 615 | |
| 616 | #Return fTop ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 617 | |
| 618 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 619 | SkRect unsorted = { 15, 25, 10, 5 };
|
| 620 | SkDebugf("unsorted.fTop: %g unsorted.top(): %g\n", unsorted.fTop, unsorted.top());
|
| 621 | SkRect sorted = unsorted.makeSorted();
|
| 622 | SkDebugf("sorted.fTop: %g sorted.top(): %g\n", sorted.fTop, sorted.top()); |
| 623 | #StdOut |
| 624 | unsorted.fTop: 25 unsorted.top(): 25
|
| 625 | sorted.fTop: 5 sorted.top(): 5 |
| 626 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 627 | ## |
| 628 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 629 | #SeeAlso fTop y() SkIRect::top() |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 630 | |
| 631 | ## |
| 632 | |
| 633 | # ------------------------------------------------------------------------------ |
| 634 | |
| 635 | #Method SkScalar right() const |
| 636 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 637 | Returns right edge of Rect, if sorted. Call isSorted to see if Rect is valid. |
| 638 | Call sort() to reverse fLeft and fRight if needed. |
| 639 | |
| 640 | #Return fRight ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 641 | |
| 642 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 643 | SkRect unsorted = { 15, 25, 10, 5 };
|
| 644 | SkDebugf("unsorted.fRight: %g unsorted.right(): %g\n", unsorted.fRight, unsorted.right());
|
| 645 | SkRect sorted = unsorted.makeSorted();
|
| 646 | SkDebugf("sorted.fRight: %g sorted.right(): %g\n", sorted.fRight, sorted.right());
|
| 647 | #StdOut |
| 648 | unsorted.fRight: 10 unsorted.right(): 10
|
| 649 | sorted.fRight: 15 sorted.right(): 15 |
| 650 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 651 | ## |
| 652 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 653 | #SeeAlso fRight SkIRect::right() |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 654 | |
| 655 | ## |
| 656 | |
| 657 | # ------------------------------------------------------------------------------ |
| 658 | |
| 659 | #Method SkScalar bottom() const |
| 660 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 661 | Returns bottom edge of Rect, if sorted. Call isEmpty to see if Rect may be invalid, |
| 662 | and sort() to reverse fTop and fBottom if needed. |
| 663 | |
| 664 | #Return fBottom ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 665 | |
| 666 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 667 | SkRect unsorted = { 15, 25, 10, 5 };
|
| 668 | SkDebugf("unsorted.fBottom: %g unsorted.bottom(): %g\n", unsorted.fBottom, unsorted.bottom());
|
| 669 | SkRect sorted = unsorted.makeSorted();
|
| 670 | SkDebugf("sorted.fBottom: %g sorted.bottom(): %g\n", sorted.fBottom, sorted.bottom());
|
| 671 | #StdOut |
| 672 | unsorted.fBottom: 5 unsorted.bottom(): 5
|
| 673 | sorted.fBottom: 25 sorted.bottom(): 25 |
| 674 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 675 | ## |
| 676 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 677 | #SeeAlso fBottom SkIRect::bottom() |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 678 | |
| 679 | ## |
| 680 | |
| 681 | # ------------------------------------------------------------------------------ |
| 682 | |
| 683 | #Method SkScalar width() const |
| 684 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 685 | Returns span on the x-axis. This does not check if Rect is sorted, or if |
| 686 | result fits in 32-bit float; result may be negative or infinity. |
| 687 | |
| 688 | #Return fRight minus fLeft ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 689 | |
| 690 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 691 | #Description |
| 692 | Compare with SkIRect::width() example. |
| 693 | ## |
| 694 | SkRect unsorted = { 15, 25, 10, 5 };
|
| 695 | SkDebugf("unsorted width: %g\n", unsorted.width());
|
| 696 | SkRect large = { -2147483647.f, 1, 2147483644.f, 2 };
|
| 697 | SkDebugf("large width: %.0f\n", large.width());
|
| 698 | #StdOut |
| 699 | unsorted width: -5
|
| 700 | large width: 4294967296 |
| 701 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 702 | ## |
| 703 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 704 | #SeeAlso height() SkIRect::width() |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 705 | |
| 706 | ## |
| 707 | |
| 708 | # ------------------------------------------------------------------------------ |
| 709 | |
| 710 | #Method SkScalar height() const |
| 711 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 712 | Returns span on the y-axis. This does not check if IRect is sorted, or if |
| 713 | result fits in 32-bit float; result may be negative or infinity. |
| 714 | |
| 715 | #Return fBottom minus fTop ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 716 | |
| 717 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 718 | #Description |
| 719 | Compare with SkIRect::height() example. |
| 720 | ## |
| 721 | SkRect unsorted = { 15, 25, 10, 20 };
|
| 722 | SkDebugf("unsorted height: %g\n", unsorted.height());
|
| 723 | SkRect large = { 1, -2147483647.f, 2, 2147483644.f };
|
| 724 | SkDebugf("large height: %.0f\n", large.height());
|
| 725 | #StdOut |
| 726 | unsorted height: -5
|
| 727 | large height: 4294967296 |
| 728 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 729 | ## |
| 730 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 731 | #SeeAlso width() SkIRect::height() |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 732 | |
| 733 | ## |
| 734 | |
| 735 | # ------------------------------------------------------------------------------ |
| 736 | |
| 737 | #Method SkScalar centerX() const |
| 738 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 739 | Returns average of left edge and right edge. Result does not change if Rect |
| 740 | is sorted. Result may overflow to infinity if Rect is far from the origin. |
| 741 | |
| 742 | #Return midpoint in x ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 743 | |
| 744 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 745 | SkRect tests[] = {{20, 30, 41, 51}, {-20, -30, -41, -51}};
|
| 746 | for (auto rect : tests) {
|
| 747 | SkDebugf("left: %3g right: %3g centerX: %3g\n", rect.left(), rect.right(), rect.centerX());
|
| 748 | rect.sort();
|
| 749 | SkDebugf("left: %3g right: %3g centerX: %3g\n", rect.left(), rect.right(), rect.centerX());
|
| 750 | }
|
| 751 | #StdOut |
| 752 | left: 20 right: 41 centerX: 30.5
|
| 753 | left: 20 right: 41 centerX: 30.5
|
| 754 | left: -20 right: -41 centerX: -30.5
|
| 755 | left: -41 right: -20 centerX: -30.5 |
| 756 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 757 | ## |
| 758 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 759 | #SeeAlso centerY SkIRect::centerX |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 760 | |
| 761 | ## |
| 762 | |
| 763 | # ------------------------------------------------------------------------------ |
| 764 | |
| 765 | #Method SkScalar centerY() const |
| 766 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 767 | Returns average of top edge and bottom edge. Result does not change if Rect |
| 768 | is sorted. Result may overflow to infinity if Rect is far from the origin. |
| 769 | |
| 770 | #Return midpoint in y ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 771 | |
| 772 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 773 | SkRect rect = { 2e+38, 2e+38, 3e+38, 3e+38 };
|
| 774 | SkDebugf("left: %g right: %g centerX: %g ", rect.left(), rect.right(), rect.centerX());
|
| 775 | SkDebugf("safe mid x: %g\n", rect.left() / 2 + rect.right() / 2);
|
| 776 | #StdOut |
| 777 | left: 2e+38 right: 3e+38 centerX: inf safe mid x: 2.5e+38 |
| 778 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 779 | ## |
| 780 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 781 | #SeeAlso centerX SkIRect::centerY |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 782 | |
| 783 | ## |
| 784 | |
| 785 | # ------------------------------------------------------------------------------ |
| 786 | |
| 787 | #Method friend bool operator==(const SkRect& a, const SkRect& b) |
| 788 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 789 | Returns true if all members in a: fLeft, fTop, fRight, and fBottom; are |
| 790 | equal to the corresponding members in b. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 791 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 792 | a and b are not equal if either contain NaN. a and b are equal if members |
| 793 | contain zeroes width different signs. |
| 794 | |
| 795 | #Param a Rect to compare ## |
| 796 | #Param b Rect to compare ## |
| 797 | |
| 798 | #Return true if members are equal ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 799 | |
| 800 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 801 | auto debugster = [](const SkRect& test) -> void {
|
| 802 | SkRect negZero = {-0.0f, -0.0f, 2, 2};
|
| 803 | SkDebugf("{%g, %g, %g, %g} %c= {%g, %g, %g, %g} %s numerically equal\n",
|
| 804 | test.fLeft, test.fTop, test.fRight, test.fBottom,
|
| 805 | negZero.fLeft, negZero.fTop, negZero.fRight, negZero.fBottom,
|
| 806 | test == negZero ? '=' : '!',
|
| 807 | test.fLeft == negZero.fLeft && test.fTop == negZero.fTop &&
|
| 808 | test.fRight == negZero.fRight && test.fBottom == negZero.fBottom ?
|
| 809 | "and are" : "yet are not");
|
| 810 | };
|
| 811 | SkRect tests[] = {{0, 0, 2, 2}, {-0, -0, 2, 2}, {0.0f, 0.0f, 2, 2}};
|
| 812 | SkDebugf("tests are %s" "equal\n", tests[0] == tests[1] && tests[1] == tests[2] ? "" : "not ");
|
| 813 | for (auto rect : tests) {
|
| 814 | debugster(rect);
|
| 815 | } |
| 816 | #StdOut
|
| 817 | tests are equal
|
| 818 | {0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal
|
| 819 | {0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal
|
| 820 | {0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal |
| 821 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 822 | ## |
| 823 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 824 | #SeeAlso operator!=(const SkRect& a, const SkRect& b) |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 825 | |
| 826 | ## |
| 827 | |
| 828 | # ------------------------------------------------------------------------------ |
| 829 | |
| 830 | #Method friend bool operator!=(const SkRect& a, const SkRect& b) |
| 831 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 832 | Returns true if any in a: fLeft, fTop, fRight, and fBottom; does not |
| 833 | equal the corresponding members in b. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 834 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 835 | a and b are not equal if either contain NaN. a and b are equal if members |
| 836 | contain zeroes width different signs. |
| 837 | |
| 838 | #Param a Rect to compare ## |
| 839 | #Param b Rect to compare ## |
| 840 | |
| 841 | #Return true if members are not equal ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 842 | |
| 843 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 844 | SkRect test = {0, 0, 2, SK_ScalarNaN};
|
| 845 | SkDebugf("test with NaN is %s" "equal to itself\n", test == test ? "" : "not ");
|
| 846 | #StdOut
|
| 847 | test with NaN is not equal to itself |
| 848 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 849 | ## |
| 850 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 851 | #SeeAlso operator==(const SkRect& a, const SkRect& b) |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 852 | |
| 853 | ## |
| 854 | |
| 855 | # ------------------------------------------------------------------------------ |
| 856 | |
| 857 | #Method void toQuad(SkPoint quad[4]) const |
| 858 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 859 | Returns four points in quad that enclose Rect ordered as: top-left, top-right, |
| 860 | bottom-right, bottom-left. |
| 861 | |
| 862 | #Private |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 863 | Consider adding param to control whether quad is CW or CCW. |
| 864 | ## |
| 865 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 866 | #Param quad storage for corners of Rect ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 867 | |
| 868 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 869 | SkRect rect = {1, 2, 3, 4};
|
| 870 | SkPoint corners[4];
|
| 871 | rect.toQuad(corners);
|
| 872 | SkDebugf("rect: {%g, %g, %g, %g}\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
|
| 873 | SkDebugf("corners:");
|
| 874 | for (auto corner : corners) {
|
| 875 | SkDebugf(" {%g, %g}", corner.fX, corner.fY);
|
| 876 | }
|
| 877 | SkDebugf("\n");
|
| 878 | #StdOut
|
| 879 | rect: {1, 2, 3, 4}
|
| 880 | corners: {1, 2} {3, 2} {3, 4} {1, 4} |
| 881 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 882 | ## |
| 883 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 884 | #SeeAlso SkPath::addRect |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 885 | |
| 886 | ## |
| 887 | |
| 888 | # ------------------------------------------------------------------------------ |
| 889 | |
| 890 | #Method void setEmpty() |
| 891 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 892 | Sets Rect to (0, 0, 0, 0). |
| 893 | |
| 894 | Many other rectangles are empty; if left is equal to or greater than right, |
| 895 | or if top is equal to or greater than bottom. Setting all members to zero |
| 896 | is a convenience, but does not designate a special empty rectangle. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 897 | |
| 898 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 899 | SkRect rect = {3, 4, 1, 2};
|
| 900 | for (int i = 0; i < 2; ++i) {
|
| 901 | SkDebugf("rect: {%g, %g, %g, %g} is %s" "empty\n", rect.fLeft, rect.fTop,
|
| 902 | rect.fRight, rect.fBottom, rect.isEmpty() ? "" : "not ");
|
| 903 | rect.setEmpty();
|
| 904 | }
|
| 905 | #StdOut
|
| 906 | rect: {3, 4, 1, 2} is empty
|
| 907 | rect: {0, 0, 0, 0} is empty
|
| 908 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 909 | ## |
| 910 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 911 | #SeeAlso MakeEmpty SkIRect::setEmpty |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 912 | |
| 913 | ## |
| 914 | |
| 915 | # ------------------------------------------------------------------------------ |
| 916 | |
| 917 | #Method void set(const SkIRect& src) |
| 918 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 919 | Sets Rect to src, promoting src members from integer to Scalar. |
| 920 | Very large values in src may lose precision. |
| 921 | |
| 922 | #Param src integer Rect ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 923 | |
| 924 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 925 | SkIRect i_rect = {3, 4, 1, 2};
|
| 926 | SkDebugf("i_rect: {%d, %d, %d, %d}\n", i_rect.fLeft, i_rect.fTop, i_rect.fRight, i_rect.fBottom);
|
| 927 | SkRect f_rect;
|
| 928 | f_rect.set(i_rect);
|
| 929 | SkDebugf("f_rect: {%g, %g, %g, %g}\n", f_rect.fLeft, f_rect.fTop, f_rect.fRight, f_rect.fBottom);
|
| 930 | #StdOut
|
| 931 | i_rect: {3, 4, 1, 2}
|
| 932 | f_rect: {3, 4, 1, 2}
|
| 933 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 934 | ## |
| 935 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 936 | #SeeAlso setLTRB SkIntToScalar |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 937 | |
| 938 | ## |
| 939 | |
| 940 | # ------------------------------------------------------------------------------ |
| 941 | |
| 942 | #Method void set(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) |
| 943 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 944 | Sets Rect to (left, top, right, bottom). |
| 945 | left and right are not sorted; left is not necessarily less than right. |
| 946 | top and bottom are not sorted; top is not necessarily less than bottom. |
| 947 | |
| 948 | #Param left stored in fLeft ## |
| 949 | #Param top stored in fTop ## |
| 950 | #Param right stored in fRight ## |
| 951 | #Param bottom stored in fBottom ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 952 | |
| 953 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 954 | SkRect rect1 = {3, 4, 1, 2};
|
| 955 | SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
|
| 956 | SkRect rect2;
|
| 957 | rect2.set(3, 4, 1, 2);
|
| 958 | SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
|
| 959 | #StdOut
|
| 960 | rect1: {3, 4, 1, 2}
|
| 961 | rect2: {3, 4, 1, 2}
|
| 962 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 963 | ## |
| 964 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 965 | #SeeAlso setLTRB setXYWH SkIRect::set |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 966 | |
| 967 | ## |
| 968 | |
| 969 | # ------------------------------------------------------------------------------ |
| 970 | |
| 971 | #Method void setLTRB(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) |
| 972 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 973 | Sets Rect to (left, top, right, bottom). |
| 974 | left and right are not sorted; left is not necessarily less than right. |
| 975 | top and bottom are not sorted; top is not necessarily less than bottom. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 976 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 977 | #Param left stored in fLeft ## |
| 978 | #Param top stored in fTop ## |
| 979 | #Param right stored in fRight ## |
| 980 | #Param bottom stored in fBottom ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 981 | |
| 982 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 983 | SkRect rect1 = {3, 4, 1, 2};
|
| 984 | SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
|
| 985 | SkRect rect2;
|
| 986 | rect2.setLTRB(3, 4, 1, 2);
|
| 987 | SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
|
| 988 | #StdOut
|
| 989 | rect1: {3, 4, 1, 2}
|
| 990 | rect2: {3, 4, 1, 2}
|
| 991 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 992 | ## |
| 993 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 994 | #SeeAlso set setXYWH SkIRect::set |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 995 | |
| 996 | ## |
| 997 | |
| 998 | # ------------------------------------------------------------------------------ |
| 999 | |
| 1000 | #Method void iset(int left, int top, int right, int bottom) |
| 1001 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1002 | Sets Rect to (left, top, right, bottom). |
| 1003 | All parameters are promoted from integer to Scalar. |
| 1004 | left and right are not sorted; left is not necessarily less than right. |
| 1005 | top and bottom are not sorted; top is not necessarily less than bottom. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1006 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1007 | #Param left promoted to SkScalar and stored in fLeft ## |
| 1008 | #Param top promoted to SkScalar and stored in fTop ## |
| 1009 | #Param right promoted to SkScalar and stored in fRight ## |
| 1010 | #Param bottom promoted to SkScalar and stored in fBottom ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1011 | |
| 1012 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1013 | SkRect rect1 = {3, 4, 1, 2};
|
| 1014 | SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
|
| 1015 | SkRect rect2;
|
| 1016 | rect2.iset(3, 4, 1, 2);
|
| 1017 | SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom);
|
| 1018 | #StdOut
|
| 1019 | rect1: {3, 4, 1, 2}
|
| 1020 | rect2: {3, 4, 1, 2}
|
| 1021 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1022 | ## |
| 1023 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1024 | #SeeAlso set setLTRB SkIRect::set SkIntToScalar |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1025 | |
| 1026 | ## |
| 1027 | |
| 1028 | # ------------------------------------------------------------------------------ |
| 1029 | |
| 1030 | #Method void isetWH(int width, int height) |
| 1031 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1032 | Sets Rect to (0, 0, width, height). |
| 1033 | width and height may be zero or negative. width and height are promoted from |
| 1034 | integer to SkScalar, large values may lose precision. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1035 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1036 | #Param width promoted to SkScalar and stored in fRight ## |
| 1037 | #Param height promoted to SkScalar and stored in fBottom ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1038 | |
| 1039 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1040 | SkRect rect1 = {0, 0, 1, 2};
|
| 1041 | SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom);
|
| 1042 | SkRect rect2;
|
| 1043 | rect2.isetWH(1, 2);
|
| 1044 | SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom); |
| 1045 | #StdOut
|
| 1046 | rect1: {0, 0, 1, 2}
|
| 1047 | rect2: {0, 0, 1, 2}
|
| 1048 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1049 | ## |
| 1050 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1051 | #SeeAlso MakeWH MakeXYWH iset() SkIRect:MakeWH |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1052 | |
| 1053 | ## |
| 1054 | |
| 1055 | # ------------------------------------------------------------------------------ |
| 1056 | |
| 1057 | #Method void set(const SkPoint pts[], int count) |
| 1058 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1059 | Sets to bounds of Point array with count entries. If count is zero or smaller, |
| 1060 | or if Point array contains an infinity or NaN, sets Rect to (0, 0, 0, 0). |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1061 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1062 | Result is either empty or sorted: fLeft is less than or equal to fRight, and |
| 1063 | fTop is less than or equal to fBottom. |
| 1064 | |
| 1065 | #Param pts Point array ## |
| 1066 | #Param count entries in array ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1067 | |
| 1068 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1069 | SkPoint points[] = {{3, 4}, {1, 2}, {5, 6}, {SK_ScalarNaN, 8}};
|
| 1070 | for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) {
|
| 1071 | SkRect rect;
|
| 1072 | rect.set(points, count);
|
| 1073 | if (count > 0) {
|
| 1074 | SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY);
|
| 1075 | } else {
|
| 1076 | SkDebugf("%14s", " ");
|
| 1077 | }
|
| 1078 | SkDebugf("count: %d rect: %g, %g, %g, %g\n", count,
|
| 1079 | rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
|
| 1080 | }
|
| 1081 | #StdOut
|
| 1082 | count: 0 rect: 0, 0, 0, 0
|
| 1083 | added: 3, 4 count: 1 rect: 3, 4, 3, 4
|
| 1084 | added: 1, 2 count: 2 rect: 1, 2, 3, 4
|
| 1085 | added: 5, 6 count: 3 rect: 1, 2, 5, 6
|
| 1086 | added: nan, 8 count: 4 rect: 0, 0, 0, 0
|
| 1087 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1088 | ## |
| 1089 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1090 | #SeeAlso setBounds setBoundsCheck SkPath::addPoly |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1091 | |
| 1092 | ## |
| 1093 | |
| 1094 | # ------------------------------------------------------------------------------ |
| 1095 | |
| 1096 | #Method void setBounds(const SkPoint pts[], int count) |
| 1097 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1098 | Sets to bounds of Point array with count entries. If count is zero or smaller, |
| 1099 | or if Point array contains an infinity or NaN, sets to (0, 0, 0, 0). |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1100 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1101 | Result is either empty or sorted: fLeft is less than or equal to fRight, and |
| 1102 | fTop is less than or equal to fBottom. |
| 1103 | |
| 1104 | #Param pts Point array ## |
| 1105 | #Param count entries in array ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1106 | |
| 1107 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1108 | SkPoint points[] = {{3, 4}, {1, 2}, {5, 6}, {SK_ScalarNaN, 8}};
|
| 1109 | for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) {
|
| 1110 | SkRect rect;
|
| 1111 | rect.setBounds(points, count);
|
| 1112 | if (count > 0) {
|
| 1113 | SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY);
|
| 1114 | } else {
|
| 1115 | SkDebugf("%14s", " ");
|
| 1116 | }
|
| 1117 | SkDebugf("count: %d rect: %g, %g, %g, %g\n", count,
|
| 1118 | rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
|
| 1119 | }
|
| 1120 | #StdOut
|
| 1121 | count: 0 rect: 0, 0, 0, 0
|
| 1122 | added: 3, 4 count: 1 rect: 3, 4, 3, 4
|
| 1123 | added: 1, 2 count: 2 rect: 1, 2, 3, 4
|
| 1124 | added: 5, 6 count: 3 rect: 1, 2, 5, 6
|
| 1125 | added: nan, 8 count: 4 rect: 0, 0, 0, 0
|
| 1126 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1127 | ## |
| 1128 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1129 | #SeeAlso set setBoundsCheck SkPath::addPoly |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1130 | |
| 1131 | ## |
| 1132 | |
| 1133 | # ------------------------------------------------------------------------------ |
| 1134 | |
| 1135 | #Method bool setBoundsCheck(const SkPoint pts[], int count) |
| 1136 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1137 | Sets to bounds of Point array with count entries. Returns false if count is |
| 1138 | zero or smaller, or if Point array contains an infinity or NaN; in these cases |
| 1139 | sets Rect to (0, 0, 0, 0). |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1140 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1141 | Result is either empty or sorted: fLeft is less than or equal to fRight, and |
| 1142 | fTop is less than or equal to fBottom. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1143 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1144 | #Param pts Point array ## |
| 1145 | #Param count entries in array ## |
| 1146 | |
| 1147 | #Return true if all Point values are finite ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1148 | |
| 1149 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1150 | SkPoint points[] = {{3, 4}, {1, 2}, {5, 6}, {SK_ScalarNaN, 8}};
|
| 1151 | for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) {
|
| 1152 | SkRect rect;
|
| 1153 | bool success = rect.setBoundsCheck(points, count);
|
| 1154 | if (count > 0) {
|
| 1155 | SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY);
|
| 1156 | } else {
|
| 1157 | SkDebugf("%14s", " ");
|
| 1158 | }
|
| 1159 | SkDebugf("count: %d rect: %g, %g, %g, %g success: %s\n", count,
|
| 1160 | rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, success ? "true" : "false");
|
| 1161 | }
|
| 1162 | #StdOut
|
| 1163 | count: 0 rect: 0, 0, 0, 0 success: true
|
| 1164 | added: 3, 4 count: 1 rect: 3, 4, 3, 4 success: true
|
| 1165 | added: 1, 2 count: 2 rect: 1, 2, 3, 4 success: true
|
| 1166 | added: 5, 6 count: 3 rect: 1, 2, 5, 6 success: true
|
| 1167 | added: nan, 8 count: 4 rect: 0, 0, 0, 0 success: false
|
| 1168 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1169 | ## |
| 1170 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1171 | #SeeAlso set setBounds SkPath::addPoly |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1172 | |
| 1173 | ## |
| 1174 | |
| 1175 | # ------------------------------------------------------------------------------ |
| 1176 | |
| 1177 | #Method void set(const SkPoint& p0, const SkPoint& p1) |
| 1178 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1179 | Sets bounds to the smallest Rect enclosing Points p0 and p1. The result is |
| 1180 | sorted and may be empty. Does not check to see if values are finite. |
| 1181 | |
| 1182 | #Param p0 corner to include ## |
| 1183 | #Param p1 corner to include ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1184 | |
| 1185 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1186 | #Description |
| 1187 | p0 and p1 may be swapped and have the same effect unless one contains NaN. |
| 1188 | ## |
| 1189 | SkPoint point1 = {SK_ScalarNaN, 8};
|
| 1190 | SkPoint point2 = {3, 4};
|
| 1191 | SkRect rect;
|
| 1192 | rect.set(point1, point2);
|
| 1193 | SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
|
| 1194 | rect.set(point2, point1);
|
| 1195 | SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1196 | ## |
| 1197 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1198 | #SeeAlso setBounds setBoundsCheck |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1199 | |
| 1200 | ## |
| 1201 | |
| 1202 | # ------------------------------------------------------------------------------ |
| 1203 | |
| 1204 | #Method void setXYWH(SkScalar x, SkScalar y, SkScalar width, SkScalar height) |
| 1205 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1206 | Sets Rect to |
| 1207 | #Formula |
| 1208 | (x, y, x + width, y + height) |
| 1209 | ## |
| 1210 | . Does not validate input; |
| 1211 | width or height may be negative. |
| 1212 | |
| 1213 | #Param x stored in fLeft ## |
| 1214 | #Param y stored in fTop ## |
| 1215 | #Param width added to x and stored in fRight ## |
| 1216 | #Param height added to y and stored in fBottom ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1217 | |
| 1218 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1219 | SkRect rect;
|
| 1220 | rect.setXYWH(5, 35, -15, 25);
|
| 1221 | SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
|
| 1222 | rect.bottom(), rect.isEmpty() ? "true" : "false");
|
| 1223 | rect.sort();
|
| 1224 | SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
|
| 1225 | rect.bottom(), rect.isEmpty() ? "true" : "false");
|
| 1226 | #StdOut |
| 1227 | rect: 5, 35, -10, 60 isEmpty: true
|
| 1228 | rect: -10, 35, 5, 60 isEmpty: false |
| 1229 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1230 | ## |
| 1231 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1232 | #SeeAlso MakeXYWH setLTRB set SkIRect::setXYWH |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1233 | |
| 1234 | ## |
| 1235 | |
| 1236 | # ------------------------------------------------------------------------------ |
| 1237 | |
| 1238 | #Method void setWH(SkScalar width, SkScalar height) |
| 1239 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1240 | Sets Rect to (0, 0, width, height). Does not validate input; |
| 1241 | width or height may be negative. |
| 1242 | |
| 1243 | #Param width stored in fRight ## |
| 1244 | #Param height stored in fBottom ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1245 | |
| 1246 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1247 | SkRect rect;
|
| 1248 | rect.setWH(-15, 25);
|
| 1249 | SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
|
| 1250 | rect.bottom(), rect.isEmpty() ? "true" : "false");
|
| 1251 | rect.sort();
|
| 1252 | SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
|
| 1253 | rect.bottom(), rect.isEmpty() ? "true" : "false");
|
| 1254 | #StdOut |
| 1255 | rect: 0, 0, -15, 25 isEmpty: true
|
| 1256 | rect: -15, 0, 0, 25 isEmpty: false |
| 1257 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1258 | ## |
| 1259 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1260 | #SeeAlso MakeWH setXYWH isetWH |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1261 | |
| 1262 | ## |
| 1263 | |
| 1264 | # ------------------------------------------------------------------------------ |
| 1265 | |
| 1266 | #Method void setLargest() |
| 1267 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1268 | Sets rectangle left and top to most negative finite value, and sets |
| 1269 | right and bottom to most positive finite value. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1270 | |
| 1271 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1272 | SkRect rect;
|
| 1273 | rect.setLargest();
|
| 1274 | SkDebugf("MakeLargest isLargest: %s\n", rect.isLargest() ? "true" : "false");
|
| 1275 | SkDebugf("MakeLargest isFinite: %s\n", rect.isFinite() ? "true" : "false");
|
| 1276 | rect.outset(1e31, 1e31);
|
| 1277 | SkDebugf("outset a little isLargest: %s\n", rect.isLargest() ? "true" : "false");
|
| 1278 | SkDebugf("outset a little isFinite: %s\n", rect.isFinite() ? "true" : "false");
|
| 1279 | rect.outset(1e32, 1e32);
|
| 1280 | SkDebugf("outset a little more isLargest: %s\n", rect.isLargest() ? "true" : "false");
|
| 1281 | SkDebugf("outset a little more isFinite: %s\n", rect.isFinite() ? "true" : "false");
|
| 1282 | #StdOut
|
| 1283 | MakeLargest isLargest: true
|
| 1284 | MakeLargest isFinite: true
|
| 1285 | outset a little isLargest: true
|
| 1286 | outset a little isFinite: true
|
| 1287 | outset a little more isLargest: false
|
| 1288 | outset a little more isFinite: false
|
| 1289 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1290 | ## |
| 1291 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1292 | #SeeAlso MakeLargest isLargest setLargestInverted SK_ScalarMin SK_ScalarMax |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1293 | |
| 1294 | ## |
| 1295 | |
| 1296 | # ------------------------------------------------------------------------------ |
| 1297 | |
| 1298 | #Method void setLargestInverted() |
| 1299 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1300 | Sets rectangle left and top to most positive finite value, and sets |
| 1301 | right and bottom to most negative finite value. |
| 1302 | |
| 1303 | Use to initial Rect before one or more calls to growToInclude. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1304 | |
| 1305 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1306 | auto debugster = [](const char* prefix, const SkRect& rect) -> void {
|
| 1307 | SkDebugf("%s ", prefix);
|
| 1308 | SkDebugf("rect: %g, %g, %g, %g ", rect.left(), rect.top(), rect.right(), rect.bottom());
|
| 1309 | SkDebugf("isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
|
| 1310 | };
|
| 1311 | SkRect ptBounds;
|
| 1312 | ptBounds.setLargestInverted();
|
| 1313 | debugster("original", ptBounds);
|
| 1314 | ptBounds.growToInclude( { 42, 24 } );
|
| 1315 | debugster("grown", ptBounds); |
| 1316 | #StdOut
|
| 1317 | original rect: 3.40282e+38, 3.40282e+38, -3.40282e+38, -3.40282e+38 isEmpty: true
|
| 1318 | grown rect: 42, 24, 42, 24 isEmpty: true
|
| 1319 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1320 | ## |
| 1321 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1322 | #SeeAlso growToInclude setEmpty setLargest |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1323 | |
| 1324 | ## |
| 1325 | |
| 1326 | # ------------------------------------------------------------------------------ |
| 1327 | |
| 1328 | #Method SkRect makeOffset(SkScalar dx, SkScalar dy) const |
| 1329 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1330 | Returns Rect offset by (dx, dy). |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1331 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1332 | If dx is negative, Rect returned is moved to the left. |
| 1333 | If dx is positive, Rect returned is moved to the right. |
| 1334 | If dy is negative, Rect returned is moved upward. |
| 1335 | If dy is positive, Rect returned is moved downward. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1336 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1337 | #Param dx added to fLeft and fRight ## |
| 1338 | #Param dy added to fTop and fBottom ## |
| 1339 | |
| 1340 | #Return Rect offset in x or y, with original width and height ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1341 | |
| 1342 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1343 | SkRect rect = { 10, 50, 20, 60 };
|
| 1344 | SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
|
| 1345 | rect.bottom(), rect.isEmpty() ? "true" : "false");
|
| 1346 | rect = rect.makeOffset(15, 32);
|
| 1347 | SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
|
| 1348 | rect.bottom(), rect.isEmpty() ? "true" : "false");
|
| 1349 | #StdOut
|
| 1350 | rect: 10, 50, 20, 60 isEmpty: false
|
| 1351 | rect: 25, 82, 35, 92 isEmpty: false
|
| 1352 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1353 | ## |
| 1354 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1355 | #SeeAlso offset() makeInset makeOutset SkIRect::makeOffset |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1356 | |
| 1357 | ## |
| 1358 | |
| 1359 | # ------------------------------------------------------------------------------ |
| 1360 | |
| 1361 | #Method SkRect makeInset(SkScalar dx, SkScalar dy) const |
| 1362 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1363 | Returns Rect, inset by (dx, dy). |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1364 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1365 | If dx is negative, Rect returned is wider. |
| 1366 | If dx is positive, Rect returned is narrower. |
| 1367 | If dy is negative, Rect returned is taller. |
| 1368 | If dy is positive, Rect returned is shorter. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1369 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1370 | #Param dx added to fLeft and subtracted from fRight ## |
| 1371 | #Param dy added to fTop and subtracted from fBottom ## |
| 1372 | |
| 1373 | #Return Rect inset symmetrically left and right, top and bottom ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1374 | |
| 1375 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1376 | SkRect rect = { 10, 50, 20, 60 };
|
| 1377 | SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
|
| 1378 | rect.bottom(), rect.isEmpty() ? "true" : "false");
|
| 1379 | rect = rect.makeInset(15, 32);
|
| 1380 | SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
|
| 1381 | rect.bottom(), rect.isEmpty() ? "true" : "false");
|
| 1382 | #StdOut
|
| 1383 | rect: 10, 50, 20, 60 isEmpty: false
|
| 1384 | rect: 25, 82, 5, 28 isEmpty: true
|
| 1385 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1386 | ## |
| 1387 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1388 | #SeeAlso inset() makeOffset makeOutset SkIRect::makeInset |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1389 | |
| 1390 | ## |
| 1391 | |
| 1392 | # ------------------------------------------------------------------------------ |
| 1393 | |
| 1394 | #Method SkRect makeOutset(SkScalar dx, SkScalar dy) const |
| 1395 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1396 | Returns Rect, outset by (dx, dy). |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1397 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1398 | If dx is negative, Rect returned is narrower. |
| 1399 | If dx is positive, Rect returned is wider. |
| 1400 | If dy is negative, Rect returned is shorter. |
| 1401 | If dy is positive, Rect returned is taller. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1402 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1403 | #Param dx subtracted to fLeft and added from fRight ## |
| 1404 | #Param dy subtracted to fTop and added from fBottom ## |
| 1405 | |
| 1406 | #Return Rect outset symmetrically left and right, top and bottom ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1407 | |
| 1408 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1409 | SkRect rect = { 10, 50, 20, 60 };
|
| 1410 | SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
|
| 1411 | rect.bottom(), rect.isEmpty() ? "true" : "false");
|
| 1412 | rect = rect.makeOutset(15, 32);
|
| 1413 | SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(),
|
| 1414 | rect.bottom(), rect.isEmpty() ? "true" : "false");
|
| 1415 | #StdOut
|
| 1416 | rect: 10, 50, 20, 60 isEmpty: false
|
| 1417 | rect: -5, 18, 35, 92 isEmpty: false
|
| 1418 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1419 | ## |
| 1420 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1421 | #SeeAlso outset() makeOffset makeInset SkIRect::makeOutset |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1422 | |
| 1423 | ## |
| 1424 | |
| 1425 | # ------------------------------------------------------------------------------ |
| 1426 | |
| 1427 | #Method void offset(SkScalar dx, SkScalar dy) |
| 1428 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1429 | Offsets Rect by adding dx to fLeft, fRight; and by adding dy to fTop, fBottom. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1430 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1431 | If dx is negative, moves Rect to the left. |
| 1432 | If dx is positive, moves Rect to the right. |
| 1433 | If dy is negative, moves Rect upward. |
| 1434 | If dy is positive, moves Rect downward. |
| 1435 | |
| 1436 | #Param dx offset added to fLeft and fRight ## |
| 1437 | #Param dy offset added to fTop and fBottom ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1438 | |
| 1439 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1440 | SkRect rect = { 10, 14, 50, 73 };
|
| 1441 | rect.offset(5, 13);
|
| 1442 | SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
|
| 1443 | #StdOut
|
| 1444 | rect: 15, 27, 55, 86
|
| 1445 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1446 | ## |
| 1447 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1448 | #SeeAlso offsetTo makeOffset SkIRect::offset |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1449 | |
| 1450 | ## |
| 1451 | |
| 1452 | # ------------------------------------------------------------------------------ |
| 1453 | |
| 1454 | #Method void offset(const SkPoint& delta) |
| 1455 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1456 | Offsets Rect by adding delta.fX to fLeft, fRight; and by adding delta.fY to |
| 1457 | fTop, fBottom. |
| 1458 | |
| 1459 | If delta.fX is negative, moves Rect to the left. |
| 1460 | If delta.fX is positive, moves Rect to the right. |
| 1461 | If delta.fY is negative, moves Rect upward. |
| 1462 | If delta.fY is positive, moves Rect downward. |
| 1463 | |
| 1464 | #Param delta added to Rect ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1465 | |
| 1466 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1467 | SkRect rect = { 10, 14, 50, 73 };
|
| 1468 | rect.offset({5, 13});
|
| 1469 | SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
|
| 1470 | #StdOut
|
| 1471 | rect: 15, 27, 55, 86
|
| 1472 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1473 | ## |
| 1474 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1475 | #SeeAlso offsetTo makeOffset SkIRect::offset |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1476 | |
| 1477 | ## |
| 1478 | |
| 1479 | # ------------------------------------------------------------------------------ |
| 1480 | |
| 1481 | #Method void offsetTo(SkScalar newX, SkScalar newY) |
| 1482 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1483 | Offsets Rect so that fLeft equals newX, and fTop equals newY. width and height |
| 1484 | are unchanged. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1485 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1486 | #Param newX stored in fLeft, preserving width() ## |
| 1487 | #Param newY stored in fTop, preserving height() ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1488 | |
| 1489 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1490 | SkRect rect = { 10, 14, 50, 73 };
|
| 1491 | rect.offsetTo(15, 27);
|
| 1492 | SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
|
| 1493 | #StdOut
|
| 1494 | rect: 15, 27, 55, 86
|
| 1495 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1496 | ## |
| 1497 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1498 | #SeeAlso offset makeOffset setXYWH SkIRect::offsetTo |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1499 | |
| 1500 | ## |
| 1501 | |
| 1502 | # ------------------------------------------------------------------------------ |
| 1503 | |
| 1504 | #Method void inset(SkScalar dx, SkScalar dy) |
| 1505 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1506 | Insets Rect by (dx, dy). |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1507 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1508 | If dx is positive, makes Rect narrower. |
| 1509 | If dx is negative, makes Rect wider. |
| 1510 | If dy is positive, makes Rect shorter. |
| 1511 | If dy is negative, makes Rect taller. |
| 1512 | |
| 1513 | #Param dx added to fLeft and subtracted from fRight ## |
| 1514 | #Param dy added to fTop and subtracted from fBottom ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1515 | |
| 1516 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1517 | SkRect rect = { 10, 14, 50, 73 };
|
| 1518 | rect.inset(5, 13);
|
| 1519 | SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
|
| 1520 | #StdOut
|
| 1521 | rect: 15, 27, 45, 60
|
| 1522 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1523 | ## |
| 1524 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1525 | #SeeAlso outset makeInset SkIRect::inset |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1526 | |
| 1527 | ## |
| 1528 | |
| 1529 | # ------------------------------------------------------------------------------ |
| 1530 | |
| 1531 | #Method void outset(SkScalar dx, SkScalar dy) |
| 1532 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1533 | Outsets Rect by (dx, dy). |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1534 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1535 | If dx is positive, makes Rect wider. |
| 1536 | If dx is negative, makes Rect narrower. |
| 1537 | If dy is positive, makes Rect taller. |
| 1538 | If dy is negative, makes Rect shorter. |
| 1539 | |
| 1540 | #Param dx subtracted to fLeft and added from fRight ## |
| 1541 | #Param dy subtracted to fTop and added from fBottom ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1542 | |
| 1543 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1544 | SkRect rect = { 10, 14, 50, 73 };
|
| 1545 | rect.outset(5, 13);
|
| 1546 | SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
|
| 1547 | #StdOut
|
| 1548 | rect: 5, 1, 55, 86
|
| 1549 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1550 | ## |
| 1551 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1552 | #SeeAlso inset makeOutset SkIRect::outset |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1553 | |
| 1554 | ## |
| 1555 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1556 | #Topic Intersection |
| 1557 | |
| 1558 | Rects intersect when they enclose a common area. To intersect, each of the pair |
| 1559 | must describe area; fLeft is less than fRight, and fTop is less than fBottom; |
| 1560 | empty() returns false. The intersection of Rect a and Rect b can be described by: |
| 1561 | #Formula |
| 1562 | (max(a.fLeft, b.fLeft), max(a.fTop, b.fTop), |
| 1563 | min(a.fRight, b.fRight), min(a.fBottom, b.fBottom)) |
| 1564 | ## |
| 1565 | The intersection is only meaningful if the resulting Rect is not empty and |
| 1566 | describes an area: fLeft is less than fRight, and fTop is less than fBottom. |
| 1567 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1568 | # ------------------------------------------------------------------------------ |
| 1569 | |
| 1570 | #Method bool intersect(const SkRect& r) |
| 1571 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1572 | Returns true if Rect intersects r, and sets Rect to intersection. |
| 1573 | Returns false if Rect does not intersect r, and leaves Rect unchanged. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1574 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1575 | Returns false if either r or Rect is empty, leaving Rect unchanged. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1576 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1577 | #Param r limit of result ## |
| 1578 | |
| 1579 | #Return true if r and Rect have area in common ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1580 | |
| 1581 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1582 | #Description |
| 1583 | Two SkDebugf calls are required. If the calls are combined, their arguments |
| 1584 | may not be evaluated in left to right order: the printed intersection may |
| 1585 | be before or after the call to intersect. |
| 1586 | ## |
| 1587 | SkRect leftRect = { 10, 40, 50, 80 };
|
| 1588 | SkRect rightRect = { 30, 60, 70, 90 };
|
| 1589 | SkDebugf("%s intersection: ", leftRect.intersect(rightRect) ? "" : "no ");
|
| 1590 | SkDebugf("%g, %g, %g, %g\n", leftRect.left(), leftRect.top(),
|
| 1591 | leftRect.right(), leftRect.bottom()); |
| 1592 | #StdOut |
| 1593 | intersection: 30, 60, 50, 80 |
| 1594 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1595 | ## |
| 1596 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1597 | #SeeAlso intersects Intersects join SkIRect::intersect |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1598 | |
| 1599 | ## |
| 1600 | |
| 1601 | # ------------------------------------------------------------------------------ |
| 1602 | |
| 1603 | #Method bool intersect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) |
| 1604 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1605 | Constructs Rect to intersect from (left, top, right, bottom). Does not sort |
| 1606 | construction. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1607 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1608 | Returns true if Rect intersects construction, and sets Rect to intersection. |
| 1609 | Returns false if Rect does not intersect construction, and leaves Rect unchanged. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1610 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1611 | Returns false if either construction or Rect is empty, leaving Rect unchanged. |
| 1612 | |
| 1613 | #Param left x minimum of constructed Rect ## |
| 1614 | #Param top y minimum of constructed Rect ## |
| 1615 | #Param right x maximum of constructed Rect ## |
| 1616 | #Param bottom y maximum of constructed Rect ## |
| 1617 | |
| 1618 | #Return true if construction and Rect have area in common ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1619 | |
| 1620 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1621 | #Description |
| 1622 | Two SkDebugf calls are required. If the calls are combined, their arguments |
| 1623 | may not be evaluated in left to right order: the printed intersection may |
| 1624 | be before or after the call to intersect. |
| 1625 | ## |
| 1626 | SkRect leftRect = { 10, 40, 50, 80 };
|
| 1627 | SkDebugf("%s intersection: ", leftRect.intersect(30, 60, 70, 90) ? "" : "no ");
|
| 1628 | SkDebugf("%g, %g, %g, %g\n", leftRect.left(), leftRect.top(),
|
| 1629 | leftRect.right(), leftRect.bottom()); |
| 1630 | #StdOut |
| 1631 | intersection: 30, 60, 50, 80 |
| 1632 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1633 | ## |
| 1634 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1635 | #SeeAlso intersects Intersects join SkIRect::intersect |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1636 | |
| 1637 | ## |
| 1638 | |
| 1639 | # ------------------------------------------------------------------------------ |
| 1640 | |
| 1641 | #Method bool SK_WARN_UNUSED_RESULT intersect(const SkRect& a, const SkRect& b) |
| 1642 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1643 | Returns true if a intersects b, and sets Rect to intersection. |
| 1644 | Returns false if a does not intersect b, and leaves Rect unchanged. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1645 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1646 | Returns false if either a or b is empty, leaving Rect unchanged. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1647 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1648 | #Param a Rect to intersect ## |
| 1649 | #Param b Rect to intersect ## |
| 1650 | |
| 1651 | #Return true if a and b have area in common ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1652 | |
| 1653 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1654 | SkRect result;
|
| 1655 | bool intersected = result.intersect({ 10, 40, 50, 80 }, { 30, 60, 70, 90 });
|
| 1656 | SkDebugf("%s intersection: %g, %g, %g, %g\n", intersected ? "" : "no ",
|
| 1657 | result.left(), result.top(), result.right(), result.bottom());
|
| 1658 | #StdOut |
| 1659 | intersection: 30, 60, 50, 80 |
| 1660 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1661 | ## |
| 1662 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1663 | #SeeAlso intersects Intersects join SkIRect::intersect |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1664 | |
| 1665 | ## |
| 1666 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1667 | # ------------------------------------------------------------------------------ |
| 1668 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1669 | #Method bool intersects(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) const |
| 1670 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1671 | Constructs Rect to intersect from (left, top, right, bottom). Does not sort |
| 1672 | construction. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1673 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1674 | Returns true if Rect intersects construction. |
| 1675 | Returns false if either construction or Rect is empty, or do not intersect. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1676 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1677 | #Param left x minimum of constructed Rect ## |
| 1678 | #Param top y minimum of constructed Rect ## |
| 1679 | #Param right x maximum of constructed Rect ## |
| 1680 | #Param bottom y maximum of constructed Rect ## |
| 1681 | |
| 1682 | #Return true if construction and Rect have area in common ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1683 | |
| 1684 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1685 | SkRect rect = { 10, 40, 50, 80 };
|
| 1686 | SkDebugf("%s intersection", rect.intersects(30, 60, 70, 90) ? "" : "no ");
|
| 1687 | #StdOut |
| 1688 | intersection |
| 1689 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1690 | ## |
| 1691 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1692 | #SeeAlso intersect Intersects SkIRect::Intersects |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1693 | |
| 1694 | ## |
| 1695 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1696 | # ------------------------------------------------------------------------------ |
| 1697 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1698 | #Method bool intersects(const SkRect& r) const |
| 1699 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1700 | Returns true if Rect intersects r. |
| 1701 | Returns false if either r or Rect is empty, or do not intersect. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1702 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1703 | #Param r Rect to intersect ## |
| 1704 | |
| 1705 | #Return true if r and Rect have area in common ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1706 | |
| 1707 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1708 | SkRect rect = { 10, 40, 50, 80 };
|
| 1709 | SkDebugf("%s intersection", rect.intersects({30, 60, 70, 90}) ? "" : "no ");
|
| 1710 | #StdOut |
| 1711 | intersection |
| 1712 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1713 | ## |
| 1714 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1715 | #SeeAlso intersect Intersects SkIRect::Intersects |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1716 | |
| 1717 | ## |
| 1718 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1719 | # ------------------------------------------------------------------------------ |
| 1720 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1721 | #Method static bool Intersects(const SkRect& a, const SkRect& b) |
| 1722 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1723 | Returns true if a intersects b. |
| 1724 | Returns false if either a or b is empty, or do not intersect. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1725 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1726 | #Param a Rect to intersect ## |
| 1727 | #Param b Rect to intersect ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1728 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1729 | #Return true if a and b have area in common ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1730 | |
| 1731 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1732 | SkDebugf("%s intersection", SkRect::Intersects({10, 40, 50, 80}, {30, 60, 70, 90}) ? "" : "no ");
|
| 1733 | #StdOut |
| 1734 | intersection |
| 1735 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1736 | ## |
| 1737 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1738 | #SeeAlso intersect intersects SkIRect::Intersects |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1739 | |
| 1740 | ## |
| 1741 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1742 | #Topic Intersection ## |
| 1743 | |
| 1744 | |
| 1745 | # ------------------------------------------------------------------------------ |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1746 | |
| 1747 | #Method void join(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) |
| 1748 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1749 | Constructs Rect to intersect from (left, top, right, bottom). Does not sort |
| 1750 | construction. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1751 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1752 | Sets Rect to the union of itself and the construction. |
| 1753 | |
| 1754 | Has no effect if construction is empty. Otherwise, if Rect is empty, sets |
| 1755 | Rect to construction. |
| 1756 | |
| 1757 | #Param left x minimum of constructed Rect ## |
| 1758 | #Param top y minimum of constructed Rect ## |
| 1759 | #Param right x maximum of constructed Rect ## |
| 1760 | #Param bottom y maximum of constructed Rect ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1761 | |
| 1762 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1763 | SkRect rect = { 10, 20, 15, 25};
|
| 1764 | rect.join(50, 60, 55, 65);
|
| 1765 | SkDebugf("join: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
|
| 1766 | #StdOut |
| 1767 | join: 10, 20, 55, 65 |
| 1768 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1769 | ## |
| 1770 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1771 | #SeeAlso joinNonEmptyArg joinPossiblyEmptyRect SkIRect::join |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1772 | |
| 1773 | ## |
| 1774 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1775 | # ------------------------------------------------------------------------------ |
| 1776 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1777 | #Method void join(const SkRect& r) |
| 1778 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1779 | Sets Rect to the union of itself and r. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1780 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1781 | Has no effect if r is empty. Otherwise, if Rect is empty, sets |
| 1782 | Rect to r. |
| 1783 | |
| 1784 | #Param r expansion Rect ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1785 | |
| 1786 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1787 | SkRect rect = { 10, 20, 15, 25};
|
| 1788 | rect.join({50, 60, 55, 65});
|
| 1789 | SkDebugf("join: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
|
| 1790 | #StdOut |
| 1791 | join: 10, 20, 55, 65 |
| 1792 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1793 | ## |
| 1794 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1795 | #SeeAlso joinNonEmptyArg joinPossiblyEmptyRect SkIRect::join |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1796 | |
| 1797 | ## |
| 1798 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1799 | # ------------------------------------------------------------------------------ |
| 1800 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1801 | #Method void joinNonEmptyArg(const SkRect& r) |
| 1802 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1803 | Sets Rect to the union of itself and r. |
| 1804 | |
| 1805 | Asserts if r is empty and SK_DEBUG is defined. |
| 1806 | If Rect is empty, sets Rect to r. |
| 1807 | |
| 1808 | May produce incorrect results if r is empty. |
| 1809 | |
| 1810 | #Param r expansion Rect ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1811 | |
| 1812 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1813 | #Description |
| 1814 | Since Rect is not sorted, first result is copy of toJoin. |
| 1815 | ## |
| 1816 | SkRect rect = { 10, 100, 15, 0};
|
| 1817 | SkRect sorted = rect.makeSorted();
|
| 1818 | SkRect toJoin = { 50, 60, 55, 65 };
|
| 1819 | rect.joinNonEmptyArg(toJoin);
|
| 1820 | SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
|
| 1821 | sorted.joinNonEmptyArg(toJoin);
|
| 1822 | SkDebugf("sorted: %g, %g, %g, %g\n", sorted.fLeft, sorted.fTop, sorted.fRight, sorted.fBottom); |
| 1823 | #StdOut |
| 1824 | rect: 50, 60, 55, 65
|
| 1825 | sorted: 10, 0, 55, 100 |
| 1826 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1827 | ## |
| 1828 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1829 | #SeeAlso join joinPossiblyEmptyRect SkIRect::join |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1830 | |
| 1831 | ## |
| 1832 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1833 | # ------------------------------------------------------------------------------ |
| 1834 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1835 | #Method void joinPossiblyEmptyRect(const SkRect& r) |
| 1836 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1837 | Sets Rect to the union of itself and the construction. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1838 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1839 | May produce incorrect results if Rect or r is empty. |
| 1840 | |
| 1841 | #Param r expansion Rect ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1842 | |
| 1843 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1844 | #Description |
| 1845 | Since Rect is not sorted, first result is not useful. |
| 1846 | ## |
| 1847 | SkRect rect = { 10, 100, 15, 0};
|
| 1848 | SkRect sorted = rect.makeSorted();
|
| 1849 | SkRect toJoin = { 50, 60, 55, 65 };
|
| 1850 | rect.joinPossiblyEmptyRect(toJoin);
|
| 1851 | SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
|
| 1852 | sorted.joinPossiblyEmptyRect(toJoin);
|
| 1853 | SkDebugf("sorted: %g, %g, %g, %g\n", sorted.fLeft, sorted.fTop, sorted.fRight, sorted.fBottom);
|
| 1854 | #StdOut |
| 1855 | rect: 10, 60, 55, 65
|
| 1856 | sorted: 10, 0, 55, 100 |
| 1857 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1858 | ## |
| 1859 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1860 | #SeeAlso joinNonEmptyArg join SkIRect::join |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1861 | |
| 1862 | ## |
| 1863 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1864 | # ------------------------------------------------------------------------------ |
| 1865 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1866 | #Method void growToInclude(SkPoint pt) |
| 1867 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1868 | Grows Rect to include (pt.fX, pt.fY), modifying it so that: |
| 1869 | #Formula |
| 1870 | fLeft <= pt.fX <= fRight && fTop <= pt.fY <= fBottom |
| 1871 | ## |
| 1872 | . |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1873 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1874 | If Rect is initialized with setLargestInverted, then Rect will contain bounds of |
| 1875 | Points after one or more calls. In this case, Rect is empty after first call. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1876 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1877 | #Param pt Point to include ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1878 | |
| 1879 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1880 | SkRect rect;
|
| 1881 | rect.setLargestInverted();
|
| 1882 | rect.growToInclude( { 42, 24 } );
|
| 1883 | SkDebugf("rect: %g, %g, %g, %g ", rect.left(), rect.top(), rect.right(), rect.bottom());
|
| 1884 | SkDebugf("isEmpty: %s\n", rect.isEmpty() ? "true" : "false");
|
| 1885 | #StdOut |
| 1886 | rect: 42, 24, 42, 24 isEmpty: true |
| 1887 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1888 | ## |
| 1889 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1890 | #SeeAlso setLargestInverted join |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1891 | |
| 1892 | ## |
| 1893 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1894 | # ------------------------------------------------------------------------------ |
| 1895 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1896 | #Method void growToInclude(const SkPoint pts[], int count) |
| 1897 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1898 | For each of count Point in pts, grows Rect to include (pt.fX, pt.fY), modifying |
| 1899 | it so that: |
| 1900 | #Formula |
| 1901 | fLeft <= pt.fX <= fRight && fTop <= pt.fY <= fBottom |
| 1902 | ## |
| 1903 | . |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1904 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1905 | If Rect is initialized with setLargestInverted, then Rect will contain bounds of |
| 1906 | Points after one or more calls. In this case, Rect is empty after first call. |
| 1907 | |
| 1908 | #Param pts Point array ## |
| 1909 | #Param count number of points in array ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1910 | |
| 1911 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1912 | SkPoint pts[] = { { 30, 50 }, { 40, 50 }, { 30, 60 } };
|
| 1913 | SkRect rect = { pts[0].fX, pts[0].fY, pts[0].fX, pts[0].fY };
|
| 1914 | rect.growToInclude( pts[1] );
|
| 1915 | rect.growToInclude( pts[2] );
|
| 1916 | SkDebugf("rect: %g, %g, %g, %g ", rect.left(), rect.top(), rect.right(), rect.bottom());
|
| 1917 | #StdOut |
| 1918 | rect: 30, 50, 40, 60 |
| 1919 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1920 | ## |
| 1921 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1922 | #SeeAlso setLargestInverted join |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1923 | |
| 1924 | ## |
| 1925 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1926 | # ------------------------------------------------------------------------------ |
| 1927 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1928 | #Method void growToInclude(const SkPoint pts[], size_t stride, int count) |
| 1929 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1930 | For each of count Point in pts, grows Rect to include (pt.fX, pt.fY), modifying |
| 1931 | it so that: |
| 1932 | #Formula |
| 1933 | fLeft <= pt.fX <= fRight && fTop <= pt.fY <= fBottom |
| 1934 | ## |
| 1935 | . Point may be followed with other data in each array element. stride is number |
| 1936 | of bytes in element; the interval to skip to advance from one Point to |
| 1937 | the next. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1938 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1939 | If Rect is initialized with setLargestInverted, then Rect will contain bounds of |
| 1940 | Points after one or more calls. In this case, Rect is empty after first call. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1941 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1942 | #Param pts array of elements beginning with Point ## |
| 1943 | #Param stride size of pts elements in 32-bit words; zero or greater ## |
| 1944 | #Param count number of elements in array ## |
| 1945 | |
| 1946 | #Bug 7142 ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1947 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1948 | SkPoint3 pts[] = { { 30, 50, -1 }, { 40, 50, -1 }, { 30, 60, -1 } };
|
| 1949 | SkRect rect;
|
| 1950 | rect.setLargestInverted();
|
| 1951 | rect.growToInclude((SkPoint* ) &pts[0].fX, sizeof(SkPoint3), SK_ARRAY_COUNT(pts));
|
| 1952 | SkDebugf("rect: %g, %g, %g, %g ", rect.left(), rect.top(), rect.right(), rect.bottom());
|
| 1953 | #StdOut |
| 1954 | #Volatile |
| 1955 | rect: 30, 50, 40, 60 |
| 1956 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1957 | ## |
| 1958 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1959 | #SeeAlso setLargestInverted join |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1960 | |
| 1961 | ## |
| 1962 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1963 | # ------------------------------------------------------------------------------ |
| 1964 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1965 | #Method bool contains(const SkRect& r) const { |
| 1966 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1967 | Returns true if Rect contains r. |
| 1968 | Returns false if Rect is empty or r is empty. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1969 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1970 | Rect contains r when Rect area completely includes r area. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1971 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1972 | #Param r Rect contained ## |
| 1973 | |
| 1974 | #Return true if all sides of Rect are outside r ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1975 | |
| 1976 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1977 | SkRect rect = { 30, 50, 40, 60 };
|
| 1978 | SkRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
|
| 1979 | for (auto contained : tests) {
|
| 1980 | SkDebugf("rect: (%g, %g, %g, %g) %s (%g, %g, %g, %g)\n",
|
| 1981 | rect.left(), rect.top(), rect.right(), rect.bottom(),
|
| 1982 | rect.contains(contained) ? "contains" : "does not contain",
|
| 1983 | contained.left(), contained.top(), contained.right(), contained.bottom());
|
| 1984 | }
|
| 1985 | #StdOut
|
| 1986 | rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
|
| 1987 | rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
|
| 1988 | rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
|
| 1989 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1990 | ## |
| 1991 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1992 | #SeeAlso SkIRect::contains |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1993 | |
| 1994 | ## |
| 1995 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 1996 | # ------------------------------------------------------------------------------ |
| 1997 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1998 | #Method bool contains(const SkIRect& r) const |
| 1999 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2000 | Returns true if Rect contains r. |
| 2001 | Returns false if Rect is empty or r is empty. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2002 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2003 | Rect contains r when Rect area completely includes r area. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2004 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2005 | #Param r IRect contained ## |
| 2006 | |
| 2007 | #Return true if all sides of Rect are outside r ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2008 | |
| 2009 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2010 | SkRect rect = { 30, 50, 40, 60 };
|
| 2011 | SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} };
|
| 2012 | for (auto contained : tests) {
|
| 2013 | SkDebugf("rect: (%g, %g, %g, %g) %s (%d, %d, %d, %d)\n",
|
| 2014 | rect.left(), rect.top(), rect.right(), rect.bottom(),
|
| 2015 | rect.contains(contained) ? "contains" : "does not contain",
|
| 2016 | contained.left(), contained.top(), contained.right(), contained.bottom());
|
| 2017 | }
|
| 2018 | #StdOut
|
| 2019 | rect: (30, 50, 40, 60) contains (30, 50, 31, 51)
|
| 2020 | rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50)
|
| 2021 | rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60)
|
| 2022 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2023 | ## |
| 2024 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2025 | #SeeAlso SkIRect::contains |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2026 | |
| 2027 | ## |
| 2028 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2029 | #Topic Round |
| 2030 | |
| 2031 | # ------------------------------------------------------------------------------ |
| 2032 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2033 | #Method void round(SkIRect* dst) const |
| 2034 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2035 | Sets IRect by adding 0.5 and discarding the fractional portion of Rect |
| 2036 | members, using |
| 2037 | #Formula |
| 2038 | (SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop), |
| 2039 | SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom)) |
| 2040 | ## |
| 2041 | . |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2042 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2043 | #Param dst storage for IRect ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2044 | |
| 2045 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2046 | SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
|
| 2047 | SkIRect round;
|
| 2048 | rect.round(&round);
|
| 2049 | SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
|
| 2050 | #StdOut |
| 2051 | round: 31, 51, 41, 61 |
| 2052 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2053 | ## |
| 2054 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2055 | #SeeAlso roundIn roundOut SkScalarRoundToInt |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2056 | |
| 2057 | ## |
| 2058 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2059 | # ------------------------------------------------------------------------------ |
| 2060 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2061 | #Method void roundOut(SkIRect* dst) const |
| 2062 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2063 | Sets IRect by discarding the fractional portion of fLeft and fTop; and |
| 2064 | rounding up fRight and FBottom, using |
| 2065 | #Formula |
| 2066 | (SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop), |
| 2067 | SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom)) |
| 2068 | ## |
| 2069 | . |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2070 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2071 | #Param dst storage for IRect ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2072 | |
| 2073 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2074 | SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
|
| 2075 | SkIRect round;
|
| 2076 | rect.roundOut(&round);
|
| 2077 | SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
|
| 2078 | #StdOut |
| 2079 | round: 30, 50, 41, 61 |
| 2080 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2081 | ## |
| 2082 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2083 | #SeeAlso roundIn round SkScalarRoundToInt |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2084 | |
| 2085 | ## |
| 2086 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2087 | # ------------------------------------------------------------------------------ |
| 2088 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2089 | #Method void roundOut(SkRect* dst) const |
| 2090 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2091 | Sets Rect by discarding the fractional portion of fLeft and fTop; and |
| 2092 | rounding up fRight and FBottom, using |
| 2093 | #Formula |
| 2094 | (SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop), |
| 2095 | SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom)) |
| 2096 | ## |
| 2097 | . |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2098 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2099 | #Param dst storage for Rect ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2100 | |
| 2101 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2102 | SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
|
| 2103 | SkRect round;
|
| 2104 | rect.roundOut(&round);
|
| 2105 | SkDebugf("round: %g, %g, %g, %g\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
|
| 2106 | #StdOut |
| 2107 | round: 30, 50, 41, 61 |
| 2108 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2109 | ## |
| 2110 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2111 | #SeeAlso roundIn round SkScalarRoundToInt |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2112 | |
| 2113 | ## |
| 2114 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2115 | # ------------------------------------------------------------------------------ |
| 2116 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2117 | #Method void roundIn(SkIRect* dst) const |
| 2118 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2119 | Sets Rect by rounding up fLeft and fTop; and |
| 2120 | discarding the fractional portion of fRight and FBottom, using |
| 2121 | #Formula |
| 2122 | (SkScalarCeilToInt(fLeft), SkScalarCeilToInt(fTop), |
| 2123 | SkScalarFloorToInt(fRight), SkScalarFloorToInt(fBottom)) |
| 2124 | ## |
| 2125 | . |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2126 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2127 | #Param dst storage for IRect ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2128 | |
| 2129 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2130 | SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
|
| 2131 | SkIRect round;
|
| 2132 | rect.roundIn(&round);
|
| 2133 | SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
|
| 2134 | #StdOut |
| 2135 | round: 31, 51, 40, 60
|
| 2136 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2137 | ## |
| 2138 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2139 | #SeeAlso roundOut round SkScalarRoundToInt |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2140 | |
| 2141 | ## |
| 2142 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2143 | # ------------------------------------------------------------------------------ |
| 2144 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2145 | #Method SkIRect round() const |
| 2146 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2147 | Returns IRect by adding 0.5 and discarding the fractional portion of Rect |
| 2148 | members, using |
| 2149 | #Formula |
| 2150 | (SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop), |
| 2151 | SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom)) |
| 2152 | ## |
| 2153 | . |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2154 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2155 | #Return rounded IRect ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2156 | |
| 2157 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2158 | SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
|
| 2159 | SkIRect round = rect.round();
|
| 2160 | SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
|
| 2161 | #StdOut |
| 2162 | round: 31, 51, 41, 61
|
| 2163 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2164 | ## |
| 2165 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2166 | #SeeAlso roundOut roundIn SkScalarRoundToInt |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2167 | |
| 2168 | ## |
| 2169 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2170 | # ------------------------------------------------------------------------------ |
| 2171 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2172 | #Method SkIRect roundOut() const |
| 2173 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2174 | Sets IRect by discarding the fractional portion of fLeft and fTop; and |
| 2175 | rounding up fRight and FBottom, using |
| 2176 | #Formula |
| 2177 | (SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop), |
| 2178 | SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom)) |
| 2179 | ## |
| 2180 | . |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2181 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2182 | #Return rounded IRect ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2183 | |
| 2184 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2185 | SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f };
|
| 2186 | SkIRect round = rect.roundOut();
|
| 2187 | SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom);
|
| 2188 | #StdOut |
| 2189 | round: 30, 50, 41, 61
|
| 2190 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2191 | ## |
| 2192 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2193 | #SeeAlso round roundIn SkScalarRoundToInt |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2194 | |
| 2195 | ## |
| 2196 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2197 | #Topic Round ## |
| 2198 | |
| 2199 | # ------------------------------------------------------------------------------ |
| 2200 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2201 | #Method void sort() |
| 2202 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2203 | Swaps fLeft and fRight if fLeft is greater than fRight; and swaps |
| 2204 | fTop and fBottom if fTop is greater than fBottom. Result may be empty; |
| 2205 | and width() and height() will be zero or positive. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2206 | |
| 2207 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2208 | SkRect rect = { 30.5f, 50.5f, 20.5f, 10.5f };
|
| 2209 | SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
|
| 2210 | rect.sort();
|
| 2211 | SkDebugf("sorted: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
|
| 2212 | #StdOut |
| 2213 | rect: 30.5, 50.5, 20.5, 10.5
|
| 2214 | sorted: 20.5, 10.5, 30.5, 50.5 |
| 2215 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2216 | ## |
| 2217 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2218 | #SeeAlso makeSorted SkIRect::sort |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2219 | |
| 2220 | ## |
| 2221 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2222 | # ------------------------------------------------------------------------------ |
| 2223 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2224 | #Method SkRect makeSorted() const |
| 2225 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2226 | Returns Rect with fLeft and fRight swapped if fLeft is greater than fRight; and |
| 2227 | with fTop and fBottom swapped if fTop is greater than fBottom. Result may be empty; |
| 2228 | and width() and height() will be zero or positive. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2229 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2230 | #Return sorted Rect ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2231 | |
| 2232 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2233 | SkRect rect = { 30.5f, 50.5f, 20.5f, 10.5f };
|
| 2234 | SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
|
| 2235 | SkRect sort = rect.makeSorted();
|
| 2236 | SkDebugf("sorted: %g, %g, %g, %g\n", sort.fLeft, sort.fTop, sort.fRight, sort.fBottom);
|
| 2237 | #StdOut |
| 2238 | rect: 30.5, 50.5, 20.5, 10.5
|
| 2239 | sorted: 20.5, 10.5, 30.5, 50.5 |
| 2240 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2241 | ## |
| 2242 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2243 | #SeeAlso sort SkIRect::makeSorted |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2244 | |
| 2245 | ## |
| 2246 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2247 | # ------------------------------------------------------------------------------ |
| 2248 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2249 | #Method const SkScalar* asScalars() const |
| 2250 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2251 | Returns pointer to first Scalar in Rect, to treat it as an array with four |
| 2252 | entries. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2253 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2254 | #Return pointer to fLeft ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2255 | |
| 2256 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2257 | SkRect rect = {7, 11, 13, 17};
|
| 2258 | SkDebugf("rect.asScalars() %c= &rect.fLeft\n", rect.asScalars() == &rect.fLeft? '=' : '!');
|
| 2259 | #StdOut
|
| 2260 | rect.asScalars() == &rect.fLeft
|
| 2261 | ##
|
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2262 | ## |
| 2263 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2264 | #SeeAlso toQuad |
| 2265 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2266 | ## |
| 2267 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2268 | # ------------------------------------------------------------------------------ |
| 2269 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2270 | #Method void dump(bool asHex) const |
| 2271 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2272 | Writes text representation of Rect to standard output. Set asHex to true to |
| 2273 | generate exact binary representations of floating point numbers. |
| 2274 | |
| 2275 | #Param asHex true if SkScalar values are written as hexadecimal ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2276 | |
| 2277 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2278 | SkRect rect = {20, 30, 40, 50}; |
| 2279 | for (bool dumpAsHex : { false, true } ) { |
| 2280 | rect.dump(dumpAsHex); |
| 2281 | SkDebugf("\n"); |
| 2282 | } |
| 2283 | #StdOut |
| 2284 | SkRect::MakeLTRB(20, 30, 40, 50);
|
| 2285 |
|
| 2286 | SkRect::MakeLTRB(SkBits2Float(0x41a00000), /* 20.000000 */
|
| 2287 | SkBits2Float(0x41f00000), /* 30.000000 */
|
| 2288 | SkBits2Float(0x42200000), /* 40.000000 */
|
| 2289 | SkBits2Float(0x42480000) /* 50.000000 */);
|
| 2290 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2291 | ## |
| 2292 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2293 | #SeeAlso dumpHex |
| 2294 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2295 | ## |
| 2296 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2297 | # ------------------------------------------------------------------------------ |
| 2298 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2299 | #Method void dump() const |
| 2300 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2301 | Writes text representation of Rect to standard output. The representation may be |
| 2302 | directly compiled as C++ code. Floating point values are written |
| 2303 | with limited precision; it may not be possible to reconstruct original Rect |
| 2304 | from output. |
| 2305 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2306 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2307 | SkRect rect = {6.f / 7, 2.f / 3, 26.f / 10, 42.f / 6};
|
| 2308 | rect.dump();
|
| 2309 | SkRect copy = SkRect::MakeLTRB(0.857143f, 0.666667f, 2.6f, 7);
|
| 2310 | SkDebugf("rect is " "%s" "equal to copy\n", rect == copy ? "" : "not ");
|
| 2311 | #StdOut |
| 2312 | SkRect::MakeLTRB(0.857143f, 0.666667f, 2.6f, 7);
|
| 2313 | rect is not equal to copy |
| 2314 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2315 | ## |
| 2316 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2317 | #SeeAlso dumpHex |
| 2318 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2319 | ## |
| 2320 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2321 | # ------------------------------------------------------------------------------ |
| 2322 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2323 | #Method void dumpHex() const |
| 2324 | |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2325 | Writes text representation of Rect to standard output. The representation may be |
| 2326 | directly compiled as C++ code. Floating point values are written |
| 2327 | in hexadecimal to preserve their exact bit pattern. The output reconstructs the |
| 2328 | original Rect. |
| 2329 | |
| 2330 | Use instead of dump() when submitting |
| 2331 | #A bug reports against Skia # http://bug.skia.org ## |
| 2332 | . |
| 2333 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2334 | #Example |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2335 | SkRect rect = {6.f / 7, 2.f / 3, 26.f / 10, 42.f / 6};
|
| 2336 | rect.dumpHex();
|
| 2337 | SkRect copy = SkRect::MakeLTRB(SkBits2Float(0x3f5b6db7), /* 0.857143 */
|
| 2338 | SkBits2Float(0x3f2aaaab), /* 0.666667 */
|
| 2339 | SkBits2Float(0x40266666), /* 2.600000 */
|
| 2340 | SkBits2Float(0x40e00000) /* 7.000000 */);
|
| 2341 | SkDebugf("rect is " "%s" "equal to copy\n", rect == copy ? "" : "not "); |
| 2342 | #StdOut |
| 2343 | SkRect::MakeLTRB(SkBits2Float(0x3f5b6db7), /* 0.857143 */
|
| 2344 | SkBits2Float(0x3f2aaaab), /* 0.666667 */
|
| 2345 | SkBits2Float(0x40266666), /* 2.600000 */
|
| 2346 | SkBits2Float(0x40e00000) /* 7.000000 */);
|
| 2347 | rect is equal to copy |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2348 | ## |
Cary Clark | 7fc1d12 | 2017-10-09 14:07:42 -0400 | [diff] [blame^] | 2349 | ## |
| 2350 | |
| 2351 | #SeeAlso dump |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2352 | |
| 2353 | ## |
| 2354 | |
| 2355 | #Struct SkRect ## |
| 2356 | |
| 2357 | #Topic Rect ## |