Honor scale setting in miniscale
This commit is contained in:
parent
acf3fff4f9
commit
83a153eaf5
2 changed files with 53 additions and 6 deletions
|
@ -17,8 +17,25 @@ export default function (so) {
|
||||||
for (let id of ['__miniscaleMetric', '__miniscaleImperial']) delete this.paths[id]
|
for (let id of ['__miniscaleMetric', '__miniscaleImperial']) delete this.paths[id]
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
const m = 12.5
|
|
||||||
const i = 12.7
|
const scale = this.context.settings.scale
|
||||||
|
|
||||||
|
// Convert scale to a value between 0 and 5, inclusive.
|
||||||
|
const scaleIndex = Math.ceil(6 * Math.max(0.1, Math.min(1, this.context.settings.scale))) - 1
|
||||||
|
|
||||||
|
// Metric size in mm / display value and imperial size in mm / display value for each scale index.
|
||||||
|
const sizes = [
|
||||||
|
[10, "1cm", 25.4 * 0.375, '⅜″'],
|
||||||
|
[13, "1.3cm", 25.4 * 0.5, '½″'],
|
||||||
|
[16, "1.6cm", 25.4 * 0.625, '⅝″'],
|
||||||
|
[19, "1.9cm", 25.4 * 0.75, '¾″'],
|
||||||
|
[22, "2.2cm", 25.4 * 0.875, '⅞″'],
|
||||||
|
[25, "2.5cm", 25.4 * 1, '1″'],
|
||||||
|
]
|
||||||
|
const m = sizes[scaleIndex][0] / 2
|
||||||
|
const i = sizes[scaleIndex][2] / 2
|
||||||
|
const metricDisplaySize = sizes[scaleIndex][1]
|
||||||
|
const imperialDisplaySize = sizes[scaleIndex][3]
|
||||||
// Box points
|
// Box points
|
||||||
this.points.__miniscaleMetricTopLeft = new this.Point(so.at.x - m, so.at.y - m)
|
this.points.__miniscaleMetricTopLeft = new this.Point(so.at.x - m, so.at.y - m)
|
||||||
this.points.__miniscaleMetricTopRight = new this.Point(so.at.x + m, so.at.y - m)
|
this.points.__miniscaleMetricTopRight = new this.Point(so.at.x + m, so.at.y - m)
|
||||||
|
@ -29,8 +46,8 @@ export default function (so) {
|
||||||
this.points.__miniscaleImperialBottomLeft = new this.Point(so.at.x - i, so.at.y + i)
|
this.points.__miniscaleImperialBottomLeft = new this.Point(so.at.x - i, so.at.y + i)
|
||||||
this.points.__miniscaleImperialBottomRight = new this.Point(so.at.x + i, so.at.y + i)
|
this.points.__miniscaleImperialBottomRight = new this.Point(so.at.x + i, so.at.y + i)
|
||||||
// Text anchor points
|
// Text anchor points
|
||||||
this.points.__miniscaleMetric = new this.Point(so.at.x, so.at.y - 2)
|
this.points.__miniscaleMetric = new this.Point(so.at.x, so.at.y - 2 * scale)
|
||||||
this.points.__miniscaleImperial = new this.Point(so.at.x, so.at.y + 8)
|
this.points.__miniscaleImperial = new this.Point(so.at.x, so.at.y + 8 * scale)
|
||||||
// Rotation
|
// Rotation
|
||||||
if (so.rotate) {
|
if (so.rotate) {
|
||||||
let points = [
|
let points = [
|
||||||
|
@ -70,9 +87,9 @@ export default function (so) {
|
||||||
.close()
|
.close()
|
||||||
// Text
|
// Text
|
||||||
this.points.__miniscaleMetric = this.points.__miniscaleMetric
|
this.points.__miniscaleMetric = this.points.__miniscaleMetric
|
||||||
.attr('data-text', '2.5cm x 2.5cm')
|
.attr('data-text', `${metricDisplaySize} x ${metricDisplaySize}`)
|
||||||
.attr('data-text-class', 'text-xs center')
|
.attr('data-text-class', 'text-xs center')
|
||||||
this.points.__miniscaleImperial = this.points.__miniscaleImperial
|
this.points.__miniscaleImperial = this.points.__miniscaleImperial
|
||||||
.attr('data-text', '1" x 1"')
|
.attr('data-text', `${imperialDisplaySize} x ${imperialDisplaySize}`)
|
||||||
.attr('data-text-class', 'text-xs center ')
|
.attr('data-text-class', 'text-xs center ')
|
||||||
}
|
}
|
||||||
|
|
|
@ -187,4 +187,34 @@ describe('Scalebox Plugin Tests', () => {
|
||||||
expect(p.__scaleboxImperial.attributes.get('data-text'))
|
expect(p.__scaleboxImperial.attributes.get('data-text'))
|
||||||
.to.equal("theBlackOutsideOfThisBoxShouldMeasure 2″ x 1″")
|
.to.equal("theBlackOutsideOfThisBoxShouldMeasure 2″ x 1″")
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("Should apply scale to the miniscale macro", () => {
|
||||||
|
const pattern = new freesewing.Pattern().use(plugin)
|
||||||
|
pattern.settings.scale = 0.5
|
||||||
|
pattern.parts.test = new pattern.Part();
|
||||||
|
pattern.parts.test.points.anchor = new pattern.Point(100, 200);
|
||||||
|
const { macro } = pattern.parts.test.shorthand()
|
||||||
|
macro("miniscale", {
|
||||||
|
at: pattern.parts.test.points.anchor
|
||||||
|
});
|
||||||
|
let p = pattern.parts.test.points;
|
||||||
|
expect(p.__miniscaleMetricTopLeft.x).to.equal(92);
|
||||||
|
expect(p.__miniscaleMetricTopLeft.y).to.equal(192);
|
||||||
|
expect(p.__miniscaleMetricTopRight.x).to.equal(108);
|
||||||
|
expect(p.__miniscaleMetricTopRight.y).to.equal(192);
|
||||||
|
expect(p.__miniscaleMetricBottomLeft.x).to.equal(92);
|
||||||
|
expect(p.__miniscaleMetricBottomLeft.y).to.equal(208);
|
||||||
|
expect(p.__miniscaleMetricBottomRight.x).to.equal(108);
|
||||||
|
expect(p.__miniscaleMetricBottomRight.y).to.equal(208);
|
||||||
|
expect(p.__miniscaleImperialTopLeft.x).to.equal(92.0625);
|
||||||
|
expect(p.__miniscaleImperialTopLeft.y).to.equal(192.0625);
|
||||||
|
expect(p.__miniscaleImperialTopRight.x).to.equal(107.9375);
|
||||||
|
expect(p.__miniscaleImperialTopRight.y).to.equal(192.0625);
|
||||||
|
expect(p.__miniscaleImperialBottomLeft.x).to.equal(92.0625);
|
||||||
|
expect(p.__miniscaleImperialBottomLeft.y).to.equal(207.9375);
|
||||||
|
expect(p.__miniscaleImperialBottomRight.x).to.equal(107.9375);
|
||||||
|
expect(p.__miniscaleImperialBottomRight.y).to.equal(207.9375);
|
||||||
|
expect(p.__miniscaleMetric.attributes.get('data-text')).to.equal("1.6cm x 1.6cm")
|
||||||
|
expect(p.__miniscaleImperial.attributes.get('data-text')).to.equal("⅝″ x ⅝″")
|
||||||
|
});
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue