Package org.gnome.graphene
Class Vec2
java.lang.Object
io.github.jwharm.javagi.base.ProxyInstance
org.gnome.graphene.Vec2
- All Implemented Interfaces:
Proxy
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
ConstructorDescriptionVec2()
Allocate a new Vec2.Allocate a new Vec2.Vec2
(MemorySegment address) Create a Vec2 proxy instance for the provided memory address.Allocate a new Vec2 with the fields set to the provided values.Allocate a new Vec2 with the fields set to the provided values. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds each component of the two passed vectors and places each result into the components ofres
.static Vec2
alloc()
Allocates a newgraphene_vec2_t
structure.void
Divides each component of the first operand this Vec2 by the corresponding component of the second operandb
, and places the results into the vectorres
.float
Computes the dot product of the two given vectors.boolean
Checks whether the two givengraphene_vec2_t
are equal.void
free()
Frees the resources allocated by this Vec2static MemoryLayout
The memory layout of the native struct.static Type
getType()
Get the GType of the Vec2 classfloat
getX()
Retrieves the X component of thegraphene_vec2_t
.float
getY()
Retrieves the Y component of thegraphene_vec2_t
.init
(float x, float y) Initializes agraphene_vec2_t
using the given values.initFromFloat
(float[] src) Initializes this Vec2 with the contents of the given array.initFromVec2
(Vec2 src) Copies the contents ofsrc
into this Vec2.void
interpolate
(Vec2 v2, double factor, Vec2 res) Linearly interpolates this Vec2 andv2
using the givenfactor
.float
length()
Computes the length of the given vector.void
Compares the two given vectors and places the maximum values of each component intores
.void
Compares the two given vectors and places the minimum values of each component intores
.void
Multiplies each component of the two passed vectors and places each result into the components ofres
.boolean
Compares the two givengraphene_vec2_t
vectors and checks whether their values are within the givenepsilon
.void
Negates the givengraphene_vec2_t
.void
Computes the normalized vector for the given vector this Vec2.static Vec2
one()
Retrieves a constant vector with (1, 1) components.Read the value of the fieldvalue
.void
Multiplies all components of the given vector with the given scalarfactor
.void
Subtracts from each component of the first operand this Vec2 the corresponding component of the second operandb
and places each result into the components ofres
.void
toFloat
(float[] dest) Stores the components of this Vec2 into an array.void
writeValue
(Simd4F value) Write a value in the fieldvalue
.static Vec2
xAxis()
Retrieves a constant vector with (1, 0) components.static Vec2
yAxis()
Retrieves a constant vector with (0, 1) components.static Vec2
zero()
Retrieves a constant vector with (0, 0) components.Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
Vec2
Create a Vec2 proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
Vec2
Allocate a new Vec2.- Parameters:
arena
- to control the memory allocation scope
-
Vec2
public Vec2()Allocate a new Vec2. The memory is allocated withArena.ofAuto()
. -
Vec2
-
Vec2
Allocate a new Vec2 with the fields set to the provided values. The memory is allocated withArena.ofAuto()
.- Parameters:
value
- value for the fieldvalue
-
-
Method Details
-
getType
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
readValue
-
writeValue
Write a value in the fieldvalue
.- Parameters:
value
- The new value for the fieldvalue
-
alloc
Allocates a newgraphene_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.
-
one
Retrieves a constant vector with (1, 1) components.- Returns:
- the one vector
-
xAxis
Retrieves a constant vector with (1, 0) components.- Returns:
- the X axis vector
-
yAxis
Retrieves a constant vector with (0, 1) components.- Returns:
- the Y axis vector
-
zero
Retrieves a constant vector with (0, 0) components.- Returns:
- the zero vector
-
add
-
divide
-
dot
Computes the dot product of the two given vectors.- Parameters:
b
- agraphene_vec2_t
- Returns:
- the dot product of the vectors
-
equal
Checks whether the two givengraphene_vec2_t
are equal.- Parameters:
v2
- agraphene_vec2_t
- Returns:
true
if the two vectors are equal, and false otherwise
-
free
public void free()Frees the resources allocated by this Vec2 -
getX
public float getX()Retrieves the X component of thegraphene_vec2_t
.- Returns:
- the value of the X component
-
getY
public float getY()Retrieves the Y component of thegraphene_vec2_t
.- Returns:
- the value of the Y component
-
init
Initializes agraphene_vec2_t
using the given values.This function can be called multiple times.
- Parameters:
x
- the X field of the vectory
- the Y field of the vector- Returns:
- the initialized vector
-
initFromFloat
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
-
initFromVec2
-
interpolate
-
length
public float length()Computes the length of the given vector.- Returns:
- the length of the vector
-
max
-
min
-
multiply
-
near
Compares the two givengraphene_vec2_t
vectors and checks whether their values are within the givenepsilon
.- Parameters:
v2
- agraphene_vec2_t
epsilon
- the threshold between the two vectors- Returns:
true
if the two vectors are near each other
-
negate
Negates the givengraphene_vec2_t
.- Parameters:
res
- return location for the result vector
-
normalize
Computes the normalized vector for the given vector this Vec2.- Parameters:
res
- return location for the normalized vector
-
scale
Multiplies all components of the given vector with the given scalarfactor
.- Parameters:
factor
- the scalar factorres
- return location for the result vector
-
subtract
-
toFloat
public void toFloat(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
-