Codebase list node-d3-shape / 3edccc1 test / polygonContext.js
3edccc1

Tree @3edccc1 (Download .tar.gz)

polygonContext.js @3edccc1raw · 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() {}
  };
};