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