✨ Added support for anchored sampling
This commit is contained in:
parent
951ba7bb3c
commit
de4ffc1d69
3 changed files with 39 additions and 0 deletions
15
src/path.js
15
src/path.js
|
@ -761,4 +761,19 @@ Path.prototype.trim = function() {
|
||||||
return this;
|
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;
|
export default Path;
|
||||||
|
|
|
@ -111,6 +111,7 @@ Pattern.prototype.sampleParts = function() {
|
||||||
*/
|
*/
|
||||||
Pattern.prototype.sampleOption = function(optionName) {
|
Pattern.prototype.sampleOption = function(optionName) {
|
||||||
let step, val;
|
let step, val;
|
||||||
|
let anchors = {};
|
||||||
let parts = this.sampleParts();
|
let parts = this.sampleParts();
|
||||||
let option = this.config.options[optionName];
|
let option = this.config.options[optionName];
|
||||||
if (typeof option.min === "undefined" || typeof option.max === "undefined") {
|
if (typeof option.min === "undefined" || typeof option.max === "undefined") {
|
||||||
|
@ -126,10 +127,25 @@ Pattern.prototype.sampleOption = function(optionName) {
|
||||||
);
|
);
|
||||||
this.draft();
|
this.draft();
|
||||||
for (let i in this.parts) {
|
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) {
|
for (let j in this.parts[i].paths) {
|
||||||
parts[i].paths[j + "_" + l] = this.parts[i].paths[j]
|
parts[i].paths[j + "_" + l] = this.parts[i].paths[j]
|
||||||
.clone()
|
.clone()
|
||||||
.attr("class", "sample-" + l, true);
|
.attr("class", "sample-" + l, true);
|
||||||
|
if (this.parts[i].points.anchor)
|
||||||
|
parts[i].paths[j + "_" + l].translate(dx, dy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val += step;
|
val += step;
|
||||||
|
|
|
@ -130,4 +130,12 @@ Point.prototype.clone = function() {
|
||||||
return clone;
|
return clone;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Applies a translate transform */
|
||||||
|
Point.prototype.translate = function(x, y) {
|
||||||
|
this.x += x;
|
||||||
|
this.y += y;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
export default Point;
|
export default Point;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue