turn off offset for tatami (for now) add libraries.

pull/68/head
Michael Aschauer 2018-12-20 12:59:56 -08:00
rodzic 731a229866
commit 3b06a8a93f
2 zmienionych plików z 156 dodań i 16 usunięć

Wyświetl plik

@ -0,0 +1,140 @@
/*
(c) 2013, Vladimir Agafonkin
Simplify.js, a high-performance JS polyline simplification library
mourner.github.io/simplify-js
*/
(function () { "use strict";
// to suit your point format, run search/replace for '[0]' and '[1]';
// for 3D version, see 3d branch (configurability would draw significant performance overhead)
// square distance between 2 points
function getSqDist(p1, p2) {
var dx = p1[0] - p2[0],
dy = p1[1] - p2[1];
return dx * dx + dy * dy;
}
// square distance from a point to a segment
function getSqSegDist(p, p1, p2) {
var x = p1[0],
y = p1[1],
dx = p2[0] - x,
dy = p2[1] - y;
if (dx !== 0 || dy !== 0) {
var t = ((p[0] - x) * dx + (p[1] - y) * dy) / (dx * dx + dy * dy);
if (t > 1) {
x = p2[0];
y = p2[1];
} else if (t > 0) {
x += dx * t;
y += dy * t;
}
}
dx = p[0] - x;
dy = p[1] - y;
return dx * dx + dy * dy;
}
// rest of the code doesn't care about point format
// basic distance-based simplification
function simplifyRadialDist(points, sqTolerance) {
var prevPoint = points[0],
newPoints = [prevPoint],
point;
for (var i = 1, len = points.length; i < len; i++) {
point = points[i];
if (getSqDist(point, prevPoint) > sqTolerance) {
newPoints.push(point);
prevPoint = point;
}
}
if (prevPoint !== point) {
newPoints.push(point);
}
return newPoints;
}
// simplification using optimized Douglas-Peucker algorithm with recursion elimination
function simplifyDouglasPeucker(points, sqTolerance) {
var len = points.length,
MarkerArray = typeof Uint8Array !== 'undefined' ? Uint8Array : Array,
markers = new MarkerArray(len),
first = 0,
last = len - 1,
stack = [],
newPoints = [],
i, maxSqDist, sqDist, index;
markers[first] = markers[last] = 1;
while (last) {
maxSqDist = 0;
for (i = first + 1; i < last; i++) {
sqDist = getSqSegDist(points[i], points[first], points[last]);
if (sqDist > maxSqDist) {
index = i;
maxSqDist = sqDist;
}
}
if (maxSqDist > sqTolerance) {
markers[index] = 1;
stack.push(first, index, index, last);
}
last = stack.pop();
first = stack.pop();
}
for (i = 0; i < len; i++) {
if (markers[i]) {
newPoints.push(points[i]);
}
}
return newPoints;
}
// both algorithms combined for awesome performance
function simplify(points, tolerance, highestQuality) {
var sqTolerance = tolerance !== undefined ? tolerance * tolerance : 1;
points = highestQuality ? points : simplifyRadialDist(points, sqTolerance);
points = simplifyDouglasPeucker(points, sqTolerance);
return points;
}
// export as AMD module / Node module / browser variable
if (typeof define === 'function' && define.amd) {
define(function() {
return simplify;
});
} else if (typeof module !== 'undefined') {
module.exports = simplify;
} else {
window.simplify = simplify;
}
})();

Wyświetl plik

@ -264,7 +264,7 @@ SpriteMorph.prototype.addStitchPoint = function(x2, y2) {
geometry.faces.push(new THREE.Face3(0, 1, 2));
geometry.faces.push(new THREE.Face3(0, 2, 3));
}
line = new THREE.Mesh(geometry, material);
line.rotation.z = (45 - this.heading) * Math.PI / 180;
line.position.set(x2,y2,0.01);
@ -390,14 +390,14 @@ SpriteMorph.prototype.satinStitch = function (width=10, center=true, autoadjust=
}
}
SpriteMorph.prototype.tatamiStitch = function (width=100, interval=30, offset=10, center=false) {
SpriteMorph.prototype.tatamiStitch = function (width=100, interval=30, offset=0, center=false) {
if (width > 0) {
this.stitchtype = "tatami";
this.isRunning = true;
this.stitchoptions = {
autoadjust: true,
width: width,
length: 2,
length: 4,
center: center,
interval: Math.max(10,interval),
offset: Math.min(offset,interval),
@ -803,26 +803,26 @@ SpriteMorph.prototype.gotoXY = function (x, y, justMe, noShadow) {
real_length = 0;
if ( Math.round(dist / this.stitchoptions.length) > 0)
real_length = dist / Math.round(dist / this.stitchoptions.length);
else
real_length = dist
else
real_length = dist
if (dist < this.stitchoptions.length )
stepsize = dist;
else
stepsize = real_length;
} else {
stepsize = this.stitchoptions.length;
}
var steps = Math.floor(dist / stepsize);
var rest = dist - (steps * stepsize);
if ( this.isRunning && this.isDown && steps > 0 ) {
rest = Math.round(rest,8);
//stepsize = Math.round(stepsize,8);
this.setHeading(angle);
this.forwardSegemensWithEndCheck(steps, stepsize);
@ -855,7 +855,7 @@ SpriteMorph.prototype.gotoXY = function (x, y, justMe, noShadow) {
}
stage.moveTurtle(this.xPosition(), this.yPosition());
}
this.setHeading(oldheading);
}
};
@ -1575,9 +1575,9 @@ SpriteMorph.prototype.initBlocks = function () {
{
only: SpriteMorph,
type: 'command',
spec: 'tatami stitch width %n interval %n offset %n center %b',
spec: 'tatami stitch width %n interval %n center %b',
category: 'embroidery',
defaults: [100, 40, 10, true]
defaults: [100, 40, true]
};
this.blocks.tieStitch =
@ -2666,8 +2666,8 @@ StageMorph.prototype.initTurtle = function() {
function( err ) {
console.log( 'error loading turtle shpe' );
}
);
);
}
this.penSize = 1;
};