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