Record Class EaseFunction.CubicBezier

java.lang.Object
java.lang.Record
net.minestom.server.utils.EaseFunction.CubicBezier
Record Components:
x1 - the x coordinate of the first control point, between 0 and 1 inclusive
y1 - the y coordinate of the first control point
x2 - the x coordinate of the second control point, between 0 and 1 inclusive
y2 - the y coordinate of the second control point
All Implemented Interfaces:
EaseFunction
Enclosing interface:
EaseFunction

public static record EaseFunction.CubicBezier(float x1, float y1, float x2, float y2) extends Record implements EaseFunction

A cubic bezier ease from (0, 0) to (1, 1), shaped by the control points (x1, y1) and (x2, y2).

Sampling treats the input as an x coordinate, finds the point of the curve with that x, and returns its y coordinate. Both x coordinates must be between 0 and 1 inclusive, which keeps x from decreasing along the curve so that each input has one output. The y coordinates are unbounded, and values outside 0 to 1 make the ease overshoot.

CODEC reads and writes the control points as {"cubic_bezier": [x1, y1, x2, y2]}. Decoding returns a Result.Error when x1 or x2 is outside 0 to 1.

  • Field Details

  • Constructor Details

    • CubicBezier

      public CubicBezier(float x1, float y1, float x2, float y2)
      Creates a cubic bezier ease from its control points.
      Throws:
      IllegalArgumentException - if x1 or x2 is outside 0 to 1
    • CubicBezier

      @Deprecated public CubicBezier(float[] controlPoints)
      Creates a cubic bezier ease from an array holding x1, y1, x2, and y2 in that order.
      Parameters:
      controlPoints - the control points, must have a length of 4
      Throws:
      IllegalArgumentException - if the array length is not 4, or if x1 or x2 is outside 0 to 1
  • Method Details

    • controlPoints

      @Deprecated public float[] controlPoints()
      Deprecated.
      use x1(), y1(), x2(), and y2() instead
      Returns the control points as a new array holding x1, y1, x2, and y2 in that order.
      Returns:
      a new array of the control points
    • sample

      public float sample(float x)
      Specified by:
      sample in interface EaseFunction
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • x1

      public float x1()
      Returns the value of the x1 record component.
      Returns:
      the value of the x1 record component
    • y1

      public float y1()
      Returns the value of the y1 record component.
      Returns:
      the value of the y1 record component
    • x2

      public float x2()
      Returns the value of the x2 record component.
      Returns:
      the value of the x2 record component
    • y2

      public float y2()
      Returns the value of the y2 record component.
      Returns:
      the value of the y2 record component