Scalable.java
package org.djunits.value;
/**
* Scalable indicates that elements of this type can be scaled by a dimensionless factor, based on their SI-values. Note that
* not all unit-carrying elements are scalable. An example is an absolute scalar (e.g., a date) that cannot be multiplied by 2.
* <p>
* Warning: scaling operations on units with an Offset Scale might lead to unexpected answers. 2 * 10 °C = 293.15 °C and
* not 20 °C. Copyright (c) 2025-2026 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All
* rights reserved. See for project information <a href="https://djunits.org" target="_blank">https://djunits.org</a>. The
* DJUNITS project is distributed under a <a href="https://djunits.org/docs/license.html" target="_blank">three-clause BSD-style
* license</a>.
* @author Alexander Verbraeck
* @param <T> the element type
*/
public interface Scalable<T extends Scalable<T>>
{
/**
* Scale the element by a dimensionless factor, based on the SI-values. Note that this can lead to unwanted effects for
* elements with Offset scales. 2 * 10 °C = 293.15 °C and not 20 °C.
* @param factor the dimensionless scale factor
* @return a new element with all of its SI-values scaled by the dimensionless factor
*/
T scaleBy(double factor);
/**
* Divide the element's value by a dimensionless factor, based on the SI-values. Note that this can lead to unwanted effects
* for elements with Offset scales. 10 °C / 2.0 = -131.575 °C and not 5 °C.
* @param divisor the dimensionless divisor
* @return a new element with all of its SI-values divided by the dimensionless divisor
*/
default T divideBy(final double divisor)
{
return scaleBy(1.0 / divisor);
}
}