tolerance.dart 1.76 KB
Newer Older
1
// Copyright 2016 The Chromium 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.

Ian Hickson's avatar
Ian Hickson committed
5 6
/// Structure that specifies maximum allowable magnitudes for distances,
/// durations, and velocity differences to be considered equal.
7
class Tolerance {
Ian Hickson's avatar
Ian Hickson committed
8 9 10 11 12
  /// 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({
13 14
    this.distance = _epsilonDefault,
    this.time = _epsilonDefault,
15
    this.velocity = _epsilonDefault,
Ian Hickson's avatar
Ian Hickson committed
16 17
  });

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

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

  /// 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.
28
  final double distance;
Ian Hickson's avatar
Ian Hickson committed
29 30 31 32 33 34

  /// 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.
35 36
  final double time;

Ian Hickson's avatar
Ian Hickson committed
37 38 39 40 41 42
  /// 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;
43

44
  @override
Ian Hickson's avatar
Ian Hickson committed
45
  String toString() => 'Tolerance(distance: ±$distance, time: ±$time, velocity: ±$velocity)';
46
}