Interface PointNFloat<P extends PointNFloat<P,R>, R extends com.github.tommyettinger.crux.PointN<?>>

Type Parameters:
P - should be the subclassing type itself
R - should be a wildcard-generic type for a sub-interface of PointN, such as Point3<?>
All Superinterfaces:
com.github.tommyettinger.crux.PointN<P>, com.github.tommyettinger.crux.PointNFloat<P,R>
All Known Implementing Classes:
Point2Float, Point3Float, Point4Float, Point5Float, Point6Float

public interface PointNFloat<P extends PointNFloat<P,R>, R extends com.github.tommyettinger.crux.PointN<?>> extends com.github.tommyettinger.crux.PointNFloat<P,R>
Groups functionality common to points with float components, in any dimension.
  • Method Summary

    Modifier and Type
    Method
    Description
    default boolean
     
    float
    get(int index)
    Gets the component at the specified index.
    default P
    interpolate(R target, float alpha, com.github.tommyettinger.digital.Interpolations.Interpolator interpolation)
    Calls lerp(PointN, float) with the alpha determined by the given interpolation.
    default PointNFloat<P,R>
    Assigns to each component of this point 1f divided by its original value.
    lerp(R target, float alpha)
    Linear-interpolates from this point toward target, moving a distance proportional to alpha and changing this point in-place if possible.
    setAt(int index, float value)
    Sets the component at the specified index to the specified value.
    Sets this PointNFloat to a randomly chosen unit vector.
    static <P extends PointNFloat<P,?>>
    P
    slerpGeometric(P start, P end, float alpha, P output)
    A geometric "slerp" (spherical linear interpolation) from the input n-dimensional float point start to the point end with the same type, moving a fraction of the distance equal to alpha, and placing the result in output (modifying it in-place).

    Methods inherited from interface com.github.tommyettinger.crux.PointN

    add, cpy, div, divide, dst, dst2, isUnit, isUnit, isZero, isZero, len, len2, minus, mutable, nor, plus, rank, scl, set, setZero, sub, times
  • Method Details

    • floatingPoint

      default boolean floatingPoint()
      Specified by:
      floatingPoint in interface com.github.tommyettinger.crux.PointN<P extends PointNFloat<P,R>>
      Specified by:
      floatingPoint in interface com.github.tommyettinger.crux.PointNFloat<P extends PointNFloat<P,R>, R extends com.github.tommyettinger.crux.PointN<?>>
    • inverse

      default PointNFloat<P,R> inverse()
      Assigns to each component of this point 1f divided by its original value. If a component is 0.0f, its value after this will be positive infinity. If a component is -0.0f, its value after this will be negative infinity. If a component is NaN, its value after this will be NaN.
      Specified by:
      inverse in interface com.github.tommyettinger.crux.PointNFloat<P extends PointNFloat<P,R>, R extends com.github.tommyettinger.crux.PointN<?>>
      Returns:
      1f divided by this point, assigned in-place to this
    • get

      float get(int index)
      Gets the component at the specified index. Kotlin-compatible using square-bracket indexing.
      Specified by:
      get in interface com.github.tommyettinger.crux.PointNFloat<P extends PointNFloat<P,R>, R extends com.github.tommyettinger.crux.PointN<?>>
      Parameters:
      index - which component to get, in order
      Returns:
      the component
    • setAt

      P setAt(int index, float value)
      Sets the component at the specified index to the specified value.
      Specified by:
      setAt in interface com.github.tommyettinger.crux.PointNFloat<P extends PointNFloat<P,R>, R extends com.github.tommyettinger.crux.PointN<?>>
      Parameters:
      index - which component to set, in order
      value - the value to assign at index
      Returns:
      this, for chaining
    • setToRandomDirection

      P setToRandomDirection(Random random)
      Sets this PointNFloat to a randomly chosen unit vector. The exact algorithm is expected to vary between dimensions. In 2D, for instance, it is sufficient to get a random float between 0 and 1, and call TrigTools.cosTurns(float) and TrigTools.sinTurns(float) to get x and y. In higher dimensions, this gets more complex. A solution that works for any dimension, but is only the best option for 4D and up, is to assign to each component a normal-distributed float using Distributor.probitF(float) with random inputs, then normalize the PointNFloat with PointN.nor().
      Parameters:
      random - any Random or subclass thereof
      Returns:
      this point after modifications, if possible, or a new PointNFloat if this is immutable
    • lerp

      P lerp(R target, float alpha)
      Linear-interpolates from this point toward target, moving a distance proportional to alpha and changing this point in-place if possible. If this point is not PointN.mutable(), this will return a new or pooled point. The alpha is expected to be in the 0 to 1 range, inclusive.
      Specified by:
      lerp in interface com.github.tommyettinger.crux.PointNFloat<P extends PointNFloat<P,R>, R extends com.github.tommyettinger.crux.PointN<?>>
      Parameters:
      target - any point with the same dimension to move toward
      alpha - between 0 and 1, inclusive
      Returns:
      this point after modifications, if possible, or a new PointNFloat if this is immutable
    • interpolate

      default P interpolate(R target, float alpha, com.github.tommyettinger.digital.Interpolations.Interpolator interpolation)
      Calls lerp(PointN, float) with the alpha determined by the given interpolation. Simply returns lerp(target, interpolation.apply(alpha)) .
      Parameters:
      target - any point with the same dimension to move toward
      alpha - between 0 and 1, inclusive
      interpolation - an Interpolator from digital, such as Interpolations.smooth
      Returns:
      this point after modifications, if possible, or a new PointNFloat if this is immutable
    • slerpGeometric

      static <P extends PointNFloat<P,?>> P slerpGeometric(P start, P end, float alpha, P output)
      A geometric "slerp" (spherical linear interpolation) from the input n-dimensional float point start to the point end with the same type, moving a fraction of the distance equal to alpha, and placing the result in output (modifying it in-place). Unlike most slerp() implementations, this works for any PointNFloat type, including 2D points on a unit circle and 4D, 5D, etc. points on hyperspheres. This does not allocate. This has undefined behavior if start and end are polar opposites; that is, points where for any coordinate a in start, that coordinate in end is -a or any positive linear scale of the point where that is true. This degenerates to a linear interpolation if either start or end is the origin, and simply returns the start if both are the origin. Otherwise, this can smoothly move points that aren't already on the unit sphere towards the distance of the other point from the origin.
      Based on the non-approximation code from an article by Volodymyr Agafonkin. Note that this is the "geometric slerp" rather than the version using quaternions in 3D (or rotors in other dimensions). It has been augmented slightly to handle start and end vectors that don't have unit length. This is very similar to RotationTools.slerp(int, float[], int, float[], int, float, float[], int).
      Parameters:
      start - an n-dimensional float point to rotate from; will not be modified
      end - another n-dimensional float point to rotate to; will not be modified
      alpha - between 0 and 1, inclusive; how much to travel from start towards end
      output - will be modified in-place so this is set to the result
      Returns:
      output, after modifications.