# all files / ol/geom/ linearring.js

70% Statements 35/50
37.5% Branches 3/8
55.56% Functions 5/9
70% Lines 35/50

    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
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    1581×

    1×
    1×
    1×
    1×
    1×
    1×
    1×
    1×
    1×

    1×

    169×

    169×

    169×

    169×

    1×

    1×

    1×

    1×

    1×
    64×

    1×

    1×
    9×

    1×

    169×
    95×

    74×
    74×
    74×

    74×

    74×

    1×

    190×
    190×

     goog.provide('ol.geom.LinearRing');

    goog.require('ol.extent');
    goog.require('ol.geom.GeometryLayout');
    goog.require('ol.geom.GeometryType');
    goog.require('ol.geom.SimpleGeometry');
    goog.require('ol.geom.flat.area');
    goog.require('ol.geom.flat.closest');
    goog.require('ol.geom.flat.deflate');
    goog.require('ol.geom.flat.inflate');
    goog.require('ol.geom.flat.simplify');

    /**
     * @classdesc
     * Linear ring geometry. Only used as part of polygon; cannot be rendered
     * on its own.
     *
     * @constructor
     * @extends {ol.geom.SimpleGeometry}
     * @param {Array.<ol.Coordinate>} coordinates Coordinates.
     * @param {ol.geom.GeometryLayout=} opt_layout Layout.
     * @api stable
     */
    ol.geom.LinearRing = function(coordinates, opt_layout) {

      goog.base(this);

      /**
       * @private
       * @type {number}
       */
      this.maxDelta_ = -1;

      /**
       * @private
       * @type {number}
       */
      this.maxDeltaRevision_ = -1;

      this.setCoordinates(coordinates, opt_layout);

    };
    goog.inherits(ol.geom.LinearRing, ol.geom.SimpleGeometry);

    /**
     * Make a complete copy of the geometry.
     * @return {!ol.geom.LinearRing} Clone.
     * @api stable
     */
    ol.geom.LinearRing.prototype.clone = function() {
      var linearRing = new ol.geom.LinearRing(null);
      linearRing.setFlatCoordinates(this.layout, this.flatCoordinates.slice());
      return linearRing;
    };

    /**
     * @inheritDoc
     */
    ol.geom.LinearRing.prototype.closestPointXY =
        function(x, y, closestPoint, minSquaredDistance) {
      if (minSquaredDistance <
          ol.extent.closestSquaredDistanceXY(this.getExtent(), x, y)) {
        return minSquaredDistance;
      }
      if (this.maxDeltaRevision_ != this.getRevision()) {
        this.maxDelta_ = Math.sqrt(ol.geom.flat.closest.getMaxSquaredDelta(
            this.flatCoordinates, 0, this.flatCoordinates.length, this.stride, 0));
        this.maxDeltaRevision_ = this.getRevision();
      }
      return ol.geom.flat.closest.getClosestPoint(
          this.flatCoordinates, 0, this.flatCoordinates.length, this.stride,
          this.maxDelta_, true, x, y, closestPoint, minSquaredDistance);
    };

    /**
     * Return the area of the linear ring on projected plane.
     * @return {number} Area (on projected plane).
     * @api stable
     */
    ol.geom.LinearRing.prototype.getArea = function() {
      return ol.geom.flat.area.linearRing(
          this.flatCoordinates, 0, this.flatCoordinates.length, this.stride);
    };

    /**
     * Return the coordinates of the linear ring.
     * @return {Array.<ol.Coordinate>} Coordinates.
     * @api stable
     */
    ol.geom.LinearRing.prototype.getCoordinates = function() {
      return ol.geom.flat.inflate.coordinates(
          this.flatCoordinates, 0, this.flatCoordinates.length, this.stride);
    };

    /**
     * @inheritDoc
     */
    ol.geom.LinearRing.prototype.getSimplifiedGeometryInternal =
        function(squaredTolerance) {
      var simplifiedFlatCoordinates = [];
      simplifiedFlatCoordinates.length = ol.geom.flat.simplify.douglasPeucker(
          this.flatCoordinates, 0, this.flatCoordinates.length, this.stride,
          squaredTolerance, simplifiedFlatCoordinates, 0);
      var simplifiedLinearRing = new ol.geom.LinearRing(null);
      simplifiedLinearRing.setFlatCoordinates(
          ol.geom.GeometryLayout.XY, simplifiedFlatCoordinates);
      return simplifiedLinearRing;
    };

    /**
     * @inheritDoc
     * @api stable
     */
    ol.geom.LinearRing.prototype.getType = function() {
      return ol.geom.GeometryType.LINEAR_RING;
    };

    /**
     * Set the coordinates of the linear ring.
     * @param {Array.<ol.Coordinate>} coordinates Coordinates.
     * @param {ol.geom.GeometryLayout=} opt_layout Layout.
     * @api stable
     */
    ol.geom.LinearRing.prototype.setCoordinates =
        function(coordinates, opt_layout) {
      if (!coordinates) {
        this.setFlatCoordinates(ol.geom.GeometryLayout.XY, null);
      } else {
        this.setLayout(opt_layout, coordinates, 1);
        Eif (!this.flatCoordinates) {
          this.flatCoordinates = [];
        }
        this.flatCoordinates.length = ol.geom.flat.deflate.coordinates(
            this.flatCoordinates, 0, coordinates, this.stride);
        this.changed();
      }
    };

    /**
     * @param {ol.geom.GeometryLayout} layout Layout.
     * @param {Array.<number>} flatCoordinates Flat coordinates.
     */
    ol.geom.LinearRing.prototype.setFlatCoordinates =
        function(layout, flatCoordinates) {
      this.setFlatCoordinatesInternal(layout, flatCoordinates);
      this.changed();
    };