Class Point2Float

java.lang.Object
com.github.yellowstonegames.grid.Point2Float
All Implemented Interfaces:
com.github.tommyettinger.crux.Point2<Point2Float>, com.github.tommyettinger.crux.PointN<Point2Float>, com.github.tommyettinger.crux.PointNFloat<Point2Float, com.github.tommyettinger.crux.Point2<?>>, com.github.tommyettinger.ds.PrimitiveCollection<Float>, com.github.tommyettinger.ds.PrimitiveCollection.OfFloat, PointNFloat<Point2Float, com.github.tommyettinger.crux.Point2<?>>

public class Point2Float extends Object implements com.github.tommyettinger.crux.Point2<Point2Float>, PointNFloat<Point2Float, com.github.tommyettinger.crux.Point2<?>>, com.github.tommyettinger.ds.PrimitiveCollection.OfFloat
A mutable 2D point with float components implementing Point2, PrimitiveCollection.OfFloat, and PointNFloat.
  • Field Details

    • x

      public float x
    • y

      public float y
  • Constructor Details

    • Point2Float

      public Point2Float()
    • Point2Float

      public Point2Float(float x, float y)
    • Point2Float

      public Point2Float(Point2Float p)
    • Point2Float

      public Point2Float(com.github.tommyettinger.crux.Point2<?> p)
  • Method Details

    • floatingPoint

      public boolean floatingPoint()
      Returns true if this type of point uses float or double for its components, or false otherwise. This always returns true.
      Specified by:
      floatingPoint in interface com.github.tommyettinger.crux.PointN<Point2Float>
      Specified by:
      floatingPoint in interface com.github.tommyettinger.crux.PointNFloat<Point2Float, com.github.tommyettinger.crux.Point2<?>>
      Specified by:
      floatingPoint in interface PointNFloat<Point2Float, com.github.tommyettinger.crux.Point2<?>>
      Returns:
      true
    • cpy

      public Point2Float cpy()
      Specified by:
      cpy in interface com.github.tommyettinger.crux.PointN<Point2Float>
    • copy

      public Point2Float copy()
    • len2

      public float len2()
      Specified by:
      len2 in interface com.github.tommyettinger.crux.PointN<Point2Float>
    • set

      public Point2Float set(Point2Float point)
      Specified by:
      set in interface com.github.tommyettinger.crux.PointN<Point2Float>
    • set

      public Point2Float set(com.github.tommyettinger.crux.Point2<?> point)
    • sub

      public Point2Float sub(Point2Float point)
      Specified by:
      sub in interface com.github.tommyettinger.crux.PointN<Point2Float>
    • sub

      public Point2Float sub(com.github.tommyettinger.crux.Point2<?> point)
    • subtract

      public Point2Float subtract(com.github.tommyettinger.crux.Point2<?> point)
    • add

      public Point2Float add(Point2Float point)
      Specified by:
      add in interface com.github.tommyettinger.crux.PointN<Point2Float>
    • add

      public Point2Float add(com.github.tommyettinger.crux.Point2<?> point)
    • plus

      public Point2Float plus(float scalar)
      Specified by:
      plus in interface com.github.tommyettinger.crux.PointN<Point2Float>
    • minus

      public Point2Float minus(float scalar)
      Specified by:
      minus in interface com.github.tommyettinger.crux.PointN<Point2Float>
    • times

      public Point2Float times(float scalar)
      Specified by:
      times in interface com.github.tommyettinger.crux.PointN<Point2Float>
    • scl

      public Point2Float scl(Point2Float point)
      Specified by:
      scl in interface com.github.tommyettinger.crux.PointN<Point2Float>
    • scl

      public Point2Float scl(com.github.tommyettinger.crux.Point2<?> point)
    • scale

      public Point2Float scale(com.github.tommyettinger.crux.Point2<?> point)
    • mul

      public Point2Float mul(Point2Float point)
    • mul

      public Point2Float mul(com.github.tommyettinger.crux.Point2<?> point)
    • multiply

      public Point2Float multiply(com.github.tommyettinger.crux.Point2<?> point)
    • div

      public Point2Float div(Point2Float point)
      Specified by:
      div in interface com.github.tommyettinger.crux.PointN<Point2Float>
    • div

      public Point2Float div(com.github.tommyettinger.crux.Point2<?> point)
    • divide

      public Point2Float divide(com.github.tommyettinger.crux.Point2<?> point)
    • dst2

      public float dst2(Point2Float point)
      Specified by:
      dst2 in interface com.github.tommyettinger.crux.PointN<Point2Float>
    • dst2

      public float dst2(com.github.tommyettinger.crux.Point2<?> point)
    • distance

      public float distance(com.github.tommyettinger.crux.Point2<?> point)
    • distanceSquared

      public float distanceSquared(com.github.tommyettinger.crux.Point2<?> point)
    • setZero

      public Point2Float setZero()
      Specified by:
      setZero in interface com.github.tommyettinger.crux.PointN<Point2Float>
    • x

      public float x()
      Specified by:
      x in interface com.github.tommyettinger.crux.Point2<Point2Float>
    • x

      public Point2Float x(float next)
      Specified by:
      x in interface com.github.tommyettinger.crux.Point2<Point2Float>
    • y

      public float y()
      Specified by:
      y in interface com.github.tommyettinger.crux.Point2<Point2Float>
    • y

      public Point2Float y(float next)
      Specified by:
      y in interface com.github.tommyettinger.crux.Point2<Point2Float>
    • set

      public Point2Float set(float x, float y)
      Specified by:
      set in interface com.github.tommyettinger.crux.Point2<Point2Float>
    • nor

      public Point2Float nor()
      Specified by:
      nor in interface com.github.tommyettinger.crux.PointN<Point2Float>
    • normalize

      public Point2Float normalize()
    • add

      public Point2Float add(float x, float y)
    • sub

      public Point2Float sub(float x, float y)
    • subtract

      public Point2Float subtract(float x, float y)
    • scl

      public Point2Float scl(float scalar)
    • scale

      public Point2Float scale(float scalar)
    • scl

      public Point2Float scl(float x, float y)
    • scale

      public Point2Float scale(float x, float y)
    • mul

      public Point2Float mul(float scalar)
      Multiplies each component of this by the given scalar, in-place, and returns this. This is an alias for scl(float).
      Parameters:
      scalar - a float that will be multiplied with each component
      Returns:
      this, for chaining
    • multiply

      public Point2Float multiply(float scalar)
      Multiplies each component of this by the given scalar, in-place, and returns this. This is an alias for scl(float).
      Parameters:
      scalar - a float that will be multiplied with each component
      Returns:
      this, for chaining
    • mul

      public Point2Float mul(float x, float y)
      Multiplies each component of this by the corresponding scalar, in-place, and returns this. This is an alias for scl(float, float).
      Parameters:
      x - a float that will be multiplied with x
      y - a float that will be multiplied with y
      Returns:
      this, for chaining
    • multiply

      public Point2Float multiply(float x, float y)
      Multiplies each component of this by the corresponding scalar, in-place, and returns this. This is an alias for scl(float, float).
      Parameters:
      x - a float that will be multiplied with x
      y - a float that will be multiplied with y
      Returns:
      this, for chaining
    • divide

      public Point2Float divide(float scalar)
      Specified by:
      divide in interface com.github.tommyettinger.crux.PointN<Point2Float>
    • addProduct

      public Point2Float addProduct(com.github.tommyettinger.crux.Point2<?> vec, float scalar)
    • mulAdd

      public Point2Float mulAdd(com.github.tommyettinger.crux.Point2<?> vec, float scalar)
    • mulAdd

      public Point2Float mulAdd(com.github.tommyettinger.crux.Point2<?> vec, com.github.tommyettinger.crux.Point2<?> mulVec)
    • addProduct

      public Point2Float addProduct(com.github.tommyettinger.crux.Point2<?> vec, com.github.tommyettinger.crux.Point2<?> mulVec)
    • limit

      public Point2Float limit(float limit)
    • limit2

      public Point2Float limit2(float limit2)
    • limitSquared

      public Point2Float limitSquared(float limit2)
    • clampLength

      public Point2Float clampLength(float min, float max)
    • setLength

      public Point2Float setLength(float len)
    • setLength2

      public Point2Float setLength2(float len2)
    • setAngleRad

      public Point2Float setAngleRad(float radians)
    • setAngleDeg

      public Point2Float setAngleDeg(float degrees)
    • setAngleTurns

      public Point2Float setAngleTurns(float turns)
    • rotateRad

      public Point2Float rotateRad(float radians)
    • rotateDeg

      public Point2Float rotateDeg(float degrees)
    • rotateTurns

      public Point2Float rotateTurns(float turns)
    • rotateAroundRad

      public Point2Float rotateAroundRad(com.github.tommyettinger.crux.Point2<?> reference, float radians)
    • rotateAroundDeg

      public Point2Float rotateAroundDeg(com.github.tommyettinger.crux.Point2<?> reference, float degrees)
    • rotateAroundTurns

      public Point2Float rotateAroundTurns(com.github.tommyettinger.crux.Point2<?> reference, float turns)
    • rotate90

      public Point2Float rotate90(int sign)
    • dot

      public float dot(com.github.tommyettinger.crux.Point2<?> other)
    • dot

      public static float dot(com.github.tommyettinger.crux.Point2<?> a, com.github.tommyettinger.crux.Point2<?> b)
    • lerp

      public Point2Float lerp(com.github.tommyettinger.crux.Point2<?> target, float alpha)
      Description copied from interface: PointNFloat
      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<Point2Float, com.github.tommyettinger.crux.Point2<?>>
      Specified by:
      lerp in interface PointNFloat<Point2Float, com.github.tommyettinger.crux.Point2<?>>
      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

      public Point2Float interpolate(com.github.tommyettinger.crux.Point2<?> target, float alpha, com.github.tommyettinger.digital.Interpolations.Interpolator interpolation)
      Description copied from interface: PointNFloat
      Calls PointNFloat.lerp(PointN, float) with the alpha determined by the given interpolation. Simply returns lerp(target, interpolation.apply(alpha)) .
      Specified by:
      interpolate in interface PointNFloat<Point2Float, com.github.tommyettinger.crux.Point2<?>>
      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

      public Point2Float slerpGeometric(Point2Float target, float alpha)
    • setToRandomDirection

      public Point2Float setToRandomDirection(Random random)
      Description copied from interface: PointNFloat
      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().
      Specified by:
      setToRandomDirection in interface PointNFloat<Point2Float, com.github.tommyettinger.crux.Point2<?>>
      Parameters:
      random - any Random or subclass thereof
      Returns:
      this point after modifications, if possible, or a new PointNFloat if this is immutable
    • clampEach

      public Point2Float clampEach(float min, float max)
      For each component, this clamps it between min and max, inclusive.
      Parameters:
      min - the minimum value allowable for any component, inclusive
      max - the maximum value allowable for any component, inclusive
      Returns:
      this, after modifications
    • fract

      public Point2Float fract()
      Sets each component so it only has a fractional value, by subtracting the floor from each component. This produces a non-negative float for each component, between 0.0 inclusive and 1.0 exclusive, unless a component is outside the safe range for MathTools.floor(float) (-16384.0 at the lowest).
      The result of fract() for a component with a value of  1.25 will be 0.25 .
      The result of fract() for a component with a value of -1.25 will be 0.75 .
      
      Returns:
      this, after modifications
    • fractional

      public Point2Float fractional()
    • inverse

      public Point2Float 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.
      Specified by:
      inverse in interface com.github.tommyettinger.crux.PointNFloat<Point2Float, com.github.tommyettinger.crux.Point2<?>>
      Specified by:
      inverse in interface PointNFloat<Point2Float, com.github.tommyettinger.crux.Point2<?>>
      Returns:
      1f divided by this point, assigned in-place to this
    • get

      public 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<Point2Float, com.github.tommyettinger.crux.Point2<?>>
      Specified by:
      get in interface PointNFloat<Point2Float, com.github.tommyettinger.crux.Point2<?>>
      Parameters:
      index - which component to get, in order
      Returns:
      the component
    • setAt

      public Point2Float 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<Point2Float, com.github.tommyettinger.crux.Point2<?>>
      Specified by:
      setAt in interface PointNFloat<Point2Float, com.github.tommyettinger.crux.Point2<?>>
      Parameters:
      index - which component to set, in order
      value - the value to assign at index
      Returns:
      this, for chaining
    • equals

      public boolean equals(Object o)
      Specified by:
      equals in interface com.github.tommyettinger.ds.PrimitiveCollection<Float>
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in interface com.github.tommyettinger.ds.PrimitiveCollection<Float>
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Converts this Point2Float to a string in the format (x,y).
      Overrides:
      toString in class Object
      Returns:
      a string representation of this object.
    • fromString

      public Point2Float fromString(String s)
      Sets this Point2Float to the value represented by the specified string according to the format of toString().
      Parameters:
      s - the string.
      Returns:
      this point for chaining
    • add

      public boolean add(float c)
      Not supported; this collection is fixed-size.
      Specified by:
      add in interface com.github.tommyettinger.ds.PrimitiveCollection.OfFloat
      Parameters:
      c - ignored
      Returns:
      never returns
      Throws:
      UnsupportedOperationException - always
    • remove

      public boolean remove(float c)
      Not supported; this collection is fixed-size.
      Specified by:
      remove in interface com.github.tommyettinger.ds.PrimitiveCollection.OfFloat
      Parameters:
      c - ignored
      Returns:
      never returns
      Throws:
      UnsupportedOperationException - always
    • clear

      public void clear()
      Not supported; this collection is fixed-size.
      Specified by:
      clear in interface com.github.tommyettinger.ds.PrimitiveCollection<Float>
      Throws:
      UnsupportedOperationException - always
    • contains

      public boolean contains(float c)
      Compares c with the components of this collection using ==; if any are considered equal, this returns true.
      Specified by:
      contains in interface com.github.tommyettinger.ds.PrimitiveCollection.OfFloat
      Parameters:
      c - a float to be compared using ==
      Returns:
      true if any component of this collection is equal to c via == comparison
    • size

      public int size()
      Specified by:
      size in interface com.github.tommyettinger.ds.PrimitiveCollection<Float>
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface com.github.tommyettinger.ds.PrimitiveCollection<Float>
    • notEmpty

      public boolean notEmpty()
      Specified by:
      notEmpty in interface com.github.tommyettinger.ds.PrimitiveCollection<Float>
    • iterator

      public PointNFloatIterator iterator()
      Specified by:
      iterator in interface com.github.tommyettinger.ds.PrimitiveCollection<Float>
      Specified by:
      iterator in interface com.github.tommyettinger.ds.PrimitiveCollection.OfFloat
    • sinCos

      public Point2Float sinCos(float radians)
      Calculates TrigTools.cos(float) and TrigTools.sin(float) simultaneously and stores their results in x and y, respectively. This is expected to be only slightly faster than calling cos() and sin() separately.
      Parameters:
      radians - the angle to calculate cos() and sin() of
      Returns:
      this, after reassignment, for chaining
    • sinCosDeg

      public Point2Float sinCosDeg(float degrees)
      Calculates TrigTools.cosDeg(float) and TrigTools.sinDeg(float) simultaneously and stores their results in x and y, respectively. This is expected to be only slightly faster than calling cosDeg() and sinDeg() separately.
      Parameters:
      degrees - the angle to calculate cosDeg() and sinDeg() of
      Returns:
      this, after reassignment, for chaining
    • sinCosTurns

      public Point2Float sinCosTurns(float turns)
      Calculates TrigTools.cosTurns(float) and TrigTools.sinTurns(float) simultaneously and stores their results in x and y, respectively. This is expected to be only slightly faster than calling cosTurns() and sinTurns() separately.
      Parameters:
      turns - the angle to calculate cosTurns() and sinTurns() of
      Returns:
      this, after reassignment, for chaining
    • sinCosSmoother

      public Point2Float sinCosSmoother(float radians)
      Calculates TrigTools.cosSmoother(float) and TrigTools.sinSmoother(float) simultaneously and stores their results in x and y, respectively. This is expected to be somewhat faster than calling cosSmoother() and sinSmoother() separately.
      Parameters:
      radians - the angle to calculate cosSmoother() and sinSmoother() of
      Returns:
      this, after reassignment, for chaining
    • sinCosSmootherDeg

      public Point2Float sinCosSmootherDeg(float degrees)
      Calculates TrigTools.cosSmootherDeg(float) and TrigTools.sinSmootherDeg(float) simultaneously and stores their results in x and y, respectively. This is expected to be somewhat faster than calling cosSmootherDeg() and sinSmootherDeg() separately.
      Parameters:
      degrees - the angle to calculate cosSmootherDeg() and sinSmootherDeg() of
      Returns:
      this, after reassignment, for chaining
    • sinCosSmootherTurns

      public Point2Float sinCosSmootherTurns(float turns)
      Calculates TrigTools.cosSmootherTurns(float) and TrigTools.sinSmootherTurns(float) simultaneously and stores their results in x and y, respectively. This is expected to be somewhat faster than calling cosSmootherTurns() and sinSmootherTurns() separately.
      Parameters:
      turns - the angle to calculate cosSmootherTurns() and sinSmootherTurns() on
      Returns:
      this, after reassignment, for chaining