How to use the ol-ext/geom/GeomUtils.ol_coordinate_dist2d function in ol-ext

To help you get started, we’ve selected a few ol-ext examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Viglino / ol-games / utils / geom.js View on Github external
ol_geom_LineString.prototype.lineRef = function (p) {
  var p0, p1, s;
  var coord = this.getCoordinates();
  var s0 = 0;
  for (var i=1; i=0 && s<=1) {
      var pi = [p0[0] + s*(p1[0]-p0[0]), p0[1] + s*(p1[1]-p0[1])];
      if (ol_coordinate_dist2d(p,pi) < 1e-10) {
        return s0 + s*ol_coordinate_dist2d(p0, p1);
      }
    } else {
      s0 += ol_coordinate_dist2d(p0,p1);
    }
  }
  // Point is not on the linestring
  return false;
};
github Viglino / ol-games / utils / geom.js View on Github external
ol_geom_LineString.prototype.lineRef = function (p) {
  var p0, p1, s;
  var coord = this.getCoordinates();
  var s0 = 0;
  for (var i=1; i=0 && s<=1) {
      var pi = [p0[0] + s*(p1[0]-p0[0]), p0[1] + s*(p1[1]-p0[1])];
      if (ol_coordinate_dist2d(p,pi) < 1e-10) {
        return s0 + s*ol_coordinate_dist2d(p0, p1);
      }
    } else {
      s0 += ol_coordinate_dist2d(p0,p1);
    }
  }
  // Point is not on the linestring
  return false;
};
github Viglino / ol-games / utils / geom.js View on Github external
if (a < 1e-10) {
      if (d0 > dl) a = -dl/2;
      else {
        dl = d0;
        a = -d0/2;
      }
    }
    else a = a/2 -dl;
  } else {
    coords.push(g[0]);
  }
  // Linear interpol
  for (var i=1; i
github Viglino / ol-games / utils / geom.js View on Github external
ol_geom_LineString.prototype.lineRef = function (p) {
  var p0, p1, s;
  var coord = this.getCoordinates();
  var s0 = 0;
  for (var i=1; i=0 && s<=1) {
      var pi = [p0[0] + s*(p1[0]-p0[0]), p0[1] + s*(p1[1]-p0[1])];
      if (ol_coordinate_dist2d(p,pi) < 1e-10) {
        return s0 + s*ol_coordinate_dist2d(p0, p1);
      }
    } else {
      s0 += ol_coordinate_dist2d(p0,p1);
    }
  }
  // Point is not on the linestring
  return false;
};
github Viglino / ol-games / feature / Sprite.js View on Github external
c[1] += dc[1];
    
    if (this.destination) {
      // Reach the destination
      if ( Math.sign(this.path[this.destination][0]-c[0]) != Math.sign(this.dir[0])
      || Math.sign(this.path[this.destination][1]-c[1]) != Math.sign(this.dir[1]) ) {
        this.destination++;
        // End of the path ?
        if (this.destination >= this.path.length) {
          this.stop();
          this.setCoordinate (this.path[this.destination-1]);
          this.destination = 0;
          this.dispatchEvent({ type:'destination' });
        } else {
          // Overpass ?
          var dl = ol_coordinate_dist2d (c, this.path[this.destination-1]);
          while (true) {
            var ds = ol_coordinate_dist2d(this.path[this.destination], this.path[this.destination-1]);
            if (ds > dl) break;
            else {
              dl -= ds;
              this.destination++;
              // End of the path ?
              if (this.destination >= this.path.length) {
                this.stop();
                this.setCoordinate (this.path[this.destination-1]);
                this.destination = 0;
                this.dispatchEvent({ type:'destination' });
                return;
              }
            }
          }
github Viglino / ol-games / feature / Sprite.js View on Github external
if (this.destination) {
      // Reach the destination
      if ( Math.sign(this.path[this.destination][0]-c[0]) != Math.sign(this.dir[0])
      || Math.sign(this.path[this.destination][1]-c[1]) != Math.sign(this.dir[1]) ) {
        this.destination++;
        // End of the path ?
        if (this.destination >= this.path.length) {
          this.stop();
          this.setCoordinate (this.path[this.destination-1]);
          this.destination = 0;
          this.dispatchEvent({ type:'destination' });
        } else {
          // Overpass ?
          var dl = ol_coordinate_dist2d (c, this.path[this.destination-1]);
          while (true) {
            var ds = ol_coordinate_dist2d(this.path[this.destination], this.path[this.destination-1]);
            if (ds > dl) break;
            else {
              dl -= ds;
              this.destination++;
              // End of the path ?
              if (this.destination >= this.path.length) {
                this.stop();
                this.setCoordinate (this.path[this.destination-1]);
                this.destination = 0;
                this.dispatchEvent({ type:'destination' });
                return;
              }
            }
          }
          
          // New position on end of the segment
github Viglino / ol-games / graph / Vector.js View on Github external
features.forEach (function (f) {
      var n = f.getGeometry().getClosestPoint(p);
      var d = ol_coordinate_dist2d(n,p);
      if (ddist) f0=null;
github Viglino / ol-games / utils / geom.js View on Github external
if (seg) {
      c = this.getCoordinates();
      seg[0] = c[c.length-2];
      seg[1] = c[c.length-1];
    }
    return this.getLastCoordinate();
  }
  if (!seg) seg=[];
  var s = 0;
  var coord = this.getCoordinates();
  for (var i=1; i= r) {
      var p0 = seg[0] = coord[i-1];
      var p1 = seg[1] = coord[i];
      d = ol_coordinate_dist2d(p0,p1)
      return [
        p0[0] + (r-s) * (p1[0]-p0[0]) /d,
        p0[1] + (r-s) * (p1[1]-p0[1]) /d
      ];
    }
    s += d;
  }
};
github Viglino / ol-games / utils / geom.js View on Github external
}
    return this.getFirstCoordinate();
  }
  if (this.getLength()-r < 1e-10) {
    if (seg) {
      c = this.getCoordinates();
      seg[0] = c[c.length-2];
      seg[1] = c[c.length-1];
    }
    return this.getLastCoordinate();
  }
  if (!seg) seg=[];
  var s = 0;
  var coord = this.getCoordinates();
  for (var i=1; i= r) {
      var p0 = seg[0] = coord[i-1];
      var p1 = seg[1] = coord[i];
      d = ol_coordinate_dist2d(p0,p1)
      return [
        p0[0] + (r-s) * (p1[0]-p0[0]) /d,
        p0[1] + (r-s) * (p1[1]-p0[1]) /d
      ];
    }
    s += d;
  }
};

ol-ext

A set of cool extensions for OpenLayers (ol) in node modules structure

BSD-3-Clause
Latest version published 24 days ago

Package Health Score

83 / 100
Full package analysis