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

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

Issue 267003002: add rounding-using-doubles methods on SkScalar and SkRect (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: fix spelling in comment Created 6 years, 7 months 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | include/core/SkScalar.h » ('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 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #ifndef SkRect_DEFINED 10 #ifndef SkRect_DEFINED
(...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 * Set the dst rectangle by rounding this rectangle's coordinates to their 725 * Set the dst rectangle by rounding this rectangle's coordinates to their
726 * nearest integer values using SkScalarRoundToInt. 726 * nearest integer values using SkScalarRoundToInt.
727 */ 727 */
728 void round(SkIRect* dst) const { 728 void round(SkIRect* dst) const {
729 SkASSERT(dst); 729 SkASSERT(dst);
730 dst->set(SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop), 730 dst->set(SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop),
731 SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom)); 731 SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom));
732 } 732 }
733 733
734 /** 734 /**
735 * Variant of round() that explicitly performs the rounding step (i.e. floo r(x + 0.5)) using
736 * double instead of SkScalar (float). It does this by calling SkDScalarRou ndToInt(), which
737 * may be slower than calling SkScalarRountToInt(), but gives slightly more accurate results.
738 *
739 * e.g.
740 * SkScalar x = 0.49999997f;
741 * int ix = SkScalarRoundToInt(x);
742 * SkASSERT(0 == ix); // <--- fails
743 * ix = SkDScalarRoundToInt(x);
744 * SkASSERT(0 == ix); // <--- succeeds
745 */
746 void dround(SkIRect* dst) const {
747 SkASSERT(dst);
748 dst->set(SkDScalarRoundToInt(fLeft), SkDScalarRoundToInt(fTop),
749 SkDScalarRoundToInt(fRight), SkDScalarRoundToInt(fBottom));
750 }
751
752 /**
735 * Set the dst rectangle by rounding "out" this rectangle, choosing the 753 * Set the dst rectangle by rounding "out" this rectangle, choosing the
736 * SkScalarFloor of top and left, and the SkScalarCeil of right and bottom. 754 * SkScalarFloor of top and left, and the SkScalarCeil of right and bottom.
737 */ 755 */
738 void roundOut(SkIRect* dst) const { 756 void roundOut(SkIRect* dst) const {
739 SkASSERT(dst); 757 SkASSERT(dst);
740 dst->set(SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop), 758 dst->set(SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
741 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom)); 759 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom));
742 } 760 }
743 761
744 /** 762 /**
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 */ 801 */
784 void sort(); 802 void sort();
785 803
786 /** 804 /**
787 * cast-safe way to treat the rect as an array of (4) SkScalars. 805 * cast-safe way to treat the rect as an array of (4) SkScalars.
788 */ 806 */
789 const SkScalar* asScalars() const { return &fLeft; } 807 const SkScalar* asScalars() const { return &fLeft; }
790 }; 808 };
791 809
792 #endif 810 #endif
OLDNEW
« no previous file with comments | « no previous file | include/core/SkScalar.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698