code
stringlengths 24
2.07M
| docstring
stringlengths 25
85.3k
| func_name
stringlengths 1
92
| language
stringclasses 1
value | repo
stringlengths 5
64
| path
stringlengths 4
172
| url
stringlengths 44
218
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
function LinearPosition$1(x0, x1, y0, y1){
this.x0 = x0;
this.x1 = x1;
this.y0 = y0;
this.y1 = y1;
}
|
Compute the curve derivative (hodograph) at t.
|
LinearPosition$1
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
svgPathProperties = function(svgString) {
var length = 0;
var partial_lengths = [];
var functions = [];
function svgProperties(string){
if(!string){return null;}
var parsed = parse$1(string);
var cur = [0, 0];
var prev_point = [0, 0];
var curve;
var ringStart;
for (var i = 0; i < parsed.length; i++){
//moveTo
if(parsed[i][0] === "M"){
cur = [parsed[i][1], parsed[i][2]];
ringStart = [cur[0], cur[1]];
functions.push(null);
} else if(parsed[i][0] === "m"){
cur = [parsed[i][1] + cur[0], parsed[i][2] + cur[1]];
ringStart = [cur[0], cur[1]];
functions.push(null);
}
//lineTo
else if(parsed[i][0] === "L"){
length = length + Math.sqrt(Math.pow(cur[0] - parsed[i][1], 2) + Math.pow(cur[1] - parsed[i][2], 2));
functions.push(new LinearPosition(cur[0], parsed[i][1], cur[1], parsed[i][2]));
cur = [parsed[i][1], parsed[i][2]];
} else if(parsed[i][0] === "l"){
length = length + Math.sqrt(Math.pow(parsed[i][1], 2) + Math.pow(parsed[i][2], 2));
functions.push(new LinearPosition(cur[0], parsed[i][1] + cur[0], cur[1], parsed[i][2] + cur[1]));
cur = [parsed[i][1] + cur[0], parsed[i][2] + cur[1]];
} else if(parsed[i][0] === "H"){
length = length + Math.abs(cur[0] - parsed[i][1]);
functions.push(new LinearPosition(cur[0], parsed[i][1], cur[1], cur[1]));
cur[0] = parsed[i][1];
} else if(parsed[i][0] === "h"){
length = length + Math.abs(parsed[i][1]);
functions.push(new LinearPosition(cur[0], cur[0] + parsed[i][1], cur[1], cur[1]));
cur[0] = parsed[i][1] + cur[0];
} else if(parsed[i][0] === "V"){
length = length + Math.abs(cur[1] - parsed[i][1]);
functions.push(new LinearPosition(cur[0], cur[0], cur[1], parsed[i][1]));
cur[1] = parsed[i][1];
} else if(parsed[i][0] === "v"){
length = length + Math.abs(parsed[i][1]);
functions.push(new LinearPosition(cur[0], cur[0], cur[1], cur[1] + parsed[i][1]));
cur[1] = parsed[i][1] + cur[1];
//Close path
} else if(parsed[i][0] === "z" || parsed[i][0] === "Z"){
length = length + Math.sqrt(Math.pow(ringStart[0] - cur[0], 2) + Math.pow(ringStart[1] - cur[1], 2));
functions.push(new LinearPosition(cur[0], ringStart[0], cur[1], ringStart[1]));
cur = [ringStart[0], ringStart[1]];
}
//Cubic Bezier curves
else if(parsed[i][0] === "C"){
curve = new Bezier(cur[0], cur[1] , parsed[i][1], parsed[i][2] , parsed[i][3], parsed[i][4] , parsed[i][5], parsed[i][6]);
length = length + curve.getTotalLength();
cur = [parsed[i][5], parsed[i][6]];
functions.push(curve);
} else if(parsed[i][0] === "c"){
curve = new Bezier(cur[0], cur[1] , cur[0] + parsed[i][1], cur[1] + parsed[i][2] , cur[0] + parsed[i][3], cur[1] + parsed[i][4] , cur[0] + parsed[i][5], cur[1] + parsed[i][6]);
length = length + curve.getTotalLength();
cur = [parsed[i][5] + cur[0], parsed[i][6] + cur[1]];
functions.push(curve);
} else if(parsed[i][0] === "S"){
if(i>0 && ["C","c","S","s"].indexOf(parsed[i-1][0]) > -1){
curve = new Bezier(cur[0], cur[1] , 2*cur[0] - parsed[i-1][parsed[i-1].length - 4], 2*cur[1] - parsed[i-1][parsed[i-1].length - 3], parsed[i][1], parsed[i][2] , parsed[i][3], parsed[i][4]);
} else {
curve = new Bezier(cur[0], cur[1] , cur[0], cur[1], parsed[i][1], parsed[i][2] , parsed[i][3], parsed[i][4]);
}
length = length + curve.getTotalLength();
cur = [parsed[i][3], parsed[i][4]];
functions.push(curve);
} else if(parsed[i][0] === "s"){ //240 225
if(i>0 && ["C","c","S","s"].indexOf(parsed[i-1][0]) > -1){
curve = new Bezier(cur[0], cur[1] , cur[0] + curve.d.x - curve.c.x, cur[1] + curve.d.y - curve.c.y, cur[0] + parsed[i][1], cur[1] + parsed[i][2] , cur[0] + parsed[i][3], cur[1] + parsed[i][4]);
} else {
curve = new Bezier(cur[0], cur[1] , cur[0], cur[1], cur[0] + parsed[i][1], cur[1] + parsed[i][2] , cur[0] + parsed[i][3], cur[1] + parsed[i][4]);
}
length = length + curve.getTotalLength();
cur = [parsed[i][3] + cur[0], parsed[i][4] + cur[1]];
functions.push(curve);
}
//Quadratic Bezier curves
else if(parsed[i][0] === "Q"){
if(cur[0] != parsed[i][1] && cur[1] != parsed[i][2]){
curve = new Bezier(cur[0], cur[1] , parsed[i][1], parsed[i][2] , parsed[i][3], parsed[i][4]);
} else {
curve = new LinearPosition(parsed[i][1], parsed[i][3], parsed[i][2], parsed[i][4]);
}
length = length + curve.getTotalLength();
functions.push(curve);
cur = [parsed[i][3], parsed[i][4]];
prev_point = [parsed[i][1], parsed[i][2]];
} else if(parsed[i][0] === "q"){
if(!(parsed[i][1] == 0 && parsed[i][2] == 0)){
curve = new Bezier(cur[0], cur[1] , cur[0] + parsed[i][1], cur[1] + parsed[i][2] , cur[0] + parsed[i][3], cur[1] + parsed[i][4]);
} else {
curve = new LinearPosition(cur[0] + parsed[i][1], cur[0] + parsed[i][3], cur[1] + parsed[i][2], cur[1] + parsed[i][4]);
}
length = length + curve.getTotalLength();
prev_point = [cur[0] + parsed[i][1], cur[1] + parsed[i][2]];
cur = [parsed[i][3] + cur[0], parsed[i][4] + cur[1]];
functions.push(curve);
} else if(parsed[i][0] === "T"){
if(i>0 && ["Q","q","T","t"].indexOf(parsed[i-1][0]) > -1){
curve = new Bezier(cur[0], cur[1] , 2 * cur[0] - prev_point[0] , 2 * cur[1] - prev_point[1] , parsed[i][1], parsed[i][2]);
} else {
curve = new LinearPosition(cur[0], parsed[i][1], cur[1], parsed[i][2]);
}
functions.push(curve);
length = length + curve.getTotalLength();
prev_point = [2 * cur[0] - prev_point[0] , 2 * cur[1] - prev_point[1]];
cur = [parsed[i][1], parsed[i][2]];
} else if(parsed[i][0] === "t"){
if(i>0 && ["Q","q","T","t"].indexOf(parsed[i-1][0]) > -1){
curve = new Bezier(cur[0], cur[1] , 2 * cur[0] - prev_point[0] , 2 * cur[1] - prev_point[1] , cur[0] + parsed[i][1], cur[1] + parsed[i][2]);
} else {
curve = new LinearPosition(cur[0], cur[0] + parsed[i][1], cur[1], cur[1] + parsed[i][2]);
}
length = length + curve.getTotalLength();
prev_point = [2 * cur[0] - prev_point[0] , 2 * cur[1] - prev_point[1]];
cur = [parsed[i][1] + cur[0], parsed[i][2] + cur[0]];
functions.push(curve);
} else if(parsed[i][0] === "A"){
curve = new Arc(cur[0], cur[1], parsed[i][1], parsed[i][2], parsed[i][3], parsed[i][4], parsed[i][5], parsed[i][6], parsed[i][7]);
length = length + curve.getTotalLength();
cur = [parsed[i][6], parsed[i][7]];
functions.push(curve);
} else if(parsed[i][0] === "a"){
curve = new Arc(cur[0], cur[1], parsed[i][1], parsed[i][2], parsed[i][3], parsed[i][4], parsed[i][5], cur[0] + parsed[i][6], cur[1] + parsed[i][7]);
length = length + curve.getTotalLength();
cur = [cur[0] + parsed[i][6], cur[1] + parsed[i][7]];
functions.push(curve);
}
partial_lengths.push(length);
}
return svgProperties;
}
svgProperties.getTotalLength = function(){
return length;
};
svgProperties.getPointAtLength = function(fractionLength){
var fractionPart = getPartAtLength(fractionLength);
return functions[fractionPart.i].getPointAtLength(fractionPart.fraction);
};
svgProperties.getTangentAtLength = function(fractionLength){
var fractionPart = getPartAtLength(fractionLength);
return functions[fractionPart.i].getTangentAtLength(fractionPart.fraction);
};
svgProperties.getPropertiesAtLength = function(fractionLength){
var fractionPart = getPartAtLength(fractionLength);
return functions[fractionPart.i].getPropertiesAtLength(fractionPart.fraction);
};
var getPartAtLength = function(fractionLength){
if(fractionLength < 0){
fractionLength = 0;
} else if(fractionLength > length){
fractionLength = length;
}
var i = partial_lengths.length - 1;
while(partial_lengths[i] >= fractionLength && partial_lengths[i] > 0){
i--;
}
i++;
return {fraction: fractionLength-partial_lengths[i-1], i: i};
};
return svgProperties(svgString);
}
|
Compute the curve derivative (hodograph) at t.
|
svgPathProperties
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function svgProperties(string){
if(!string){return null;}
var parsed = parse$1(string);
var cur = [0, 0];
var prev_point = [0, 0];
var curve;
var ringStart;
for (var i = 0; i < parsed.length; i++){
//moveTo
if(parsed[i][0] === "M"){
cur = [parsed[i][1], parsed[i][2]];
ringStart = [cur[0], cur[1]];
functions.push(null);
} else if(parsed[i][0] === "m"){
cur = [parsed[i][1] + cur[0], parsed[i][2] + cur[1]];
ringStart = [cur[0], cur[1]];
functions.push(null);
}
//lineTo
else if(parsed[i][0] === "L"){
length = length + Math.sqrt(Math.pow(cur[0] - parsed[i][1], 2) + Math.pow(cur[1] - parsed[i][2], 2));
functions.push(new LinearPosition(cur[0], parsed[i][1], cur[1], parsed[i][2]));
cur = [parsed[i][1], parsed[i][2]];
} else if(parsed[i][0] === "l"){
length = length + Math.sqrt(Math.pow(parsed[i][1], 2) + Math.pow(parsed[i][2], 2));
functions.push(new LinearPosition(cur[0], parsed[i][1] + cur[0], cur[1], parsed[i][2] + cur[1]));
cur = [parsed[i][1] + cur[0], parsed[i][2] + cur[1]];
} else if(parsed[i][0] === "H"){
length = length + Math.abs(cur[0] - parsed[i][1]);
functions.push(new LinearPosition(cur[0], parsed[i][1], cur[1], cur[1]));
cur[0] = parsed[i][1];
} else if(parsed[i][0] === "h"){
length = length + Math.abs(parsed[i][1]);
functions.push(new LinearPosition(cur[0], cur[0] + parsed[i][1], cur[1], cur[1]));
cur[0] = parsed[i][1] + cur[0];
} else if(parsed[i][0] === "V"){
length = length + Math.abs(cur[1] - parsed[i][1]);
functions.push(new LinearPosition(cur[0], cur[0], cur[1], parsed[i][1]));
cur[1] = parsed[i][1];
} else if(parsed[i][0] === "v"){
length = length + Math.abs(parsed[i][1]);
functions.push(new LinearPosition(cur[0], cur[0], cur[1], cur[1] + parsed[i][1]));
cur[1] = parsed[i][1] + cur[1];
//Close path
} else if(parsed[i][0] === "z" || parsed[i][0] === "Z"){
length = length + Math.sqrt(Math.pow(ringStart[0] - cur[0], 2) + Math.pow(ringStart[1] - cur[1], 2));
functions.push(new LinearPosition(cur[0], ringStart[0], cur[1], ringStart[1]));
cur = [ringStart[0], ringStart[1]];
}
//Cubic Bezier curves
else if(parsed[i][0] === "C"){
curve = new Bezier(cur[0], cur[1] , parsed[i][1], parsed[i][2] , parsed[i][3], parsed[i][4] , parsed[i][5], parsed[i][6]);
length = length + curve.getTotalLength();
cur = [parsed[i][5], parsed[i][6]];
functions.push(curve);
} else if(parsed[i][0] === "c"){
curve = new Bezier(cur[0], cur[1] , cur[0] + parsed[i][1], cur[1] + parsed[i][2] , cur[0] + parsed[i][3], cur[1] + parsed[i][4] , cur[0] + parsed[i][5], cur[1] + parsed[i][6]);
length = length + curve.getTotalLength();
cur = [parsed[i][5] + cur[0], parsed[i][6] + cur[1]];
functions.push(curve);
} else if(parsed[i][0] === "S"){
if(i>0 && ["C","c","S","s"].indexOf(parsed[i-1][0]) > -1){
curve = new Bezier(cur[0], cur[1] , 2*cur[0] - parsed[i-1][parsed[i-1].length - 4], 2*cur[1] - parsed[i-1][parsed[i-1].length - 3], parsed[i][1], parsed[i][2] , parsed[i][3], parsed[i][4]);
} else {
curve = new Bezier(cur[0], cur[1] , cur[0], cur[1], parsed[i][1], parsed[i][2] , parsed[i][3], parsed[i][4]);
}
length = length + curve.getTotalLength();
cur = [parsed[i][3], parsed[i][4]];
functions.push(curve);
} else if(parsed[i][0] === "s"){ //240 225
if(i>0 && ["C","c","S","s"].indexOf(parsed[i-1][0]) > -1){
curve = new Bezier(cur[0], cur[1] , cur[0] + curve.d.x - curve.c.x, cur[1] + curve.d.y - curve.c.y, cur[0] + parsed[i][1], cur[1] + parsed[i][2] , cur[0] + parsed[i][3], cur[1] + parsed[i][4]);
} else {
curve = new Bezier(cur[0], cur[1] , cur[0], cur[1], cur[0] + parsed[i][1], cur[1] + parsed[i][2] , cur[0] + parsed[i][3], cur[1] + parsed[i][4]);
}
length = length + curve.getTotalLength();
cur = [parsed[i][3] + cur[0], parsed[i][4] + cur[1]];
functions.push(curve);
}
//Quadratic Bezier curves
else if(parsed[i][0] === "Q"){
if(cur[0] != parsed[i][1] && cur[1] != parsed[i][2]){
curve = new Bezier(cur[0], cur[1] , parsed[i][1], parsed[i][2] , parsed[i][3], parsed[i][4]);
} else {
curve = new LinearPosition(parsed[i][1], parsed[i][3], parsed[i][2], parsed[i][4]);
}
length = length + curve.getTotalLength();
functions.push(curve);
cur = [parsed[i][3], parsed[i][4]];
prev_point = [parsed[i][1], parsed[i][2]];
} else if(parsed[i][0] === "q"){
if(!(parsed[i][1] == 0 && parsed[i][2] == 0)){
curve = new Bezier(cur[0], cur[1] , cur[0] + parsed[i][1], cur[1] + parsed[i][2] , cur[0] + parsed[i][3], cur[1] + parsed[i][4]);
} else {
curve = new LinearPosition(cur[0] + parsed[i][1], cur[0] + parsed[i][3], cur[1] + parsed[i][2], cur[1] + parsed[i][4]);
}
length = length + curve.getTotalLength();
prev_point = [cur[0] + parsed[i][1], cur[1] + parsed[i][2]];
cur = [parsed[i][3] + cur[0], parsed[i][4] + cur[1]];
functions.push(curve);
} else if(parsed[i][0] === "T"){
if(i>0 && ["Q","q","T","t"].indexOf(parsed[i-1][0]) > -1){
curve = new Bezier(cur[0], cur[1] , 2 * cur[0] - prev_point[0] , 2 * cur[1] - prev_point[1] , parsed[i][1], parsed[i][2]);
} else {
curve = new LinearPosition(cur[0], parsed[i][1], cur[1], parsed[i][2]);
}
functions.push(curve);
length = length + curve.getTotalLength();
prev_point = [2 * cur[0] - prev_point[0] , 2 * cur[1] - prev_point[1]];
cur = [parsed[i][1], parsed[i][2]];
} else if(parsed[i][0] === "t"){
if(i>0 && ["Q","q","T","t"].indexOf(parsed[i-1][0]) > -1){
curve = new Bezier(cur[0], cur[1] , 2 * cur[0] - prev_point[0] , 2 * cur[1] - prev_point[1] , cur[0] + parsed[i][1], cur[1] + parsed[i][2]);
} else {
curve = new LinearPosition(cur[0], cur[0] + parsed[i][1], cur[1], cur[1] + parsed[i][2]);
}
length = length + curve.getTotalLength();
prev_point = [2 * cur[0] - prev_point[0] , 2 * cur[1] - prev_point[1]];
cur = [parsed[i][1] + cur[0], parsed[i][2] + cur[0]];
functions.push(curve);
} else if(parsed[i][0] === "A"){
curve = new Arc(cur[0], cur[1], parsed[i][1], parsed[i][2], parsed[i][3], parsed[i][4], parsed[i][5], parsed[i][6], parsed[i][7]);
length = length + curve.getTotalLength();
cur = [parsed[i][6], parsed[i][7]];
functions.push(curve);
} else if(parsed[i][0] === "a"){
curve = new Arc(cur[0], cur[1], parsed[i][1], parsed[i][2], parsed[i][3], parsed[i][4], parsed[i][5], cur[0] + parsed[i][6], cur[1] + parsed[i][7]);
length = length + curve.getTotalLength();
cur = [cur[0] + parsed[i][6], cur[1] + parsed[i][7]];
functions.push(curve);
}
partial_lengths.push(length);
}
return svgProperties;
}
|
Compute the curve derivative (hodograph) at t.
|
svgProperties
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
getPartAtLength = function(fractionLength){
if(fractionLength < 0){
fractionLength = 0;
} else if(fractionLength > length){
fractionLength = length;
}
var i = partial_lengths.length - 1;
while(partial_lengths[i] >= fractionLength && partial_lengths[i] > 0){
i--;
}
i++;
return {fraction: fractionLength-partial_lengths[i-1], i: i};
}
|
Compute the curve derivative (hodograph) at t.
|
getPartAtLength
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function distance(a, b) {
return Math.sqrt(
(a[0] - b[0]) * (a[0] - b[0]) + (a[1] - b[1]) * (a[1] - b[1])
);
}
|
Compute the curve derivative (hodograph) at t.
|
distance
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function pointAlong(a, b, pct) {
return [a[0] + (b[0] - a[0]) * pct, a[1] + (b[1] - a[1]) * pct];
}
|
Compute the curve derivative (hodograph) at t.
|
pointAlong
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function samePoint(a, b) {
return distance(a, b) < 1e-9;
}
|
Compute the curve derivative (hodograph) at t.
|
samePoint
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function interpolatePoints(a, b, string) {
var interpolators = a.map(function (d, i) { return interpolatePoint(d, b[i]); });
return function(t) {
var values = interpolators.map(function (fn) { return fn(t); });
return string ? toPathString(values) : values;
};
}
|
Compute the curve derivative (hodograph) at t.
|
interpolatePoints
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function interpolatePoint(a, b) {
return function(t) {
return a.map(function (d, i) { return d + t * (b[i] - d); });
};
}
|
Compute the curve derivative (hodograph) at t.
|
interpolatePoint
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function isFiniteNumber(number) {
return typeof number === "number" && isFinite(number);
}
|
Compute the curve derivative (hodograph) at t.
|
isFiniteNumber
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function polygonCentroid$$1(polygon) {
return nonZeroArea(polygon)
? d3Centroid(polygon)
: [
(polygon[0][0] + polygon[polygon.length - 1][0]) / 2,
(polygon[0][1] + polygon[polygon.length - 1][1]) / 2
];
}
|
Compute the curve derivative (hodograph) at t.
|
polygonCentroid$$1
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function nonZeroArea(polygon) {
for (var i = 0; i < polygon.length - 2; i++) {
var a = polygon[i],
b = polygon[i + 1],
c = polygon[i + 2];
if (a[0] * (b[1] - c[1]) + b[0] * (c[1] - a[1]) + c[0] * (a[1] - b[1])) {
return true;
}
}
return false;
}
|
Compute the curve derivative (hodograph) at t.
|
nonZeroArea
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function parse$$1(str) {
return new svgpath(str).abs();
}
|
Compute the curve derivative (hodograph) at t.
|
parse$$1
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function split(parsed) {
return parsed
.toString()
.split("M")
.map(function (d, i) {
d = d.trim();
return i && d ? "M" + d : d;
})
.filter(function (d) { return d; });
}
|
Compute the curve derivative (hodograph) at t.
|
split
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function toPathString(ring) {
return "M" + ring.join("L") + "Z";
}
|
Compute the curve derivative (hodograph) at t.
|
toPathString
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function splitPathString(str) {
return split(parse$$1(str));
}
|
Compute the curve derivative (hodograph) at t.
|
splitPathString
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function pathStringToRing(str, maxSegmentLength) {
var parsed = parse$$1(str);
return exactRing(parsed) || approximateRing(parsed, maxSegmentLength);
}
|
Compute the curve derivative (hodograph) at t.
|
pathStringToRing
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function exactRing(parsed) {
var segments = parsed.segments || [],
ring = [];
if (!segments.length || segments[0][0] !== "M") {
return false;
}
for (var i = 0; i < segments.length; i++) {
var ref = segments[i];
var command = ref[0];
var x = ref[1];
var y = ref[2];
if ((command === "M" && i) || command === "Z") {
break;
} else if (command === "M" || command === "L") {
ring.push([x, y]);
} else if (command === "H") {
ring.push([x, ring[ring.length - 1][1]]);
} else if (command === "V") {
ring.push([ring[ring.length - 1][0], x]);
} else {
return false;
}
}
return ring.length ? { ring: ring } : false;
}
|
Compute the curve derivative (hodograph) at t.
|
exactRing
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function approximateRing(parsed, maxSegmentLength) {
var ringPath = split(parsed)[0],
ring = [],
len,
m,
numPoints = 3;
if (!ringPath) {
throw new TypeError(INVALID_INPUT);
}
m = measure(ringPath);
len = m.getTotalLength();
if (
maxSegmentLength &&
isFiniteNumber(maxSegmentLength) &&
maxSegmentLength > 0
) {
numPoints = Math.max(numPoints, Math.ceil(len / maxSegmentLength));
}
for (var i = 0; i < numPoints; i++) {
var p = m.getPointAtLength((len * i) / numPoints);
ring.push([p.x, p.y]);
}
return {
ring: ring,
skipBisect: true
};
}
|
Compute the curve derivative (hodograph) at t.
|
approximateRing
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function measure(d) {
// Use native browser measurement if running in browser
if (typeof window !== "undefined" && window && window.document) {
try {
var path = window.document.createElementNS(
"http://www.w3.org/2000/svg",
"path"
);
path.setAttributeNS(null, "d", d);
return path;
} catch (e) {}
}
// Fall back to svg-path-properties
return svgPathProperties(d);
}
|
Compute the curve derivative (hodograph) at t.
|
measure
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function addPoints(ring, numPoints) {
var desiredLength = ring.length + numPoints,
step = polygonLength(ring) / numPoints;
var i = 0,
cursor = 0,
insertAt = step / 2;
while (ring.length < desiredLength) {
var a = ring[i],
b = ring[(i + 1) % ring.length],
segment = distance(a, b);
if (insertAt <= cursor + segment) {
ring.splice(
i + 1,
0,
segment ? pointAlong(a, b, (insertAt - cursor) / segment) : a.slice(0)
);
insertAt += step;
continue;
}
cursor += segment;
i++;
}
}
|
Compute the curve derivative (hodograph) at t.
|
addPoints
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function bisect(ring, maxSegmentLength) {
if ( maxSegmentLength === void 0 ) maxSegmentLength = Infinity;
for (var i = 0; i < ring.length; i++) {
var a = ring[i],
b = i === ring.length - 1 ? ring[0] : ring[i + 1];
// Could splice the whole set for a segment instead, but a bit messy
while (distance(a, b) > maxSegmentLength) {
b = pointAlong(a, b, 0.5);
ring.splice(i + 1, 0, b);
}
}
}
|
Compute the curve derivative (hodograph) at t.
|
bisect
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function normalizeRing(ring, maxSegmentLength) {
var points, area, skipBisect;
if (typeof ring === "string") {
var converted = pathStringToRing(ring, maxSegmentLength);
ring = converted.ring;
skipBisect = converted.skipBisect;
} else if (!Array.isArray(ring)) {
throw new TypeError(INVALID_INPUT);
}
points = ring.slice(0);
if (!validRing(points)) {
throw new TypeError(INVALID_INPUT);
}
// TODO skip this test to avoid scale issues?
// Chosen epsilon (1e-6) is problematic for small coordinate range
if (points.length > 1 && samePoint(points[0], points[points.length - 1])) {
points.pop();
}
area = polygonArea(points);
// Make all rings clockwise
if (area > 0) {
points.reverse();
}
if (
!skipBisect &&
maxSegmentLength &&
isFiniteNumber(maxSegmentLength) &&
maxSegmentLength > 0
) {
bisect(points, maxSegmentLength);
}
return points;
}
|
Compute the curve derivative (hodograph) at t.
|
normalizeRing
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function validRing(ring) {
return ring.every(function(point) {
return (
Array.isArray(point) &&
point.length >= 2 &&
isFiniteNumber(point[0]) &&
isFiniteNumber(point[1])
);
});
}
|
Compute the curve derivative (hodograph) at t.
|
validRing
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
rotate = function(ring, vs) {
var len = ring.length,
min = Infinity,
bestOffset,
sumOfSquares,
spliced;
var loop = function ( offset ) {
sumOfSquares = 0;
vs.forEach(function(p, i) {
var d = distance(ring[(offset + i) % len], p);
sumOfSquares += d * d;
});
if (sumOfSquares < min) {
min = sumOfSquares;
bestOffset = offset;
}
};
for (var offset = 0; offset < len; offset++) loop( offset );
if (bestOffset) {
spliced = ring.splice(0, bestOffset);
ring.splice.apply(ring, [ ring.length, 0 ].concat( spliced ));
}
}
|
Compute the curve derivative (hodograph) at t.
|
rotate
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
loop = function ( offset ) {
sumOfSquares = 0;
vs.forEach(function(p, i) {
var d = distance(ring[(offset + i) % len], p);
sumOfSquares += d * d;
});
if (sumOfSquares < min) {
min = sumOfSquares;
bestOffset = offset;
}
}
|
Compute the curve derivative (hodograph) at t.
|
loop
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
interpolate = function(
fromShape,
toShape,
ref
) {
if ( ref === void 0 ) ref = {};
var maxSegmentLength = ref.maxSegmentLength; if ( maxSegmentLength === void 0 ) maxSegmentLength = 10;
var string = ref.string; if ( string === void 0 ) string = true;
var fromRing = normalizeRing(fromShape, maxSegmentLength),
toRing = normalizeRing(toShape, maxSegmentLength),
interpolator = interpolateRing(fromRing, toRing, string);
// Extra optimization for near either end with path strings
if (
!string ||
(typeof fromShape !== "string" && typeof toShape !== "string")
) {
return interpolator;
}
return function (t) {
if (t < 1e-4 && typeof fromShape === "string") {
return fromShape;
}
if (1 - t < 1e-4 && typeof toShape === "string") {
return toShape;
}
return interpolator(t);
};
}
|
Compute the curve derivative (hodograph) at t.
|
interpolate
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function interpolateRing(fromRing, toRing, string) {
var diff;
diff = fromRing.length - toRing.length;
// TODO bisect and add points in one step?
addPoints(fromRing, diff < 0 ? diff * -1 : 0);
addPoints(toRing, diff > 0 ? diff : 0);
rotate(fromRing, toRing);
return interpolatePoints(fromRing, toRing, string);
}
|
Compute the curve derivative (hodograph) at t.
|
interpolateRing
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function earcut(data, holeIndices, dim) {
dim = dim || 2;
var hasHoles = holeIndices && holeIndices.length,
outerLen = hasHoles ? holeIndices[0] * dim : data.length,
outerNode = linkedList(data, 0, outerLen, dim, true),
triangles = [];
if (!outerNode || outerNode.next === outerNode.prev) { return triangles; }
var minX, minY, maxX, maxY, x, y, invSize;
if (hasHoles) { outerNode = eliminateHoles(data, holeIndices, outerNode, dim); }
// if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
if (data.length > 80 * dim) {
minX = maxX = data[0];
minY = maxY = data[1];
for (var i = dim; i < outerLen; i += dim) {
x = data[i];
y = data[i + 1];
if (x < minX) { minX = x; }
if (y < minY) { minY = y; }
if (x > maxX) { maxX = x; }
if (y > maxY) { maxY = y; }
}
// minX, minY and invSize are later used to transform coords into integers for z-order calculation
invSize = Math.max(maxX - minX, maxY - minY);
invSize = invSize !== 0 ? 1 / invSize : 0;
}
earcutLinked(outerNode, triangles, dim, minX, minY, invSize);
return triangles;
}
|
Compute the curve derivative (hodograph) at t.
|
earcut
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function linkedList(data, start, end, dim, clockwise) {
var i, last;
if (clockwise === (signedArea(data, start, end, dim) > 0)) {
for (i = start; i < end; i += dim) { last = insertNode(i, data[i], data[i + 1], last); }
} else {
for (i = end - dim; i >= start; i -= dim) { last = insertNode(i, data[i], data[i + 1], last); }
}
if (last && equals(last, last.next)) {
removeNode(last);
last = last.next;
}
return last;
}
|
Compute the curve derivative (hodograph) at t.
|
linkedList
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function filterPoints(start, end) {
if (!start) { return start; }
if (!end) { end = start; }
var p = start,
again;
do {
again = false;
if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
removeNode(p);
p = end = p.prev;
if (p === p.next) { break; }
again = true;
} else {
p = p.next;
}
} while (again || p !== end);
return end;
}
|
Compute the curve derivative (hodograph) at t.
|
filterPoints
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
if (!ear) { return; }
// interlink polygon nodes in z-order
if (!pass && invSize) { indexCurve(ear, minX, minY, invSize); }
var stop = ear,
prev, next;
// iterate through ears, slicing them one by one
while (ear.prev !== ear.next) {
prev = ear.prev;
next = ear.next;
if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
// cut off the triangle
triangles.push(prev.i / dim);
triangles.push(ear.i / dim);
triangles.push(next.i / dim);
removeNode(ear);
// skipping the next vertex leads to less sliver triangles
ear = next.next;
stop = next.next;
continue;
}
ear = next;
// if we looped through the whole remaining polygon and can't find any more ears
if (ear === stop) {
// try filtering points and slicing again
if (!pass) {
earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1);
// if this didn't work, try curing all small self-intersections locally
} else if (pass === 1) {
ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
earcutLinked(ear, triangles, dim, minX, minY, invSize, 2);
// as a last resort, try splitting the remaining polygon into two
} else if (pass === 2) {
splitEarcut(ear, triangles, dim, minX, minY, invSize);
}
break;
}
}
}
|
Compute the curve derivative (hodograph) at t.
|
earcutLinked
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function isEar(ear) {
var a = ear.prev,
b = ear,
c = ear.next;
if (area(a, b, c) >= 0) { return false; } // reflex, can't be an ear
// now make sure we don't have other points inside the potential ear
var p = ear.next.next;
while (p !== ear.prev) {
if (pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) &&
area(p.prev, p, p.next) >= 0) { return false; }
p = p.next;
}
return true;
}
|
Compute the curve derivative (hodograph) at t.
|
isEar
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function isEarHashed(ear, minX, minY, invSize) {
var a = ear.prev,
b = ear,
c = ear.next;
if (area(a, b, c) >= 0) { return false; } // reflex, can't be an ear
// triangle bbox; min & max are calculated like this for speed
var minTX = a.x < b.x ? (a.x < c.x ? a.x : c.x) : (b.x < c.x ? b.x : c.x),
minTY = a.y < b.y ? (a.y < c.y ? a.y : c.y) : (b.y < c.y ? b.y : c.y),
maxTX = a.x > b.x ? (a.x > c.x ? a.x : c.x) : (b.x > c.x ? b.x : c.x),
maxTY = a.y > b.y ? (a.y > c.y ? a.y : c.y) : (b.y > c.y ? b.y : c.y);
// z-order range for the current triangle bbox;
var minZ = zOrder(minTX, minTY, minX, minY, invSize),
maxZ = zOrder(maxTX, maxTY, minX, minY, invSize);
var p = ear.prevZ,
n = ear.nextZ;
// look for points inside the triangle in both directions
while (p && p.z >= minZ && n && n.z <= maxZ) {
if (p !== ear.prev && p !== ear.next &&
pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) &&
area(p.prev, p, p.next) >= 0) { return false; }
p = p.prevZ;
if (n !== ear.prev && n !== ear.next &&
pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y) &&
area(n.prev, n, n.next) >= 0) { return false; }
n = n.nextZ;
}
// look for remaining points in decreasing z-order
while (p && p.z >= minZ) {
if (p !== ear.prev && p !== ear.next &&
pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) &&
area(p.prev, p, p.next) >= 0) { return false; }
p = p.prevZ;
}
// look for remaining points in increasing z-order
while (n && n.z <= maxZ) {
if (n !== ear.prev && n !== ear.next &&
pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y) &&
area(n.prev, n, n.next) >= 0) { return false; }
n = n.nextZ;
}
return true;
}
|
Compute the curve derivative (hodograph) at t.
|
isEarHashed
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function cureLocalIntersections(start, triangles, dim) {
var p = start;
do {
var a = p.prev,
b = p.next.next;
if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
triangles.push(a.i / dim);
triangles.push(p.i / dim);
triangles.push(b.i / dim);
// remove two nodes involved
removeNode(p);
removeNode(p.next);
p = start = b;
}
p = p.next;
} while (p !== start);
return filterPoints(p);
}
|
Compute the curve derivative (hodograph) at t.
|
cureLocalIntersections
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function splitEarcut(start, triangles, dim, minX, minY, invSize) {
// look for a valid diagonal that divides the polygon into two
var a = start;
do {
var b = a.next.next;
while (b !== a.prev) {
if (a.i !== b.i && isValidDiagonal(a, b)) {
// split the polygon in two by the diagonal
var c = splitPolygon(a, b);
// filter colinear points around the cuts
a = filterPoints(a, a.next);
c = filterPoints(c, c.next);
// run earcut on each half
earcutLinked(a, triangles, dim, minX, minY, invSize);
earcutLinked(c, triangles, dim, minX, minY, invSize);
return;
}
b = b.next;
}
a = a.next;
} while (a !== start);
}
|
Compute the curve derivative (hodograph) at t.
|
splitEarcut
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function eliminateHoles(data, holeIndices, outerNode, dim) {
var queue = [],
i, len, start, end, list;
for (i = 0, len = holeIndices.length; i < len; i++) {
start = holeIndices[i] * dim;
end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
list = linkedList(data, start, end, dim, false);
if (list === list.next) { list.steiner = true; }
queue.push(getLeftmost(list));
}
queue.sort(compareX);
// process holes from left to right
for (i = 0; i < queue.length; i++) {
eliminateHole(queue[i], outerNode);
outerNode = filterPoints(outerNode, outerNode.next);
}
return outerNode;
}
|
Compute the curve derivative (hodograph) at t.
|
eliminateHoles
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function compareX(a, b) {
return a.x - b.x;
}
|
Compute the curve derivative (hodograph) at t.
|
compareX
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function eliminateHole(hole, outerNode) {
outerNode = findHoleBridge(hole, outerNode);
if (outerNode) {
var b = splitPolygon(outerNode, hole);
filterPoints(b, b.next);
}
}
|
Compute the curve derivative (hodograph) at t.
|
eliminateHole
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function findHoleBridge(hole, outerNode) {
var p = outerNode,
hx = hole.x,
hy = hole.y,
qx = -Infinity,
m;
// find a segment intersected by a ray from the hole's leftmost point to the left;
// segment's endpoint with lesser x will be potential connection point
do {
if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
var x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
if (x <= hx && x > qx) {
qx = x;
if (x === hx) {
if (hy === p.y) { return p; }
if (hy === p.next.y) { return p.next; }
}
m = p.x < p.next.x ? p : p.next;
}
}
p = p.next;
} while (p !== outerNode);
if (!m) { return null; }
if (hx === qx) { return m; } // hole touches outer segment; pick leftmost endpoint
// look for points inside the triangle of hole point, segment intersection and endpoint;
// if there are no points found, we have a valid connection;
// otherwise choose the point of the minimum angle with the ray as connection point
var stop = m,
mx = m.x,
my = m.y,
tanMin = Infinity,
tan;
p = m;
do {
if (hx >= p.x && p.x >= mx && hx !== p.x &&
pointInTriangle(hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y)) {
tan = Math.abs(hy - p.y) / (hx - p.x); // tangential
if (locallyInside(p, hole) &&
(tan < tanMin || (tan === tanMin && (p.x > m.x || (p.x === m.x && sectorContainsSector(m, p)))))) {
m = p;
tanMin = tan;
}
}
p = p.next;
} while (p !== stop);
return m;
}
|
Compute the curve derivative (hodograph) at t.
|
findHoleBridge
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function sectorContainsSector(m, p) {
return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;
}
|
Compute the curve derivative (hodograph) at t.
|
sectorContainsSector
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function indexCurve(start, minX, minY, invSize) {
var p = start;
do {
if (p.z === null) { p.z = zOrder(p.x, p.y, minX, minY, invSize); }
p.prevZ = p.prev;
p.nextZ = p.next;
p = p.next;
} while (p !== start);
p.prevZ.nextZ = null;
p.prevZ = null;
sortLinked(p);
}
|
Compute the curve derivative (hodograph) at t.
|
indexCurve
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function sortLinked(list) {
var i, p, q, e, tail, numMerges, pSize, qSize,
inSize = 1;
do {
p = list;
list = null;
tail = null;
numMerges = 0;
while (p) {
numMerges++;
q = p;
pSize = 0;
for (i = 0; i < inSize; i++) {
pSize++;
q = q.nextZ;
if (!q) { break; }
}
qSize = inSize;
while (pSize > 0 || (qSize > 0 && q)) {
if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
e = p;
p = p.nextZ;
pSize--;
} else {
e = q;
q = q.nextZ;
qSize--;
}
if (tail) { tail.nextZ = e; }
else { list = e; }
e.prevZ = tail;
tail = e;
}
p = q;
}
tail.nextZ = null;
inSize *= 2;
} while (numMerges > 1);
return list;
}
|
Compute the curve derivative (hodograph) at t.
|
sortLinked
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function zOrder(x, y, minX, minY, invSize) {
// coords are transformed into non-negative 15-bit integer range
x = 32767 * (x - minX) * invSize;
y = 32767 * (y - minY) * invSize;
x = (x | (x << 8)) & 0x00FF00FF;
x = (x | (x << 4)) & 0x0F0F0F0F;
x = (x | (x << 2)) & 0x33333333;
x = (x | (x << 1)) & 0x55555555;
y = (y | (y << 8)) & 0x00FF00FF;
y = (y | (y << 4)) & 0x0F0F0F0F;
y = (y | (y << 2)) & 0x33333333;
y = (y | (y << 1)) & 0x55555555;
return x | (y << 1);
}
|
Compute the curve derivative (hodograph) at t.
|
zOrder
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function getLeftmost(start) {
var p = start,
leftmost = start;
do {
if (p.x < leftmost.x || (p.x === leftmost.x && p.y < leftmost.y)) { leftmost = p; }
p = p.next;
} while (p !== start);
return leftmost;
}
|
Compute the curve derivative (hodograph) at t.
|
getLeftmost
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
return (cx - px) * (ay - py) - (ax - px) * (cy - py) >= 0 &&
(ax - px) * (by - py) - (bx - px) * (ay - py) >= 0 &&
(bx - px) * (cy - py) - (cx - px) * (by - py) >= 0;
}
|
Compute the curve derivative (hodograph) at t.
|
pointInTriangle
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function isValidDiagonal(a, b) {
return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && // dones't intersect other edges
(locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b) && // locally visible
(area(a.prev, a, b.prev) || area(a, b.prev, b)) || // does not create opposite-facing sectors
equals(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0); // special zero-length case
}
|
Compute the curve derivative (hodograph) at t.
|
isValidDiagonal
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function area(p, q, r) {
return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
}
|
Compute the curve derivative (hodograph) at t.
|
area
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function equals(p1, p2) {
return p1.x === p2.x && p1.y === p2.y;
}
|
Compute the curve derivative (hodograph) at t.
|
equals
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function intersects(p1, q1, p2, q2) {
var o1 = sign(area(p1, q1, p2));
var o2 = sign(area(p1, q1, q2));
var o3 = sign(area(p2, q2, p1));
var o4 = sign(area(p2, q2, q1));
if (o1 !== o2 && o3 !== o4) { return true; } // general case
if (o1 === 0 && onSegment(p1, p2, q1)) { return true; } // p1, q1 and p2 are collinear and p2 lies on p1q1
if (o2 === 0 && onSegment(p1, q2, q1)) { return true; } // p1, q1 and q2 are collinear and q2 lies on p1q1
if (o3 === 0 && onSegment(p2, p1, q2)) { return true; } // p2, q2 and p1 are collinear and p1 lies on p2q2
if (o4 === 0 && onSegment(p2, q1, q2)) { return true; } // p2, q2 and q1 are collinear and q1 lies on p2q2
return false;
}
|
Compute the curve derivative (hodograph) at t.
|
intersects
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function onSegment(p, q, r) {
return q.x <= Math.max(p.x, r.x) && q.x >= Math.min(p.x, r.x) && q.y <= Math.max(p.y, r.y) && q.y >= Math.min(p.y, r.y);
}
|
Compute the curve derivative (hodograph) at t.
|
onSegment
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function sign(num) {
return num > 0 ? 1 : num < 0 ? -1 : 0;
}
|
Compute the curve derivative (hodograph) at t.
|
sign
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function intersectsPolygon(a, b) {
var p = a;
do {
if (p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i &&
intersects(p, p.next, a, b)) { return true; }
p = p.next;
} while (p !== a);
return false;
}
|
Compute the curve derivative (hodograph) at t.
|
intersectsPolygon
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function locallyInside(a, b) {
return area(a.prev, a, a.next) < 0 ?
area(a, b, a.next) >= 0 && area(a, a.prev, b) >= 0 :
area(a, b, a.prev) < 0 || area(a, a.next, b) < 0;
}
|
Compute the curve derivative (hodograph) at t.
|
locallyInside
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function middleInside(a, b) {
var p = a,
inside = false,
px = (a.x + b.x) / 2,
py = (a.y + b.y) / 2;
do {
if (((p.y > py) !== (p.next.y > py)) && p.next.y !== p.y &&
(px < (p.next.x - p.x) * (py - p.y) / (p.next.y - p.y) + p.x))
{ inside = !inside; }
p = p.next;
} while (p !== a);
return inside;
}
|
Compute the curve derivative (hodograph) at t.
|
middleInside
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function splitPolygon(a, b) {
var a2 = new Node(a.i, a.x, a.y),
b2 = new Node(b.i, b.x, b.y),
an = a.next,
bp = b.prev;
a.next = b;
b.prev = a;
a2.next = an;
an.prev = a2;
b2.next = a2;
a2.prev = b2;
bp.next = b2;
b2.prev = bp;
return b2;
}
|
Compute the curve derivative (hodograph) at t.
|
splitPolygon
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function insertNode(i, x, y, last) {
var p = new Node(i, x, y);
if (!last) {
p.prev = p;
p.next = p;
} else {
p.next = last.next;
p.prev = last;
last.next.prev = p;
last.next = p;
}
return p;
}
|
Compute the curve derivative (hodograph) at t.
|
insertNode
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function removeNode(p) {
p.next.prev = p.prev;
p.prev.next = p.next;
if (p.prevZ) { p.prevZ.nextZ = p.nextZ; }
if (p.nextZ) { p.nextZ.prevZ = p.prevZ; }
}
|
Compute the curve derivative (hodograph) at t.
|
removeNode
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function Node(i, x, y) {
// vertex index in coordinates array
this.i = i;
// vertex coordinates
this.x = x;
this.y = y;
// previous and next vertex nodes in a polygon ring
this.prev = null;
this.next = null;
// z-order curve value
this.z = null;
// previous and next nodes in z-order
this.prevZ = null;
this.nextZ = null;
// indicates whether this is a steiner point
this.steiner = false;
}
|
Compute the curve derivative (hodograph) at t.
|
Node
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function signedArea(data, start, end, dim) {
var sum = 0;
for (var i = start, j = end - dim; i < end; i += dim) {
sum += (data[j] - data[i]) * (data[i + 1] + data[j + 1]);
j = i;
}
return sum;
}
|
Compute the curve derivative (hodograph) at t.
|
signedArea
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
identity = function(x) {
return x;
}
|
Compute the curve derivative (hodograph) at t.
|
identity
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
transform = function(transform) {
if (transform == null) { return identity; }
var x0,
y0,
kx = transform.scale[0],
ky = transform.scale[1],
dx = transform.translate[0],
dy = transform.translate[1];
return function(input, i) {
if (!i) { x0 = y0 = 0; }
var j = 2, n = input.length, output = new Array(n);
output[0] = (x0 += input[0]) * kx + dx;
output[1] = (y0 += input[1]) * ky + dy;
while (j < n) { output[j] = input[j], ++j; }
return output;
};
}
|
Compute the curve derivative (hodograph) at t.
|
transform
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
reverse = function(array, n) {
var t, j = array.length, i = j - n;
while (i < --j) { t = array[i], array[i++] = array[j], array[j] = t; }
}
|
Compute the curve derivative (hodograph) at t.
|
reverse
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
feature = function(topology, o) {
return o.type === "GeometryCollection"
? {type: "FeatureCollection", features: o.geometries.map(function(o) { return feature$1(topology, o); })}
: feature$1(topology, o);
}
|
Compute the curve derivative (hodograph) at t.
|
feature
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function feature$1(topology, o) {
var id = o.id,
bbox = o.bbox,
properties = o.properties == null ? {} : o.properties,
geometry = object(topology, o);
return id == null && bbox == null ? {type: "Feature", properties: properties, geometry: geometry}
: bbox == null ? {type: "Feature", id: id, properties: properties, geometry: geometry}
: {type: "Feature", id: id, bbox: bbox, properties: properties, geometry: geometry};
}
|
Compute the curve derivative (hodograph) at t.
|
feature$1
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function object(topology, o) {
var transformPoint = transform(topology.transform),
arcs = topology.arcs;
function arc(i, points) {
if (points.length) { points.pop(); }
for (var a = arcs[i < 0 ? ~i : i], k = 0, n = a.length; k < n; ++k) {
points.push(transformPoint(a[k], k));
}
if (i < 0) { reverse(points, n); }
}
function point(p) {
return transformPoint(p);
}
function line(arcs) {
var points = [];
for (var i = 0, n = arcs.length; i < n; ++i) { arc(arcs[i], points); }
if (points.length < 2) { points.push(points[0]); } // This should never happen per the specification.
return points;
}
function ring(arcs) {
var points = line(arcs);
while (points.length < 4) { points.push(points[0]); } // This may happen if an arc has only two points.
return points;
}
function polygon(arcs) {
return arcs.map(ring);
}
function geometry(o) {
var type = o.type, coordinates;
switch (type) {
case "GeometryCollection": return {type: type, geometries: o.geometries.map(geometry)};
case "Point": coordinates = point(o.coordinates); break;
case "MultiPoint": coordinates = o.coordinates.map(point); break;
case "LineString": coordinates = line(o.arcs); break;
case "MultiLineString": coordinates = o.arcs.map(line); break;
case "Polygon": coordinates = polygon(o.arcs); break;
case "MultiPolygon": coordinates = o.arcs.map(polygon); break;
default: return null;
}
return {type: type, coordinates: coordinates};
}
return geometry(o);
}
|
Compute the curve derivative (hodograph) at t.
|
object
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function arc(i, points) {
if (points.length) { points.pop(); }
for (var a = arcs[i < 0 ? ~i : i], k = 0, n = a.length; k < n; ++k) {
points.push(transformPoint(a[k], k));
}
if (i < 0) { reverse(points, n); }
}
|
Compute the curve derivative (hodograph) at t.
|
arc
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function point(p) {
return transformPoint(p);
}
|
Compute the curve derivative (hodograph) at t.
|
point
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function line(arcs) {
var points = [];
for (var i = 0, n = arcs.length; i < n; ++i) { arc(arcs[i], points); }
if (points.length < 2) { points.push(points[0]); } // This should never happen per the specification.
return points;
}
|
Compute the curve derivative (hodograph) at t.
|
line
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function ring(arcs) {
var points = line(arcs);
while (points.length < 4) { points.push(points[0]); } // This may happen if an arc has only two points.
return points;
}
|
Compute the curve derivative (hodograph) at t.
|
ring
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function polygon(arcs) {
return arcs.map(ring);
}
|
Compute the curve derivative (hodograph) at t.
|
polygon
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function geometry(o) {
var type = o.type, coordinates;
switch (type) {
case "GeometryCollection": return {type: type, geometries: o.geometries.map(geometry)};
case "Point": coordinates = point(o.coordinates); break;
case "MultiPoint": coordinates = o.coordinates.map(point); break;
case "LineString": coordinates = line(o.arcs); break;
case "MultiLineString": coordinates = o.arcs.map(line); break;
case "Polygon": coordinates = polygon(o.arcs); break;
case "MultiPolygon": coordinates = o.arcs.map(polygon); break;
default: return null;
}
return {type: type, coordinates: coordinates};
}
|
Compute the curve derivative (hodograph) at t.
|
geometry
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
stitch = function(topology, arcs) {
var stitchedArcs = {},
fragmentByStart = {},
fragmentByEnd = {},
fragments = [],
emptyIndex = -1;
// Stitch empty arcs first, since they may be subsumed by other arcs.
arcs.forEach(function(i, j) {
var arc = topology.arcs[i < 0 ? ~i : i], t;
if (arc.length < 3 && !arc[1][0] && !arc[1][1]) {
t = arcs[++emptyIndex], arcs[emptyIndex] = i, arcs[j] = t;
}
});
arcs.forEach(function(i) {
var e = ends(i),
start = e[0],
end = e[1],
f, g;
if (f = fragmentByEnd[start]) {
delete fragmentByEnd[f.end];
f.push(i);
f.end = end;
if (g = fragmentByStart[end]) {
delete fragmentByStart[g.start];
var fg = g === f ? f : f.concat(g);
fragmentByStart[fg.start = f.start] = fragmentByEnd[fg.end = g.end] = fg;
} else {
fragmentByStart[f.start] = fragmentByEnd[f.end] = f;
}
} else if (f = fragmentByStart[end]) {
delete fragmentByStart[f.start];
f.unshift(i);
f.start = start;
if (g = fragmentByEnd[start]) {
delete fragmentByEnd[g.end];
var gf = g === f ? f : g.concat(f);
fragmentByStart[gf.start = g.start] = fragmentByEnd[gf.end = f.end] = gf;
} else {
fragmentByStart[f.start] = fragmentByEnd[f.end] = f;
}
} else {
f = [i];
fragmentByStart[f.start = start] = fragmentByEnd[f.end = end] = f;
}
});
function ends(i) {
var arc = topology.arcs[i < 0 ? ~i : i], p0 = arc[0], p1;
if (topology.transform) { p1 = [0, 0], arc.forEach(function(dp) { p1[0] += dp[0], p1[1] += dp[1]; }); }
else { p1 = arc[arc.length - 1]; }
return i < 0 ? [p1, p0] : [p0, p1];
}
function flush(fragmentByEnd, fragmentByStart) {
for (var k in fragmentByEnd) {
var f = fragmentByEnd[k];
delete fragmentByStart[f.start];
delete f.start;
delete f.end;
f.forEach(function(i) { stitchedArcs[i < 0 ? ~i : i] = 1; });
fragments.push(f);
}
}
flush(fragmentByEnd, fragmentByStart);
flush(fragmentByStart, fragmentByEnd);
arcs.forEach(function(i) { if (!stitchedArcs[i < 0 ? ~i : i]) { fragments.push([i]); } });
return fragments;
}
|
Compute the curve derivative (hodograph) at t.
|
stitch
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function ends(i) {
var arc = topology.arcs[i < 0 ? ~i : i], p0 = arc[0], p1;
if (topology.transform) { p1 = [0, 0], arc.forEach(function(dp) { p1[0] += dp[0], p1[1] += dp[1]; }); }
else { p1 = arc[arc.length - 1]; }
return i < 0 ? [p1, p0] : [p0, p1];
}
|
Compute the curve derivative (hodograph) at t.
|
ends
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function flush(fragmentByEnd, fragmentByStart) {
for (var k in fragmentByEnd) {
var f = fragmentByEnd[k];
delete fragmentByStart[f.start];
delete f.start;
delete f.end;
f.forEach(function(i) { stitchedArcs[i < 0 ? ~i : i] = 1; });
fragments.push(f);
}
}
|
Compute the curve derivative (hodograph) at t.
|
flush
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function planarRingArea(ring) {
var i = -1, n = ring.length, a, b = ring[n - 1], area = 0;
while (++i < n) { a = b, b = ring[i], area += a[0] * b[1] - a[1] * b[0]; }
return Math.abs(area); // Note: doubled area!
}
|
Compute the curve derivative (hodograph) at t.
|
planarRingArea
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function mergeArcs(topology, objects) {
var polygonsByArc = {},
polygons = [],
groups = [];
objects.forEach(geometry);
function geometry(o) {
switch (o.type) {
case "GeometryCollection": o.geometries.forEach(geometry); break;
case "Polygon": extract(o.arcs); break;
case "MultiPolygon": o.arcs.forEach(extract); break;
}
}
function extract(polygon) {
polygon.forEach(function(ring) {
ring.forEach(function(arc) {
(polygonsByArc[arc = arc < 0 ? ~arc : arc] || (polygonsByArc[arc] = [])).push(polygon);
});
});
polygons.push(polygon);
}
function area(ring) {
return planarRingArea(object(topology, {type: "Polygon", arcs: [ring]}).coordinates[0]);
}
polygons.forEach(function(polygon) {
if (!polygon._) {
var group = [],
neighbors = [polygon];
polygon._ = 1;
groups.push(group);
while (polygon = neighbors.pop()) {
group.push(polygon);
polygon.forEach(function(ring) {
ring.forEach(function(arc) {
polygonsByArc[arc < 0 ? ~arc : arc].forEach(function(polygon) {
if (!polygon._) {
polygon._ = 1;
neighbors.push(polygon);
}
});
});
});
}
}
});
polygons.forEach(function(polygon) {
delete polygon._;
});
return {
type: "MultiPolygon",
arcs: groups.map(function(polygons) {
var arcs = [], n;
// Extract the exterior (unique) arcs.
polygons.forEach(function(polygon) {
polygon.forEach(function(ring) {
ring.forEach(function(arc) {
if (polygonsByArc[arc < 0 ? ~arc : arc].length < 2) {
arcs.push(arc);
}
});
});
});
// Stitch the arcs into one or more rings.
arcs = stitch(topology, arcs);
// If more than one ring is returned,
// at most one of these rings can be the exterior;
// choose the one with the greatest absolute area.
if ((n = arcs.length) > 1) {
for (var i = 1, k = area(arcs[0]), ki, t; i < n; ++i) {
if ((ki = area(arcs[i])) > k) {
t = arcs[0], arcs[0] = arcs[i], arcs[i] = t, k = ki;
}
}
}
return arcs;
}).filter(function(arcs) {
return arcs.length > 0;
})
};
}
|
Compute the curve derivative (hodograph) at t.
|
mergeArcs
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function geometry(o) {
switch (o.type) {
case "GeometryCollection": o.geometries.forEach(geometry); break;
case "Polygon": extract(o.arcs); break;
case "MultiPolygon": o.arcs.forEach(extract); break;
}
}
|
Compute the curve derivative (hodograph) at t.
|
geometry
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function extract(polygon) {
polygon.forEach(function(ring) {
ring.forEach(function(arc) {
(polygonsByArc[arc = arc < 0 ? ~arc : arc] || (polygonsByArc[arc] = [])).push(polygon);
});
});
polygons.push(polygon);
}
|
Compute the curve derivative (hodograph) at t.
|
extract
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function area(ring) {
return planarRingArea(object(topology, {type: "Polygon", arcs: [ring]}).coordinates[0]);
}
|
Compute the curve derivative (hodograph) at t.
|
area
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
bisect$1 = function(a, x) {
var lo = 0, hi = a.length;
while (lo < hi) {
var mid = lo + hi >>> 1;
if (a[mid] < x) { lo = mid + 1; }
else { hi = mid; }
}
return lo;
}
|
Compute the curve derivative (hodograph) at t.
|
bisect$1
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
neighbors = function(objects) {
var indexesByArc = {}, // arc index -> array of object indexes
neighbors = objects.map(function() { return []; });
function line(arcs, i) {
arcs.forEach(function(a) {
if (a < 0) { a = ~a; }
var o = indexesByArc[a];
if (o) { o.push(i); }
else { indexesByArc[a] = [i]; }
});
}
function polygon(arcs, i) {
arcs.forEach(function(arc) { line(arc, i); });
}
function geometry(o, i) {
if (o.type === "GeometryCollection") { o.geometries.forEach(function(o) { geometry(o, i); }); }
else if (o.type in geometryType) { geometryType[o.type](o.arcs, i); }
}
var geometryType = {
LineString: line,
MultiLineString: polygon,
Polygon: polygon,
MultiPolygon: function(arcs, i) { arcs.forEach(function(arc) { polygon(arc, i); }); }
};
objects.forEach(geometry);
for (var i in indexesByArc) {
for (var indexes = indexesByArc[i], m = indexes.length, j = 0; j < m; ++j) {
for (var k = j + 1; k < m; ++k) {
var ij = indexes[j], ik = indexes[k], n;
if ((n = neighbors[ij])[i = bisect$1(n, ik)] !== ik) { n.splice(i, 0, ik); }
if ((n = neighbors[ik])[i = bisect$1(n, ij)] !== ij) { n.splice(i, 0, ij); }
}
}
}
return neighbors;
}
|
Compute the curve derivative (hodograph) at t.
|
neighbors
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function line(arcs, i) {
arcs.forEach(function(a) {
if (a < 0) { a = ~a; }
var o = indexesByArc[a];
if (o) { o.push(i); }
else { indexesByArc[a] = [i]; }
});
}
|
Compute the curve derivative (hodograph) at t.
|
line
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function polygon(arcs, i) {
arcs.forEach(function(arc) { line(arc, i); });
}
|
Compute the curve derivative (hodograph) at t.
|
polygon
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function geometry(o, i) {
if (o.type === "GeometryCollection") { o.geometries.forEach(function(o) { geometry(o, i); }); }
else if (o.type in geometryType) { geometryType[o.type](o.arcs, i); }
}
|
Compute the curve derivative (hodograph) at t.
|
geometry
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
ascending = function(a, b) {
return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
}
|
Compute the curve derivative (hodograph) at t.
|
ascending
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
bisector = function(compare) {
if (compare.length === 1) { compare = ascendingComparator(compare); }
return {
left: function(a, x, lo, hi) {
if (lo == null) { lo = 0; }
if (hi == null) { hi = a.length; }
while (lo < hi) {
var mid = lo + hi >>> 1;
if (compare(a[mid], x) < 0) { lo = mid + 1; }
else { hi = mid; }
}
return lo;
},
right: function(a, x, lo, hi) {
if (lo == null) { lo = 0; }
if (hi == null) { hi = a.length; }
while (lo < hi) {
var mid = lo + hi >>> 1;
if (compare(a[mid], x) > 0) { hi = mid; }
else { lo = mid + 1; }
}
return lo;
}
};
}
|
Compute the curve derivative (hodograph) at t.
|
bisector
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function ascendingComparator(f) {
return function(d, x) {
return ascending(f(d), x);
};
}
|
Compute the curve derivative (hodograph) at t.
|
ascendingComparator
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function pair(a, b) {
return [a, b];
}
|
Compute the curve derivative (hodograph) at t.
|
pair
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
number$1 = function(x) {
return x === null ? NaN : +x;
}
|
Compute the curve derivative (hodograph) at t.
|
number$1
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
extent = function(values, valueof) {
var n = values.length,
i = -1,
value,
min,
max;
if (valueof == null) {
while (++i < n) { // Find the first comparable value.
if ((value = values[i]) != null && value >= value) {
min = max = value;
while (++i < n) { // Compare the remaining values.
if ((value = values[i]) != null) {
if (min > value) { min = value; }
if (max < value) { max = value; }
}
}
}
}
}
else {
while (++i < n) { // Find the first comparable value.
if ((value = valueof(values[i], i, values)) != null && value >= value) {
min = max = value;
while (++i < n) { // Compare the remaining values.
if ((value = valueof(values[i], i, values)) != null) {
if (min > value) { min = value; }
if (max < value) { max = value; }
}
}
}
}
}
return [min, max];
}
|
Compute the curve derivative (hodograph) at t.
|
extent
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
identity$1 = function(x) {
return x;
}
|
Compute the curve derivative (hodograph) at t.
|
identity$1
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
range = function(start, stop, step) {
start = +start, stop = +stop, step = (n = arguments.length) < 2 ? (stop = start, start = 0, 1) : n < 3 ? 1 : +step;
var i = -1,
n = Math.max(0, Math.ceil((stop - start) / step)) | 0,
range = new Array(n);
while (++i < n) {
range[i] = start + i * step;
}
return range;
}
|
Compute the curve derivative (hodograph) at t.
|
range
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function tickIncrement(start, stop, count) {
var step = (stop - start) / Math.max(0, count),
power = Math.floor(Math.log(step) / Math.LN10),
error = step / Math.pow(10, power);
return power >= 0
? (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1) * Math.pow(10, power)
: -Math.pow(10, -power) / (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1);
}
|
Compute the curve derivative (hodograph) at t.
|
tickIncrement
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function tickStep(start, stop, count) {
var step0 = Math.abs(stop - start) / Math.max(0, count),
step1 = Math.pow(10, Math.floor(Math.log(step0) / Math.LN10)),
error = step0 / step1;
if (error >= e10) { step1 *= 10; }
else if (error >= e5) { step1 *= 5; }
else if (error >= e2) { step1 *= 2; }
return stop < start ? -step1 : step1;
}
|
Compute the curve derivative (hodograph) at t.
|
tickStep
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
sturges = function(values) {
return Math.ceil(Math.log(values.length) / Math.LN2) + 1;
}
|
Compute the curve derivative (hodograph) at t.
|
sturges
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
quantile = function(values, p, valueof) {
if (valueof == null) { valueof = number$1; }
if (!(n = values.length)) { return; }
if ((p = +p) <= 0 || n < 2) { return +valueof(values[0], 0, values); }
if (p >= 1) { return +valueof(values[n - 1], n - 1, values); }
var n,
i = (n - 1) * p,
i0 = Math.floor(i),
value0 = +valueof(values[i0], i0, values),
value1 = +valueof(values[i0 + 1], i0 + 1, values);
return value0 + (value1 - value0) * (i - i0);
}
|
Compute the curve derivative (hodograph) at t.
|
quantile
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
min = function(values, valueof) {
var n = values.length,
i = -1,
value,
min;
if (valueof == null) {
while (++i < n) { // Find the first comparable value.
if ((value = values[i]) != null && value >= value) {
min = value;
while (++i < n) { // Compare the remaining values.
if ((value = values[i]) != null && min > value) {
min = value;
}
}
}
}
}
else {
while (++i < n) { // Find the first comparable value.
if ((value = valueof(values[i], i, values)) != null && value >= value) {
min = value;
while (++i < n) { // Compare the remaining values.
if ((value = valueof(values[i], i, values)) != null && min > value) {
min = value;
}
}
}
}
}
return min;
}
|
Compute the curve derivative (hodograph) at t.
|
min
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function length$1(d) {
return d.length;
}
|
Compute the curve derivative (hodograph) at t.
|
length$1
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
function createTopology(triangles, ring) {
var arcIndices = {},
topology = {
type: "Topology",
objects: {
triangles: {
type: "GeometryCollection",
geometries: []
}
},
arcs: []
};
triangles.forEach(function(triangle) {
var geometry = [];
triangle.forEach(function(arc, i) {
var slug = arc[0] < arc[1] ? arc.join(",") : arc[1] + "," + arc[0],
coordinates = arc.map(function(pointIndex) {
return ring[pointIndex];
});
if (slug in arcIndices) {
geometry.push(~arcIndices[slug]);
} else {
geometry.push((arcIndices[slug] = topology.arcs.length));
topology.arcs.push(coordinates);
}
});
topology.objects.triangles.geometries.push({
type: "Polygon",
area: Math.abs(
polygonArea(
triangle.map(function(d) {
return ring[d[0]];
})
)
),
arcs: [geometry]
});
});
// Sort smallest first
// TODO sorted insertion?
topology.objects.triangles.geometries.sort(function (a, b) { return a.area - b.area; });
return topology;
}
|
Compute the curve derivative (hodograph) at t.
|
createTopology
|
javascript
|
veltman/flubber
|
build/flubber.js
|
https://github.com/veltman/flubber/blob/master/build/flubber.js
|
MIT
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.