tolerance.dart 1.83 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
import 'package:flutter/foundation.dart';

Ian Hickson's avatar
Ian Hickson committed
7 8
/// Structure that specifies maximum allowable magnitudes for distances,
/// durations, and velocity differences to be considered equal.
9
class Tolerance {
Ian Hickson's avatar
Ian Hickson committed
10 11 12 13 14
  /// Creates a [Tolerance] object. By default, the distance, time, and velocity
  /// tolerances are all ±0.001; the constructor arguments override this.
  ///
  /// The arguments should all be positive values.
  const Tolerance({
15 16
    this.distance = _epsilonDefault,
    this.time = _epsilonDefault,
17
    this.velocity = _epsilonDefault,
Ian Hickson's avatar
Ian Hickson committed
18 19
  });

20
  static const double _epsilonDefault = 1e-3;
Ian Hickson's avatar
Ian Hickson committed
21 22

  /// A default tolerance of 0.001 for all three values.
23
  static const Tolerance defaultTolerance = Tolerance();
Ian Hickson's avatar
Ian Hickson committed
24 25 26 27 28 29

  /// The magnitude of the maximum distance between two points for them to be
  /// considered within tolerance.
  ///
  /// The units for the distance tolerance must be the same as the units used
  /// for the distances that are to be compared to this tolerance.
30
  final double distance;
Ian Hickson's avatar
Ian Hickson committed
31 32 33 34 35 36

  /// The magnitude of the maximum duration between two times for them to be
  /// considered within tolerance.
  ///
  /// The units for the time tolerance must be the same as the units used
  /// for the times that are to be compared to this tolerance.
37 38
  final double time;

Ian Hickson's avatar
Ian Hickson committed
39 40 41 42 43 44
  /// The magnitude of the maximum difference between two velocities for them to
  /// be considered within tolerance.
  ///
  /// The units for the velocity tolerance must be the same as the units used
  /// for the velocities that are to be compared to this tolerance.
  final double velocity;
45

46
  @override
47
  String toString() => '${objectRuntimeType(this, 'Tolerance')}(distance: ±$distance, time: ±$time, velocity: ±$velocity)';
48
}