Package org.gnome.graphene
Class Vec2
java.lang.Object
org.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
ConstructorsConstructorDescriptionVec2()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 TypeMethodDescriptionvoidAdds each component of the two passed vectors and places each result into the components ofres.static Vec2alloc()Allocates a newgraphene_vec2_tstructure.voidDivides each component of the first operand this Vec2 by the corresponding component of the second operandb,and places the results into the vectorres.floatComputes the dot product of the two given vectors.booleanChecks whether the two givengraphene_vec2_tare equal.voidfree()Frees the resources allocated by this Vec2static MemoryLayoutThe memory layout of the native struct.static @Nullable TypegetType()Get the GType of the Vec2 classfloatgetX()Retrieves the X component of thegraphene_vec2_t.floatgetY()Retrieves the Y component of thegraphene_vec2_t.init(float x, float y) Initializes agraphene_vec2_tusing the given values.initFromFloat(@org.jspecify.annotations.Nullable float @Nullable [] src) Initializes this Vec2 with the contents of the given array.initFromVec2(Vec2 src) Copies the contents ofsrcintov.voidinterpolate(Vec2 v2, double factor, Vec2 res) Linearly interpolates this Vec2 andv2using the givenfactor.floatlength()Computes the length of the given vector.voidCompares the two given vectors and places the maximum values of each component intores.voidCompares the two given vectors and places the minimum values of each component intores.voidMultiplies each component of the two passed vectors and places each result into the components ofres.booleanCompares the two givengraphene_vec2_tvectors and checks whether their values are within the givenepsilon.voidNegates the givengraphene_vec2_t.voidComputes the normalized vector for the given vectorv.static Vec2one()Retrieves a constant vector with (1, 1) components.@Nullable Simd4FRead the value of the fieldvalue.voidMultiplies all components of the given vector with the given scalarfactor.voidSubtracts from each component of the first operand this Vec2 the corresponding component of the second operandband places each result into the components ofres.voidStores the components of this Vec2 into an array.voidwriteValue(@Nullable Simd4F value) Write a value in the fieldvalue.static Vec2xAxis()Retrieves a constant vector with (1, 0) components.static Vec2yAxis()Retrieves a constant vector with (0, 1) components.static Vec2zero()Retrieves a constant vector with (0, 0) components.Methods inherited from class org.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
Read the value of the fieldvalue.- Returns:
- The value of the field
value
-
writeValue
Write a value in the fieldvalue.- Parameters:
value- The new value for the fieldvalue
-
alloc
Allocates a newgraphene_vec2_tstructure.The contents of the returned structure are undefined.
Use graphene_vec2_init() to initialize the vector.
- Returns:
- the newly allocated
graphene_vec2_tstructure. Use graphene_vec2_free() to free the resources allocated by this function. - Since:
- 1.0
-
one
Retrieves a constant vector with (1, 1) components.- Returns:
- the one vector
- Since:
- 1.0
-
xAxis
Retrieves a constant vector with (1, 0) components.- Returns:
- the X axis vector
- Since:
- 1.0
-
yAxis
Retrieves a constant vector with (0, 1) components.- Returns:
- the Y axis vector
- Since:
- 1.0
-
zero
Retrieves a constant vector with (0, 0) components.- Returns:
- the zero vector
- Since:
- 1.0
-
add
-
divide
-
dot
Computes the dot product of the two given vectors.- Parameters:
b- agraphene_vec2_t- Returns:
- the dot product of the vectors
- Since:
- 1.0
-
equal
Checks whether the two givengraphene_vec2_tare equal.- Parameters:
v2- agraphene_vec2_t- Returns:
trueif 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 thegraphene_vec2_t.- Returns:
- the value of the X component
- Since:
- 1.0
-
getY
public float getY()Retrieves the Y component of thegraphene_vec2_t.- Returns:
- the value of the Y component
- Since:
- 1.0
-
init
Initializes agraphene_vec2_tusing 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
- Since:
- 1.0
-
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
- Throws:
IllegalArgumentException- when length ofsrcis less than 2- Since:
- 1.0
-
initFromVec2
-
interpolate
-
length
public float length()Computes the length of the given vector.- Returns:
- the length of the vector
- Since:
- 1.0
-
max
-
min
-
multiply
-
near
Compares the two givengraphene_vec2_tvectors and checks whether their values are within the givenepsilon.- Parameters:
v2- agraphene_vec2_tepsilon- the threshold between the two vectors- Returns:
trueif the two vectors are near each other- Since:
- 1.2
-
negate
Negates the givengraphene_vec2_t.- Parameters:
res- return location for the result vector- Since:
- 1.2
-
normalize
Computes the normalized vector for the given vectorv.- Parameters:
res- return location for the normalized vector- Since:
- 1.0
-
scale
Multiplies all components of the given vector with the given scalarfactor.- Parameters:
factor- the scalar factorres- return location for the result vector- Since:
- 1.2
-
subtract
-
toFloat
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
-