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

Side by Side Diff: tools/dom/src/Rectangle.dart

Issue 25785003: "Reverting 28184" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « tools/dom/src/Point.dart ('k') | tools/dom/templates/html/dart2js/html_dart2js.darttemplate » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of $LIBRARYNAME; 5 part of html;
6 6
7 @DocsEditable() 7 /**
8 $(ANNOTATIONS)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS implements Rectangle$IM PLEMENTS$NATIVESPEC { 8 * A base class for representing two-dimensional rectangles. This will hopefully
9 * be moved merged with the dart:math Rect.
10 */
11 // TODO(efortuna): Merge with Math rect after finalizing with Florian.
12 abstract class RectBase {
13 // Not used, but keeps the VM from complaining about Rect having a const
14 // constructor and this one not.
15 const RectBase();
9 16
10 // NOTE! All code below should be common with RectangleBase. 17 num get left;
18 num get top;
19 num get width;
20 num get height;
21
22 num get right => left + width;
23 num get bottom => top + height;
24
25 // NOTE! All code below should be common with Rect.
26
11 String toString() { 27 String toString() {
12 return '($left, $top, $width, $height)'; 28 return '($left, $top, $width, $height)';
13 } 29 }
14 30
15 bool operator ==(other) { 31 bool operator ==(other) {
16 if (other is !Rect) return false; 32 if (other is !Rect) return false;
17 return left == other.left && top == other.top && width == other.width && 33 return left == other.left && top == other.top && width == other.width &&
18 height == other.height; 34 height == other.height;
19 } 35 }
20 36
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 /** 108 /**
93 * Truncates coordinates to integers and returns the result as a new 109 * Truncates coordinates to integers and returns the result as a new
94 * rectangle. 110 * rectangle.
95 */ 111 */
96 Rect toInt() => new Rect(left.toInt(), top.toInt(), width.toInt(), 112 Rect toInt() => new Rect(left.toInt(), top.toInt(), width.toInt(),
97 height.toInt()); 113 height.toInt());
98 114
99 Point get topLeft => new Point(this.left, this.top); 115 Point get topLeft => new Point(this.left, this.top);
100 Point get bottomRight => new Point(this.left + this.width, 116 Point get bottomRight => new Point(this.left + this.width,
101 this.top + this.height); 117 this.top + this.height);
102 $!MEMBERS} 118 }
119
120
121
122 /**
123 * A class for representing two-dimensional rectangles.
124 *
125 * This class is distinctive from RectBase in that it enforces that its
126 * properties are immutable.
127 */
128 class Rect extends RectBase {
129 final num left;
130 final num top;
131 final num width;
132 final num height;
133
134 const Rect(this.left, this.top, this.width, this.height): super();
135
136 factory Rect.fromPoints(Point a, Point b) {
137 var left;
138 var width;
139 if (a.x < b.x) {
140 left = a.x;
141 width = b.x - left;
142 } else {
143 left = b.x;
144 width = a.x - left;
145 }
146 var top;
147 var height;
148 if (a.y < b.y) {
149 top = a.y;
150 height = b.y - top;
151 } else {
152 top = b.y;
153 height = a.y - top;
154 }
155
156 return new Rect(left, top, width, height);
157 }
158 }
OLDNEW
« no previous file with comments | « tools/dom/src/Point.dart ('k') | tools/dom/templates/html/dart2js/html_dart2js.darttemplate » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698