Index: tools/dom/templates/html/impl/impl_ClientRect.darttemplate |
diff --git a/tools/dom/templates/html/impl/impl_ClientRect.darttemplate b/tools/dom/templates/html/impl/impl_ClientRect.darttemplate |
index 14769ecafd111d407d8e87b7786e2fba5169cae5..15efb79a427234e3e311e4744a986bcb74e51e40 100644 |
--- a/tools/dom/templates/html/impl/impl_ClientRect.darttemplate |
+++ b/tools/dom/templates/html/impl/impl_ClientRect.darttemplate |
@@ -5,29 +5,27 @@ |
part of $LIBRARYNAME; |
@DocsEditable() |
-$(ANNOTATIONS)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS implements Rect$IMPLEMENTS$NATIVESPEC { |
- |
- // NOTE! All code below should be common with Rect. |
- // TODO(blois): implement with mixins when available. |
+$(ANNOTATIONS)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS implements Rectangle$IMPLEMENTS$NATIVESPEC { |
+ // NOTE! All code below should be common with RectangleBase. |
String toString() { |
return '($left, $top, $width, $height)'; |
} |
bool operator ==(other) { |
- if (other is !Rect) return false; |
+ if (other is !Rectangle) return false; |
return left == other.left && top == other.top && width == other.width && |
height == other.height; |
} |
- int get hashCode => JenkinsSmiHash.hash4(left.hashCode, top.hashCode, |
+ int get hashCode => _JenkinsSmiHash.hash4(left.hashCode, top.hashCode, |
width.hashCode, height.hashCode); |
/** |
* Computes the intersection of this rectangle and the rectangle parameter. |
* Returns null if there is no intersection. |
*/ |
- Rect intersection(Rect rect) { |
+ Rectangle intersection(Rectangle rect) { |
var x0 = max(left, rect.left); |
var x1 = min(left + width, rect.left + rect.width); |
@@ -36,7 +34,7 @@ $(ANNOTATIONS)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS implements Rect$IMPLEME |
var y1 = min(top + height, rect.top + rect.height); |
if (y0 <= y1) { |
- return new Rect(x0, y0, x1 - x0, y1 - y0); |
+ return new Rectangle(x0, y0, x1 - x0, y1 - y0); |
} |
} |
return null; |
@@ -46,7 +44,7 @@ $(ANNOTATIONS)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS implements Rect$IMPLEME |
/** |
* Returns whether a rectangle intersects this rectangle. |
*/ |
- bool intersects(Rect other) { |
+ bool intersects(Rectangle other) { |
return (left <= other.left + other.width && other.left <= left + width && |
top <= other.top + other.height && other.top <= top + height); |
} |
@@ -55,20 +53,20 @@ $(ANNOTATIONS)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS implements Rect$IMPLEME |
* Returns a new rectangle which completely contains this rectangle and the |
* input rectangle. |
*/ |
- Rect union(Rect rect) { |
+ Rectangle union(Rectangle rect) { |
var right = max(this.left + this.width, rect.left + rect.width); |
var bottom = max(this.top + this.height, rect.top + rect.height); |
var left = min(this.left, rect.left); |
var top = min(this.top, rect.top); |
- return new Rect(left, top, right - left, bottom - top); |
+ return new Rectangle(left, top, right - left, bottom - top); |
} |
/** |
* Tests whether this rectangle entirely contains another rectangle. |
*/ |
- bool containsRect(Rect another) { |
+ bool contains(Rectangle another) { |
return left <= another.left && |
left + width >= another.left + another.width && |
top <= another.top && |
@@ -85,20 +83,58 @@ $(ANNOTATIONS)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS implements Rect$IMPLEME |
another.y <= top + height; |
} |
- Rect ceil() => new Rect(left.ceil(), top.ceil(), width.ceil(), height.ceil()); |
- Rect floor() => new Rect(left.floor(), top.floor(), width.floor(), |
+ Rectangle ceil() => new Rectangle(left.ceil(), top.ceil(), width.ceil(), |
+ height.ceil()); |
+ Rectangle floor() => new Rectangle(left.floor(), top.floor(), width.floor(), |
height.floor()); |
- Rect round() => new Rect(left.round(), top.round(), width.round(), |
+ Rectangle round() => new Rectangle(left.round(), top.round(), width.round(), |
height.round()); |
/** |
* Truncates coordinates to integers and returns the result as a new |
* rectangle. |
*/ |
- Rect toInt() => new Rect(left.toInt(), top.toInt(), width.toInt(), |
- height.toInt()); |
+ Rectangle truncate() => new Rectangle(left.toInt(), top.toInt(), |
+ width.toInt(), height.toInt()); |
Point get topLeft => new Point(this.left, this.top); |
Point get bottomRight => new Point(this.left + this.width, |
this.top + this.height); |
$!MEMBERS} |
+ |
+/** |
+ * This is the [Jenkins hash function][1] but using masking to keep |
+ * values in SMI range. |
+ * |
+ * [1]: http://en.wikipedia.org/wiki/Jenkins_hash_function |
+ * |
+ * Use: |
+ * Hash each value with the hash of the previous value, then get the final |
+ * hash by calling finish. |
+ * |
+ * var hash = 0; |
+ * for (var value in values) { |
+ * hash = JenkinsSmiHash.combine(hash, value.hashCode); |
+ * } |
+ * hash = JenkinsSmiHash.finish(hash); |
+ */ |
+class _JenkinsSmiHash { |
+ // TODO(11617): This class should be optimized and standardized elsewhere. |
+ |
+ static int combine(int hash, int value) { |
+ hash = 0x1fffffff & (hash + value); |
+ hash = 0x1fffffff & (hash + ((0x0007ffff & hash) << 10)); |
+ return hash ^ (hash >> 6); |
+ } |
+ |
+ static int finish(int hash) { |
+ hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3)); |
+ hash = hash ^ (hash >> 11); |
+ return 0x1fffffff & (hash + ((0x00003fff & hash) << 15)); |
+ } |
+ |
+ static int hash2(a, b) => finish(combine(combine(0, a), b)); |
+ |
+ static int hash4(a, b, c, d) => |
+ finish(combine(combine(combine(combine(0, a), b), c), d)); |
+} |