# all files / ol/ rotationconstraint.js

51.85% Statements 14/27
41.67% Branches 5/12
33.33% Functions 2/6
51.85% Lines 14/27

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    881×
    1×

    1×

    1×

    1×

    1×

    1×

    1×
    176×
    176×

    18×
    18×
    11×

    7×

     goog.provide('ol.RotationConstraint');
    goog.provide('ol.RotationConstraintType');

    goog.require('ol.math');

    /**
     * @typedef {function((number|undefined), number): (number|undefined)}
     */
    ol.RotationConstraintType;

    /**
     * @param {number|undefined} rotation Rotation.
     * @param {number} delta Delta.
     * @return {number|undefined} Rotation.
     */
    ol.RotationConstraint.disable = function(rotation, delta) {
      if (rotation !== undefined) {
        return 0;
      } else {
        return undefined;
      }
    };

    /**
     * @param {number|undefined} rotation Rotation.
     * @param {number} delta Delta.
     * @return {number|undefined} Rotation.
     */
    ol.RotationConstraint.none = function(rotation, delta) {
      if (rotation !== undefined) {
        return rotation + delta;
      } else {
        return undefined;
      }
    };

    /**
     * @param {number} n N.
     * @return {ol.RotationConstraintType} Rotation constraint.
     */
    ol.RotationConstraint.createSnapToN = function(n) {
      var theta = 2 * Math.PI / n;
      return (
          /**
           * @param {number|undefined} rotation Rotation.
           * @param {number} delta Delta.
           * @return {number|undefined} Rotation.
           */
          function(rotation, delta) {
            if (rotation !== undefined) {
              rotation = Math.floor((rotation + delta) / theta + 0.5) * theta;
              return rotation;
            } else {
              return undefined;
            }
          });
    };

    /**
     * @param {number=} opt_tolerance Tolerance.
     * @return {ol.RotationConstraintType} Rotation constraint.
     */
    ol.RotationConstraint.createSnapToZero = function(opt_tolerance) {
      var tolerance = opt_tolerance || ol.math.toRadians(5);
      return (
          /**
           * @param {number|undefined} rotation Rotation.
           * @param {number} delta Delta.
           * @return {number|undefined} Rotation.
           */
          function(rotation, delta) {
            Eif (rotation !== undefined) {
              if (Math.abs(rotation + delta) <= tolerance) {
                return 0;
              } else {
                return rotation + delta;
              }
            } else {
              return undefined;
            }
          });
    };