# all files / ol/geom/ geometry.js

100% Statements 45/45
83.33% Branches 5/6
100% Functions 6/6
100% Lines 45/45

    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
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    2621×
    1×
    1×

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

    1×

    1×

    1×

    2527×

    2527×

    2527×

    2527×

    2527×

    2527×

    1×

    1×

    1×

    1×
    13×
    13×
    13×

    1×
    52×

    1×

    1×

    1×
    920×
    592×
    592×

    920×

    1×
    3×

    1×

    1×

    1×

    1×

    1×

    1×
    71×

    71×
    71×

     goog.provide('ol.geom.Geometry');
    goog.provide('ol.geom.GeometryLayout');
    goog.provide('ol.geom.GeometryType');

    goog.require('goog.asserts');
    goog.require('goog.functions');
    goog.require('ol.Object');
    goog.require('ol.extent');
    goog.require('ol.proj');
    goog.require('ol.proj.Units');

    /**
     * The geometry type. One of `'Point'`, `'LineString'`, `'LinearRing'`,
     * `'Polygon'`, `'MultiPoint'`, `'MultiLineString'`, `'MultiPolygon'`,
     * `'GeometryCollection'`, `'Circle'`.
     * @enum {string}
     * @api stable
     */
    ol.geom.GeometryType = {
      POINT: 'Point',
      LINE_STRING: 'LineString',
      LINEAR_RING: 'LinearRing',
      POLYGON: 'Polygon',
      MULTI_POINT: 'MultiPoint',
      MULTI_LINE_STRING: 'MultiLineString',
      MULTI_POLYGON: 'MultiPolygon',
      GEOMETRY_COLLECTION: 'GeometryCollection',
      CIRCLE: 'Circle'
    };

    /**
     * The coordinate layout for geometries, indicating whether a 3rd or 4th z ('Z')
     * or measure ('M') coordinate is available. Supported values are `'XY'`,
     * `'XYZ'`, `'XYM'`, `'XYZM'`.
     * @enum {string}
     * @api stable
     */
    ol.geom.GeometryLayout = {
      XY: 'XY',
      XYZ: 'XYZ',
      XYM: 'XYM',
      XYZM: 'XYZM'
    };

    /**
     * @classdesc
     * Abstract base class; normally only used for creating subclasses and not
     * instantiated in apps.
     * Base class for vector geometries.
     *
     * To get notified of changes to the geometry, register a listener for the
     * generic `change` event on your geometry instance.
     *
     * @constructor
     * @extends {ol.Object}
     * @api stable
     */
    ol.geom.Geometry = function() {

      goog.base(this);

      /**
       * @private
       * @type {ol.Extent}
       */
      this.extent_ = ol.extent.createEmpty();

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

      /**
       * @protected
       * @type {Object.<string, ol.geom.Geometry>}
       */
      this.simplifiedGeometryCache = {};

      /**
       * @protected
       * @type {number}
       */
      this.simplifiedGeometryMaxMinSquaredTolerance = 0;

      /**
       * @protected
       * @type {number}
       */
      this.simplifiedGeometryRevision = 0;

    };
    goog.inherits(ol.geom.Geometry, ol.Object);

    /**
     * Make a complete copy of the geometry.
     * @function
     * @return {!ol.geom.Geometry} Clone.
     */
    ol.geom.Geometry.prototype.clone = goog.abstractMethod;

    /**
     * @param {number} x X.
     * @param {number} y Y.
     * @param {ol.Coordinate} closestPoint Closest point.
     * @param {number} minSquaredDistance Minimum squared distance.
     * @return {number} Minimum squared distance.
     */
    ol.geom.Geometry.prototype.closestPointXY = goog.abstractMethod;

    /**
     * Return the closest point of the geometry to the passed point as
     * {@link ol.Coordinate coordinate}.
     * @param {ol.Coordinate} point Point.
     * @param {ol.Coordinate=} opt_closestPoint Closest point.
     * @return {ol.Coordinate} Closest point.
     * @api stable
     */
    ol.geom.Geometry.prototype.getClosestPoint = function(point, opt_closestPoint) {
      var closestPoint = opt_closestPoint ? opt_closestPoint : [NaN, NaN];
      this.closestPointXY(point[0], point[1], closestPoint, Infinity);
      return closestPoint;
    };

    /**
     * @param {ol.Coordinate} coordinate Coordinate.
     * @return {boolean} Contains coordinate.
     */
    ol.geom.Geometry.prototype.containsCoordinate = function(coordinate) {
      return this.containsXY(coordinate[0], coordinate[1]);
    };

    /**
     * @param {ol.Extent} extent Extent.
     * @protected
     * @return {ol.Extent} extent Extent.
     */
    ol.geom.Geometry.prototype.computeExtent = goog.abstractMethod;

    /**
     * @param {number} x X.
     * @param {number} y Y.
     * @return {boolean} Contains (x, y).
     */
    ol.geom.Geometry.prototype.containsXY = goog.functions.FALSE;

    /**
     * Get the extent of the geometry.
     * @param {ol.Extent=} opt_extent Extent.
     * @return {ol.Extent} extent Extent.
     * @api stable
     */
    ol.geom.Geometry.prototype.getExtent = function(opt_extent) {
      if (this.extentRevision_ != this.getRevision()) {
        this.extent_ = this.computeExtent(this.extent_);
        this.extentRevision_ = this.getRevision();
      }
      return ol.extent.returnOrUpdate(this.extent_, opt_extent);
    };

    /**
     * Create a simplified version of this geometry.  For linestrings, this uses
     * the the {@link
     * https://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm
     * Douglas Peucker} algorithm.  For polygons, a quantization-based
     * simplification is used to preserve topology.
     * @function
     * @param {number} tolerance The tolerance distance for simplification.
     * @return {ol.geom.Geometry} A new, simplified version of the original
     *     geometry.
     * @api
     */
    ol.geom.Geometry.prototype.simplify = function(tolerance) {
      return this.getSimplifiedGeometry(tolerance * tolerance);
    };

    /**
     * Create a simplified version of this geometry using the Douglas Peucker
     * algorithm.
     * @see https://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm
     * @function
     * @param {number} squaredTolerance Squared tolerance.
     * @return {ol.geom.Geometry} Simplified geometry.
     */
    ol.geom.Geometry.prototype.getSimplifiedGeometry = goog.abstractMethod;

    /**
     * Get the type of this geometry.
     * @function
     * @return {ol.geom.GeometryType} Geometry type.
     */
    ol.geom.Geometry.prototype.getType = goog.abstractMethod;

    /**
     * Apply a transform function to each coordinate of the geometry.
     * The geometry is modified in place.
     * If you do not want the geometry modified in place, first clone() it and
     * then use this function on the clone.
     * @function
     * @param {ol.TransformFunction} transformFn Transform.
     */
    ol.geom.Geometry.prototype.applyTransform = goog.abstractMethod;

    /**
     * Test if the geometry and the passed extent intersect.
     * @param {ol.Extent} extent Extent.
     * @return {boolean} `true` if the geometry and the extent intersect.
     * @function
     */
    ol.geom.Geometry.prototype.intersectsExtent = goog.abstractMethod;

    /**
     * Translate the geometry.  This modifies the geometry coordinates in place.  If
     * instead you want a new geometry, first `clone()` this geometry.
     * @param {number} deltaX Delta X.
     * @param {number} deltaY Delta Y.
     * @function
     */
    ol.geom.Geometry.prototype.translate = goog.abstractMethod;

    /**
     * Transform each coordinate of the geometry from one coordinate reference
     * system to another. The geometry is modified in place.
     * For example, a line will be transformed to a line and a circle to a circle.
     * If you do not want the geometry modified in place, first clone() it and
     * then use this function on the clone.
     *
     * @param {ol.proj.ProjectionLike} source The current projection.  Can be a
     *     string identifier or a {@link ol.proj.Projection} object.
     * @param {ol.proj.ProjectionLike} destination The desired projection.  Can be a
     *     string identifier or a {@link ol.proj.Projection} object.
     * @return {ol.geom.Geometry} This geometry.  Note that original geometry is
     *     modified in place.
     * @api stable
     */
    ol.geom.Geometry.prototype.transform = function(source, destination) {
      goog.asserts.assert(
          ol.proj.get(source).getUnits() !== ol.proj.Units.TILE_PIXELS &&
          ol.proj.get(destination).getUnits() !== ol.proj.Units.TILE_PIXELS,
          'cannot transform geometries with TILE_PIXELS units');
      this.applyTransform(ol.proj.getTransform(source, destination));
      return this;
    };