Skip to content

Commit e2fba01

Browse files
committed
added helper function. has to check entire matrix
1 parent bdf32a7 commit e2fba01

File tree

1 file changed

+47
-13
lines changed

1 file changed

+47
-13
lines changed

packages/camera/camera_android_camerax/test/preview_rotation_test.dart

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import 'package:camera_android_camerax/src/camerax_library.dart';
77
import 'package:camera_android_camerax/src/camerax_proxy.dart';
88
import 'package:camera_platform_interface/camera_platform_interface.dart';
99
import 'package:flutter/services.dart';
10-
import 'package:flutter/widgets.dart' show RotatedBox, Texture, Transform;
10+
import 'package:flutter/widgets.dart' show MatrixUtils, RotatedBox, Texture, Transform;
1111
import 'package:flutter_test/flutter_test.dart';
1212
import 'package:mockito/mockito.dart';
1313

@@ -380,6 +380,40 @@ void main() {
380380
) =>
381381
'Expected the preview to be rotated by $expectedQuarterTurns quarter turns (which is ${expectedQuarterTurns * 90} degrees clockwise) but instead was rotated $actualQuarterTurns quarter turns.';
382382

383+
/// Checks that the transform matrix (Matrix4) mirrors across the x-axis by
384+
/// confirming the following to be the transformation matrix:
385+
/// [[-1.0, 0.0, 0.0, 0.0],
386+
/// [ 0.0, 1.0, 0.0, 0.0],
387+
/// [ 0.0, 0.0, 1.0, 0.0],
388+
/// [ 0.0, 0.0, 0.0, 1.0]]
389+
void checkXAxisIsMirrored(Matrix4 transformationMatrix) {
390+
final Matrix4 mirrorAcrossXMatrix = Matrix4(
391+
-1.0, 0.0, 0.0, 0.0,
392+
0.0, 1.0, 0.0, 0.0,
393+
0.0, 0.0, 1.0, 0.0,
394+
0.0, 0.0, 0.0, 1.0
395+
);
396+
397+
expect(MatrixUtils.matrixEquals(mirrorAcrossXMatrix, transformationMatrix), isTrue);
398+
}
399+
400+
/// Checks that the transform matrix (Matrix4) mirrors across the y-axis by
401+
/// confirming the following to be the transformation matrix:
402+
/// [[1.0, 0.0, 0.0, 0.0],
403+
/// [ 0.0, -1.0, 0.0, 0.0],
404+
/// [ 0.0, 0.0, 1.0, 0.0],
405+
/// [ 0.0, 0.0, 0.0, 1.0]]
406+
void checkYAxisIsMirrored(Matrix4 transformationMatrix) {
407+
final Matrix4 mirrorAcrossYMatrix = Matrix4(
408+
1.0, 0.0, 0.0, 0.0,
409+
0.0, -1.0, 0.0, 0.0,
410+
0.0, 0.0, 1.0, 0.0,
411+
0.0, 0.0, 0.0, 1.0
412+
);
413+
414+
expect(MatrixUtils.matrixEquals(mirrorAcrossYMatrix, transformationMatrix), isTrue);
415+
}
416+
383417
group('when handlesCropAndRotation is true', () {
384418
// Test that preview rotation responds to initial default display rotation:
385419
group('initial device orientation is landscapeRight,', () {
@@ -1178,7 +1212,7 @@ void main() {
11781212

11791213
// Since the front camera is in portrait mode, we expect the camera
11801214
// preview to be mirrored across the y-axis.
1181-
expect(transformedPreviewMatrix.storage[5], closeTo(-1.0, 0.0001));
1215+
checkYAxisIsMirrored(transformedPreviewMatrix);
11821216
expect((transformedPreview.child! as Texture).textureId, cameraId);
11831217
expect(
11841218
rotatedBox.quarterTurns,
@@ -1239,7 +1273,7 @@ void main() {
12391273

12401274
// Since the front camera is in landscape mode, we expect the camera
12411275
// preview to be mirrored across the x-axis.
1242-
expect(transformedPreviewMatrix.storage[0], closeTo(-1.0, 0.0001));
1276+
checkXAxisIsMirrored(transformedPreviewMatrix);
12431277
expect((transformedPreview.child! as Texture).textureId, cameraId);
12441278
expect(
12451279
rotatedBox.quarterTurns,
@@ -1300,7 +1334,7 @@ void main() {
13001334

13011335
// Since the front camera is in portrait mode, we expect the camera
13021336
// preview to be mirrored across the y-axis.
1303-
expect(transformedPreviewMatrix.storage[5], closeTo(-1.0, 0.0001));
1337+
checkYAxisIsMirrored(transformedPreviewMatrix);
13041338
expect((transformedPreview.child! as Texture).textureId, cameraId);
13051339
expect(
13061340
rotatedBox.quarterTurns,
@@ -1361,7 +1395,7 @@ void main() {
13611395

13621396
// Since the front camera is in landscape mode, we expect the camera
13631397
// preview to be mirrored across the x-axis.
1364-
expect(transformedPreviewMatrix.storage[0], closeTo(-1.0, 0.0001));
1398+
checkXAxisIsMirrored(transformedPreviewMatrix);
13651399
expect((transformedPreview.child! as Texture).textureId, cameraId);
13661400
expect(
13671401
rotatedBox.quarterTurns,
@@ -1464,7 +1498,7 @@ void main() {
14641498

14651499
// Since the front camera is in landscape mode, we expect the camera
14661500
// preview to be mirrored across the x-axis.
1467-
expect(transformedPreviewMatrix.storage[0], closeTo(-1.0, 0.0001));
1501+
checkXAxisIsMirrored(transformedPreviewMatrix);
14681502
expect((transformedPreview.child! as Texture).textureId, cameraId);
14691503
expect(
14701504
rotatedBox.quarterTurns,
@@ -1525,7 +1559,7 @@ void main() {
15251559

15261560
// Since the front camera is in landscape mode, we expect the camera
15271561
// preview to be mirrored across the x-axis.
1528-
expect(transformedPreviewMatrix.storage[0], closeTo(-1.0, 0.0001));
1562+
checkXAxisIsMirrored(transformedPreviewMatrix);
15291563
expect((transformedPreview.child! as Texture).textureId, cameraId);
15301564

15311565
final int clockwiseQuarterTurns = rotatedBox.quarterTurns + 4;
@@ -1586,7 +1620,7 @@ void main() {
15861620

15871621
// Since the front camera is in landscape mode, we expect the camera
15881622
// preview to be mirrored across the x-axis.
1589-
expect(transformedPreviewMatrix.storage[0], closeTo(-1.0, 0.0001));
1623+
checkXAxisIsMirrored(transformedPreviewMatrix);
15901624
expect((transformedPreview.child! as Texture).textureId, cameraId);
15911625

15921626
final int clockwiseQuarterTurns = rotatedBox.quarterTurns + 4;
@@ -1649,7 +1683,7 @@ void main() {
16491683

16501684
// Since the front camera is in landscape mode, we expect the camera
16511685
// preview to be mirrored across the x-axis.
1652-
expect(transformedPreviewMatrix.storage[0], closeTo(-1.0, 0.0001));
1686+
checkXAxisIsMirrored(transformedPreviewMatrix);
16531687
expect((transformedPreview.child! as Texture).textureId, cameraId);
16541688

16551689
final int clockwiseQuarterTurns = rotatedBox.quarterTurns + 4;
@@ -1770,7 +1804,7 @@ void main() {
17701804

17711805
// Since the front camera is in landscape mode, we expect the camera
17721806
// preview to be mirrored across the x-axis.
1773-
expect(transformedPreviewMatrix.storage[0], closeTo(-1.0, 0.0001));
1807+
checkXAxisIsMirrored(transformedPreviewMatrix);
17741808
expect((transformedPreview.child! as Texture).textureId, cameraId);
17751809

17761810
final int clockwiseQuarterTurns =
@@ -1884,9 +1918,9 @@ void main() {
18841918
// across the y-axis.
18851919
if (currentDeviceOrientation == DeviceOrientation.landscapeLeft ||
18861920
currentDeviceOrientation == DeviceOrientation.landscapeRight) {
1887-
expect(transformedPreviewMatrix.storage[0], closeTo(-1.0, 0.0001));
1921+
checkXAxisIsMirrored(transformedPreviewMatrix);
18881922
} else {
1889-
expect(transformedPreviewMatrix.storage[5], closeTo(-1.0, 0.0001));
1923+
checkYAxisIsMirrored(transformedPreviewMatrix);
18901924
}
18911925
expect((transformedPreview.child! as Texture).textureId, cameraId);
18921926
final int clockwiseQuarterTurns =
@@ -2152,7 +2186,7 @@ void main() {
21522186

21532187
// Since the front camera is in landscape mode, we expect the camera
21542188
// preview to be mirrored across the x-axis.
2155-
expect(transformedPreviewMatrix.storage[0], closeTo(-1.0, 0.0001));
2189+
checkXAxisIsMirrored(transformedPreviewMatrix);
21562190
expect((transformedPreview.child! as Texture).textureId, cameraId);
21572191
expect(
21582192
rotatedBox.quarterTurns,

0 commit comments

Comments
 (0)