mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-03 04:18:25 +08:00
* 👌 Use `Offset` type directly in `JoystickAction.update` calculations (#631) * Move files to src and comply with the dart package layout convention * Fixing widgets example Co-authored-by: Serge Matveenko <lig@countzero.co> Co-authored-by: Erick Zanardo <erickzanardoo@gmail.com>
88 lines
2.7 KiB
Dart
88 lines
2.7 KiB
Dart
import 'dart:math' as math;
|
|
|
|
import 'package:flame/components.dart';
|
|
import 'package:test/test.dart';
|
|
|
|
class MyComponent extends PositionComponent {}
|
|
|
|
void main() {
|
|
group('PositionComponent overlap test', () {
|
|
test('overlap', () {
|
|
final PositionComponent component = MyComponent();
|
|
component.position = Vector2(2.0, 2.0);
|
|
component.size = Vector2(4.0, 4.0);
|
|
component.angle = 0.0;
|
|
component.anchor = Anchor.center;
|
|
|
|
final point = Vector2(2.0, 2.0);
|
|
expect(component.checkOverlap(point), true);
|
|
});
|
|
|
|
test('overlap on edge', () {
|
|
final PositionComponent component = MyComponent();
|
|
component.position = Vector2(2.0, 2.0);
|
|
component.size = Vector2(2.0, 2.0);
|
|
component.angle = 0.0;
|
|
component.anchor = Anchor.center;
|
|
|
|
final point = Vector2(1.0, 1.0);
|
|
expect(component.checkOverlap(point), true);
|
|
});
|
|
|
|
test('not overlapping with x', () {
|
|
final PositionComponent component = MyComponent();
|
|
component.position = Vector2(2.0, 2.0);
|
|
component.size = Vector2(2.0, 2.0);
|
|
component.angle = 0.0;
|
|
component.anchor = Anchor.center;
|
|
|
|
final point = Vector2(4.0, 1.0);
|
|
expect(component.checkOverlap(point), false);
|
|
});
|
|
|
|
test('not overlapping with y', () {
|
|
final PositionComponent component = MyComponent();
|
|
component.position = Vector2(2.0, 2.0);
|
|
component.size = Vector2(2.0, 2.0);
|
|
component.angle = 0.0;
|
|
component.anchor = Anchor.center;
|
|
|
|
final point = Vector2(1.0, 4.0);
|
|
expect(component.checkOverlap(point), false);
|
|
});
|
|
|
|
test('overlapping with angle', () {
|
|
final PositionComponent component = MyComponent();
|
|
component.position = Vector2(2.0, 2.0);
|
|
component.size = Vector2(2.0, 2.0);
|
|
component.angle = math.pi / 4;
|
|
component.anchor = Anchor.center;
|
|
|
|
final point = Vector2(3.1, 2.0);
|
|
expect(component.checkOverlap(point), true);
|
|
});
|
|
|
|
test('not overlapping with angle', () {
|
|
final PositionComponent component = MyComponent();
|
|
component.position = Vector2(2.0, 2.0);
|
|
component.size = Vector2(2.0, 2.0);
|
|
component.angle = math.pi / 4;
|
|
component.anchor = Anchor.center;
|
|
|
|
final point = Vector2(1.0, 0.1);
|
|
expect(component.checkOverlap(point), false);
|
|
});
|
|
|
|
test('overlapping with angle and topLeft anchor', () {
|
|
final PositionComponent component = MyComponent();
|
|
component.position = Vector2(1.0, 1.0);
|
|
component.size = Vector2(2.0, 2.0);
|
|
component.angle = math.pi / 4;
|
|
component.anchor = Anchor.topLeft;
|
|
|
|
final point = Vector2(1.0, 3.1);
|
|
expect(component.checkOverlap(point), true);
|
|
});
|
|
});
|
|
}
|