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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 /** | 61 /** |
62 * Represents the interval { x | start <= x < end }. | 62 * Represents the interval { x | start <= x < end }. |
63 */ | 63 */ |
64 class Interval { | 64 class Interval { |
65 | 65 |
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 |