Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1 | #Topic Point |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 2 | #Alias Points ## |
| 3 | #Alias Point_Reference ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 4 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 5 | #Struct SkPoint |
| 6 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 7 | SkPoint holds two 32-bit floating point coordinates. |
| 8 | |
| 9 | #Subtopic Overview |
| 10 | #Populate |
| 11 | ## |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 12 | |
| 13 | #Subtopic Related_Function |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 14 | #Populate |
| 15 | ## |
Cary Clark | 5081eed | 2018-01-22 07:55:48 -0500 | [diff] [blame] | 16 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 17 | #Subtopic Member_Function |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 18 | #Populate |
| 19 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 20 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 21 | #Subtopic Member |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 22 | #Populate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 23 | |
| 24 | #Member SkScalar fX |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 25 | #Line # x-axis value ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 26 | x-axis value used by both Point and Vector. May contain any value, including |
| 27 | infinities and NaN. |
| 28 | ## |
| 29 | |
| 30 | #Member SkScalar fY |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 31 | #Line # y-axis value ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 32 | y-axis value used by both Point and Vector. May contain any value, including |
| 33 | infinities and NaN. |
| 34 | ## |
| 35 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 36 | #Subtopic Member ## |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 37 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 38 | # ------------------------------------------------------------------------------ |
| 39 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 40 | #Subtopic Constructor |
| 41 | #Populate |
| 42 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 43 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 44 | #Method static constexpr SkPoint Make(SkScalar x, SkScalar y) |
| 45 | #In Constructor |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 46 | #Line # constructs from SkScalar inputs ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 47 | Sets fX to x, fY to y. Used both to set Point and Vector. |
| 48 | |
| 49 | #Param x SkScalar x-axis value of constructed Point or Vector ## |
| 50 | #Param y SkScalar y-axis value of constructed Point or Vector ## |
| 51 | |
| 52 | #Return Point (x, y) ## |
| 53 | |
| 54 | #Example |
| 55 | SkPoint pt1 = {45, 66}; |
| 56 | SkPoint pt2 = SkPoint::Make(45, 66); |
| 57 | SkVector v1 = {45, 66}; |
| 58 | SkVector v2 = SkPoint::Make(45, 66); |
| 59 | SkDebugf("all %s" "equal\n", pt1 == pt2 && pt2 == v1 && v1 == v2 ? "" : "not "); |
| 60 | #StdOut |
| 61 | all equal |
| 62 | ## |
| 63 | ## |
| 64 | |
| 65 | #SeeAlso set() iset() SkIPoint::Make |
| 66 | |
| 67 | #Method ## |
| 68 | |
| 69 | # ------------------------------------------------------------------------------ |
| 70 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 71 | #Subtopic Property |
| 72 | #Line # member values ## |
| 73 | #Populate |
| 74 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 75 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 76 | #Method SkScalar x() const |
| 77 | #In Property |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 78 | #Line # returns fX ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 79 | Returns x-axis value of Point or Vector. |
| 80 | |
| 81 | #Return fX ## |
| 82 | |
| 83 | #Example |
| 84 | SkPoint pt1 = {45, 66}; |
| 85 | SkDebugf("pt1.fX %c= pt1.x()\n", pt1.fX == pt1.x() ? '=' : '!'); |
| 86 | #StdOut |
| 87 | pt1.fX == pt1.x() |
| 88 | ## |
| 89 | ## |
| 90 | |
| 91 | #SeeAlso y() SkIPoint::x() |
| 92 | |
| 93 | #Method ## |
| 94 | |
| 95 | # ------------------------------------------------------------------------------ |
| 96 | |
| 97 | #Method SkScalar y() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 98 | #In Property |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 99 | #Line # returns fY ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 100 | Returns y-axis value of Point or Vector. |
| 101 | |
| 102 | #Return fY ## |
| 103 | |
| 104 | #Example |
| 105 | SkPoint pt1 = {45, 66}; |
| 106 | SkDebugf("pt1.fY %c= pt1.y()\n", pt1.fY == pt1.y() ? '=' : '!'); |
| 107 | #StdOut |
| 108 | pt1.fY == pt1.y() |
| 109 | ## |
| 110 | ## |
| 111 | |
| 112 | #SeeAlso x() SkIPoint::y() |
| 113 | |
| 114 | #Method ## |
| 115 | |
| 116 | # ------------------------------------------------------------------------------ |
| 117 | |
| 118 | #Method bool isZero() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 119 | #In Property |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 120 | #Line # returns true if both members equal zero ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 121 | Returns true if fX and fY are both zero. |
| 122 | |
| 123 | #Return true if fX is zero and fY is zero ## |
| 124 | |
| 125 | #Example |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 126 | SkPoint pt = { 0.f, -0.f}; |
| 127 | SkDebugf("pt.fX=%c%g pt.fY=%c%g\n", std::signbit(pt.fX) ? '-' : '+', fabsf(pt.fX), |
| 128 | std::signbit(pt.fY) ? '-' : '+', fabsf(pt.fY)); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 129 | SkDebugf("pt.isZero() == %s\n", pt.isZero() ? "true" : "false"); |
| 130 | #StdOut |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 131 | pt.fX=+0 pt.fY=-0 |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 132 | pt.isZero() == true |
| 133 | ## |
| 134 | ## |
| 135 | |
| 136 | #SeeAlso isFinite SkIPoint::isZero |
| 137 | |
| 138 | #Method ## |
| 139 | |
| 140 | # ------------------------------------------------------------------------------ |
| 141 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 142 | #Subtopic Set |
| 143 | #Populate |
| 144 | #Line # replaces all values ## |
| 145 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 146 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 147 | #Method void set(SkScalar x, SkScalar y) |
| 148 | #In Set |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 149 | #Line # sets to SkScalar input ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 150 | Sets fX to x and fY to y. |
| 151 | |
| 152 | #Param x new value for fX ## |
| 153 | #Param y new value for fY ## |
| 154 | |
| 155 | #Example |
| 156 | SkPoint pt1, pt2 = { SK_ScalarPI, SK_ScalarSqrt2 }; |
| 157 | pt1.set(SK_ScalarPI, SK_ScalarSqrt2); |
| 158 | SkDebugf("pt1 %c= pt2\n", pt1 == pt2 ? '=' : '!'); |
| 159 | #StdOut |
| 160 | pt1 == pt2 |
| 161 | ## |
| 162 | ## |
| 163 | |
| 164 | #SeeAlso iset() Make |
| 165 | |
| 166 | #Method ## |
| 167 | |
| 168 | # ------------------------------------------------------------------------------ |
| 169 | |
| 170 | #Method void iset(int32_t x, int32_t y) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 171 | #In Set |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 172 | #Line # sets to integer input ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 173 | Sets fX to x and fY to y, promoting integers to SkScalar values. |
| 174 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 175 | Assigning a large integer value directly to fX or fY may cause a compiler |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 176 | error, triggered by narrowing conversion of int to SkScalar. This safely |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 177 | casts x and y to avoid the error. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 178 | |
| 179 | #Param x new value for fX ## |
| 180 | #Param y new value for fY ## |
| 181 | |
| 182 | #Example |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 183 | SkPoint pt1, pt2 = { SK_MinS16, SK_MaxS16 }; |
| 184 | pt1.iset(SK_MinS16, SK_MaxS16); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 185 | SkDebugf("pt1 %c= pt2\n", pt1 == pt2 ? '=' : '!'); |
| 186 | ## |
| 187 | |
| 188 | #SeeAlso set Make SkIPoint::set |
| 189 | |
| 190 | #Method ## |
| 191 | |
| 192 | # ------------------------------------------------------------------------------ |
| 193 | |
| 194 | #Method void iset(const SkIPoint& p) |
| 195 | |
| 196 | Sets fX to p.fX and fY to p.fY, promoting integers to SkScalar values. |
| 197 | |
| 198 | Assigning an IPoint containing a large integer value directly to fX or fY may |
| 199 | cause a compiler error, triggered by narrowing conversion of int to SkScalar. |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 200 | This safely casts p.fX and p.fY to avoid the error. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 201 | |
| 202 | #Param p IPoint members promoted to SkScalar ## |
| 203 | |
| 204 | #Example |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 205 | SkIPoint iPt = { SK_MinS32, SK_MaxS32 }; |
| 206 | SkPoint fPt; |
| 207 | fPt.iset(iPt); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 208 | SkDebugf("iPt: %d, %d\n", iPt.fX, iPt.fY); |
| 209 | SkDebugf("fPt: %g, %g\n", fPt.fX, fPt.fY); |
| 210 | #StdOut |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 211 | iPt: -2147483647, 2147483647 |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 212 | fPt: -2.14748e+09, 2.14748e+09 |
| 213 | ## |
| 214 | ## |
| 215 | |
| 216 | #SeeAlso set Make SkIPoint::set |
| 217 | |
| 218 | #Method ## |
| 219 | |
| 220 | # ------------------------------------------------------------------------------ |
| 221 | |
| 222 | #Method void setAbs(const SkPoint& pt) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 223 | #In Set |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 224 | #Line # sets sign of both members to positive ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 225 | Sets fX to absolute value of pt.fX; and fY to absolute value of pt.fY. |
| 226 | |
| 227 | #Param pt members providing magnitude for fX and fY ## |
| 228 | |
| 229 | #Example |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 230 | SkPoint test[] = { {0.f, -0.f}, {-1, -2}, |
| 231 | { SK_ScalarInfinity, SK_ScalarNegativeInfinity }, |
| 232 | { SK_ScalarNaN, -SK_ScalarNaN } }; |
| 233 | for (const SkPoint& pt : test) { |
| 234 | SkPoint absPt; |
| 235 | absPt.setAbs(pt); |
| 236 | SkDebugf("pt: %g, %g abs: %g, %g\n", pt.fX, pt.fY, absPt.fX, absPt.fY); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 237 | } |
| 238 | #StdOut |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 239 | pt: 0, -0 abs: 0, 0 |
| 240 | pt: -1, -2 abs: 1, 2 |
| 241 | pt: inf, -inf abs: inf, inf |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 242 | pt: nan, -nan abs: nan, nan |
| 243 | ## |
| 244 | ## |
| 245 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 246 | #SeeAlso set Make negate |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 247 | |
| 248 | #Method ## |
| 249 | |
| 250 | # ------------------------------------------------------------------------------ |
| 251 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 252 | #Subtopic Offset |
| 253 | #Line # moves sides ## |
| 254 | #Populate |
| 255 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 256 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 257 | #Method static void Offset(SkPoint points[], int count, const SkVector& offset) |
| 258 | #In Offset |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 259 | #Line # translates Point array ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 260 | Adds offset to each Point in points array with count entries. |
| 261 | |
| 262 | #Param points Point array ## |
| 263 | #Param count entries in array ## |
| 264 | #Param offset Vector added to points ## |
| 265 | |
| 266 | #Example |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 267 | SkPaint paint; |
| 268 | paint.setAntiAlias(true); |
| 269 | SkPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 }, |
| 270 | { 6, 4 }, { 7, 5 }, { 5, 7 }, |
| 271 | { 4, 6 }, { 3, 7 }, { 1, 5 }, |
| 272 | { 2, 4 }, { 1, 3 }, { 3, 1 } }; |
| 273 | canvas->scale(30, 15); |
| 274 | paint.setStyle(SkPaint::kStroke_Style); |
| 275 | canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint); |
| 276 | SkPoint::Offset(points, SK_ARRAY_COUNT(points), { 1, 9 } ); |
| 277 | canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 278 | ## |
| 279 | |
| 280 | #SeeAlso offset operator+=(const SkVector& v) |
| 281 | |
| 282 | #Method ## |
| 283 | |
| 284 | # ------------------------------------------------------------------------------ |
| 285 | |
| 286 | #Method static void Offset(SkPoint points[], int count, SkScalar dx, SkScalar dy) |
| 287 | |
| 288 | Adds offset (dx, dy) to each Point in points array of length count. |
| 289 | |
| 290 | #Param points Point array ## |
| 291 | #Param count entries in array ## |
| 292 | #Param dx added to fX in points ## |
| 293 | #Param dy added to fY in points ## |
| 294 | |
| 295 | #Example |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 296 | SkPaint paint; |
| 297 | paint.setAntiAlias(true); |
| 298 | SkPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 }, |
| 299 | { 6, 4 }, { 7, 5 }, { 5, 7 }, |
| 300 | { 4, 6 }, { 3, 7 }, { 1, 5 }, |
| 301 | { 2, 4 }, { 1, 3 }, { 3, 1 } }; |
| 302 | canvas->scale(30, 15); |
| 303 | paint.setStyle(SkPaint::kStroke_Style); |
| 304 | canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint); |
| 305 | SkPoint::Offset(points, SK_ARRAY_COUNT(points), 1, 9); |
| 306 | canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 307 | ## |
| 308 | |
| 309 | #SeeAlso offset operator+=(const SkVector& v) |
| 310 | |
| 311 | #Method ## |
| 312 | |
| 313 | # ------------------------------------------------------------------------------ |
| 314 | |
| 315 | #Method void offset(SkScalar dx, SkScalar dy) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 316 | #In Offset |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 317 | #Line # translates Point ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 318 | Adds offset (dx, dy) to Point. |
| 319 | |
| 320 | #Param dx added to fX ## |
| 321 | #Param dy added to fY ## |
| 322 | |
| 323 | #Example |
| 324 | #Height 128 |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 325 | SkPaint paint; |
| 326 | paint.setAntiAlias(true); |
| 327 | SkPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 }, |
| 328 | { 6, 4 }, { 7, 5 }, { 5, 7 }, |
| 329 | { 4, 6 }, { 3, 7 }, { 1, 5 }, |
| 330 | { 2, 4 }, { 1, 3 }, { 3, 1 } }; |
| 331 | canvas->scale(30, 15); |
| 332 | paint.setStyle(SkPaint::kStroke_Style); |
| 333 | canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint); |
| 334 | points[1].offset(1, 1); |
| 335 | paint.setColor(SK_ColorRED); |
| 336 | canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 337 | ## |
| 338 | |
| 339 | #SeeAlso Offset operator+=(const SkVector& v) |
| 340 | |
| 341 | #Method ## |
| 342 | |
| 343 | # ------------------------------------------------------------------------------ |
| 344 | |
| 345 | #Method SkScalar length() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 346 | #In Property |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 347 | #Line # returns straight-line distance to origin ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 348 | Returns the Euclidean_Distance from origin, computed as: |
| 349 | #Code |
| 350 | #Literal |
| 351 | sqrt(fX * fX + fY * fY) |
| 352 | ## |
| 353 | . |
| 354 | |
| 355 | #Return straight-line distance to origin ## |
| 356 | |
| 357 | #Example |
| 358 | #Height 192 |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 359 | SkPaint paint; |
| 360 | paint.setAntiAlias(true); |
| 361 | const SkPoint points[] = { { 90, 30 }, { 120, 150 }, { 150, 30 }, { 210, 90 } }; |
| 362 | const SkPoint origin = {30, 140}; |
| 363 | for (auto point : points) { |
| 364 | canvas->drawLine(origin, point, paint); |
| 365 | SkAutoCanvasRestore acr(canvas, true); |
| 366 | SkScalar angle = SkScalarATan2((point.fY - origin.fY), point.fX - origin.fX); |
| 367 | canvas->rotate(angle * 180 / SK_ScalarPI, origin.fX, origin.fY); |
| 368 | SkString length("length = "); |
| 369 | length.appendScalar(point.length()); |
| 370 | canvas->drawString(length, origin.fX + 25, origin.fY - 4, paint); |
| 371 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 372 | ## |
| 373 | |
| 374 | #SeeAlso distanceToOrigin Length setLength Distance |
| 375 | |
| 376 | #Method ## |
| 377 | |
| 378 | # ------------------------------------------------------------------------------ |
| 379 | |
| 380 | #Method SkScalar distanceToOrigin() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 381 | #In Property |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 382 | #Line # returns straight-line distance to origin ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 383 | Returns the Euclidean_Distance from origin, computed as: |
| 384 | #Code |
| 385 | #Literal |
| 386 | sqrt(fX * fX + fY * fY) |
| 387 | ## |
| 388 | . |
| 389 | |
| 390 | #Return straight-line distance to origin ## |
| 391 | |
| 392 | #Example |
| 393 | #Height 192 |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 394 | SkPaint paint; |
| 395 | paint.setAntiAlias(true); |
| 396 | const SkPoint points[] = { { 60, -110 }, { 90, 10 }, { 120, -110 }, { 180, -50 } }; |
| 397 | const SkPoint origin = {0, 0}; |
| 398 | canvas->translate(30, 140); |
| 399 | for (auto point : points) { |
| 400 | canvas->drawLine(origin, point, paint); |
| 401 | SkAutoCanvasRestore acr(canvas, true); |
| 402 | SkScalar angle = SkScalarATan2((point.fY - origin.fY), point.fX - origin.fX); |
| 403 | canvas->rotate(angle * 180 / SK_ScalarPI, origin.fX, origin.fY); |
| 404 | SkString distance("distance = "); |
| 405 | distance.appendScalar(point.distanceToOrigin()); |
| 406 | canvas->drawString(distance, origin.fX + 25, origin.fY - 4, paint); |
| 407 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 408 | ## |
| 409 | |
| 410 | #SeeAlso length Length setLength Distance |
| 411 | |
| 412 | #Method ## |
| 413 | |
| 414 | # ------------------------------------------------------------------------------ |
| 415 | |
| 416 | #Method bool normalize() |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 417 | #In Set |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 418 | #Line # sets length to one, preserving direction ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 419 | Scales (fX, fY) so that length() returns one, while preserving ratio of fX to fY, |
| 420 | if possible. If prior length is nearly zero, sets Vector to (0, 0) and returns |
| 421 | false; otherwise returns true. |
| 422 | |
| 423 | #Return true if former length is not zero or nearly zero ## |
| 424 | |
| 425 | #Example |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 426 | SkPaint paint; |
| 427 | paint.setAntiAlias(true); |
| 428 | const SkPoint lines[][2] = { {{ 30, 110 }, { 190, 30 }}, |
| 429 | {{ 120, 140 }, { 30, 220 }}}; |
| 430 | for (auto line : lines) { |
| 431 | canvas->drawLine(line[0], line[1], paint); |
| 432 | SkVector vector = line[1] - line[0]; |
| 433 | if (vector.normalize()) { |
| 434 | SkVector rotate90 = { -vector.fY, vector.fX }; |
| 435 | rotate90 *= 10.f; |
| 436 | canvas->drawLine(line[0] - rotate90, line[0] + rotate90, paint); |
| 437 | canvas->drawLine(line[1] - rotate90, line[1] + rotate90, paint); |
| 438 | } |
| 439 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 440 | ## |
| 441 | |
| 442 | #SeeAlso Normalize setLength length Length |
| 443 | |
| 444 | #Method ## |
| 445 | |
| 446 | # ------------------------------------------------------------------------------ |
| 447 | |
| 448 | #Method bool setNormalize(SkScalar x, SkScalar y) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 449 | #In Set |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 450 | #Line # sets length to one, in direction of (x, y) ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 451 | Sets Vector to (x, y) scaled so length() returns one, and so that |
| 452 | (fX, fY) is proportional to (x, y). If (x, y) length is nearly zero, |
| 453 | sets Vector to (0, 0) and returns false; otherwise returns true. |
| 454 | |
| 455 | #Param x proportional value for fX ## |
| 456 | #Param y proportional value for fY ## |
| 457 | |
| 458 | #Return true if (x, y) length is not zero or nearly zero ## |
| 459 | |
| 460 | #Example |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 461 | SkPaint paint; |
| 462 | paint.setAntiAlias(true); |
| 463 | const SkPoint points[] = { { 60, -110 }, { 90, 10 }, { 120, -110 }, { 180, -50 } }; |
| 464 | const SkPoint origin = {0, 0}; |
| 465 | canvas->translate(30, 140); |
| 466 | for (auto point : points) { |
| 467 | paint.setStrokeWidth(1); |
| 468 | paint.setColor(SK_ColorBLACK); |
| 469 | canvas->drawLine(origin, point, paint); |
| 470 | SkVector normal; |
| 471 | normal.setNormalize(point.fX, point.fY); |
| 472 | normal *= 100; |
| 473 | paint.setStrokeWidth(10); |
| 474 | paint.setColor(0x3f4512bf); |
| 475 | canvas->drawLine(origin, normal, paint); |
| 476 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 477 | ## |
| 478 | |
| 479 | #SeeAlso normalize setLength |
| 480 | |
| 481 | #Method ## |
| 482 | |
| 483 | # ------------------------------------------------------------------------------ |
| 484 | |
| 485 | #Method bool setLength(SkScalar length) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 486 | #In Set |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 487 | #Line # sets straight-line distance to origin ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 488 | Scales Vector so that distanceToOrigin returns length, if possible. If former |
| 489 | length is nearly zero, sets Vector to (0, 0) and return false; otherwise returns |
| 490 | true. |
| 491 | |
| 492 | #Param length straight-line distance to origin ## |
| 493 | |
| 494 | #Return true if former length is not zero or nearly zero ## |
| 495 | |
| 496 | #Example |
| 497 | #Height 160 |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 498 | SkPaint paint; |
| 499 | paint.setAntiAlias(true); |
| 500 | const SkPoint points[] = { { 60, -110 }, { 90, 10 }, { 120, -110 }, { 180, -50 } }; |
| 501 | const SkPoint origin = {0, 0}; |
| 502 | canvas->translate(30, 140); |
| 503 | for (auto point : points) { |
| 504 | paint.setStrokeWidth(1); |
| 505 | paint.setColor(SK_ColorBLACK); |
| 506 | canvas->drawLine(origin, point, paint); |
| 507 | SkVector normal = point; |
| 508 | normal.setLength(100); |
| 509 | paint.setStrokeWidth(10); |
| 510 | paint.setColor(0x3f45bf12); |
| 511 | canvas->drawLine(origin, normal, paint); |
| 512 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 513 | ## |
| 514 | |
| 515 | #SeeAlso length Length setNormalize setAbs |
| 516 | |
| 517 | #Method ## |
| 518 | |
| 519 | # ------------------------------------------------------------------------------ |
| 520 | |
| 521 | #Method bool setLength(SkScalar x, SkScalar y, SkScalar length) |
| 522 | |
| 523 | Sets Vector to (x, y) scaled to length, if possible. If former |
| 524 | length is nearly zero, sets Vector to (0, 0) and return false; otherwise returns |
| 525 | true. |
| 526 | |
| 527 | #Param x proportional value for fX ## |
| 528 | #Param y proportional value for fY ## |
| 529 | #Param length straight-line distance to origin ## |
| 530 | |
| 531 | #Return true if (x, y) length is not zero or nearly zero ## |
| 532 | |
| 533 | #Example |
| 534 | #Height 160 |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 535 | SkPaint paint; |
| 536 | paint.setAntiAlias(true); |
| 537 | const SkPoint points[] = { { 60, -110 }, { 90, 10 }, { 120, -110 }, { 180, -50 } }; |
| 538 | const SkPoint origin = {0, 0}; |
| 539 | canvas->translate(30, 140); |
| 540 | for (auto point : points) { |
| 541 | paint.setStrokeWidth(1); |
| 542 | paint.setColor(SK_ColorBLACK); |
| 543 | canvas->drawLine(origin, point, paint); |
| 544 | SkVector normal; |
| 545 | normal.setLength(point.fX, point.fY, 100); |
| 546 | paint.setStrokeWidth(10); |
| 547 | paint.setColor(0x3fbf4512); |
| 548 | canvas->drawLine(origin, normal, paint); |
| 549 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 550 | ## |
| 551 | |
| 552 | #SeeAlso length Length setNormalize setAbs |
| 553 | |
| 554 | #Method ## |
| 555 | |
| 556 | # ------------------------------------------------------------------------------ |
| 557 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 558 | #Subtopic Operator |
| 559 | #Populate |
| 560 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 561 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 562 | #Method void scale(SkScalar scale, SkPoint* dst) const |
| 563 | #In Offset |
| 564 | #In Operator |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 565 | #Line # multiplies Point by scale factor ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 566 | Sets dst to Point times scale. dst may be Point to modify Point in place. |
| 567 | |
| 568 | #Param scale factor to multiply Point by ## |
| 569 | #Param dst storage for scaled Point ## |
| 570 | |
| 571 | #Example |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 572 | SkPaint paint; |
| 573 | paint.setAntiAlias(true); |
| 574 | SkPoint point = {40, -15}, scaled; |
| 575 | SkPoint origin = {30, 110}; |
| 576 | for (auto scale : {1, 2, 3, 5}) { |
| 577 | paint.setStrokeWidth(scale * 5); |
| 578 | paint.setARGB(0x7f, 0x9f, 0xbf, 0x33 * scale); |
| 579 | point.scale(scale, &scaled); |
| 580 | canvas->drawLine(origin, origin + scaled, paint); |
| 581 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 582 | ## |
| 583 | |
| 584 | #SeeAlso operator*(SkScalar scale)_const operator*=(SkScalar scale) setLength |
| 585 | |
| 586 | #Method ## |
| 587 | |
| 588 | # ------------------------------------------------------------------------------ |
| 589 | |
| 590 | #Method void scale(SkScalar value) |
| 591 | |
| 592 | Scales Point in place by scale. |
| 593 | |
| 594 | #Param value factor to multiply Point by ## |
| 595 | |
| 596 | #Example |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 597 | SkPaint paint; |
| 598 | paint.setAntiAlias(true); |
| 599 | SkPoint point = {40, -15}; |
| 600 | SkPoint origin = {30, 110}; |
| 601 | for (auto scale : {1, 2, 3, 5}) { |
| 602 | paint.setStrokeWidth(scale * 5); |
| 603 | paint.setARGB(0x7f, 0x9f, 0xbf, 0x33 * scale); |
| 604 | point.scale(scale); |
| 605 | canvas->drawLine(origin, origin + point, paint); |
| 606 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 607 | ## |
| 608 | |
| 609 | #SeeAlso operator*(SkScalar scale)_const operator*=(SkScalar scale) setLength |
| 610 | |
| 611 | #Method ## |
| 612 | |
| 613 | # ------------------------------------------------------------------------------ |
| 614 | |
| 615 | #Method void negate() |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 616 | #In Operator |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 617 | #Line # reverses the sign of both members ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 618 | Changes the sign of fX and fY. |
| 619 | |
| 620 | #Example |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 621 | SkPoint test[] = { {0.f, -0.f}, {-1, -2}, |
| 622 | { SK_ScalarInfinity, SK_ScalarNegativeInfinity }, |
| 623 | { SK_ScalarNaN, -SK_ScalarNaN } }; |
| 624 | for (const SkPoint& pt : test) { |
| 625 | SkPoint negPt = pt; |
| 626 | negPt.negate(); |
| 627 | SkDebugf("pt: %g, %g negate: %g, %g\n", pt.fX, pt.fY, negPt.fX, negPt.fY); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 628 | } |
| 629 | #StdOut |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 630 | pt: 0, -0 negate: -0, 0 |
| 631 | pt: -1, -2 negate: 1, 2 |
| 632 | pt: inf, -inf negate: -inf, inf |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 633 | pt: nan, -nan negate: -nan, nan |
| 634 | ## |
| 635 | ## |
| 636 | |
| 637 | #SeeAlso operator-()_const setAbs |
| 638 | |
| 639 | #Method ## |
| 640 | |
| 641 | # ------------------------------------------------------------------------------ |
| 642 | |
| 643 | #Method SkPoint operator-()_const |
| 644 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 645 | #Line # reverses sign of Point ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 646 | Returns Point changing the signs of fX and fY. |
| 647 | |
| 648 | #Return Point as (-fX, -fY) ## |
| 649 | |
| 650 | #Example |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 651 | SkPoint test[] = { {0.f, -0.f}, {-1, -2}, |
| 652 | { SK_ScalarInfinity, SK_ScalarNegativeInfinity }, |
| 653 | { SK_ScalarNaN, -SK_ScalarNaN } }; |
| 654 | for (const SkPoint& pt : test) { |
| 655 | SkPoint negPt = -pt; |
| 656 | SkDebugf("pt: %g, %g negate: %g, %g\n", pt.fX, pt.fY, negPt.fX, negPt.fY); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 657 | } |
| 658 | #StdOut |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 659 | pt: 0, -0 negate: -0, 0 |
| 660 | pt: -1, -2 negate: 1, 2 |
| 661 | pt: inf, -inf negate: -inf, inf |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 662 | pt: nan, -nan negate: -nan, nan |
| 663 | ## |
| 664 | ## |
| 665 | |
| 666 | #SeeAlso negate operator-(const SkPoint& a, const SkPoint& b) operator-=(const SkVector& v) SkIPoint::operator-()_const |
| 667 | |
| 668 | #Method ## |
| 669 | |
| 670 | # ------------------------------------------------------------------------------ |
| 671 | |
| 672 | #Method void operator+=(const SkVector& v) |
| 673 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 674 | #Line # adds Vector to Point ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 675 | Adds Vector v to Point. Sets Point to: |
| 676 | #Formula |
| 677 | (fX + v.fX, fY + v.fY) |
| 678 | ## |
| 679 | . |
| 680 | |
| 681 | #Param v Vector to add ## |
| 682 | |
| 683 | #Example |
| 684 | #Height 128 |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 685 | SkPaint paint; |
| 686 | paint.setAntiAlias(true); |
| 687 | SkPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 }, |
| 688 | { 6, 4 }, { 7, 5 }, { 5, 7 }, |
| 689 | { 4, 6 }, { 3, 7 }, { 1, 5 }, |
| 690 | { 2, 4 }, { 1, 3 }, { 3, 1 } }; |
| 691 | canvas->scale(30, 15); |
| 692 | paint.setStyle(SkPaint::kStroke_Style); |
| 693 | canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint); |
| 694 | points[1] += {1, 1}; |
| 695 | points[2] += {-1, -1}; |
| 696 | paint.setColor(SK_ColorRED); |
| 697 | canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 698 | ## |
| 699 | |
| 700 | #SeeAlso offset() operator+(const SkPoint& a, const SkVector& b) SkIPoint::operator+=(const SkIVector& v) |
| 701 | |
| 702 | #Method ## |
| 703 | |
| 704 | # ------------------------------------------------------------------------------ |
| 705 | |
| 706 | #Method void operator-=(const SkVector& v) |
| 707 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 708 | #Line # subtracts Vector from Point ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 709 | Subtracts Vector v from Point. Sets Point to: |
| 710 | #Formula |
| 711 | (fX - v.fX, fY - v.fY) |
| 712 | ## |
| 713 | . |
| 714 | |
| 715 | #Param v Vector to subtract ## |
| 716 | |
| 717 | #Example |
| 718 | #Height 128 |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 719 | SkPaint paint; |
| 720 | paint.setAntiAlias(true); |
| 721 | SkPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 }, |
| 722 | { 6, 4 }, { 7, 5 }, { 5, 7 }, |
| 723 | { 4, 6 }, { 3, 7 }, { 1, 5 }, |
| 724 | { 2, 4 }, { 1, 3 }, { 3, 1 } }; |
| 725 | canvas->scale(30, 15); |
| 726 | paint.setStyle(SkPaint::kStroke_Style); |
| 727 | canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint); |
| 728 | points[1] -= {1, 1}; |
| 729 | points[2] -= {-1, -1}; |
| 730 | paint.setColor(SK_ColorRED); |
| 731 | canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 732 | ## |
| 733 | |
| 734 | #SeeAlso offset() operator-(const SkPoint& a, const SkPoint& b) SkIPoint::operator-=(const SkIVector& v) |
| 735 | |
| 736 | #Method ## |
| 737 | |
| 738 | # ------------------------------------------------------------------------------ |
| 739 | |
| 740 | #Method SkPoint operator*(SkScalar scale)_const |
| 741 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 742 | #Line # returns Point multiplied by scale ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 743 | Returns Point multiplied by scale. |
| 744 | |
| 745 | #Param scale Scalar to multiply by ## |
| 746 | |
| 747 | #Return Point as (fX * scale, fY * scale) ## |
| 748 | |
| 749 | #Example |
| 750 | #Height 128 |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 751 | SkPaint paint; |
| 752 | paint.setAntiAlias(true); |
| 753 | SkPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 }, |
| 754 | { 6, 4 }, { 7, 5 }, { 5, 7 }, |
| 755 | { 4, 6 }, { 3, 7 }, { 1, 5 }, |
| 756 | { 2, 4 }, { 1, 3 }, { 3, 1 } }; |
| 757 | canvas->scale(15, 10); |
| 758 | paint.setStyle(SkPaint::kStroke_Style); |
| 759 | canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint); |
| 760 | for (auto& point : points) { |
| 761 | point = point * 1.5f; |
| 762 | } |
| 763 | paint.setColor(SK_ColorRED); |
| 764 | canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 765 | ## |
| 766 | |
| 767 | #SeeAlso operator*=(SkScalar scale) scale() setLength setNormalize |
| 768 | |
| 769 | #Method ## |
| 770 | |
| 771 | # ------------------------------------------------------------------------------ |
| 772 | |
| 773 | #Method SkPoint& operator*=(SkScalar scale) |
| 774 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 775 | #Line # multiplies Point by scale factor ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 776 | Multiplies Point by scale. Sets Point to: |
| 777 | #Formula |
| 778 | (fX * scale, fY * scale) |
| 779 | ## |
| 780 | |
| 781 | #Param scale Scalar to multiply by ## |
| 782 | |
| 783 | #Return reference to Point ## |
| 784 | |
| 785 | #Example |
| 786 | #Height 128 |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 787 | SkPaint paint; |
| 788 | paint.setAntiAlias(true); |
| 789 | SkPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 }, |
| 790 | { 6, 4 }, { 7, 5 }, { 5, 7 }, |
| 791 | { 4, 6 }, { 3, 7 }, { 1, 5 }, |
| 792 | { 2, 4 }, { 1, 3 }, { 3, 1 } }; |
| 793 | canvas->scale(15, 10); |
| 794 | paint.setStyle(SkPaint::kStroke_Style); |
| 795 | canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint); |
| 796 | for (auto& point : points) { |
| 797 | point *= 2; |
| 798 | } |
| 799 | paint.setColor(SK_ColorRED); |
| 800 | canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 801 | ## |
| 802 | |
| 803 | #SeeAlso operator*(SkScalar scale)_const scale() setLength setNormalize |
| 804 | |
| 805 | #Method ## |
| 806 | |
| 807 | # ------------------------------------------------------------------------------ |
| 808 | |
| 809 | #Method bool isFinite() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 810 | #In Property |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 811 | #Line # returns true if no member is infinite or NaN ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 812 | Returns true if both fX and fY are measurable values. |
| 813 | |
| 814 | #Return true for values other than infinities and NaN ## |
| 815 | |
| 816 | #Example |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 817 | SkPoint test[] = { {0, -0.f}, {-1, -2}, {SK_ScalarInfinity, 1}, {SK_ScalarNaN, -1} }; |
| 818 | for (const SkPoint& pt : test) { |
| 819 | SkDebugf("pt: %g, %g finite: %s\n", pt.fX, pt.fY, pt.isFinite() ? "true" : "false"); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 820 | } |
| 821 | #StdOut |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 822 | pt: 0, -0 finite: true |
| 823 | pt: -1, -2 finite: true |
| 824 | pt: inf, 1 finite: false |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 825 | pt: nan, -1 finite: false |
| 826 | ## |
| 827 | ## |
| 828 | |
| 829 | #SeeAlso SkRect::isFinite SkPath::isFinite |
| 830 | |
| 831 | #Method ## |
| 832 | |
| 833 | # ------------------------------------------------------------------------------ |
| 834 | |
| 835 | #Method bool equals(SkScalar x, SkScalar y) const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 836 | #In Operator |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 837 | #Line # returns true if Points are equal ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 838 | Returns true if Point is equivalent to Point constructed from (x, y). |
| 839 | |
| 840 | #Param x value compared with fX ## |
| 841 | #Param y value compared with fY ## |
| 842 | |
| 843 | #Return true if Point equals (x, y) ## |
| 844 | |
| 845 | #Example |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 846 | SkPoint test[] = { {0, -0.f}, {-1, -2}, {SK_ScalarInfinity, 1}, {SK_ScalarNaN, -1} }; |
| 847 | for (const SkPoint& pt : test) { |
| 848 | SkDebugf("pt: %g, %g %c= pt\n", pt.fX, pt.fY, pt.equals(pt.fX, pt.fY) ? '=' : '!'); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 849 | } |
| 850 | #StdOut |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 851 | pt: 0, -0 == pt |
| 852 | pt: -1, -2 == pt |
| 853 | pt: inf, 1 == pt |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 854 | pt: nan, -1 != pt |
| 855 | ## |
| 856 | ## |
| 857 | |
| 858 | #SeeAlso operator==(const SkPoint& a, const SkPoint& b) |
| 859 | |
| 860 | #Method ## |
| 861 | |
| 862 | # ------------------------------------------------------------------------------ |
| 863 | |
| 864 | #Method bool operator==(const SkPoint& a, const SkPoint& b) |
| 865 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 866 | #Line # returns true if Point are equal ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 867 | Returns true if a is equivalent to b. |
| 868 | |
| 869 | #Param a Point to compare ## |
| 870 | #Param b Point to compare ## |
| 871 | |
| 872 | #Return true if a.fX == b.fX and a.fY == b.fY ## |
| 873 | |
| 874 | #Example |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 875 | SkPoint test[] = { {0, -0.f}, {-1, -2}, {SK_ScalarInfinity, 1}, {SK_ScalarNaN, -1} }; |
| 876 | for (const SkPoint& pt : test) { |
| 877 | SkDebugf("pt: %g, %g %c= pt\n", pt.fX, pt.fY, pt == pt ? '=' : '!'); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 878 | } |
| 879 | #StdOut |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 880 | pt: 0, -0 == pt |
| 881 | pt: -1, -2 == pt |
| 882 | pt: inf, 1 == pt |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 883 | pt: nan, -1 != pt |
| 884 | ## |
| 885 | ## |
| 886 | |
| 887 | #SeeAlso equals() operator!=(const SkPoint& a, const SkPoint& b) |
| 888 | |
| 889 | #Method ## |
| 890 | |
| 891 | # ------------------------------------------------------------------------------ |
| 892 | |
| 893 | #Method bool operator!=(const SkPoint& a, const SkPoint& b) |
| 894 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 895 | #Line # returns true if Point are unequal ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 896 | Returns true if a is not equivalent to b. |
| 897 | |
| 898 | #Param a Point to compare ## |
| 899 | #Param b Point to compare ## |
| 900 | |
| 901 | #Return true if a.fX != b.fX or a.fY != b.fY ## |
| 902 | |
| 903 | #Example |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 904 | SkPoint test[] = { {0, -0.f}, {-1, -2}, {SK_ScalarInfinity, 1}, {SK_ScalarNaN, -1} }; |
| 905 | for (const SkPoint& pt : test) { |
| 906 | SkDebugf("pt: %g, %g %c= pt\n", pt.fX, pt.fY, pt != pt ? '!' : '='); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 907 | } |
| 908 | #StdOut |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 909 | pt: 0, -0 == pt |
| 910 | pt: -1, -2 == pt |
| 911 | pt: inf, 1 == pt |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 912 | pt: nan, -1 != pt |
| 913 | ## |
| 914 | ## |
| 915 | |
| 916 | #SeeAlso operator==(const SkPoint& a, const SkPoint& b) equals() |
| 917 | |
| 918 | #Method ## |
| 919 | |
| 920 | # ------------------------------------------------------------------------------ |
| 921 | |
| 922 | #Method SkVector operator-(const SkPoint& a, const SkPoint& b) |
| 923 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 924 | #Line # returns Vector between Points ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 925 | Returns Vector from b to a, computed as |
| 926 | #Formula |
| 927 | (a.fX - b.fX, a.fY - b.fY) |
| 928 | ## |
| 929 | . |
| 930 | |
| 931 | Can also be used to subtract Vector from Point, returning Point. |
| 932 | Can also be used to subtract Vector from Vector, returning Vector. |
| 933 | |
| 934 | #Param a Point to subtract from ## |
| 935 | #Param b Point to subtract ## |
| 936 | |
| 937 | #Return Vector from b to a ## |
| 938 | |
| 939 | #Example |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 940 | SkPaint paint; |
| 941 | paint.setAntiAlias(true); |
| 942 | SkPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 }, |
| 943 | { 6, 4 }, { 7, 5 }, { 5, 7 }, |
| 944 | { 4, 6 }, { 3, 7 }, { 1, 5 }, |
| 945 | { 2, 4 }, { 1, 3 }, { 3, 1 } }; |
| 946 | canvas->scale(30, 15); |
| 947 | paint.setStyle(SkPaint::kStroke_Style); |
| 948 | canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint); |
| 949 | points[1] += points[0] - points[2]; |
| 950 | points[2] -= points[3] - points[5]; |
| 951 | paint.setColor(SK_ColorRED); |
| 952 | canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 953 | ## |
| 954 | |
| 955 | #SeeAlso operator-=(const SkVector& v) offset() |
| 956 | |
| 957 | #Method ## |
| 958 | |
| 959 | # ------------------------------------------------------------------------------ |
| 960 | |
| 961 | #Method SkPoint operator+(const SkPoint& a, const SkVector& b) |
| 962 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 963 | #Line # returns Point offset by Vector ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 964 | Returns Point resulting from Point a offset by Vector b, computed as: |
| 965 | #Formula |
| 966 | (a.fX + b.fX, a.fY + b.fY) |
| 967 | ## |
| 968 | . |
| 969 | |
| 970 | Can also be used to offset Point b by Vector a, returning Point. |
| 971 | Can also be used to add Vector to Vector, returning Vector. |
| 972 | |
| 973 | #Param a Point or Vector to add to ## |
| 974 | #Param b Point or Vector to add ## |
| 975 | |
| 976 | #Return Point equal to a offset by b ## |
| 977 | |
| 978 | #Example |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 979 | SkPaint paint; |
| 980 | paint.setAntiAlias(true); |
| 981 | SkPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 }, |
| 982 | { 6, 4 }, { 7, 5 }, { 5, 7 }, |
| 983 | { 4, 6 }, { 3, 7 }, { 1, 5 }, |
| 984 | { 2, 4 }, { 1, 3 }, { 3, 1 } }; |
| 985 | canvas->scale(30, 15); |
| 986 | paint.setStyle(SkPaint::kStroke_Style); |
| 987 | canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint); |
| 988 | SkVector mod = {1, 1}; |
| 989 | for (auto& point : points) { |
| 990 | point = point + mod; |
| 991 | mod.fX *= 1.1f; |
| 992 | mod.fY += .2f; |
| 993 | } |
| 994 | paint.setColor(SK_ColorRED); |
| 995 | canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint); |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 996 | ## |
| 997 | |
| 998 | #SeeAlso operator+=(const SkVector& v) offset() |
| 999 | |
| 1000 | #Method ## |
| 1001 | |
| 1002 | # ------------------------------------------------------------------------------ |
| 1003 | |
| 1004 | #Method static SkScalar Length(SkScalar x, SkScalar y) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1005 | #In Property |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1006 | #Line # returns straight-line distance to origin ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1007 | Returns the Euclidean_Distance from origin, computed as: |
| 1008 | #Code |
| 1009 | #Literal |
| 1010 | sqrt(x * x + y * y) |
| 1011 | ## |
| 1012 | . |
| 1013 | |
| 1014 | #Param x component of length ## |
| 1015 | #Param y component of length ## |
| 1016 | |
| 1017 | #Return straight-line distance to origin ## |
| 1018 | |
| 1019 | #Example |
| 1020 | #Height 192 |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 1021 | SkPaint paint; |
| 1022 | paint.setAntiAlias(true); |
| 1023 | const SkPoint points[] = { { 90, 30 }, { 120, 150 }, { 150, 30 }, { 210, 90 } }; |
| 1024 | const SkPoint origin = {30, 140}; |
| 1025 | for (auto point : points) { |
| 1026 | canvas->drawLine(origin, point, paint); |
| 1027 | SkAutoCanvasRestore acr(canvas, true); |
| 1028 | SkScalar angle = SkScalarATan2((point.fY - origin.fY), point.fX - origin.fX); |
| 1029 | canvas->rotate(angle * 180 / SK_ScalarPI, origin.fX, origin.fY); |
| 1030 | SkString length("length = "); |
| 1031 | length.appendScalar(SkPoint::Length(point.fX, point.fY)); |
| 1032 | canvas->drawString(length, origin.fX + 25, origin.fY - 4, paint); |
| 1033 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1034 | ## |
| 1035 | |
| 1036 | #SeeAlso length() Distance setLength |
| 1037 | |
| 1038 | #Method ## |
| 1039 | |
| 1040 | # ------------------------------------------------------------------------------ |
| 1041 | |
| 1042 | #Method static SkScalar Normalize(SkVector* vec) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1043 | #In Offset |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1044 | #Line # sets length to one, and returns prior length ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1045 | Scales (vec->fX, vec->fY) so that length() returns one, while preserving ratio of vec->fX to vec->fY, |
| 1046 | if possible. If original length is nearly zero, sets vec to (0, 0) and returns zero; |
| 1047 | otherwise, returns length of vec before vec is scaled. |
| 1048 | |
| 1049 | Returned prior length may be SK_ScalarInfinity if it can not be represented by SkScalar. |
| 1050 | |
| 1051 | Note that normalize() is faster if prior length is not required. |
| 1052 | |
| 1053 | #Param vec normalized to unit length ## |
| 1054 | |
| 1055 | #Return original vec length ## |
| 1056 | |
| 1057 | #Example |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 1058 | SkPaint paint; |
| 1059 | paint.setAntiAlias(true); |
| 1060 | const SkPoint lines[][2] = { {{ 30, 110 }, { 190, 30 }}, |
| 1061 | {{ 30, 220 }, { 120, 140 }}}; |
| 1062 | for (auto line : lines) { |
| 1063 | canvas->drawLine(line[0], line[1], paint); |
| 1064 | SkVector vector = line[1] - line[0]; |
| 1065 | SkScalar priorLength = SkPoint::Normalize(&vector); |
| 1066 | SkVector rotate90 = { -vector.fY, vector.fX }; |
| 1067 | rotate90 *= 10.f; |
| 1068 | canvas->drawLine(line[0] - rotate90, line[0] + rotate90, paint); |
| 1069 | canvas->drawLine(line[1] - rotate90, line[1] + rotate90, paint); |
| 1070 | SkString length("length = "); |
| 1071 | length.appendScalar(priorLength); |
| 1072 | canvas->drawString(length, line[0].fX + 25, line[0].fY - 4, paint); |
| 1073 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1074 | ## |
| 1075 | |
| 1076 | #SeeAlso normalize() setLength Length |
| 1077 | |
| 1078 | #Method ## |
| 1079 | |
| 1080 | # ------------------------------------------------------------------------------ |
| 1081 | |
| 1082 | #Method static SkScalar Distance(const SkPoint& a, const SkPoint& b) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1083 | #In Property |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1084 | #Line # returns straight-line distance between points ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1085 | Returns the Euclidean_Distance between a and b. |
| 1086 | |
| 1087 | #Param a line end point ## |
| 1088 | #Param b line end point ## |
| 1089 | |
| 1090 | #Return straight-line distance from a to b ## |
| 1091 | |
| 1092 | #Example |
| 1093 | #Height 192 |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 1094 | SkPaint paint; |
| 1095 | paint.setAntiAlias(true); |
| 1096 | const SkPoint lines[][2] = {{{-10, -10}, {90, 30}}, {{0, 0}, {150, 30}}, {{10, 25}, {120, 150}}}; |
| 1097 | const SkPoint origin = {30, 160}; |
| 1098 | for (auto line : lines) { |
| 1099 | SkPoint a = origin + line[0]; |
| 1100 | const SkPoint& b = line[1]; |
| 1101 | canvas->drawLine(a, b, paint); |
| 1102 | SkAutoCanvasRestore acr(canvas, true); |
| 1103 | SkScalar angle = SkScalarATan2((b.fY - a.fY), b.fX - a.fX); |
| 1104 | canvas->rotate(angle * 180 / SK_ScalarPI, a.fX, a.fY); |
| 1105 | SkString distance("distance = "); |
| 1106 | distance.appendScalar(SkPoint::Distance(a, b)); |
| 1107 | canvas->drawString(distance, a.fX + 25, a.fY - 4, paint); |
| 1108 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1109 | ## |
| 1110 | |
| 1111 | #SeeAlso length() setLength |
| 1112 | |
| 1113 | #Method ## |
| 1114 | |
| 1115 | # ------------------------------------------------------------------------------ |
| 1116 | |
| 1117 | #Method static SkScalar DotProduct(const SkVector& a, const SkVector& b) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1118 | #In Operator |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1119 | #Line # returns dot product ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1120 | Returns the dot product of Vector a and Vector b. |
| 1121 | |
| 1122 | #Param a left side of dot product ## |
| 1123 | #Param b right side of dot product ## |
| 1124 | |
| 1125 | #Return product of input magnitudes and cosine of the angle between them ## |
| 1126 | |
| 1127 | #Example |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 1128 | SkPaint paint; |
| 1129 | paint.setAntiAlias(true); |
| 1130 | SkVector vectors[][2] = {{{50, 2}, {-14, 20}}, {{0, 50}, {-50, 0}}, {{-20, 25}, {25, -20}}, |
| 1131 | {{-20, -24}, {-24, -20}}}; |
| 1132 | SkPoint center[] = {{32, 32}, {160, 32}, {32, 160}, {160, 160}}; |
| 1133 | paint.setStrokeWidth(2); |
| 1134 | for (size_t i = 0; i < 4; ++i) { |
| 1135 | canvas->drawLine(center[i], center[i] + vectors[i][0], paint); |
| 1136 | canvas->drawLine(center[i], center[i] + vectors[i][1], paint); |
| 1137 | SkString str; |
| 1138 | str.printf("dot = %g", SkPoint::DotProduct(vectors[i][0], vectors[i][1])); |
| 1139 | canvas->drawString(str, center[i].fX, center[i].fY, paint); |
| 1140 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1141 | ## |
| 1142 | |
| 1143 | #SeeAlso dot CrossProduct |
| 1144 | |
| 1145 | #Method ## |
| 1146 | |
| 1147 | # ------------------------------------------------------------------------------ |
| 1148 | |
| 1149 | #Method static SkScalar CrossProduct(const SkVector& a, const SkVector& b) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1150 | #In Operator |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1151 | #Line # returns cross product ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1152 | Returns the cross product of Vector a and Vector b. |
| 1153 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1154 | a and b form three-dimensional vectors with z-axis value equal to zero. The |
| 1155 | cross product is a three-dimensional vector with x-axis and y-axis values equal |
| 1156 | to zero. The cross product z-axis component is returned. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1157 | |
| 1158 | #Param a left side of cross product ## |
| 1159 | #Param b right side of cross product ## |
| 1160 | |
| 1161 | #Return area spanned by Vectors signed by angle direction ## |
| 1162 | |
| 1163 | #Example |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 1164 | SkPaint paint; |
| 1165 | paint.setAntiAlias(true); |
| 1166 | SkVector vectors[][2] = {{{50, 2}, {-14, 20}}, {{0, 50}, {-50, 0}}, {{-20, 25}, {25, -20}}, |
| 1167 | {{-20, -24}, {-24, -20}}}; |
| 1168 | SkPoint center[] = {{32, 32}, {160, 32}, {32, 160}, {160, 160}}; |
| 1169 | paint.setStrokeWidth(2); |
| 1170 | for (size_t i = 0; i < 4; ++i) { |
| 1171 | paint.setColor(SK_ColorRED); |
| 1172 | canvas->drawLine(center[i], center[i] + vectors[i][0], paint); |
| 1173 | paint.setColor(SK_ColorBLUE); |
| 1174 | canvas->drawLine(center[i], center[i] + vectors[i][1], paint); |
| 1175 | SkString str; |
| 1176 | SkScalar cross = SkPoint::CrossProduct(vectors[i][1], vectors[i][0]); |
| 1177 | str.printf("cross = %g", cross); |
| 1178 | paint.setColor(cross >= 0 ? SK_ColorRED : SK_ColorBLUE); |
| 1179 | canvas->drawString(str, center[i].fX, center[i].fY, paint); |
| 1180 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1181 | ## |
| 1182 | |
| 1183 | #SeeAlso cross DotProduct |
| 1184 | |
| 1185 | #Method ## |
| 1186 | |
| 1187 | # ------------------------------------------------------------------------------ |
| 1188 | |
| 1189 | #Method SkScalar cross(const SkVector& vec) const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1190 | #In Operator |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1191 | #Line # returns cross product ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1192 | Returns the cross product of Vector and vec. |
| 1193 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1194 | Vector and vec form three-dimensional vectors with z-axis value equal to zero. |
| 1195 | The cross product is a three-dimensional vector with x-axis and y-axis values |
| 1196 | equal to zero. The cross product z-axis component is returned. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1197 | |
| 1198 | #Param vec right side of cross product ## |
| 1199 | |
| 1200 | #Return area spanned by Vectors signed by angle direction ## |
| 1201 | |
| 1202 | #Example |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 1203 | SkPaint paint; |
| 1204 | paint.setAntiAlias(true); |
| 1205 | SkVector vectors[][2] = {{{50, 2}, {-14, 20}}, {{0, 50}, {-50, 0}}, {{-20, 25}, {25, -20}}, |
| 1206 | {{-20, -24}, {-24, -20}}}; |
| 1207 | SkPoint center[] = {{32, 32}, {160, 32}, {32, 160}, {160, 160}}; |
| 1208 | paint.setStrokeWidth(2); |
| 1209 | for (size_t i = 0; i < 4; ++i) { |
| 1210 | paint.setColor(SK_ColorRED); |
| 1211 | canvas->drawLine(center[i], center[i] + vectors[i][0], paint); |
| 1212 | paint.setColor(SK_ColorBLUE); |
| 1213 | canvas->drawLine(center[i], center[i] + vectors[i][1], paint); |
| 1214 | SkString str; |
| 1215 | SkScalar cross = vectors[i][0].cross(vectors[i][1]); |
| 1216 | str.printf("cross = %g", cross); |
| 1217 | paint.setColor(cross >= 0 ? SK_ColorRED : SK_ColorBLUE); |
| 1218 | canvas->drawString(str, center[i].fX, center[i].fY, paint); |
| 1219 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1220 | ## |
| 1221 | |
| 1222 | #SeeAlso CrossProduct dot |
| 1223 | |
| 1224 | #Method ## |
| 1225 | |
| 1226 | # ------------------------------------------------------------------------------ |
| 1227 | |
| 1228 | #Method SkScalar dot(const SkVector& vec) const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1229 | #In Operator |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1230 | #Line # returns dot product ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1231 | Returns the dot product of Vector and Vector vec. |
| 1232 | |
| 1233 | #Param vec right side of dot product ## |
| 1234 | |
| 1235 | #Return product of input magnitudes and cosine of the angle between them ## |
| 1236 | |
| 1237 | #Example |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 1238 | SkPaint paint; |
| 1239 | paint.setAntiAlias(true); |
| 1240 | SkVector vectors[][2] = {{{50, 2}, {-14, 20}}, {{0, 50}, {-50, 0}}, {{-20, 25}, {25, -20}}, |
| 1241 | {{-20, -24}, {-24, -20}}}; |
| 1242 | SkPoint center[] = {{32, 32}, {160, 32}, {32, 160}, {160, 160}}; |
| 1243 | paint.setStrokeWidth(2); |
| 1244 | for (size_t i = 0; i < 4; ++i) { |
| 1245 | canvas->drawLine(center[i], center[i] + vectors[i][0], paint); |
| 1246 | canvas->drawLine(center[i], center[i] + vectors[i][1], paint); |
| 1247 | SkString str; |
| 1248 | str.printf("dot = %g", vectors[i][0].dot(vectors[i][1])); |
| 1249 | canvas->drawString(str, center[i].fX, center[i].fY, paint); |
| 1250 | } |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1251 | ## |
| 1252 | |
| 1253 | #SeeAlso DotProduct cross |
| 1254 | |
| 1255 | #Method ## |
| 1256 | |
| 1257 | #Struct SkPoint ## |
| 1258 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1259 | |
| 1260 | # ------------------------------------------------------------------------------ |
| 1261 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1262 | #Subtopic Vector |
| 1263 | #Line # alias for Point ## |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 1264 | #Alias Vector ## |
| 1265 | #Alias Vectors ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1266 | #Typedef SkPoint SkVector |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1267 | #Line # alias for Point ## |
| 1268 | #Code |
| 1269 | typedef SkPoint SkVector; |
| 1270 | ## |
| 1271 | SkVector provides an alternative name for SkPoint. SkVector and SkPoint can |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 1272 | be used interchangeably for all purposes. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1273 | #Typedef ## |
| 1274 | ## |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1275 | |
| 1276 | #Topic Point ## |