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

Unified Diff: sky/engine/core/painting/Rect.dart

Issue 1152213003: Flesh out Rect/Point/Size classes in dart:sky (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: 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 | « sky/engine/core/painting/Point.dart ('k') | sky/engine/core/painting/Size.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/engine/core/painting/Rect.dart
diff --git a/sky/engine/core/painting/Rect.dart b/sky/engine/core/painting/Rect.dart
index cb2afec7d773e004e1ec77a276ea82dce7d6df77..be9cc9906d13175136798098f009cf2073056764 100644
--- a/sky/engine/core/painting/Rect.dart
+++ b/sky/engine/core/painting/Rect.dart
@@ -11,7 +11,38 @@ class Rect {
double get right => _value[2];
double get bottom => _value[3];
+ Rect() : new Float32List(4);
+
+ Rect.fromPointAndSize(Point point, Size size) {
Hixie 2015/05/28 17:20:11 why isn't this a constructor?
+ _value = new Float32List(4)
+ ..[0] = point.x
+ ..[1] = point.y
+ ..[2] = point.x + size.width
+ ..[3] = point.y + size.height;
+ }
+
+ Rect.fromLTRB(double left, double top, double right, double bottom) {
Hixie 2015/05/28 17:20:11 ditto
+ _value = new Float32List(4)
+ ..[0] = left
+ ..[1] = top
+ ..[2] = right
+ ..[3] = bottom;
+ }
+
+ Point get upperLeft => new Point(left, top);
+ Point get lowerRight => new Point(right, bottom);
+
+ Size get size => new Rect(right - left, bottom - top);
Matt Perry 2015/05/28 16:41:21 new Size
+
+ // Rects are inclusive of the top and left edges but exclusive of the bottom
+ // right edges.
+ bool contains(Point point) => point.x >= left && point.x < right
+ && point.y >= top && point.y < bottom;
+
void setLTRB(double left, double top, double right, double bottom) {
- _value = new Float32List.fromList([left, top, right, bottom]);
+ _value[0] = left
+ ..[1] = top
+ ..[2] = right
+ ..[3] = bottom;
}
}
« no previous file with comments | « sky/engine/core/painting/Point.dart ('k') | sky/engine/core/painting/Size.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698