refactor: moved Shapes to pinball_flame (#410)

* refactor: moved Shapes to pinball_flame package

* refactor: simplified BezierCurveShape test

* test: properly used isA matcher
pull/412/head
Alejandro Santiago 3 years ago committed by GitHub
parent fdb9075738
commit d0b9bc204f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -3,6 +3,7 @@ import 'dart:math' as math;
import 'package:flame/components.dart';
import 'package:flame_forge2d/flame_forge2d.dart';
import 'package:pinball_components/pinball_components.dart';
import 'package:pinball_flame/pinball_flame.dart';
/// {@template baseboard}
/// Wing-shaped board piece to corral the [Ball] towards the [Flipper]s.

@ -26,7 +26,6 @@ export 'multiplier/multiplier.dart';
export 'plunger.dart';
export 'rocket.dart';
export 'score_component/score_component.dart';
export 'shapes/shapes.dart';
export 'signpost/signpost.dart';
export 'skill_shot/skill_shot.dart';
export 'slingshot.dart';

@ -17,8 +17,6 @@ dependencies:
ref: a50d4a1e7d9eaf66726ed1bb9894c9d495547d8f
flutter:
sdk: flutter
geometry:
path: ../geometry
intl: ^0.17.0
pinball_flame:
path: ../pinball_flame

@ -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]),
);
}
});
});
});
}

@ -8,4 +8,5 @@ export 'src/keyboard_input_controller.dart';
export 'src/layer.dart';
export 'src/parent_is_a.dart';
export 'src/pinball_forge2d_game.dart';
export 'src/shapes/shapes.dart';
export 'src/sprite_animation.dart';

@ -35,17 +35,4 @@ class ArcShape extends ChainShape {
/// Angle in radians to rotate the arc around its [center].
final double rotation;
ArcShape copyWith({
Vector2? center,
double? arcRadius,
double? angle,
double? rotation,
}) =>
ArcShape(
center: center ?? this.center,
arcRadius: arcRadius ?? this.arcRadius,
angle: angle ?? this.angle,
rotation: rotation ?? this.rotation,
);
}

@ -1,4 +1,3 @@
import 'package:flame/extensions.dart';
import 'package:flame_forge2d/flame_forge2d.dart';
import 'package:geometry/geometry.dart';
@ -18,9 +17,4 @@ class BezierCurveShape extends ChainShape {
/// First and last [controlPoints] set the beginning and end of the curve,
/// inner points between them set its final shape.
final List<Vector2> controlPoints;
/// Rotates the bezier curve by a given [angle] in radians.
void rotate(double angle) {
vertices.map((vector) => vector..rotate(angle)).toList();
}
}

@ -34,17 +34,8 @@ class EllipseShape extends ChainShape {
/// Rotates the ellipse by a given [angle] in radians.
void rotate(double angle) {
vertices.map((vector) => vector..rotate(angle)).toList();
for (final vector in vertices) {
vector.rotate(angle);
}
}
EllipseShape copyWith({
Vector2? center,
double? majorRadius,
double? minorRadius,
}) =>
EllipseShape(
center: center ?? this.center,
majorRadius: majorRadius ?? this.majorRadius,
minorRadius: minorRadius ?? this.minorRadius,
);
}

@ -17,6 +17,8 @@ dependencies:
ref: a50d4a1e7d9eaf66726ed1bb9894c9d495547d8f
flutter:
sdk: flutter
geometry:
path: ../geometry
dev_dependencies:
flame_test: ^1.3.0

@ -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…
Cancel
Save