Skip to content

Commit f4cbdf4

Browse files
committed
Bumped to version 0.2.1
1 parent 8cb8219 commit f4cbdf4

File tree

4 files changed

+3
-277
lines changed

4 files changed

+3
-277
lines changed

dist/StretchTransform.js

Lines changed: 1 addition & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ var Q = glm.quat;
1515
var ORIGINS = 0;
1616
var TARGETS = 1;
1717

18-
// Constants for weightingMode
19-
var SIMPLE = 0;
20-
var DIRECTIONAL = 1;
21-
2218
var TWO_PI = Math.PI * 2;
2319

2420
/**
@@ -505,7 +501,6 @@ function Anchor(pOrigin, pTarget) {
505501
this.originPosition = V.create();
506502
this.targetPosition = V.create();
507503
this.transformMatrix = M.create();
508-
this.directionalMatrices = [];
509504

510505
if (pTarget == undefined) pTarget = pOrigin;
511506

@@ -551,138 +546,6 @@ function Anchor(pOrigin, pTarget) {
551546
}
552547

553548

554-
Anchor.prototype.updateDirectionalMatrices = function(anchors) {
555-
this.directionalMatrices = [];
556-
557-
for (var i = 0; i < anchors.length; i++) {
558-
var otherAnchor = anchors[i];
559-
var matrix = M.create();
560-
var matrixDirection = V.create();
561-
562-
if (otherAnchor != this) {
563-
var originI = this.getOriginPosition();
564-
var originJ = otherAnchor.getOriginPosition();
565-
var targetI = this.getTargetPosition();
566-
var targetJ = otherAnchor.getTargetPosition();
567-
568-
// translation
569-
M.fromTranslation(matrix, V.fromValues(this.targetPosition[0] - this.originPosition[0], this.targetPosition[1] - this.originPosition[1], 0, 0));
570-
571-
// rotation
572-
var w1 = Math.atan2(originJ[1] - originI[1], originJ[0] - originI[0]);
573-
var w2 = Math.atan2(targetJ[1] - targetI[1], targetJ[0] - targetI[0]);
574-
var w = H.angleDifference(w2, w1);
575-
576-
M.rotate(matrix, matrix, w);
577-
578-
// scaling
579-
var d1 = V.dist(originJ, originI);
580-
var d2 = V.dist(targetJ, targetI);
581-
var s = d2 / d1;
582-
583-
if (d1 == 0 && d2 == 0)
584-
s = 1;
585-
else if (d1 == 0)
586-
s = 10;
587-
588-
M.scale(matrix, matrix, [s, s]);
589-
590-
// direction for this directionalMatrix
591-
matrixDirection = V.clone(originJ);
592-
V.sub(matrixDirection, matrixDirection, originI);
593-
V.normalize(matrixDirection, matrixDirection);
594-
595-
this.directionalMatrices.push(new DirectionalMatrix(matrix, matrixDirection));
596-
} else {
597-
this.directionalMatrices.push(null);
598-
}
599-
}
600-
}
601-
602-
Anchor.prototype.applyCumulatedMatrix = function(aToP, exponent, distweights) {
603-
var aToPResult = V.create();
604-
605-
var aToPNorm = V.clone(aToP);
606-
V.normalize(aToPNorm, aToPNorm);
607-
608-
var weights = [];
609-
var sum = 0;
610-
611-
for (var i = 0; i < this.directionalMatrices.length; i++) {
612-
if (this.directionalMatrices[i] != null) {
613-
var w = 1;
614-
615-
// weight depending on direction from anchor to point
616-
if (V.len(this.directionalMatrices[i].matrixDirection) > 0 && V.len(aToPNorm) > 0) {
617-
w = V.dot(this.directionalMatrices[i].matrixDirection, aToPNorm) + 1;
618-
if (w < 0) w = 0;
619-
w = Math.pow(w, exponent);
620-
}
621-
622-
// weight depending on distance
623-
w *= distweights[i];
624-
// w *= (0.5 + 0.5 * distweights[i]);
625-
626-
weights[i] = w;
627-
sum += weights[i];
628-
}
629-
}
630-
631-
for (var i = 0; i < this.directionalMatrices.length; i++) {
632-
if (this.directionalMatrices[i] != null) {
633-
var matrix = this.directionalMatrices[i].matrix;
634-
635-
weights[i] = weights[i] / sum;
636-
637-
var aToPTrans = V.create();
638-
V.transformMat4(aToPTrans, aToP, matrix);
639-
640-
// offset between the delta vector and the transformed delta vector
641-
var dvecOffset = V.create();
642-
V.sub(dvecOffset, aToPTrans, aToP);
643-
644-
// multiply this offset by the weight of this anchor
645-
V.scale(dvecOffset, dvecOffset, weights[i]);
646-
647-
// add up all offset
648-
V.add(aToPResult, aToPResult, dvecOffset);
649-
}
650-
}
651-
652-
return aToPResult;
653-
}
654-
655-
656-
657-
/*
658-
* float[] calcWeights(PVector p, ArrayList<Anchor> anchors, int mode) {
659-
*
660-
* // calculate distances between point and all original anchors float[]
661-
* dists = new float[anchors.length]; int n = dists.length;
662-
*
663-
* int k = -1; float minDist = 10000000;
664-
*
665-
* for (int i = 0; i < n; i++) { PVector otherPoint; if (mode ==
666-
* MultiTransform.ORIGINS) { otherPoint =
667-
* anchors[i].getOriginPosition(); } else { otherPoint =
668-
* anchors[i].getTargetPosition(); }
669-
*
670-
* dists[i] = PVector.dist(p, otherPoint); if (dists[i] < minDist && i !=
671-
* excludeIndex) { minDist = dists[i]; k = i; } }
672-
*
673-
* // calc attraction weights (sum of all weights must be 1) float[] weights
674-
* = new float[n];
675-
*
676-
* if (minDist == 0) { weights[k] = 1; } else { float[] distfacs = new
677-
* float[n]; float sum = 0;
678-
*
679-
* for (int i = 0; i < n; i++) { if (i != excludeIndex) { distfacs[i] = 1f /
680-
* (pow(dists[i], 1)); sum += distfacs[i]; } }
681-
*
682-
* for (int i = 0; i < n; i++) { weights[i] = distfacs[i] / sum; } }
683-
*
684-
* return weights; }
685-
*/
686549
}
687550

