1
0
Fork 0

Added support for anchored sampling

This commit is contained in:
Joost De Cock 2018-09-06 15:32:43 +02:00
parent 951ba7bb3c
commit de4ffc1d69
3 changed files with 39 additions and 0 deletions

View file

@ -761,4 +761,19 @@ Path.prototype.trim = function() {
return this;
};
/** Applies a path translate transform */
Path.prototype.translate = function(x, y) {
for (let op of this.ops) {
if (op.type !== "close") {
op.to = op.to.translate(x, y);
}
if (op.type === "curve") {
op.cp1 = op.cp1.translate(x, y);
op.cp2 = op.cp2.translate(x, y);
}
}
return this;
};
export default Path;

View file

@ -111,6 +111,7 @@ Pattern.prototype.sampleParts = function() {
*/
Pattern.prototype.sampleOption = function(optionName) {
let step, val;
let anchors = {};
let parts = this.sampleParts();
let option = this.config.options[optionName];
if (typeof option.min === "undefined" || typeof option.max === "undefined") {
@ -126,10 +127,25 @@ Pattern.prototype.sampleOption = function(optionName) {
);
this.draft();
for (let i in this.parts) {
let anchor = false;
let dx = 0;
let dy = 0;
if (this.parts[i].points.anchor) {
if (typeof anchors[i] === "undefined")
anchors[i] = this.parts[i].points.anchor;
else {
if (!anchors[i].sitsOn(this.parts[i].points.anchor)) {
dx = this.parts[i].points.anchor.dx(anchors[i]);
dy = this.parts[i].points.anchor.dy(anchors[i]);
}
}
}
for (let j in this.parts[i].paths) {
parts[i].paths[j + "_" + l] = this.parts[i].paths[j]
.clone()
.attr("class", "sample-" + l, true);
if (this.parts[i].points.anchor)
parts[i].paths[j + "_" + l].translate(dx, dy);
}
}
val += step;

View file

@ -130,4 +130,12 @@ Point.prototype.clone = function() {
return clone;
};
/** Applies a translate transform */
Point.prototype.translate = function(x, y) {
this.x += x;
this.y += y;
return this;
};
export default Point;