diff --git a/engine/core/painting/Point.dart b/engine/core/painting/Point.dart index 856f3360fdfc0c2addab930972c4bea341c6920b..82d2875e3b82c72a145429c439229f2d92c3839d 100644 --- a/engine/core/painting/Point.dart +++ b/engine/core/painting/Point.dart @@ -4,9 +4,22 @@ part of dart.sky; +/// Holds 2 floating-point coordinates. class Point { double x; double y; Point(this.x, this.y); + + bool operator ==(other) { + if (!(other is Point)) return false; + return x == other.x && y == other.y; + } + int get hashCode { + int result = 373; + result = 37 * result + x.hashCode; + result = 37 * result + y.hashCode; + return result; + } + String toString() => "Point($x, $y)"; } diff --git a/engine/core/painting/Rect.dart b/engine/core/painting/Rect.dart index a54f7aeaf9cbeffd2f17600846bb8cf9268ba14e..4c958fdbcfe0c7a940cfd16c4874285218aa2fe9 100644 --- a/engine/core/painting/Rect.dart +++ b/engine/core/painting/Rect.dart @@ -4,29 +4,26 @@ part of dart.sky; +/// Holds 4 floating-point coordinates for a rectangle. class Rect { - Float32List _value; + final Float32List _value = new Float32List(4); double get left => _value[0]; double get top => _value[1]; double get right => _value[2]; double get bottom => _value[3]; - Rect() : new Float32List(4); + Rect(); Rect.fromPointAndSize(Point point, Size size) { - _value = new Float32List(4) - ..[0] = point.x - ..[1] = point.y - ..[2] = point.x + size.width - ..[3] = point.y + size.height; + _value + ..[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) { - _value = new Float32List(4) - ..[0] = left - ..[1] = top - ..[2] = right - ..[3] = bottom; + setLTRB(left, top, right, bottom); } Point get upperLeft => new Point(left, top); @@ -36,13 +33,26 @@ 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) => + point.x >= left && point.x < right && point.y >= top && point.y < bottom; void setLTRB(double left, double top, double right, double bottom) { - _value[0] = left - ..[1] = top - ..[2] = right - ..[3] = bottom; + _value + ..[0] = left + ..[1] = top + ..[2] = right + ..[3] = bottom; } + + bool operator ==(other) { + if (!(other is Rect)) return false; + for (var i = 0; i < 4; ++i) { + 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)"; } diff --git a/engine/core/painting/Size.dart b/engine/core/painting/Size.dart index cf41608b8a9936efb4b5dee1837fd8d2d0d40457..5697086c319c9361d59a5c736e3956d5e571b96e 100644 --- a/engine/core/painting/Size.dart +++ b/engine/core/painting/Size.dart @@ -4,9 +4,22 @@ part of dart.sky; +/// Holds a 2D floating-point size. class Size { double width; double height; - Point(this.width, this.height); + Size(this.width, this.height); + + bool operator ==(other) { + if (!(other is Size)) return false; + return width == other.width && height == other.height; + } + int get hashCode { + int result = 373; + result = 37 * result + width.hashCode; + result = 37 * result + height.hashCode; + return result; + } + String toString() => "Size($width, $height)"; }