mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[wpiunits] Add Measure.per overloads for all known unit types (#7699)
Instead of only providing per(TimeUnit) Useful for making conversion factors easier, eg `Inches.of(10).per(Rotation)` vs `Inches.of(10).per(Rotation.one())` Update VelocityUnit.one() and VelocityUnit.zero() to return Velocity objects instead of generic Measure<? extends VelocityUnit<D>>; VelocityUnit is final, so the wildcard generic is unnecessary, and this makes the generated `per` functions possible for this type
This commit is contained in:
@@ -86,11 +86,6 @@ public interface {{ helpers['type_decl'](name) }} extends Measure<{{ helpers['mt
|
||||
default {{ helpers['type_usage'](name) }} divide(double divisor) {
|
||||
return ({{ helpers['type_usage'](name) }}) div(divisor);
|
||||
}
|
||||
|
||||
@Override
|
||||
default {{ config[name]['divide']['Time'] or "Velocity<{}>".format(helpers['mtou'](name)) }} per(TimeUnit period) {
|
||||
return div(period.of(1));
|
||||
}
|
||||
{% for unit in math_units -%}
|
||||
{% if unit == "Dimensionless" %}
|
||||
@Override
|
||||
@@ -147,6 +142,15 @@ public interface {{ helpers['type_decl'](name) }} extends Measure<{{ helpers['mt
|
||||
default {{ config[name]['divide'][unit] }} divide({{ unit }} divisor) {
|
||||
return div(divisor);
|
||||
}
|
||||
|
||||
@Override
|
||||
default {{ config[name]['divide'][unit] }} per({{ helpers['mtou'](unit) }} divisorUnit) {
|
||||
{%- if unit == "Mult<?, ?>" or unit == "Per<?, ?>" %}
|
||||
return div(divisorUnit.ofNative(1));
|
||||
{%- else %}
|
||||
return div(divisorUnit.one());
|
||||
{%- endif %}
|
||||
}
|
||||
{% elif unit == "Time" %}
|
||||
@Override
|
||||
default Velocity<{{ helpers['mtou'](name) }}> div({{ unit }} divisor) {
|
||||
@@ -164,6 +168,15 @@ public interface {{ helpers['type_decl'](name) }} extends Measure<{{ helpers['mt
|
||||
default Velocity<{{ helpers['mtou'](name) }}> divide({{ unit }} divisor) {
|
||||
return div(divisor);
|
||||
}
|
||||
|
||||
@Override
|
||||
default Velocity<{{ helpers['mtou'](name) }}> per({{ helpers['mtou'](unit) }} divisorUnit) {
|
||||
{%- if unit == "Mult<?, ?>" or unit == "Per<?, ?>" %}
|
||||
return div(divisorUnit.ofNative(1));
|
||||
{%- else %}
|
||||
return div(divisorUnit.one());
|
||||
{%- endif %}
|
||||
}
|
||||
{% elif unit == name %}
|
||||
@Override
|
||||
default Dimensionless div({{ unit }} divisor) {
|
||||
@@ -181,6 +194,11 @@ public interface {{ helpers['type_decl'](name) }} extends Measure<{{ helpers['mt
|
||||
default Dimensionless divide({{ unit }} divisor) {
|
||||
return div(divisor);
|
||||
}
|
||||
|
||||
@Override
|
||||
default Dimensionless per({{ helpers['mtou'](unit) }} divisorUnit) {
|
||||
return div(divisorUnit.one());
|
||||
}
|
||||
{% else %}
|
||||
@Override
|
||||
default Per<{{ helpers['mtou'](name) }}, {{ helpers['mtou'](unit) }}> div({{ unit }} divisor) {
|
||||
@@ -198,6 +216,15 @@ public interface {{ helpers['type_decl'](name) }} extends Measure<{{ helpers['mt
|
||||
default Per<{{ helpers['mtou'](name) }}, {{ helpers['mtou'](unit) }}> divide({{ unit }} divisor) {
|
||||
return div(divisor);
|
||||
}
|
||||
|
||||
@Override
|
||||
default Per<{{ helpers['mtou'](name) }}, {{ helpers['mtou'](unit) }}> per({{ helpers['mtou'](unit) }} divisorUnit) {
|
||||
{%- if unit == "Mult<?, ?>" or unit == "Per<?, ?>" %}
|
||||
return div(divisorUnit.ofNative(1));
|
||||
{%- else %}
|
||||
return div(divisorUnit.one());
|
||||
{%- endif %}
|
||||
}
|
||||
{% endif -%}
|
||||
{% endif -%}
|
||||
{% endfor -%}
|
||||
|
||||
Reference in New Issue
Block a user