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