From 072abb09b6d740979901eca68e0469440e36ec66 Mon Sep 17 00:00:00 2001 From: Joost De Cock Date: Fri, 24 Aug 2018 20:16:01 +0200 Subject: [PATCH] :sparkles: Added support for focus sampling of models (comparison) --- src/pattern.js | 11 ++++++++--- tests/pattern.test.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/pattern.js b/src/pattern.js index 84dc46ad0f9..9337ccf31fd 100644 --- a/src/pattern.js +++ b/src/pattern.js @@ -81,7 +81,10 @@ Pattern.prototype.sample = function() { } else if (this.settings.sample.type === "measurement") { return this.sampleMeasurement(this.settings.sample.measurement); } 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 */ -Pattern.prototype.sampleModels = function(models) { +Pattern.prototype.sampleModels = function(models, focus = false) { let parts = this.sampleParts(); let count = 0; for (let l in models) { @@ -172,7 +175,9 @@ Pattern.prototype.sampleModels = function(models) { for (let j in this.parts[i].paths) { parts[i].paths[j + "_" + count] = this.parts[i].paths[j] .clone() - .attr("class", "sample-" + count, true); + .attr("class", "sample sample-" + count, true); + if (l === focus) + parts[i].paths[j + "_" + count].attr("class", "sample-focus"); } } } diff --git a/tests/pattern.test.js b/tests/pattern.test.js index ab1a8786899..4ce854967c2 100644 --- a/tests/pattern.test.js +++ b/tests/pattern.test.js @@ -108,6 +108,36 @@ it("Should sample models", () => { 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", () => { let pattern = new freesewing.Pattern(); let count = 0;