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

Side by Side Diff: tools/dom/templates/html/impl/impl_ClientRect.darttemplate

Issue 12493003: Exposing Point & Rect types (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 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
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 html; 5 part of $LIBRARYNAME;
6 6
7 /** 7 @DocsEditable
8 * A class for representing two-dimensional rectangles. 8 $(ANNOTATIONS)class $CLASSNAME implements Rect$IMPLEMENTS$NATIVESPEC {
9 */
10 class Rect {
11 final num left;
12 final num top;
13 final num width;
14 final num height;
15
16 const Rect(this.left, this.top, this.width, this.height);
17
18 factory Rect.fromPoints(Point a, Point b) {
19 var left;
20 var width;
21 if (a.x < b.x) {
22 left = a.x;
23 width = b.x - left;
24 } else {
25 left = b.x;
26 width = a.x - left;
27 }
28 var top;
29 var height;
30 if (a.y < b.y) {
31 top = a.y;
32 height = b.y - top;
33 } else {
34 top = b.y;
35 height = a.y - top;
36 }
37
38 return new Rect(left, top, width, height);
39 }
40
41 num get right => left + width;
42 num get bottom => top + height;
43 9
44 // NOTE! All code below should be common with Rect. 10 // NOTE! All code below should be common with Rect.
45 // TODO: implement with mixins when available. 11 // TODO(blois): implement with mixins when available.
46 12
47 String toString() { 13 String toString() {
48 return '($left, $top, $width, $height)'; 14 return '($left, $top, $width, $height)';
49 } 15 }
50 16
51 bool operator ==(other) { 17 bool operator ==(other) {
52 if (other is !Rect) return false; 18 if (other is !Rect) return false;
53 return left == other.left && top == other.top && width == other.width && 19 return left == other.left && top == other.top && width == other.width &&
54 height == other.height; 20 height == other.height;
55 } 21 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 /** 91 /**
126 * Truncates coordinates to integers and returns the result as a new 92 * Truncates coordinates to integers and returns the result as a new
127 * rectangle. 93 * rectangle.
128 */ 94 */
129 Rect toInt() => new Rect(left.toInt(), top.toInt(), width.toInt(), 95 Rect toInt() => new Rect(left.toInt(), top.toInt(), width.toInt(),
130 height.toInt()); 96 height.toInt());
131 97
132 Point get topLeft => new Point(this.left, this.top); 98 Point get topLeft => new Point(this.left, this.top);
133 Point get bottomRight => new Point(this.left + this.width, 99 Point get bottomRight => new Point(this.left + this.width,
134 this.top + this.height); 100 this.top + this.height);
135 } 101 $!MEMBERS}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698