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

Unified Diff: site/user/api/skrect.md

Issue 1127383010: Documentation: SkCanvas API (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-05-19 (Tuesday) 13:19:57 EDT Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « site/user/api/skpaint.md ('k') | site/user/api/skregion.md » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: site/user/api/skrect.md
diff --git a/site/user/api/skrect.md b/site/user/api/skrect.md
new file mode 100644
index 0000000000000000000000000000000000000000..c2ebef1d0fea76be9bb263f522fa3d64970a0d8e
--- /dev/null
+++ b/site/user/api/skrect.md
@@ -0,0 +1,73 @@
+SkRect
+======
+
+*Rectangles*
+
+<!--Updated Mar 4, 2011-->
+
+SkRect is basic to many drawing and measuring operations. It can be
+drawn using canvas.drawRect(), but it is also used to return the
+bounds of objects like paths and text characters. It is specified
+using SkScalar values.
+
+SkIRect is the integer counter part to SkRect, but is specified using
+32bit integers.
+
+<!--?prettify lang=cc?-->
+
+ struct SkRect {
+ SkScalar fLeft;
+ SkScalar fTop;
+ SkScalar fRight;
+ SkScalar fBottom;
+ // methods
+ };
+
+ SkRect rect = SkRect::MakeLTRB(left, top, right, bottom);
+
+SkRect has the usual getters, to return width(), height(), centerX(),
+etc. It also has methods to compute unions and intersections between
+rectangles.
+
+Converting between SkRect and SkIRect is asymetric. Short of overflow
+issues when SkScalar is an int, converting from SkIRect to SkRect is
+straight forward:
+
+<!--?prettify lang=cc?-->
+
+ SkRect::set(const SkIRect&);
+
+However, convert from SkRect to SkIRect needs to know how to go from
+fractional values to integers.
+
+<!--?prettify lang=cc?-->
+
+ SkRect::round(SkIRect*) const; // Round each coordinate.
+ SkRect::roundOut(SkIRect*) const; // Apply floor to left/top,
+ // and ceil to right/bottom.
+
+In Skia, rectangle coordinates describe the boundary of what is drawn,
+such that an empty rectangle encloses zero pixels:
+
+bool SkRect::isEmpty() const { return fLeft >= fRight || fTop >= fBottom; }
+
+<!--?prettify lang=cc?-->
+
+ SkScalar SkRect::width() const { return fRight - fLeft; }
+
+ SkScalar SkRect::height() const { return fBottom - fTop; }
+
+ bool SkRect::contains(SkScalar x, SkScalar y) const {
+ return fLeft <= x && x < fRight && fTop <= y && y < fBottom;
+ }
+
+Thus, to draw a single pixel (assuming no matrix on the canvas), the
+rectangle should be initialized as follows:
+
+<!--?prettify lang=cc?-->
+
+ SkRect r = SkRect::MakeXYWH(x, y, SkIntToScalar(1), SkIntToScalar(1));
+
+The same conventions hold for the integer counterpart: SkIRect. This
+also dovetails with SkRegion, which has the same model for set
+membership, and which uses SkIRect.
« no previous file with comments | « site/user/api/skpaint.md ('k') | site/user/api/skregion.md » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698