Codebase list node-d3-shape / b5924c2 test / polygonContext.js
b5924c2

Tree @b5924c2 (Download .tar.gz)

polygonContext.js @b5924c2raw · history · blame

var polygon = require("d3-polygon");

module.exports = function() {
  return {
    points: null,
    area: function() { return Math.abs(polygon.polygonArea(this.points)); },
    moveTo: function(x, y) { this.points = [[x, y]]; },
    lineTo: function(x, y) { this.points.push([x, y]); },
    rect: function(x, y, w, h) { this.points = [[x, y], [x + w, y], [x + w, y + h], [x, y + h]]; },
    closePath: function() {}
  };
};