✨ Added support for focus sampling of models (comparison)
This commit is contained in:
parent
f0793335f7
commit
072abb09b6
2 changed files with 38 additions and 3 deletions
|
@ -81,7 +81,10 @@ Pattern.prototype.sample = function() {
|
||||||
} else if (this.settings.sample.type === "measurement") {
|
} else if (this.settings.sample.type === "measurement") {
|
||||||
return this.sampleMeasurement(this.settings.sample.measurement);
|
return this.sampleMeasurement(this.settings.sample.measurement);
|
||||||
} else if (this.settings.sample.type === "models") {
|
} else if (this.settings.sample.type === "models") {
|
||||||
return this.sampleModels(this.settings.sample.models);
|
return this.sampleModels(
|
||||||
|
this.settings.sample.models,
|
||||||
|
this.settings.sample.focus || false
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -160,7 +163,7 @@ Pattern.prototype.sampleMeasurement = function(measurement) {
|
||||||
/**
|
/**
|
||||||
* Handles models sampling
|
* Handles models sampling
|
||||||
*/
|
*/
|
||||||
Pattern.prototype.sampleModels = function(models) {
|
Pattern.prototype.sampleModels = function(models, focus = false) {
|
||||||
let parts = this.sampleParts();
|
let parts = this.sampleParts();
|
||||||
let count = 0;
|
let count = 0;
|
||||||
for (let l in models) {
|
for (let l in models) {
|
||||||
|
@ -172,7 +175,9 @@ Pattern.prototype.sampleModels = function(models) {
|
||||||
for (let j in this.parts[i].paths) {
|
for (let j in this.parts[i].paths) {
|
||||||
parts[i].paths[j + "_" + count] = this.parts[i].paths[j]
|
parts[i].paths[j + "_" + count] = this.parts[i].paths[j]
|
||||||
.clone()
|
.clone()
|
||||||
.attr("class", "sample-" + count, true);
|
.attr("class", "sample sample-" + count, true);
|
||||||
|
if (l === focus)
|
||||||
|
parts[i].paths[j + "_" + count].attr("class", "sample-focus");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,6 +108,36 @@ it("Should sample models", () => {
|
||||||
expect(pattern.parts.b.paths.test_2.ops[1].to.x).to.equal(10);
|
expect(pattern.parts.b.paths.test_2.ops[1].to.x).to.equal(10);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("Should sample models with focus", () => {
|
||||||
|
let pattern = new freesewing.Pattern();
|
||||||
|
pattern.draft = function() {
|
||||||
|
pattern.parts.a = new pattern.Part();
|
||||||
|
pattern.parts.b = new pattern.Part();
|
||||||
|
let a = pattern.parts.a;
|
||||||
|
a.points.from = new a.Point(0, 0);
|
||||||
|
a.points.to = new a.Point(10, a.context.config.measurements.headToToe);
|
||||||
|
a.paths.test = new a.Path().move(a.points.from).line(a.points.to);
|
||||||
|
pattern.parts.b.copy(a);
|
||||||
|
};
|
||||||
|
pattern.settings.sample = {
|
||||||
|
type: "models",
|
||||||
|
focus: "a",
|
||||||
|
models: {
|
||||||
|
a: { headToToe: 1980 },
|
||||||
|
b: { headToToe: 1700 }
|
||||||
|
}
|
||||||
|
};
|
||||||
|
pattern.sample();
|
||||||
|
expect(pattern.parts.a.paths.test_1.render).to.equal(true);
|
||||||
|
expect(pattern.parts.b.paths.test_2.ops[1].to.x).to.equal(10);
|
||||||
|
expect(pattern.parts.a.paths.test_1.attributes.get("class")).to.equal(
|
||||||
|
"sample sample-1 sample-focus"
|
||||||
|
);
|
||||||
|
expect(pattern.parts.b.paths.test_2.attributes.get("class")).to.equal(
|
||||||
|
"sample sample-2"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it("Should register a hook via on", () => {
|
it("Should register a hook via on", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new freesewing.Pattern();
|
||||||
let count = 0;
|
let count = 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue