tolerance.dart 1.77 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 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
  /// 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({
    this.distance: _kEpsilonDefault,
    this.time: _kEpsilonDefault,
    this.velocity: _kEpsilonDefault
  });

  static const double _kEpsilonDefault = 1e-3;

  /// A default tolerance of 0.001 for all three values.
  static const Tolerance defaultTolerance = const Tolerance();

  /// 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
}