diff --git a/engine/core/core.gni b/engine/core/core.gni index 3408e713795..1f9ed57cef7 100644 --- a/engine/core/core.gni +++ b/engine/core/core.gni @@ -1138,8 +1138,9 @@ core_idl_files = get_path_info([ "abspath") core_dart_files = get_path_info([ - "painting/Rect.dart", "painting/Point.dart", + "painting/Rect.dart", + "painting/Size.dart", ], "abspath") diff --git a/engine/core/painting/Point.dart b/engine/core/painting/Point.dart index 9fc7082e707..856f3360fdf 100644 --- a/engine/core/painting/Point.dart +++ b/engine/core/painting/Point.dart @@ -10,4 +10,3 @@ class Point { Point(this.x, this.y); } - diff --git a/engine/core/painting/Rect.dart b/engine/core/painting/Rect.dart index cb2afec7d77..a54f7aeaf9c 100644 --- a/engine/core/painting/Rect.dart +++ b/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) { + _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) { + _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 Size(right - left, bottom - top); + + // 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; } } diff --git a/engine/core/painting/Size.dart b/engine/core/painting/Size.dart new file mode 100644 index 00000000000..cf41608b8a9 --- /dev/null +++ b/engine/core/painting/Size.dart @@ -0,0 +1,12 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +part of dart.sky; + +class Size { + double width; + double height; + + Point(this.width, this.height); +}