1 #Topic IPoint 2 #Alias IPoints 3 #Alias IPoint_Reference 4 5 #Subtopic Overview 6 #Subtopic Subtopic 7 #Populate 8 ## 9 ## 10 11 #Struct SkIPoint 12 13 SkIPoint holds two 32 bit integer coordinates. 14 15 #Subtopic Related_Function 16 #Populate 17 ## 18 19 #Subtopic Member_Function 20 #Populate 21 ## 22 23 #Subtopic Member 24 #Populate 25 26 #Member int32_t fX 27 #Line # x-axis value ## 28 x-axis value used by IPoint. 29 ## 30 31 #Member int32_t fY 32 #Line # y-axis value ## 33 y-axis value used by IPoint. 34 ## 35 36 #Subtopic Member ## 37 38 # ------------------------------------------------------------------------------ 39 40 #Subtopic Constructor 41 #Populate 42 ## 43 44 #Method static constexpr SkIPoint Make(int32_t x, int32_t y) 45 46 #In Constructor 47 #Line # constructs from integer inputs ## 48 Sets fX to x, fY to y. 49 50 #Param x integer x-axis value of constructed IPoint ## 51 #Param y integer y-axis value of constructed IPoint ## 52 53 #Return IPoint (x, y) ## 54 55 #Example 56 SkIPoint pt1 = {45, 66}; 57 SkIPoint pt2 = SkIPoint::Make(45, 66); 58 SkDebugf("pt1 %c= pt2\n", pt1 == pt2 ? '=' : '!'); 59 #StdOut 60 pt1 == pt2 61 ## 62 ## 63 64 #SeeAlso set() SkPoint::iset() SkPoint::Make SkIPoint16::Make 65 66 #Method ## 67 68 # ------------------------------------------------------------------------------ 69 70 #Subtopic Property 71 #Line # member values ## 72 #Populate 73 ## 74 75 #Method int32_t x() const 76 #In Property 77 #Line # returns fX ## 78 Returns x-axis value of IPoint. 79 80 #Return fX ## 81 82 #Example 83 SkIPoint pt1 = {45, 66}; 84 SkDebugf("pt1.fX %c= pt1.x()\n", pt1.fX == pt1.x() ? '=' : '!'); 85 #StdOut 86 pt1.fX == pt1.x() 87 ## 88 ## 89 90 #SeeAlso y() SkPoint::x() SkIPoint16::x() 91 92 #Method ## 93 94 # ------------------------------------------------------------------------------ 95 96 #Method int32_t y() const 97 #In Property 98 #Line # returns fY ## 99 Returns y-axis value of IPoint. 100 101 #Return fY ## 102 103 #Example 104 SkIPoint pt1 = {45, 66}; 105 SkDebugf("pt1.fY %c= pt1.y()\n", pt1.fY == pt1.y() ? '=' : '!'); 106 #StdOut 107 pt1.fY == pt1.y() 108 ## 109 ## 110 111 #SeeAlso x() SkPoint::y() SkIPoint16::y() 112 113 #Method ## 114 115 # ------------------------------------------------------------------------------ 116 117 #Method bool isZero() const 118 #In Property 119 #Line # returns true if both members equal zero ## 120 Returns true if fX and fY are both zero. 121 122 #Return true if fX is zero and fY is zero ## 123 124 #Example 125 SkIPoint pt = { 0, -0}; 126 SkDebugf("pt.isZero() == %s\n", pt.isZero() ? "true" : "false"); 127 #StdOut 128 pt.isZero() == true 129 ## 130 ## 131 132 #SeeAlso SkPoint::isZero 133 134 #Method ## 135 136 # ------------------------------------------------------------------------------ 137 138 #Subtopic Set 139 #Populate 140 #Line # replaces all values ## 141 ## 142 143 #Method void set(int32_t x, int32_t y) 144 #In Set 145 #Line # sets to integer input ## 146 Sets fX to x and fY to y. 147 148 #Param x new value for fX ## 149 #Param y new value for fY ## 150 151 #Example 152 SkIPoint pt1, pt2 = { SK_MinS32, SK_MaxS32 }; 153 pt1.set(SK_MinS32, SK_MaxS32); 154 SkDebugf("pt1 %c= pt2\n", pt1 == pt2 ? '=' : '!'); 155 #StdOut 156 pt1 == pt2 157 ## 158 ## 159 160 #SeeAlso Make SkIPoint16::set 161 162 #Method ## 163 164 # ------------------------------------------------------------------------------ 165 #Subtopic Operator 166 #Populate 167 ## 168 169 #Method SkIPoint operator-()_const 170 171 #Line # reverses sign of IPoint ## 172 Returns IPoint changing the signs of fX and fY. 173 174 #Return IPoint as (-fX, -fY) ## 175 176 #Example 177 SkIPoint test[] = { {0, -0}, {-1, -2}, 178 { SK_MaxS32, SK_MinS32 }, 179 { SK_NaN32, -SK_NaN32 } }; 180 for (const SkIPoint& pt : test) { 181 SkIPoint negPt = -pt; 182 SkDebugf("pt: %d, %d negate: %d, %d\n", pt.fX, pt.fY, negPt.fX, negPt.fY); 183 } 184 #StdOut 185 pt: 0, 0 negate: 0, 0 186 pt: -1, -2 negate: 1, 2 187 pt: 2147483647, -2147483647 negate: -2147483647, 2147483647 188 pt: -2147483648, -2147483648 negate: -2147483648, -2147483648 189 ## 190 ## 191 192 #SeeAlso operator-(const SkIPoint& a, const SkIPoint& b) operator-=(const SkIVector& v) SkPoint::operator-()_const 193 194 #Method ## 195 196 # ------------------------------------------------------------------------------ 197 198 #Method void operator+=(const SkIVector& v) 199 200 #Line # adds IVector to IPoint ## 201 Offsets IPoint by IVector v. Sets IPoint to 202 #Formula 203 (fX + v.fX, fY + v.fY) 204 ## 205 . 206 207 #Param v IVector to add ## 208 209 #Example 210 #Height 64 211 auto draw_lines = [=](const SkIPoint pts[], size_t count, SkPaint& paint) -> void { 212 for (size_t i = 0; i < count - 1; ++i) { 213 SkPoint p0, p1; 214 p0.iset(pts[i]); 215 p1.iset(pts[i + 1]); 216 canvas->drawLine(p0, p1, paint); 217 } 218 }; 219 SkIPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 } }; 220 SkPaint paint; 221 paint.setAntiAlias(true); 222 paint.setStyle(SkPaint::kStroke_Style); 223 canvas->scale(30, 15); 224 draw_lines(points, SK_ARRAY_COUNT(points), paint); 225 points[1] += {1, 1}; 226 points[2] += {-1, -1}; 227 paint.setColor(SK_ColorRED); 228 draw_lines(points, SK_ARRAY_COUNT(points), paint); 229 ## 230 231 #SeeAlso operator+(const SkIPoint& a, const SkIVector& b) SkPoint::operator+=(const SkVector& v) 232 233 #Method ## 234 235 # ------------------------------------------------------------------------------ 236 237 #Method void operator-=(const SkIVector& v) 238 239 #Line # subtracts IVector from IPoint ## 240 Subtracts IVector v from IPoint. Sets IPoint to: 241 #Formula 242 (fX - v.fX, fY - v.fY) 243 ## 244 . 245 246 #Param v IVector to subtract ## 247 248 #Example 249 #Height 64 250 auto draw_lines = [=](const SkIPoint pts[], size_t count, SkPaint& paint) -> void { 251 for (size_t i = 0; i < count - 1; ++i) { 252 SkPoint p0, p1; 253 p0.iset(pts[i]); 254 p1.iset(pts[i + 1]); 255 canvas->drawLine(p0, p1, paint); 256 } 257 }; 258 SkIPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 } }; 259 SkPaint paint; 260 paint.setAntiAlias(true); 261 paint.setStyle(SkPaint::kStroke_Style); 262 canvas->scale(30, 15); 263 draw_lines(points, SK_ARRAY_COUNT(points), paint); 264 points[1] -= {1, 1}; 265 points[2] -= {-1, -1}; 266 paint.setColor(SK_ColorRED); 267 draw_lines(points, SK_ARRAY_COUNT(points), paint); 268 ## 269 270 #SeeAlso operator-(const SkIPoint& a, const SkIPoint& b) SkPoint::operator-=(const SkVector& v) 271 272 #Method ## 273 274 # ------------------------------------------------------------------------------ 275 276 #Method bool equals(int32_t x, int32_t y) const 277 #In Operator 278 #Line # returns true if members are equal ## 279 Returns true if IPoint is equivalent to IPoint constructed from (x, y). 280 281 #Param x value compared with fX ## 282 #Param y value compared with fY ## 283 284 #Return true if IPoint equals (x, y) ## 285 286 #Example 287 SkIPoint test[] = { {0, -0}, {-1, -2}, {SK_MaxS32, -1}, {SK_NaN32, -1} }; 288 for (const SkIPoint& pt : test) { 289 SkDebugf("pt: %d, %d %c= pt\n", pt.fX, pt.fY, pt.equals(pt.fX, pt.fY) ? '=' : '!'); 290 } 291 #StdOut 292 pt: 0, 0 == pt 293 pt: -1, -2 == pt 294 pt: 2147483647, -1 == pt 295 pt: -2147483648, -1 == pt 296 ## 297 ## 298 299 #SeeAlso operator==(const SkIPoint& a, const SkIPoint& b) 300 301 #Method ## 302 303 # ------------------------------------------------------------------------------ 304 305 #Method bool operator==(const SkIPoint& a, const SkIPoint& b) 306 307 #Line # returns true if IPoints are equal ## 308 Returns true if a is equivalent to b. 309 310 #Param a IPoint to compare ## 311 #Param b IPoint to compare ## 312 313 #Return true if a.fX == b.fX and a.fY == b.fY ## 314 315 #Example 316 SkIPoint test[] = { {0, -0}, {-1, -2}, {SK_MaxS32, -1}, {SK_NaN32, -1} }; 317 for (const SkIPoint& pt : test) { 318 SkDebugf("pt: %d, %d %c= pt\n", pt.fX, pt.fY, pt == pt ? '=' : '!'); 319 } 320 #StdOut 321 pt: 0, 0 == pt 322 pt: -1, -2 == pt 323 pt: 2147483647, -1 == pt 324 pt: -2147483648, -1 == pt 325 ## 326 ## 327 328 #SeeAlso equals() operator!=(const SkIPoint& a, const SkIPoint& b) 329 330 #Method ## 331 332 # ------------------------------------------------------------------------------ 333 334 #Method bool operator!=(const SkIPoint& a, const SkIPoint& b) 335 336 #Line # returns true if IPoints are unequal ## 337 Returns true if a is not equivalent to b. 338 339 #Param a IPoint to compare ## 340 #Param b IPoint to compare ## 341 342 #Return true if a.fX != b.fX or a.fY != b.fY ## 343 344 #Example 345 SkIPoint test[] = { {0, -0}, {-1, -2}, {SK_MaxS32, -1}, {SK_NaN32, -1} }; 346 for (const SkIPoint& pt : test) { 347 SkDebugf("pt: %d, %d %c= pt\n", pt.fX, pt.fY, pt != pt ? '!' : '='); 348 } 349 #StdOut 350 pt: 0, 0 == pt 351 pt: -1, -2 == pt 352 pt: 2147483647, -1 == pt 353 pt: -2147483648, -1 == pt 354 ## 355 ## 356 357 #SeeAlso operator==(const SkIPoint& a, const SkIPoint& b) equals() 358 359 #Method ## 360 361 # ------------------------------------------------------------------------------ 362 363 #Method SkIVector operator-(const SkIPoint& a, const SkIPoint& b) 364 365 #Line # returns IVector between IPoints ## 366 Returns IVector from b to a; computed as 367 #Formula 368 (a.fX - b.fX, a.fY - b.fY) 369 ## 370 . 371 372 Can also be used to subtract IVector from IVector, returning IVector. 373 374 #Param a IPoint or IVector to subtract from ## 375 #Param b IVector to subtract ## 376 377 #Return IVector from b to a ## 378 379 #Example 380 #Height 64 381 auto draw_lines = [=](const SkIPoint pts[], size_t count, SkPaint& paint) -> void { 382 for (size_t i = 0; i < count - 1; ++i) { 383 SkPoint p0, p1; 384 p0.iset(pts[i]); 385 p1.iset(pts[i + 1]); 386 canvas->drawLine(p0, p1, paint); 387 } 388 }; 389 SkIPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 } }; 390 SkPaint paint; 391 paint.setAntiAlias(true); 392 paint.setStyle(SkPaint::kStroke_Style); 393 canvas->scale(30, 15); 394 draw_lines(points, SK_ARRAY_COUNT(points), paint); 395 points[1] += points[0] - points[3]; 396 points[2] -= points[1] - points[0]; 397 paint.setColor(SK_ColorRED); 398 draw_lines(points, SK_ARRAY_COUNT(points), paint); 399 ## 400 401 #SeeAlso operator-=(const SkIVector& v) 402 403 #Method ## 404 405 # ------------------------------------------------------------------------------ 406 407 #Method SkIPoint operator+(const SkIPoint& a, const SkIVector& b) 408 409 #Line # returns IPoint offset by IVector ## 410 Returns IPoint resulting from IPoint a offset by IVector b, computed as: 411 #Formula 412 (a.fX + b.fX, a.fY + b.fY) 413 ## 414 . 415 416 Can also be used to offset IPoint b by IVector a, returning IPoint. 417 Can also be used to add IVector to IVector, returning IVector. 418 419 #Param a IPoint or IVector to add to ## 420 #Param b IPoint or IVector to add ## 421 422 #Return IPoint equal to a offset by b ## 423 424 #Example 425 #Height 128 426 auto draw_lines = [=](const SkIPoint pts[], size_t count, SkPaint& paint) -> void { 427 for (size_t i = 0; i < count - 1; ++i) { 428 SkPoint p0, p1; 429 p0.iset(pts[i]); 430 p1.iset(pts[i + 1]); 431 canvas->drawLine(p0, p1, paint); 432 } 433 }; 434 SkIPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 } }; 435 SkPaint paint; 436 paint.setAntiAlias(true); 437 paint.setStyle(SkPaint::kStroke_Style); 438 canvas->scale(30, 15); 439 draw_lines(points, SK_ARRAY_COUNT(points), paint); 440 SkIPoint mod = {4, 1}; 441 for (auto& point : points) { 442 point = point + mod; 443 mod.fX -= 1; 444 mod.fY += 1; 445 } 446 paint.setColor(SK_ColorRED); 447 draw_lines(points, SK_ARRAY_COUNT(points), paint); 448 ## 449 450 #SeeAlso operator+=(const SkIVector& v) 451 452 #Method ## 453 454 #Struct SkIPoint ## 455 456 #Topic IPoint ## 457 458 #Topic IVector 459 #Alias IVectors 460 #Typedef SkIPoint SkIVector 461 #Typedef ## 462 ## 463