提交 57fef366 编写于 作者: H Hixie

Provide Point+Size, Point-Point, Point.toSize(), and Rect.toPoint().

Also some minor code cleanup in affected files and nearby files.

R=mpcomplete@chromium.org

Review URL: https://codereview.chromium.org/1160453006
上级 8c097b08
......@@ -16,6 +16,7 @@ class Color {
((b & 0xff) << 0));
bool operator ==(other) => other is Color && _value == other._value;
int get hashCode => _value.hashCode;
String toString() => "Color(0x${_value.toRadixString(16).padLeft(8, '0')})";
}
......@@ -11,10 +11,13 @@ class Point {
const Point(this.x, this.y);
bool operator ==(other) {
if (!(other is Point)) return false;
return x == other.x && y == other.y;
}
bool operator ==(other) => other is Point && x == other.x && y == other.y;
Size operator -(Point other) => new Size(x - other.x, y - other.y);
Point operator +(Size size) => new Point(x + size.width, y + size.height);
// does the equivalent of "return this - Point(0,0)"
Size toSize() => new Size(x, y);
int get hashCode {
int result = 373;
result = 37 * result + x.hashCode;
......
......@@ -44,18 +44,22 @@ class Rect {
// 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;
bool contains(Point point) {
return point.x >= left && point.x < right && point.y >= top && point.y < bottom;
}
bool operator ==(other) {
if (!(other is Rect)) return false;
if (other is! Rect)
return false;
for (var i = 0; i < 4; ++i) {
if (_value[i] != other._value[i]) return false;
if (_value[i] != other._value[i])
return false;
}
return true;
}
int get hashCode {
return _value.fold(373, (value, item) => (37 * value + item.hashCode));
}
String toString() => "Rect.LTRB($left, $top, $right, $bottom)";
String toString() => "Rect.fromLTRB($left, $top, $right, $bottom)";
}
......@@ -5,6 +5,7 @@
part of dart.sky;
/// Holds a 2D floating-point size.
/// Think of this as a vector from Point(0,0) to Point(size.width, size.height)
class Size {
final double width;
final double height;
......@@ -16,10 +17,11 @@ class Size {
const Size.fromWidth(this.width) : height = double.INFINITY;
const Size.fromHeight(this.height) : width = double.INFINITY;
bool operator ==(other) {
if (!(other is Size)) return false;
return width == other.width && height == other.height;
}
bool operator ==(other) => other is Size && width == other.width && height == other.height;
// does the equivalent of "return new Point(0,0) + this"
Point toPoint() => new Point(this.width, this.height);
int get hashCode {
int result = 373;
result = 37 * result + width.hashCode;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册