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