bordado.spacing_to_size

Contents

bordado.spacing_to_size#

bordado.spacing_to_size(start, stop, spacing, *, adjust='spacing')[source]#

Convert a spacing to the number of points between start and stop.

Takes into account if the spacing or the interval needs to be adjusted in order to fit exactly. This is needed when the interval is not a multiple of the spacing.

Parameters:
startfloat

The starting value of the sequence.

stopfloat

The end value of the sequence.

spacingfloat

The step size (interval) between points in the sequence.

adjust{‘spacing’, ‘region’}

Whether to adjust the spacing or the interval/region if required. Defaults to adjusting the spacing.

Returns:
sizeint

The number of points between start and stop.

startfloat

The end of the interval, which may or may not have been adjusted.

stopfloat

The end of the interval, which may or may not have been adjusted.

Examples

If the spacing is a multiple of the interval, then the size is how many points fit in the interval and the start and stop values are maintained:

>>> size, start, stop = spacing_to_size(0, 1, 0.5)
>>> print(size, start, stop)
3 0 1

If the spacing is not a multiple, then it will be adjusted to fit the interval by default. In this case, then number of points remains the same:

>>> size, start, stop = spacing_to_size(0, 1, 0.6)
>>> print(size, start, stop)
3 0 1

Alternatively, we can ask it to adjust the region instead of the spacing between points:

>>> size, start, stop = spacing_to_size(0, 1, 0.6, adjust="region")
>>> print(f"{size} {start:.1f} {stop:.1f}")
3 -0.1 1.1