How to use the d3-polygon.polygonHull function in d3-polygon

To help you get started, we’ve selected a few d3-polygon 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 DefinitelyTyped / DefinitelyTyped / d3-polygon / d3-polygon-tests.ts View on Github external
let num: number;
let containsFlag: boolean;
let point: [number, number] = [15, 15];
let polygon: Array<[number, number]> = [[10, 10], [20, 20], [10, 30]];
let pointArray: Array<[number, number]> = [[10, 10], [20, 20], [10, 30], [15, 15]];
let hull: Array<[number, number]>;

// -----------------------------------------------------------------------------
// Tests
// -----------------------------------------------------------------------------

num = d3Polygon.polygonArea(polygon);

point = d3Polygon.polygonCentroid(polygon);

hull = d3Polygon.polygonHull(pointArray);

containsFlag = d3Polygon.polygonContains(polygon, point);

num = d3Polygon.polygonLength(polygon);
github DefinitelyTyped / DefinitelyTyped / types / d3-polygon / d3-polygon-tests.ts View on Github external
let num: number;
let containsFlag: boolean;
let point: [number, number] = [15, 15];
let polygon: Array<[number, number]> = [[10, 10], [20, 20], [10, 30]];
let pointArray: Array<[number, number]> = [[10, 10], [20, 20], [10, 30], [15, 15]];
let hull: Array<[number, number]>;

// -----------------------------------------------------------------------------
// Tests
// -----------------------------------------------------------------------------

num = d3Polygon.polygonArea(polygon);

point = d3Polygon.polygonCentroid(polygon);

hull = d3Polygon.polygonHull(pointArray);

containsFlag = d3Polygon.polygonContains(polygon, point);

num = d3Polygon.polygonLength(polygon);
github Kcnarf / d3-weighted-voronoi / src / d3-weighted-voronoi.js View on Github external
return clip;
    }

    xExtent = d3Extent(
      _.map(function (c) {
        return c[0];
      })
    );
    yExtent = d3Extent(
      _.map(function (c) {
        return c[1];
      })
    );
    direction = polygonDirection(_);
    if (direction === undefined) {
      clip = d3PolygonHull(_); // ensure clip to be a convex, hole-free, counterclockwise polygon
    } else if (direction === 1) {
      clip = _.reverse(); // already convex, order array in the same direction as d3-polygon.polygonHull(...)
    } else {
      clip = _;
    }
    extent = [
      [xExtent[0], yExtent[0]],
      [xExtent[1], yExtent[1]]
    ];
    size = [xExtent[1] - xExtent[0], yExtent[1] - yExtent[0]];
    return _weightedVoronoi;
  };
