Index: tools/dom/src/Rectangle.dart |
diff --git a/tools/dom/src/Rectangle.dart b/tools/dom/src/Rectangle.dart |
index e6a80b2f0edc67caa2607040ede9ad3f7d5653c8..294fa8581aa691f99f84cc0a2c25db922eefec37 100644 |
--- a/tools/dom/src/Rectangle.dart |
+++ b/tools/dom/src/Rectangle.dart |
@@ -5,44 +5,24 @@ |
part of html; |
/** |
- * A class for representing two-dimensional rectangles. |
+ * A base class for representing two-dimensional rectangles. This will hopefully |
+ * be moved merged with the dart:math Rect. |
*/ |
-class Rect { |
- final num left; |
- final num top; |
- final num width; |
- final num height; |
- |
- const Rect(this.left, this.top, this.width, this.height); |
- |
- factory Rect.fromPoints(Point a, Point b) { |
- var left; |
- var width; |
- if (a.x < b.x) { |
- left = a.x; |
- width = b.x - left; |
- } else { |
- left = b.x; |
- width = a.x - left; |
- } |
- var top; |
- var height; |
- if (a.y < b.y) { |
- top = a.y; |
- height = b.y - top; |
- } else { |
- top = b.y; |
- height = a.y - top; |
- } |
+// TODO(efortuna): Merge with Math rect after finalizing with Florian. |
+abstract class RectBase { |
+ // Not used, but keeps the VM from complaining about Rect having a const |
+ // constructor and this one not. |
+ const RectBase(); |
- return new Rect(left, top, width, height); |
- } |
+ num get left; |
+ num get top; |
+ num get width; |
+ num get height; |
num get right => left + width; |
num get bottom => top + height; |
// NOTE! All code below should be common with Rect. |
- // TODO: implement with mixins when available. |
String toString() { |
return '($left, $top, $width, $height)'; |
@@ -136,3 +116,43 @@ class Rect { |
Point get bottomRight => new Point(this.left + this.width, |
this.top + this.height); |
} |
+ |
+ |
+ |
+/** |
+ * A class for representing two-dimensional rectangles. |
+ * |
+ * This class is distinctive from RectBase in that it enforces that its |
+ * properties are immutable. |
+ */ |
+class Rect extends RectBase { |
+ final num left; |
+ final num top; |
+ final num width; |
+ final num height; |
+ |
+ const Rect(this.left, this.top, this.width, this.height): super(); |
+ |
+ factory Rect.fromPoints(Point a, Point b) { |
+ var left; |
+ var width; |
+ if (a.x < b.x) { |
+ left = a.x; |
+ width = b.x - left; |
+ } else { |
+ left = b.x; |
+ width = a.x - left; |
+ } |
+ var top; |
+ var height; |
+ if (a.y < b.y) { |
+ top = a.y; |
+ height = b.y - top; |
+ } else { |
+ top = b.y; |
+ height = a.y - top; |
+ } |
+ |
+ return new Rect(left, top, width, height); |
+ } |
+} |