blob: 4a4a020f097e53f8f18bb19c5fd5c57327dd3279 [file] [log] [blame]
 /* * Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file * for details. All rights reserved. Use of this source code is governed by a * BSD-style license that can be found in the LICENSE file. */ /** * @assertion * @description */ import "dart:html"; import "dart:math" as Math; import "../../../testharness.dart"; import "../resources/subpixel-utils.dart" as SubPixelLayout; const String htmlEL1 = r''' '''; const String htmlEL2 = r'''

The left edges of the three black squares should follow the outer ellipse boundary and each square should appear on a subsequent line.

X
X
X
'''; Rectangle elementRect(elementId) { Rectangle s = document.getElementById("container").getBoundingClientRect(); Rectangle r = document.getElementById(elementId).getBoundingClientRect(); return new Rectangle(r.left - s.left, r.top - s.top, r.width, r.height); } // You'll find the equation for the X intercept of an elliptical arc here (among other places): // http://hansmuller-webkit.blogspot.com/2012/07/computing-horizonal-rounded-rectangle.html String marginEllipseLeftXIntercept(y, cx, rx, ry) { var f = SubPixelLayout.snapToLayoutUnit(cx + rx * Math.sqrt(1 - Math.pow((ry - y) / ry, 2))); return f.round().toString(); } // In the ".left" tests below, it's the lower edge of the 20px Ahem glyph that that defines the element rect's left edge. // That's why the Y coordinate in each of those tests is 20 greater than the ".top" test. void main() { document.head.appendHtml(htmlEL1, treeSanitizer: new NullTreeSanitizer()); document.body.appendHtml(htmlEL2, treeSanitizer: new NullTreeSanitizer()); shouldBe(elementRect('s1').top, 0); shouldBe(elementRect('s1').left, marginEllipseLeftXIntercept(20, 225, 225, 125)); shouldBe(elementRect('s2').top, 20); shouldBe(elementRect('s2').left, marginEllipseLeftXIntercept(40, 225, 225, 125)); shouldBe(elementRect('s3').top, 40); shouldBe(elementRect('s3').left, marginEllipseLeftXIntercept(60, 225, 225, 125)); checkTestFailures(); }