pctBasedOn in more options in Simon?

Dunno whether this is ‘help with software’ or ‘help with patterns’. It’s about the code for Simon.

Is there a reason why many of the options have no ‘…pctBasedOn()’? E.g., I want to specify my button (hole) placket width in cm, not in %. It would be easy if there was the aforementioned annotation in the buttonPlacketWidth.

Would it be bad (i.e., cause problems somehow) to add those and make a pull request from it? Or are there dependencies that would clash with backward compatibility or something? Any reasons why this would not work as easily as I imagine?

Best regards,

Henrik

As far as I understand it, most, if not all, of those percentage options on patterns are done that way as they are a percentage of another measurement, eg sleeve length is a percentage of shoulder to wrist measurement. It’s the easiest way to calculate those measurements, while having them scale to the intended wearer. the placket measurement is likely a percentage of chest circumference for the front placket and wrist circumference for the cuff placket

Sometimes this is possible, because the percentage is a direct part of a measurement. Sometimes it is not possible (easily) because it is a percentage of something that is itself based on more than one thing. And that cannot be expressed in the pctBasedOn or toAbs.

I just added options to simon for short sleeves, and the length of the sleeve and the size of the hem are simple percentages of a measurement. So I added those pctBasedOn functions to the options.

Since I haven’t created a PR yet for it, I’ll have a look at the other existing options.

1 Like

Many designs (including Simon) predate that feature. And going back to backport the feature into the design is one of those things that is perpetually on my todo list, but I never seem to get around to.

Obviously, as Wouter said, for some options it might not be trivial to do so, but even where it us trivial it’s often not done because it’s a lot of work to go through all designs and add it in.

1 Like

Ah, OK, no problem.

A related question: Is there a way to add a percentage on other computed values, too? Or only on measurements? E.g., in my local copy, I added a button placket shift to better hide the button placket under the button hole placket (without shifting the button line, of course), and it only makes sense to adjust it within 0% to 50% of the button placket width, but I don’t seem to be able to do …pctBasedOn(‘buttonPlacketWidth’), I get NaNcm then. :stuck_out_tongue: But making it 0%..4% of ‘neck’ measurement is kinda a bit awkward. Works, but it’s not ideal. I suppose making it work on computed measurements (in the store) isn’t trivial because we’d run into an ordering problem in the computation, right? Or maybe the computations are not at all done when the UI renderer needs them.

Just my curiosity, I am still reading and learning how the parts of the code interact.

It’s a good question. The pctBasedOn() method is a helper function to facilitate the (common) use case where an option’s absolute value is a percentage of a given measurement.

For those options where things are not so straight-forward, such as your option that relies on the button placket width, you can implement your own logic by specifying an toAbs() method.

This method has the following signature:

function toAbs(percentage, settings, mergedOptions) {   
  // return value in millimeter here 
}

[docs here]

So, this function receives the current options percentage, the settings are used by the user, and the merged options, which are the options selected by the user merged with the default values for options.

So, you can do a lot more this way.

1 Like

The source code for pctBasedOn() should make it pretty clear how it works:

export function pctBasedOn(measurement) {
  return {
    toAbs: (val, { measurements }) => measurements[measurement] * val,
    fromAbs: (val, { measurements }) =>
      Math.round((10000 * val) / measurements[measurement]) / 10000,
  }
}

It’s just a convenient way to add a toAbs and fromAbs based on a measurement. But nothing stops you from adding your own based on some other logic.

1 Like

Wow, thanks for the detailed pointers!! :slight_smile:

Since I was working on an enhancement for simon, I went through all the options and added pctBasedOn or toAbs where is was reasonable to implement. PR is done.

3 Likes

So fast! You are amazing, thank you! I’d probably have tried to tackle it next week, but you were faster. :slight_smile: