001// Copyright (c) FIRST and other WPILib contributors.
002// Open Source Software; you can modify and/or share it under the terms of
003// the WPILib BSD license file in the root directory of this project.
004
005package edu.wpi.first.units;
006
007import edu.wpi.first.units.measure.AngularAcceleration;
008
009/** A unit of angular acceleration, such as {@link Units#RadiansPerSecondPerSecond}. */
010public final class AngularAccelerationUnit extends PerUnit<AngularVelocityUnit, TimeUnit> {
011  private static final CombinatoryUnitCache<AngularVelocityUnit, TimeUnit, AngularAccelerationUnit>
012      cache = new CombinatoryUnitCache<>(AngularAccelerationUnit::new);
013
014  AngularAccelerationUnit(AngularVelocityUnit velocity, TimeUnit period) {
015    super(
016        velocity.isBaseUnit() && period.isBaseUnit()
017            ? null
018            : combine(velocity.getBaseUnit(), period.getBaseUnit()),
019        velocity,
020        period);
021  }
022
023  AngularAccelerationUnit(
024      AngularAccelerationUnit baseUnit,
025      UnaryFunction toBaseConverter,
026      UnaryFunction fromBaseConverter,
027      String name,
028      String symbol) {
029    super(baseUnit, toBaseConverter, fromBaseConverter, name, symbol);
030  }
031
032  /**
033   * Combines an angular velocity and time period unit into an angular acceleration.
034   *
035   * @param velocity the unit of velocity
036   * @param period the unit of time
037   * @return the combined angular acceleration unit
038   */
039  public static AngularAccelerationUnit combine(AngularVelocityUnit velocity, TimeUnit period) {
040    return cache.combine(velocity, period);
041  }
042
043  @Override
044  public AngularAccelerationUnit getBaseUnit() {
045    return (AngularAccelerationUnit) super.getBaseUnit();
046  }
047
048  @Override
049  public AngularAcceleration of(double magnitude) {
050    return new AngularAcceleration(magnitude, toBaseUnits(magnitude), this);
051  }
052
053  @Override
054  public AngularAcceleration ofBaseUnits(double baseUnitMagnitude) {
055    return new AngularAcceleration(fromBaseUnits(baseUnitMagnitude), baseUnitMagnitude, this);
056  }
057
058  @Override
059  public AngularAcceleration zero() {
060    return (AngularAcceleration) super.zero();
061  }
062
063  @Override
064  public AngularAcceleration one() {
065    return (AngularAcceleration) super.one();
066  }
067
068  @Override
069  public VelocityUnit<AngularAccelerationUnit> per(TimeUnit time) {
070    return VelocityUnit.combine(this, time);
071  }
072
073  /**
074   * Creates a ratio unit between this unit and an arbitrary other unit.
075   *
076   * @param other the other unit
077   * @param <U> the type of the other unit
078   * @return the ratio unit
079   */
080  public <U extends Unit> PerUnit<AngularAccelerationUnit, U> per(U other) {
081    return PerUnit.combine(this, other);
082  }
083
084  /**
085   * Converts a measurement value in terms of another unit to this unit.
086   *
087   * @param magnitude the magnitude of the measurement in terms of the other unit
088   * @param otherUnit the other unit
089   * @return the value of the measurement in terms of this unit
090   */
091  public double convertFrom(double magnitude, AngularAccelerationUnit otherUnit) {
092    return fromBaseUnits(otherUnit.toBaseUnits(magnitude));
093  }
094}