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