github ideditor / id-sdk / packages / math / geom / built / geom.js View on Github external
function geomGetSmallestSurroundingRectangle(points) {
  var hull = d3_polygon_1.polygonHull(points);
  var centroid = d3_polygon_1.polygonCentroid(hull);
  var minArea = Infinity;
  var ssrExtent = new extent_1.Extent();
  var ssrAngle = 0;
  var c1 = hull[0];
  for (var i = 0; i <= hull.length - 1; i++) {
    var c2 = i === hull.length - 1 ? hull[0] : hull[i + 1];
    var angle = Math.atan2(c2[1] - c1[1], c2[0] - c1[0]);
    var poly = geomRotatePoints(hull, -angle, centroid);
    var extent = poly.reduce(function(acc, point) {
      // update Extent min/max in-place for speed
      acc.min[0] = Math.min(acc.min[0], point[0]);
      acc.min[1] = Math.min(acc.min[1], point[1]);
      acc.max[0] = Math.max(acc.max[0], point[0]);
      acc.max[1] = Math.max(acc.max[1], point[1]);
      return acc;
github openstreetmap / iD / modules / modes / rotate.js View on Github external
var projection = context.projection;
        var currTransform = projection.transform();
        if (!_prevTransform ||
            currTransform.k !== _prevTransform.k ||
            currTransform.x !== _prevTransform.x ||
            currTransform.y !== _prevTransform.y) {

            var nodes = utilGetAllNodes(entityIDs, context.graph());
            var points = nodes.map(function(n) { return projection(n.loc); });

            if (points.length === 1) {  // degenerate case
                _pivot = points[0];
            } else if (points.length === 2) {
                _pivot = geoVecInterp(points[0], points[1], 0.5);
            } else {
                _pivot = d3_polygonCentroid(d3_polygonHull(points));
            }
            _prevAngle = undefined;
        }


        var currMouse = context.mouse();
        var currAngle = Math.atan2(currMouse[1] - _pivot[1], currMouse[0] - _pivot[0]);

        if (typeof _prevAngle === 'undefined') _prevAngle = currAngle;
        var delta = currAngle - _prevAngle;

        fn(actionRotate(entityIDs, _pivot, delta, projection), annotation);

        _prevTransform = currTransform;
        _prevAngle = currAngle;
        _prevGraph = context.graph();
github nteract / semiotic / src / components / annotationRules / baseRules.js View on Github external
export const hullEnclosure = ({ points, d, i }) => {
  const {
    color = "black",
    dx = -25,
    dy = -25,
    label,
    padding = 10,
    buffer = padding,
    strokeWidth = 10
  } = d

  const hullPoints = polygonHull(points)

  const offset = new Offset()

  const bufferedHull = offset
    .data([...hullPoints, hullPoints[0]])
    .margin(buffer)[0]

  const hullD = `M${bufferedHull.map(d => d.join(",")).join("L")}Z`

  const firstCoord = bufferedHull[0]

  const { nx = firstCoord[0] + dx, ny = firstCoord[1] + dy } = d

  const closestCoordinates = bufferedHull.reduce((p, c) => {
    if (Math.hypot(nx - p[0], ny - p[1]) > Math.hypot(nx - c[0], ny - c[1])) {
      p = c
github rolyatmax / sketches / sketches / 2018.08.14-18.46.36.js View on Github external
function makeBlobFromPoints (points, curviness) {
  const hull = polygonHull(points)
  const anchors = hull.slice()
  anchors.push(anchors[0], anchors[1], anchors[2])
  const spline = catRomSpline(anchors, { samples: 15, knot: curviness })
  return spline
}
github ideditor / id-sdk / packages / math / geom / lib / geom.js View on Github external
export function geomGetSmallestSurroundingRectangle(points) {
  var hull = d3_polygonHull(points);
  var centroid = d3_polygonCentroid(hull);
  var minArea = Infinity;
  var ssrExtent = [];
  var ssrAngle = 0;
  var c1 = hull[0];

  for (var i = 0; i <= hull.length - 1; i++) {
    var c2 = i === hull.length - 1 ? hull[0] : hull[i + 1];
    var angle = Math.atan2(c2[1] - c1[1], c2[0] - c1[0]);
    var poly = geomRotatePoints(hull, -angle, centroid);
    var extent = poly.reduce(function(extent, point) {
      return extent.extend(Extent(point));
    }, Extent());

    var area = extent.area();
    if (area < minArea) {
github openstreetmap / iD / modules / modes / rotate.js View on Github external
function getPivot(points) {
        var _pivot;
        if (points.length === 1) {
            _pivot = points[0];
        } else if (points.length === 2) {
            _pivot = geoVecInterp(points[0], points[1], 0.5);
        } else {
            var polygonHull = d3_polygonHull(points);
            if (polygonHull.length === 2) {
                _pivot = geoVecInterp(points[0], points[1], 0.5);
            } else {
                _pivot = d3_polygonCentroid(d3_polygonHull(points));
            }
        }
        return _pivot;
    }

d3-polygon

Operations for two-dimensional polygons.

ISC
Latest version published 3 years ago

Package Health Score

71 / 100
Full package analysis