Files
sdk/tests/lib_2/html/canvasrendering/arc_test.dart
T
Leaf Petersen b101a7d002 Add language versions to _2 test libraries
Change-Id: Ib33169c3e0ffc870915c189404074a1dea472546
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/196548
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Commit-Queue: Leaf Petersen <leafp@google.com>
2021-04-26 17:58:57 +00:00

106 lines
3.3 KiB
Dart

// Copyright (c) 2020, 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.
// @dart = 2.9
library canvas_rendering_context_2d_test;
import 'dart:html';
import 'dart:math';
import 'canvas_rendering_util.dart';
import 'package:expect/minitest.dart';
main() {
setUp(setupFunc);
tearDown(tearDownFunc);
test('default arc should be clockwise', () {
context.beginPath();
final r = 10;
// Center of arc.
final cx = 20;
final cy = 20;
// Arc centered at (20, 20) with radius 10 will go clockwise
// from (20 + r, 20) to (20, 20 + r), which is 1/4 of a circle.
context.arc(cx, cy, r, 0, pi / 2);
context.strokeStyle = 'green';
context.lineWidth = 2;
context.stroke();
// Center should not be filled.
expectPixelUnfilled(cx, cy);
// (cx + r, cy) should be filled.
expectPixelFilled(cx + r, cy, true);
// (cx, cy + r) should be filled.
expectPixelFilled(cx, cy + r, true);
// (cx - r, cy) should be empty.
expectPixelFilled(cx - r, cy, false);
// (cx, cy - r) should be empty.
expectPixelFilled(cx, cy - r, false);
// (cx + r/SQRT2, cy + r/SQRT2) should be filled.
expectPixelFilled((cx + r / sqrt2).toInt(), (cy + r / sqrt2).toInt(), true);
// (cx - r/SQRT2, cy - r/SQRT2) should be empty.
expectPixelFilled(
(cx - r / sqrt2).toInt(), (cy + r / sqrt2).toInt(), false);
// (cx + r/SQRT2, cy + r/SQRT2) should be empty.
expectPixelFilled(
(cx - r / sqrt2).toInt(), (cy - r / sqrt2).toInt(), false);
// (cx - r/SQRT2, cy - r/SQRT2) should be empty.
expectPixelFilled(
(cx + r / sqrt2).toInt(), (cy - r / sqrt2).toInt(), false);
});
test('arc anticlockwise', () {
context.beginPath();
final r = 10;
// Center of arc.
final cx = 20;
final cy = 20;
// Arc centered at (20, 20) with radius 10 will go anticlockwise
// from (20 + r, 20) to (20, 20 + r), which is 3/4 of a circle.
// Because of the way arc work, when going anti-clockwise, the end points
// are not included, so small values are added to radius to make a little
// more than a 3/4 circle.
context.arc(cx, cy, r, .1, pi / 2 - .1, true);
context.strokeStyle = 'green';
context.lineWidth = 2;
context.stroke();
// Center should not be filled.
expectPixelUnfilled(cx, cy);
// (cx + r, cy) should be filled.
expectPixelFilled(cx + r, cy, true);
// (cx, cy + r) should be filled.
expectPixelFilled(cx, cy + r, true);
// (cx - r, cy) should be filled.
expectPixelFilled(cx - r, cy, true);
// (cx, cy - r) should be filled.
expectPixelFilled(cx, cy - r, true);
// (cx + r/SQRT2, cy + r/SQRT2) should be empty.
expectPixelFilled(
(cx + r / sqrt2).toInt(), (cy + r / sqrt2).toInt(), false);
// (cx - r/SQRT2, cy - r/SQRT2) should be filled.
expectPixelFilled((cx - r / sqrt2).toInt(), (cy + r / sqrt2).toInt(), true);
// (cx + r/SQRT2, cy + r/SQRT2) should be filled.
expectPixelFilled((cx - r / sqrt2).toInt(), (cy - r / sqrt2).toInt(), true);
// (cx - r/SQRT2, cy - r/SQRT2) should be filled.
expectPixelFilled((cx + r / sqrt2).toInt(), (cy - r / sqrt2).toInt(), true);
});
}