Sha256: 212dd14edf06ad5d38a69615f6bb3849c55ae8ab6d9aeb1ba03029aacb6a50d6

Contents?: true

Size: 1 KB

Versions: 4

Compression:

Stored size: 1 KB

Contents

import "../core/noop";

// TODO Unify this code with d3.geom.polygon area?

var d3_geo_pathAreaSum, d3_geo_pathAreaPolygon, d3_geo_pathArea = {
  point: d3_noop,
  lineStart: d3_noop,
  lineEnd: d3_noop,

  // Only count area for polygon rings.
  polygonStart: function() {
    d3_geo_pathAreaPolygon = 0;
    d3_geo_pathArea.lineStart = d3_geo_pathAreaRingStart;
  },
  polygonEnd: function() {
    d3_geo_pathArea.lineStart = d3_geo_pathArea.lineEnd = d3_geo_pathArea.point = d3_noop;
    d3_geo_pathAreaSum += Math.abs(d3_geo_pathAreaPolygon / 2);
  }
};

function d3_geo_pathAreaRingStart() {
  var x00, y00, x0, y0;

  // For the first point, …
  d3_geo_pathArea.point = function(x, y) {
    d3_geo_pathArea.point = nextPoint;
    x00 = x0 = x, y00 = y0 = y;
  };

  // For subsequent points, …
  function nextPoint(x, y) {
    d3_geo_pathAreaPolygon += y0 * x - x0 * y;
    x0 = x, y0 = y;
  }

  // For the last point, return to the start.
  d3_geo_pathArea.lineEnd = function() {
    nextPoint(x00, y00);
  };
}

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
stripchart-0.0.3 lib/stripchart/public/components/d3/src/geo/path-area.js
stripmem-0.0.3 lib/stripmem/public/components/d3/src/geo/path-area.js
stripmem-0.0.2 lib/stripmem/public/components/d3/src/geo/path-area.js
stripmem-0.0.1 lib/stripmem/public/components/d3/src/geo/path-area.js