Class Vec2

All Implemented Interfaces:
Proxy

@Generated("org.javagi.JavaGI") public class Vec2 extends ProxyInstance

A structure capable of holding a vector with two dimensions, x and y.

The contents of the graphene_vec2_t structure are private and should never be accessed directly.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Allocate a new Vec2.
    Vec2(Arena arena)
    Allocate a new Vec2.
    Create a Vec2 proxy instance for the provided memory address.
    Vec2(Simd4F value)
    Allocate a new Vec2 with the fields set to the provided values.
    Vec2(Simd4F value, Arena arena)
    Allocate a new Vec2 with the fields set to the provided values.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(Vec2 b, Vec2 res)
    Adds each component of the two passed vectors and places each result into the components of res.
    static Vec2
    Allocates a new graphene_vec2_t structure.
    void
    divide(Vec2 b, Vec2 res)
    Divides each component of the first operand this Vec2 by the corresponding component of the second operand b, and places the results into the vector res.
    float
    dot(Vec2 b)
    Computes the dot product of the two given vectors.
    boolean
    equal(Vec2 v2)
    Checks whether the two given graphene_vec2_t are equal.
    void
    Frees the resources allocated by this Vec2
    The memory layout of the native struct.
    static @Nullable Type
    Get the GType of the Vec2 class.
    float
    Retrieves the X component of the graphene_vec2_t.
    float
    Retrieves the Y component of the graphene_vec2_t.
    init(float x, float y)
    Initializes a graphene_vec2_t using the given values.
    initFromFloat(@Nullable float @Nullable [] src)
    Initializes this Vec2 with the contents of the given array.
    Copies the contents of src into v.
    void
    interpolate(Vec2 v2, double factor, Vec2 res)
    Linearly interpolates this Vec2 and v2 using the given factor.
    float
    Computes the length of the given vector.
    void
    max(Vec2 b, Vec2 res)
    Compares the two given vectors and places the maximum values of each component into res.
    void
    min(Vec2 b, Vec2 res)
    Compares the two given vectors and places the minimum values of each component into res.
    void
    multiply(Vec2 b, Vec2 res)
    Multiplies each component of the two passed vectors and places each result into the components of res.
    boolean
    near(Vec2 v2, float epsilon)
    Compares the two given graphene_vec2_t vectors and checks whether their values are within the given epsilon.
    void
    negate(Vec2 res)
    Negates the given graphene_vec2_t.
    void
    Computes the normalized vector for the given vector v.
    static Vec2
    one()
    Retrieves a constant vector with (1, 1) components.
    @Nullable Simd4F
    Read the value of the field value.
    void
    scale(float factor, Vec2 res)
    Multiplies all components of the given vector with the given scalar factor.
    void
    subtract(Vec2 b, Vec2 res)
    Subtracts from each component of the first operand this Vec2 the corresponding component of the second operand b and places each result into the components of res.
    void
    toFloat(@Nullable Out<float[]> dest)
    Stores the components of this Vec2 into an array.
    void
    writeValue(@Nullable Simd4F value)
    Write a value in the field value.
    static Vec2
    Retrieves a constant vector with (1, 0) components.
    static Vec2
    Retrieves a constant vector with (0, 1) components.
    static Vec2
    Retrieves a constant vector with (0, 0) components.

    Methods inherited from class ProxyInstance

    equals, handle, hashCode

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Vec2

      public Vec2(MemorySegment address)
      Create a Vec2 proxy instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • Vec2

      public Vec2(Arena arena)
      Allocate a new Vec2.
      Parameters:
      arena - to control the memory allocation scope
    • Vec2

      public Vec2()
      Allocate a new Vec2. The memory is allocated with Arena.ofAuto().
    • Vec2

      public Vec2(Simd4F value, Arena arena)
      Allocate a new Vec2 with the fields set to the provided values.
      Parameters:
      value - value for the field value
      arena - to control the memory allocation scope
    • Vec2

      public Vec2(Simd4F value)
      Allocate a new Vec2 with the fields set to the provided values. The memory is allocated with Arena.ofAuto().
      Parameters:
      value - value for the field value
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the Vec2 class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • readValue

      public @Nullable Simd4F readValue()
      Read the value of the field value.
      Returns:
      The value of the field value
    • writeValue

      public void writeValue(@Nullable Simd4F value)
      Write a value in the field value.
      Parameters:
      value - The new value for the field value
    • alloc

      public static Vec2 alloc()

      Allocates a new graphene_vec2_t structure.

      The contents of the returned structure are undefined.

      Use graphene_vec2_init() to initialize the vector.

      Returns:
      the newly allocated graphene_vec2_t structure. Use graphene_vec2_free() to free the resources allocated by this function.
      Since:
      1.0
    • one

      public static Vec2 one()
      Retrieves a constant vector with (1, 1) components.
      Returns:
      the one vector
      Since:
      1.0
    • xAxis

      public static Vec2 xAxis()
      Retrieves a constant vector with (1, 0) components.
      Returns:
      the X axis vector
      Since:
      1.0
    • yAxis

      public static Vec2 yAxis()
      Retrieves a constant vector with (0, 1) components.
      Returns:
      the Y axis vector
      Since:
      1.0
    • zero

      public static Vec2 zero()
      Retrieves a constant vector with (0, 0) components.
      Returns:
      the zero vector
      Since:
      1.0
    • add

      public void add(Vec2 b, Vec2 res)
      Adds each component of the two passed vectors and places each result into the components of res.
      Parameters:
      b - a graphene_vec2_t
      res - return location for the result
      Since:
      1.0
    • divide

      public void divide(Vec2 b, Vec2 res)
      Divides each component of the first operand this Vec2 by the corresponding component of the second operand b, and places the results into the vector res.
      Parameters:
      b - a graphene_vec2_t
      res - return location for the result
      Since:
      1.0
    • dot

      public float dot(Vec2 b)
      Computes the dot product of the two given vectors.
      Parameters:
      b - a graphene_vec2_t
      Returns:
      the dot product of the vectors
      Since:
      1.0
    • equal

      public boolean equal(Vec2 v2)
      Checks whether the two given graphene_vec2_t are equal.
      Parameters:
      v2 - a graphene_vec2_t
      Returns:
      true if the two vectors are equal, and false otherwise
      Since:
      1.2
    • free

      public void free()
      Frees the resources allocated by this Vec2
      Since:
      1.0
    • getX

      public float getX()
      Retrieves the X component of the graphene_vec2_t.
      Returns:
      the value of the X component
      Since:
      1.0
    • getY

      public float getY()
      Retrieves the Y component of the graphene_vec2_t.
      Returns:
      the value of the Y component
      Since:
      1.0
    • init

      public Vec2 init(float x, float y)

      Initializes a graphene_vec2_t using the given values.

      This function can be called multiple times.

      Parameters:
      x - the X field of the vector
      y - the Y field of the vector
      Returns:
      the initialized vector
      Since:
      1.0
    • initFromFloat

      public Vec2 initFromFloat(@Nullable float @Nullable [] src)
      Initializes this Vec2 with the contents of the given array.
      Parameters:
      src - an array of floating point values with at least two elements
      Returns:
      the initialized vector
      Throws:
      IllegalArgumentException - when length of src is less than 2
      Since:
      1.0
    • initFromVec2

      public Vec2 initFromVec2(Vec2 src)
      Copies the contents of src into v.
      Parameters:
      src - a graphene_vec2_t
      Returns:
      the initialized vector
      Since:
      1.0
    • interpolate

      public void interpolate(Vec2 v2, double factor, Vec2 res)
      Linearly interpolates this Vec2 and v2 using the given factor.
      Parameters:
      v2 - a graphene_vec2_t
      factor - the interpolation factor
      res - the interpolated vector
      Since:
      1.10
    • length

      public float length()
      Computes the length of the given vector.
      Returns:
      the length of the vector
      Since:
      1.0
    • max

      public void max(Vec2 b, Vec2 res)
      Compares the two given vectors and places the maximum values of each component into res.
      Parameters:
      b - a graphene_vec2_t
      res - the resulting vector
      Since:
      1.0
    • min

      public void min(Vec2 b, Vec2 res)
      Compares the two given vectors and places the minimum values of each component into res.
      Parameters:
      b - a graphene_vec2_t
      res - the resulting vector
      Since:
      1.0
    • multiply

      public void multiply(Vec2 b, Vec2 res)
      Multiplies each component of the two passed vectors and places each result into the components of res.
      Parameters:
      b - a graphene_vec2_t
      res - return location for the result
      Since:
      1.0
    • near

      public boolean near(Vec2 v2, float epsilon)
      Compares the two given graphene_vec2_t vectors and checks whether their values are within the given epsilon.
      Parameters:
      v2 - a graphene_vec2_t
      epsilon - the threshold between the two vectors
      Returns:
      true if the two vectors are near each other
      Since:
      1.2
    • negate

      public void negate(Vec2 res)
      Negates the given graphene_vec2_t.
      Parameters:
      res - return location for the result vector
      Since:
      1.2
    • normalize

      public void normalize(Vec2 res)
      Computes the normalized vector for the given vector v.
      Parameters:
      res - return location for the normalized vector
      Since:
      1.0
    • scale

      public void scale(float factor, Vec2 res)
      Multiplies all components of the given vector with the given scalar factor.
      Parameters:
      factor - the scalar factor
      res - return location for the result vector
      Since:
      1.2
    • subtract

      public void subtract(Vec2 b, Vec2 res)
      Subtracts from each component of the first operand this Vec2 the corresponding component of the second operand b and places each result into the components of res.
      Parameters:
      b - a graphene_vec2_t
      res - return location for the result
      Since:
      1.0
    • toFloat

      public void toFloat(@Nullable Out<float[]> dest)
      Stores the components of this Vec2 into an array.
      Parameters:
      dest - return location for an array of floating point values with at least 2 elements
      Since:
      1.0