Skip to content

Commit b254a7e

Browse files
committed
bit simpler
1 parent ce3b694 commit b254a7e

File tree

1 file changed

+19
-28
lines changed

1 file changed

+19
-28
lines changed

flutter/lib/src/screenshot/sentry_screenshot_widget.dart

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:math';
2+
13
import 'package:flutter/material.dart';
24
import 'package:meta/meta.dart';
35
import '../../sentry_flutter.dart';
@@ -198,42 +200,31 @@ class SentryScreenshotWidgetStatus {
198200

199201
if (orientation != other.orientation) return false;
200202

201-
if (!_pixelRatioAlmostEqual(
202-
pixelRatio, other.pixelRatio, _pixelRatioTolerance)) {
203-
return false;
204-
}
203+
final pr1 = pixelRatio?.roundToResolution(_pixelRatioTolerance);
204+
final pr2 = other.pixelRatio?.roundToResolution(_pixelRatioTolerance);
205+
if (pr1 != pr2) return false;
205206

206-
if (!_sizeAlmostEqual(size, other.size, _sizeTolerance)) {
207-
return false;
208-
}
207+
final w1 = size?.width.roundToResolution(_sizeTolerance);
208+
final h1 = size?.height.roundToResolution(_sizeTolerance);
209+
final w2 = other.size?.width.roundToResolution(_sizeTolerance);
210+
final h2 = other.size?.height.roundToResolution(_sizeTolerance);
211+
if (w1 != w2 || h1 != h2) return false;
209212

210213
return true;
211214
}
212215

213216
@override
214217
int get hashCode {
215-
final prHash = _quantize(pixelRatio, _pixelRatioTolerance);
216-
final wHash = _quantize(size?.width, _sizeTolerance);
217-
final hHash = _quantize(size?.height, _sizeTolerance);
218-
219-
return Object.hash(orientation, prHash, wHash, hHash);
220-
}
221-
222-
static bool _pixelRatioAlmostEqual(double? a, double? b, double tol) {
223-
if (a == b) return true;
224-
if (a == null || b == null) return false;
225-
return (a - b).abs() <= tol;
226-
}
227-
228-
static bool _sizeAlmostEqual(Size? a, Size? b, double tol) {
229-
if (a == b) return true;
230-
if (a == null || b == null) return false;
231-
return (a.width - b.width).abs() <= tol &&
232-
(a.height - b.height).abs() <= tol;
218+
final pr = pixelRatio?.roundToResolution(_pixelRatioTolerance);
219+
final w = size?.width.roundToResolution(_sizeTolerance);
220+
final h = size?.height.roundToResolution(_sizeTolerance);
221+
return Object.hash(orientation, pr, w, h);
233222
}
223+
}
234224

235-
static int _quantize(double? value, double tol) {
236-
if (value == null) return 0;
237-
return (value / tol).round();
225+
extension _RoundToTolerance on double {
226+
/// Rounds this value to the nearest multiple of [resolution].
227+
double roundToResolution(double resolution) {
228+
return (this / resolution).round() * resolution;
238229
}
239230
}

0 commit comments

Comments
 (0)