OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 /** | 5 /** |
6 * Represents a point in 2 dimensional space. | 6 * Represents a point in 2 dimensional space. |
7 */ | 7 */ |
8 class Coordinate { | 8 class Coordinate { |
9 | 9 |
10 /** | 10 /** |
(...skipping 19 matching lines...) Expand all Loading... |
30 return new Coordinate(a.x - b.x, a.y - b.y); | 30 return new Coordinate(a.x - b.x, a.y - b.y); |
31 } | 31 } |
32 | 32 |
33 static num distance(Coordinate a, Coordinate b) { | 33 static num distance(Coordinate a, Coordinate b) { |
34 final dx = a.x - b.x; | 34 final dx = a.x - b.x; |
35 final dy = a.y - b.y; | 35 final dy = a.y - b.y; |
36 return Math.sqrt(dx * dx + dy * dy); | 36 return Math.sqrt(dx * dx + dy * dy); |
37 } | 37 } |
38 | 38 |
39 bool operator ==(Coordinate other) { | 39 bool operator ==(Coordinate other) { |
40 return other !== null && x == other.x && y == other.y; | 40 return other != null && x == other.x && y == other.y; |
41 } | 41 } |
42 | 42 |
43 static num squaredDistance(Coordinate a, Coordinate b) { | 43 static num squaredDistance(Coordinate a, Coordinate b) { |
44 final dx = a.x - b.x; | 44 final dx = a.x - b.x; |
45 final dy = a.y - b.y; | 45 final dy = a.y - b.y; |
46 return dx * dx + dy * dy; | 46 return dx * dx + dy * dy; |
47 } | 47 } |
48 | 48 |
49 static Coordinate sum(Coordinate a, Coordinate b) { | 49 static Coordinate sum(Coordinate a, Coordinate b) { |
50 return new Coordinate(a.x + b.x, a.y + b.y); | 50 return new Coordinate(a.x + b.x, a.y + b.y); |
(...skipping 15 matching lines...) Expand all Loading... |
66 final num start; | 66 final num start; |
67 final num end; | 67 final num end; |
68 | 68 |
69 Interval(num this.start, num this.end) {} | 69 Interval(num this.start, num this.end) {} |
70 | 70 |
71 num get length { | 71 num get length { |
72 return end - start; | 72 return end - start; |
73 } | 73 } |
74 | 74 |
75 bool operator ==(Interval other) { | 75 bool operator ==(Interval other) { |
76 return other !== null && other.start == start && other.end == end; | 76 return other != null && other.start == start && other.end == end; |
77 } | 77 } |
78 | 78 |
79 Interval union(Interval other) { | 79 Interval union(Interval other) { |
80 return new Interval(Math.min(start, other.start), | 80 return new Interval(Math.min(start, other.start), |
81 Math.max(end, other.end)); | 81 Math.max(end, other.end)); |
82 } | 82 } |
83 | 83 |
84 bool contains(num value) { | 84 bool contains(num value) { |
85 return value >= start && value < end; | 85 return value >= start && value < end; |
86 } | 86 } |
87 | 87 |
88 String toString() { | 88 String toString() { |
89 return '(${start}, ${end})'; | 89 return '(${start}, ${end})'; |
90 } | 90 } |
91 } | 91 } |
OLD | NEW |