Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Side by Side Diff: include/core/SkPoint.h

Issue 785933003: change SkPoint::setLength to set itself to (0,0) if it starting length is degenerate (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/core/SkPath.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef SkPoint_DEFINED 8 #ifndef SkPoint_DEFINED
9 #define SkPoint_DEFINED 9 #define SkPoint_DEFINED
10 10
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 // Simple enough (and performance critical sometimes) so we inline it. 251 // Simple enough (and performance critical sometimes) so we inline it.
252 return (dx*dx + dy*dy) > (SK_ScalarNearlyZero * SK_ScalarNearlyZero); 252 return (dx*dx + dy*dy) > (SK_ScalarNearlyZero * SK_ScalarNearlyZero);
253 } 253 }
254 254
255 bool canNormalize() const { 255 bool canNormalize() const {
256 return CanNormalize(fX, fY); 256 return CanNormalize(fX, fY);
257 } 257 }
258 258
259 /** Set the point (vector) to be unit-length in the same direction as it 259 /** Set the point (vector) to be unit-length in the same direction as it
260 already points. If the point has a degenerate length (i.e. nearly 0) 260 already points. If the point has a degenerate length (i.e. nearly 0)
261 then return false and do nothing; otherwise return true. 261 then set it to (0,0) and return false; otherwise return true.
262 */ 262 */
263 bool normalize(); 263 bool normalize();
264 264
265 /** Set the point (vector) to be unit-length in the same direction as the 265 /** Set the point (vector) to be unit-length in the same direction as the
266 x,y params. If the vector (x,y) has a degenerate length (i.e. nearly 0) 266 x,y params. If the vector (x,y) has a degenerate length (i.e. nearly 0)
267 then return false and do nothing, otherwise return true. 267 then set it to (0,0) and return false, otherwise return true.
268 */ 268 */
269 bool setNormalize(SkScalar x, SkScalar y); 269 bool setNormalize(SkScalar x, SkScalar y);
270 270
271 /** Scale the point (vector) to have the specified length, and return that 271 /** Scale the point (vector) to have the specified length, and return that
272 length. If the original length is degenerately small (nearly zero), 272 length. If the original length is degenerately small (nearly zero),
273 do nothing and return false, otherwise return true. 273 set it to (0,0) and return false, otherwise return true.
274 */ 274 */
275 bool setLength(SkScalar length); 275 bool setLength(SkScalar length);
276 276
277 /** Set the point (vector) to have the specified length in the same 277 /** Set the point (vector) to have the specified length in the same
278 direction as (x,y). If the vector (x,y) has a degenerate length 278 direction as (x,y). If the vector (x,y) has a degenerate length
279 (i.e. nearly 0) then return false and do nothing, otherwise return true. 279 (i.e. nearly 0) then set it to (0,0) and return false, otherwise return tru e.
280 */ 280 */
281 bool setLength(SkScalar x, SkScalar y, SkScalar length); 281 bool setLength(SkScalar x, SkScalar y, SkScalar length);
282 282
283 /** Same as setLength, but favoring speed over accuracy. 283 /** Same as setLength, but favoring speed over accuracy.
284 */ 284 */
285 bool setLengthFast(SkScalar length); 285 bool setLengthFast(SkScalar length);
286 286
287 /** Same as setLength, but favoring speed over accuracy. 287 /** Same as setLength, but favoring speed over accuracy.
288 */ 288 */
289 bool setLengthFast(SkScalar x, SkScalar y, SkScalar length); 289 bool setLengthFast(SkScalar x, SkScalar y, SkScalar length);
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 SkPoint v; 416 SkPoint v;
417 v.set(a.fX + b.fX, a.fY + b.fY); 417 v.set(a.fX + b.fX, a.fY + b.fY);
418 return v; 418 return v;
419 } 419 }
420 420
421 /** Returns the euclidian distance from (0,0) to (x,y) 421 /** Returns the euclidian distance from (0,0) to (x,y)
422 */ 422 */
423 static SkScalar Length(SkScalar x, SkScalar y); 423 static SkScalar Length(SkScalar x, SkScalar y);
424 424
425 /** Normalize pt, returning its previous length. If the prev length is too 425 /** Normalize pt, returning its previous length. If the prev length is too
426 small (degenerate), return 0 and leave pt unchanged. This uses the same 426 small (degenerate), set pt to (0,0) and return 0. This uses the same
427 tolerance as CanNormalize. 427 tolerance as CanNormalize.
428 428
429 Note that this method may be significantly more expensive than 429 Note that this method may be significantly more expensive than
430 the non-static normalize(), because it has to return the previous length 430 the non-static normalize(), because it has to return the previous length
431 of the point. If you don't need the previous length, call the 431 of the point. If you don't need the previous length, call the
432 non-static normalize() method instead. 432 non-static normalize() method instead.
433 */ 433 */
434 static SkScalar Normalize(SkPoint* pt); 434 static SkScalar Normalize(SkPoint* pt);
435 435
436 /** Returns the euclidian distance between a and b 436 /** Returns the euclidian distance between a and b
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 533
534 /** 534 /**
535 * cast-safe way to treat the point as an array of (2) SkScalars. 535 * cast-safe way to treat the point as an array of (2) SkScalars.
536 */ 536 */
537 const SkScalar* asScalars() const { return &fX; } 537 const SkScalar* asScalars() const { return &fX; }
538 }; 538 };
539 539
540 typedef SkPoint SkVector; 540 typedef SkPoint SkVector;
541 541
542 #endif 542 #endif
OLDNEW
« no previous file with comments | « no previous file | src/core/SkPath.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698