688551

@@ -814,7 +677,7 @@ THE SOFTWARE.
814677
},{}],3:[function(require,module,exports){
815678
module.exports={
816679
"name": "StretchTransform.js",
817-
"version": "0.2.0",
680+
"version": "0.2.1",
818681
"description": "A javascript library to transform a plane in a rubbery way.",
819682
"license": "MIT",
820683
"main": "index.js",

dist/StretchTransform.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js

Lines changed: 0 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ var Q = glm.quat;
1414
var ORIGINS = 0;
1515
var TARGETS = 1;
1616

17-
// Constants for weightingMode
18-
var SIMPLE = 0;
19-
var DIRECTIONAL = 1;
20-
2117
var TWO_PI = Math.PI * 2;
2218

2319
/**
@@ -504,7 +500,6 @@ function Anchor(pOrigin, pTarget) {
504500
this.originPosition = V.create();
505501
this.targetPosition = V.create();
506502
this.transformMatrix = M.create();
507-
this.directionalMatrices = [];
508503

509504
if (pTarget == undefined) pTarget = pOrigin;
510505

@@ -550,138 +545,6 @@ function Anchor(pOrigin, pTarget) {
550545
}
551546

552547

553-
Anchor.prototype.updateDirectionalMatrices = function(anchors) {
554-
this.directionalMatrices = [];
555-
556-
for (var i = 0; i < anchors.length; i++) {
557-
var otherAnchor = anchors[i];
558-
var matrix = M.create();
559-
var matrixDirection = V.create();
560-
561-
if (otherAnchor != this) {
562-
var originI = this.getOriginPosition();
563-
var originJ = otherAnchor.getOriginPosition();
564-
var targetI = this.getTargetPosition();
565-
var targetJ = otherAnchor.getTargetPosition();
566-
567-
// translation
568-
M.fromTranslation(matrix, V.fromValues(this.targetPosition[0] - this.originPosition[0], this.targetPosition[1] - this.originPosition[1], 0, 0));
569-
570-
// rotation
571-
var w1 = Math.atan2(originJ[1] - originI[1], originJ[0] - originI[0]);
572-
var w2 = Math.atan2(targetJ[1] - targetI[1], targetJ[0] - targetI[0]);
573-
var w = H.angleDifference(w2, w1);
574-
575-
M.rotate(matrix, matrix, w);
576-
577-
// scaling
578-
var d1 = V.dist(originJ, originI);
579-
var d2 = V.dist(targetJ, targetI);
580-
var s = d2 / d1;
581-
582-
if (d1 == 0 && d2 == 0)
583-
s = 1;
584-
else if (d1 == 0)
585-
s = 10;
586-
587-
M.scale(matrix, matrix, [s, s]);
588-
589-
// direction for this directionalMatrix
590-
matrixDirection = V.clone(originJ);
591-
V.sub(matrixDirection, matrixDirection, originI);
592-
V.normalize(matrixDirection, matrixDirection);
593-
594-
this.directionalMatrices.push(new DirectionalMatrix(matrix, matrixDirection));
595-
} else {
596-
this.directionalMatrices.push(null);
597-
}
598-
}
599-
}
600-
601-
Anchor.prototype.applyCumulatedMatrix = function(aToP, exponent, distweights) {
602-
var aToPResult = V.create();
603-
604-
var aToPNorm = V.clone(aToP);
605-
V.normalize(aToPNorm, aToPNorm);
606-
607-
var weights = [];
608-
var sum = 0;
609-
610-
for (var i = 0; i < this.directionalMatrices.length; i++) {
611-
if (this.directionalMatrices[i] != null) {
612-
var w = 1;
613-
614-
// weight depending on direction from anchor to point
615-
if (V.len(this.directionalMatrices[i].matrixDirection) > 0 && V.len(aToPNorm) > 0) {
616-
w = V.dot(this.directionalMatrices[i].matrixDirection, aToPNorm) + 1;
617-
if (w < 0) w = 0;
618-
w = Math.pow(w, exponent);
619-
}
620-
621-
// weight depending on distance
622-
w *= distweights[i];
623-
// w *= (0.5 + 0.5 * distweights[i]);
624-
625-
weights[i] = w;
626-
sum += weights[i];
627-
}
628-
}
629-
630-
for (var i = 0; i < this.directionalMatrices.length; i++) {
631-
if (this.directionalMatrices[i] != null) {
632-
var matrix = this.directionalMatrices[i].matrix;
633-
634-
weights[i] = weights[i] / sum;
635-
636-
var aToPTrans = V.create();
637-
V.transformMat4(aToPTrans, aToP, matrix);
638-
639-
// offset between the delta vector and the transformed delta vector
640-
var dvecOffset = V.create();
641-
V.sub(dvecOffset, aToPTrans, aToP);
642-
643-
// multiply this offset by the weight of this anchor
644-
V.scale(dvecOffset, dvecOffset, weights[i]);
645-
646-
// add up all offset
647-
V.add(aToPResult, aToPResult, dvecOffset);
648-
}
649-
}
650-
651-
return aToPResult;
652-
}
653-
654-
655-
656-
/*
657-
* float[] calcWeights(PVector p, ArrayList<Anchor> anchors, int mode) {
658-
*
659-
* // calculate distances between point and all original anchors float[]
660-
* dists = new float[anchors.length]; int n = dists.length;
661-
*
662-
* int k = -1; float minDist = 10000000;
663-
*
664-
* for (int i = 0; i < n; i++) { PVector otherPoint; if (mode ==
665-
* MultiTransform.ORIGINS) { otherPoint =
666-
* anchors[i].getOriginPosition(); } else { otherPoint =
667-
* anchors[i].getTargetPosition(); }
668-
*
669-
* dists[i] = PVector.dist(p, otherPoint); if (dists[i] < minDist && i !=
670-
* excludeIndex) { minDist = dists[i]; k = i; } }
671-
*
672-
* // calc attraction weights (sum of all weights must be 1) float[] weights
673-
* = new float[n];
674-
*
675-
* if (minDist == 0) { weights[k] = 1; } else { float[] distfacs = new
676-
* float[n]; float sum = 0;
677-
*
678-
* for (int i = 0; i < n; i++) { if (i != excludeIndex) { distfacs[i] = 1f /
679-
* (pow(dists[i], 1)); sum += distfacs[i]; } }
680-
*
681-
* for (int i = 0; i < n; i++) { weights[i] = distfacs[i] / sum; } }
682-
*
683-
* return weights; }
684-
*/
685548
}
686549

687550

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "StretchTransform.js",
3-
"version": "0.2.0",
3+
"version": "0.2.1",
44
"description": "A javascript library to transform a plane in a rubbery way.",
55
"license": "MIT",
66
"main": "index.js",

0 commit comments

Comments
 (0)