Skip to content

Commit

Permalink
Remove TOO_FEW_POINTS
Browse files Browse the repository at this point in the history
  • Loading branch information
veltman committed Jul 21, 2017
1 parent 8b16a87 commit b5f936a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 25 deletions.
9 changes: 0 additions & 9 deletions build/flubber.js
Expand Up @@ -2352,10 +2352,6 @@ var INVALID_INPUT = "All shapes must be supplied as arrays of [x, y] points or a

var INVALID_INPUT_ALL = "flubber.all() expects two arrays of equal length as arguments. Each element in both arrays should be an array of [x, y] points or an SVG path string (https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d).";



var TOO_FEW_POINTS = "Polygons must have at least three points.";

function parse$$1(str) {
return new index(str).abs();
}
Expand Down Expand Up @@ -2520,11 +2516,6 @@ function normalizeRing(ring, maxSegmentLength) {
points.pop();
}

// 3+ points to make a polygon
if (points.length < 3) {
throw new TypeError(TOO_FEW_POINTS);
}

area = polygonArea(points);

// Make all rings clockwise
Expand Down
2 changes: 0 additions & 2 deletions build/flubber.min.js

This file was deleted.

2 changes: 0 additions & 2 deletions src/errors.js
Expand Up @@ -9,5 +9,3 @@ export const INVALID_INPUT_ALL = `flubber.all() expects two arrays of equal leng
export const INVALID_PATH_STRING = `Invalid SVG path string supplied.
Path string reference: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d
`;

export const TOO_FEW_POINTS = `Polygons must have at least three points.`;
7 changes: 1 addition & 6 deletions src/normalize.js
Expand Up @@ -2,7 +2,7 @@ import { polygonArea } from "d3-polygon";
import { pathStringToRing } from "./svg.js";
import { samePoint, isFiniteNumber } from "./math.js";
import { bisect } from "./add.js";
import { INVALID_INPUT, TOO_FEW_POINTS } from "./errors.js";
import { INVALID_INPUT } from "./errors.js";

export default function normalizeRing(ring, maxSegmentLength) {
let points, area, skipBisect;
Expand All @@ -26,11 +26,6 @@ export default function normalizeRing(ring, maxSegmentLength) {
points.pop();
}

// 3+ points to make a polygon
if (points.length < 3) {
throw new TypeError(TOO_FEW_POINTS);
}

area = polygonArea(points);

// Make all rings clockwise
Expand Down
18 changes: 12 additions & 6 deletions test/normalize-test.js
@@ -1,7 +1,7 @@
import { supertape } from "./utils.js";
import * as shapes from "./shapes.js";
import normalizeRing from "../src/normalize.js";
import { INVALID_INPUT, TOO_FEW_POINTS } from "../src/errors.js";
import { INVALID_INPUT } from "../src/errors.js";

let tape = supertape();

Expand Down Expand Up @@ -54,11 +54,17 @@ tape("Expects valid ring or string", function(test) {
// Partially valid
test.throws(() => normalizeRing([[0, 0], [1, 1], [2, 2], "x"]), err);

// Too short
test.throws(() => normalizeRing([[0, 0], [1, 1]]), new RegExp(TOO_FEW_POINTS));
test.throws(() => normalizeRing([[0, 0], [1, 1], [0, 0]]), new RegExp(TOO_FEW_POINTS));
test.end();
});

test.doesNotThrow(() => normalizeRing([[0, 0], [1, 1], [2, 2]]));
tape("Bisect", function(test) {

// No bisecting zero-length segments
test.deepEqual(normalizeRing([[0, 0]], 1e-6), [[0, 0]]);
test.deepEqual(normalizeRing([[0, 0], [0, 0], [0, 0]], 1e-6), [[0, 0], [0, 0]]);
test.deepEqual(normalizeRing([[0, 0], [0, 0], [1, 0]], 0.6), [[0, 0], [0, 0], [0.5, 0], [1, 0], [0.5, 0]]);

test.deepEqual(normalizeRing([[0, 0], [1, 0]], 0.6), [[0, 0], [0.5, 0], [1, 0], [0.5, 0]]);
test.end();

test.end();
});

0 comments on commit b5f936a

Please sign in to comment.