mirror of https://github.com/flutter/pinball.git
refactor: moved Shapes to pinball_flame (#410)
* refactor: moved Shapes to pinball_flame package * refactor: simplified BezierCurveShape test * test: properly used isA matcherpull/412/head
parent
fdb9075738
commit
d0b9bc204f
@ -1,66 +0,0 @@
|
|||||||
import 'dart:math' as math;
|
|
||||||
import 'package:flame/extensions.dart';
|
|
||||||
import 'package:flame/game.dart';
|
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
|
||||||
import 'package:pinball_components/src/components/components.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
group('ArcShape', () {
|
|
||||||
test('can be instantiated', () {
|
|
||||||
expect(
|
|
||||||
ArcShape(
|
|
||||||
center: Vector2.zero(),
|
|
||||||
arcRadius: 10,
|
|
||||||
angle: 2 * math.pi,
|
|
||||||
),
|
|
||||||
isNotNull,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
group('copyWith', () {
|
|
||||||
test(
|
|
||||||
'copies correctly '
|
|
||||||
'when no argument specified', () {
|
|
||||||
final arcShape = ArcShape(
|
|
||||||
center: Vector2.zero(),
|
|
||||||
arcRadius: 10,
|
|
||||||
angle: 2 * math.pi,
|
|
||||||
);
|
|
||||||
final arcShapeCopied = arcShape.copyWith();
|
|
||||||
|
|
||||||
for (var index = 0; index < arcShape.vertices.length; index++) {
|
|
||||||
expect(
|
|
||||||
arcShape.vertices[index],
|
|
||||||
equals(arcShapeCopied.vertices[index]),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test(
|
|
||||||
'copies correctly '
|
|
||||||
'when all arguments specified', () {
|
|
||||||
final arcShapeExpected = ArcShape(
|
|
||||||
center: Vector2.all(10),
|
|
||||||
arcRadius: 15,
|
|
||||||
angle: 2 * math.pi,
|
|
||||||
);
|
|
||||||
final arcShapeCopied = ArcShape(
|
|
||||||
center: Vector2.zero(),
|
|
||||||
arcRadius: 10,
|
|
||||||
angle: math.pi,
|
|
||||||
).copyWith(
|
|
||||||
center: Vector2.all(10),
|
|
||||||
arcRadius: 15,
|
|
||||||
angle: 2 * math.pi,
|
|
||||||
);
|
|
||||||
|
|
||||||
for (var index = 0; index < arcShapeCopied.vertices.length; index++) {
|
|
||||||
expect(
|
|
||||||
arcShapeCopied.vertices[index],
|
|
||||||
equals(arcShapeExpected.vertices[index]),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
@ -1,51 +0,0 @@
|
|||||||
import 'dart:math' as math;
|
|
||||||
import 'package:flame/extensions.dart';
|
|
||||||
import 'package:flame/game.dart';
|
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
|
||||||
import 'package:pinball_components/src/components/components.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
group('BezierCurveShape', () {
|
|
||||||
final controlPoints = [
|
|
||||||
Vector2(0, 0),
|
|
||||||
Vector2(10, 0),
|
|
||||||
Vector2(0, 10),
|
|
||||||
Vector2(10, 10),
|
|
||||||
];
|
|
||||||
|
|
||||||
test('can be instantiated', () {
|
|
||||||
expect(
|
|
||||||
BezierCurveShape(
|
|
||||||
controlPoints: controlPoints,
|
|
||||||
),
|
|
||||||
isNotNull,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
group('rotate', () {
|
|
||||||
test('returns vertices rotated', () {
|
|
||||||
const rotationAngle = 2 * math.pi;
|
|
||||||
final controlPoints = [
|
|
||||||
Vector2(0, 0),
|
|
||||||
Vector2(10, 0),
|
|
||||||
Vector2(0, 10),
|
|
||||||
Vector2(10, 10),
|
|
||||||
];
|
|
||||||
|
|
||||||
final bezierCurveShape = BezierCurveShape(
|
|
||||||
controlPoints: controlPoints,
|
|
||||||
);
|
|
||||||
final bezierCurveShapeRotated = BezierCurveShape(
|
|
||||||
controlPoints: controlPoints,
|
|
||||||
)..rotate(rotationAngle);
|
|
||||||
|
|
||||||
for (var index = 0; index < bezierCurveShape.vertices.length; index++) {
|
|
||||||
expect(
|
|
||||||
bezierCurveShape.vertices[index]..rotate(rotationAngle),
|
|
||||||
equals(bezierCurveShapeRotated.vertices[index]),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
@ -1,83 +0,0 @@
|
|||||||
import 'dart:math' as math;
|
|
||||||
import 'package:flame/extensions.dart';
|
|
||||||
import 'package:flame/game.dart';
|
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
|
||||||
import 'package:pinball_components/src/components/components.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
group('EllipseShape', () {
|
|
||||||
test('can be instantiated', () {
|
|
||||||
expect(
|
|
||||||
EllipseShape(
|
|
||||||
center: Vector2.zero(),
|
|
||||||
majorRadius: 10,
|
|
||||||
minorRadius: 8,
|
|
||||||
),
|
|
||||||
isNotNull,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
group('rotate', () {
|
|
||||||
test('returns vertices rotated', () {
|
|
||||||
const rotationAngle = 2 * math.pi;
|
|
||||||
final ellipseShape = EllipseShape(
|
|
||||||
center: Vector2.zero(),
|
|
||||||
majorRadius: 10,
|
|
||||||
minorRadius: 8,
|
|
||||||
);
|
|
||||||
final ellipseShapeRotated = EllipseShape(
|
|
||||||
center: Vector2.zero(),
|
|
||||||
majorRadius: 10,
|
|
||||||
minorRadius: 8,
|
|
||||||
)..rotate(rotationAngle);
|
|
||||||
|
|
||||||
for (var index = 0; index < ellipseShape.vertices.length; index++) {
|
|
||||||
expect(
|
|
||||||
ellipseShape.vertices[index]..rotate(rotationAngle),
|
|
||||||
equals(ellipseShapeRotated.vertices[index]),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
group('copyWith', () {
|
|
||||||
test('returns same shape when no properties are passed', () {
|
|
||||||
final ellipseShape = EllipseShape(
|
|
||||||
center: Vector2.zero(),
|
|
||||||
majorRadius: 10,
|
|
||||||
minorRadius: 8,
|
|
||||||
);
|
|
||||||
final ellipseShapeCopied = ellipseShape.copyWith();
|
|
||||||
|
|
||||||
for (var index = 0; index < ellipseShape.vertices.length; index++) {
|
|
||||||
expect(
|
|
||||||
ellipseShape.vertices[index],
|
|
||||||
equals(ellipseShapeCopied.vertices[index]),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test('returns object with updated properties when are passed', () {
|
|
||||||
final ellipseShapeExpected = EllipseShape(
|
|
||||||
center: Vector2.all(10),
|
|
||||||
majorRadius: 10,
|
|
||||||
minorRadius: 8,
|
|
||||||
);
|
|
||||||
final ellipseShapeCopied = EllipseShape(
|
|
||||||
center: Vector2.zero(),
|
|
||||||
majorRadius: 10,
|
|
||||||
minorRadius: 8,
|
|
||||||
).copyWith(center: Vector2.all(10));
|
|
||||||
|
|
||||||
for (var index = 0;
|
|
||||||
index < ellipseShapeCopied.vertices.length;
|
|
||||||
index++) {
|
|
||||||
expect(
|
|
||||||
ellipseShapeCopied.vertices[index],
|
|
||||||
equals(ellipseShapeExpected.vertices[index]),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
@ -0,0 +1,20 @@
|
|||||||
|
import 'dart:math' as math;
|
||||||
|
import 'package:flame/extensions.dart';
|
||||||
|
import 'package:flame/game.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:pinball_flame/pinball_flame.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
group('ArcShape', () {
|
||||||
|
test('can be instantiated', () {
|
||||||
|
expect(
|
||||||
|
ArcShape(
|
||||||
|
center: Vector2.zero(),
|
||||||
|
arcRadius: 10,
|
||||||
|
angle: 2 * math.pi,
|
||||||
|
),
|
||||||
|
isA<ArcShape>(),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
import 'package:flame/extensions.dart';
|
||||||
|
import 'package:flame/game.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:pinball_flame/pinball_flame.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
group('BezierCurveShape', () {
|
||||||
|
test('can be instantiated', () {
|
||||||
|
expect(
|
||||||
|
BezierCurveShape(
|
||||||
|
controlPoints: [
|
||||||
|
Vector2(0, 0),
|
||||||
|
Vector2(10, 0),
|
||||||
|
Vector2(0, 10),
|
||||||
|
Vector2(10, 10),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
isA<BezierCurveShape>(),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
import 'dart:math' as math;
|
||||||
|
import 'package:flame/extensions.dart';
|
||||||
|
import 'package:flame/game.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:pinball_flame/pinball_flame.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
group('EllipseShape', () {
|
||||||
|
test('can be instantiated', () {
|
||||||
|
expect(
|
||||||
|
EllipseShape(
|
||||||
|
center: Vector2.zero(),
|
||||||
|
majorRadius: 10,
|
||||||
|
minorRadius: 8,
|
||||||
|
),
|
||||||
|
isA<EllipseShape>(),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('rotate returns vertices rotated', () {
|
||||||
|
const rotationAngle = 2 * math.pi;
|
||||||
|
final ellipseShape = EllipseShape(
|
||||||
|
center: Vector2.zero(),
|
||||||
|
majorRadius: 10,
|
||||||
|
minorRadius: 8,
|
||||||
|
);
|
||||||
|
final ellipseShapeRotated = EllipseShape(
|
||||||
|
center: Vector2.zero(),
|
||||||
|
majorRadius: 10,
|
||||||
|
minorRadius: 8,
|
||||||
|
)..rotate(rotationAngle);
|
||||||
|
|
||||||
|
for (var index = 0; index < ellipseShape.vertices.length; index++) {
|
||||||
|
expect(
|
||||||
|
ellipseShape.vertices[index]..rotate(rotationAngle),
|
||||||
|
equals(ellipseShapeRotated.vertices[index]),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in new issue