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

Side by Side Diff: sky/engine/core/painting/Size.dart

Issue 1160453006: Provide Point+Size, Point-Point, Point.toSize(), and Rect.toPoint(). (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 part of dart.sky; 5 part of dart.sky;
6 6
7 /// Holds a 2D floating-point size. 7 /// Holds a 2D floating-point size.
8 /// Think of this as a vector from Point(0,0) to Point(size.width, size.height)
8 class Size { 9 class Size {
9 final double width; 10 final double width;
10 final double height; 11 final double height;
11 12
12 const Size(this.width, this.height); 13 const Size(this.width, this.height);
13 14
14 const Size.infinite() : width = double.INFINITY, height = double.INFINITY; 15 const Size.infinite() : width = double.INFINITY, height = double.INFINITY;
15 16
16 const Size.fromWidth(this.width) : height = double.INFINITY; 17 const Size.fromWidth(this.width) : height = double.INFINITY;
17 const Size.fromHeight(this.height) : width = double.INFINITY; 18 const Size.fromHeight(this.height) : width = double.INFINITY;
18 19
19 bool operator ==(other) { 20 bool operator ==(other) => other is Size && width == other.width && height == other.height;
20 if (!(other is Size)) return false; 21
21 return width == other.width && height == other.height; 22 // does the equivalent of "return new Point(0,0) + this"
22 } 23 Point toPoint() => new Point(this.width, this.height);
24
23 int get hashCode { 25 int get hashCode {
24 int result = 373; 26 int result = 373;
25 result = 37 * result + width.hashCode; 27 result = 37 * result + width.hashCode;
26 result = 37 * result + height.hashCode; 28 result = 37 * result + height.hashCode;
27 return result; 29 return result;
28 } 30 }
29 String toString() => "Size($width, $height)"; 31 String toString() => "Size($width, $height)";
30 } 32 }
OLDNEW
« sky/engine/core/painting/Rect.dart ('K') | « sky/engine/core/painting/Rect.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698