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.Angle;
008
009/**
010 * Unit of angular dimension.
011 *
012 * <p>This is the base type for units of angular dimension. It is also used to specify the dimension
013 * for {@link Measure}: <code>Measure&lt;AngleUnit&gt;</code>.
014 *
015 * <p>Actual units (such as {@link Units#Degrees} and {@link Units#Radians}) can be found in the
016 * {@link Units} class.
017 */
018// technically, angles are unitless dimensions
019// eg MassUnit * DistanceUnit * VelocityUnit<AngleUnit> is equivalent to (MassUnit * DistanceUnit) /
020// TimeUnit - otherwise known
021// as PowerUnit - in other words, VelocityUnit<AngleUnit> is /actually/ Frequency
022public final class AngleUnit extends Unit {
023  AngleUnit(AngleUnit baseUnit, double baseUnitEquivalent, String name, String symbol) {
024    super(baseUnit, baseUnitEquivalent, name, symbol);
025  }
026
027  AngleUnit(
028      AngleUnit baseUnit,
029      UnaryFunction toBaseConverter,
030      UnaryFunction fromBaseConverter,
031      String name,
032      String symbol) {
033    super(baseUnit, toBaseConverter, fromBaseConverter, name, symbol);
034  }
035
036  @Override
037  public AngleUnit getBaseUnit() {
038    return (AngleUnit) super.getBaseUnit();
039  }
040
041  @Override
042  public Angle of(double magnitude) {
043    return Angle.ofRelativeUnits(magnitude, this);
044  }
045
046  @Override
047  public Angle ofBaseUnits(double baseUnitMagnitude) {
048    return Angle.ofBaseUnits(baseUnitMagnitude, this);
049  }
050
051  @Override
052  public AngularVelocityUnit per(TimeUnit period) {
053    return AngularVelocityUnit.combine(this, period);
054  }
055
056  /**
057   * Creates a ratio unit between this unit and an arbitrary other unit.
058   *
059   * @param other the other unit
060   * @param <U> the type of the other unit
061   * @return the ratio unit
062   */
063  public <U extends Unit> PerUnit<AngleUnit, U> per(U other) {
064    return PerUnit.combine(this, other);
065  }
066
067  /**
068   * Converts a measurement value in terms of another angle unit to this unit.
069   *
070   * @param magnitude the magnitude of the measurement in terms of the other angle unit
071   * @param otherUnit the other angle unit
072   * @return the value of the measurement in terms of this unit
073   */
074  public double convertFrom(double magnitude, AngleUnit otherUnit) {
075    return fromBaseUnits(otherUnit.toBaseUnits(magnitude));
076  }
077
078  @Override
079  public Angle zero() {
080    return (Angle) super.zero();
081  }
082
083  @Override
084  public Angle one() {
085    return (Angle) super.one();
086  }
087}