Class PathPoint
- All Implemented Interfaces:
Proxy
GskPathPoint
is an opaque type representing a point on a path.
It can be queried for properties of the path at that point, such as its tangent or its curvature.
To obtain a GskPathPoint
, use Path.getClosestPoint(org.gnome.graphene.Point, float, org.gnome.gsk.PathPoint, io.github.jwharm.javagi.base.Out<java.lang.Float>)
,
Path.getStartPoint(org.gnome.gsk.PathPoint)
, Path.getEndPoint(org.gnome.gsk.PathPoint)
or PathMeasure.getPoint(float, org.gnome.gsk.PathPoint)
.
Note that GskPathPoint
structs are meant to be stack-allocated,
and don't hold a reference to the path object they are obtained from.
It is the callers responsibility to keep a reference to the path
as long as the GskPathPoint
is used.
-
Constructor Summary
ConstructorDescriptionAllocate a new PathPoint.Allocate a new PathPoint.PathPoint
(MemorySegment address) Create a PathPoint proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionint
Returns whether this PathPoint is before or afterpoint2
.copy()
Copies a path point.boolean
Returns whether the two path points refer to the same location on all paths.void
free()
Frees a path point copied bycopy()
.float
getCurvature
(Path path, PathDirection direction, @Nullable Point center) Calculates the curvature of the path at the point.float
getDistance
(PathMeasure measure) Returns the distance from the beginning of the path to this PathPoint.static MemoryLayout
The memory layout of the native struct.void
getPosition
(Path path, Point position) Gets the position of the point.float
getRotation
(Path path, PathDirection direction) Gets the direction of the tangent at a given point.void
getTangent
(Path path, PathDirection direction, Vec2 tangent) Gets the tangent of the path at the point.static Type
getType()
Get the GType of the PathPoint classRead the value of the fieldalignment
.void
writeAlignment
(Vec4 alignment) Write a value in the fieldalignment
.Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
PathPoint
Create a PathPoint proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
PathPoint
Allocate a new PathPoint.- Parameters:
arena
- to control the memory allocation scope
-
PathPoint
public PathPoint()Allocate a new PathPoint. The memory is allocated withArena.ofAuto()
.
-
-
Method Details
-
getType
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
readAlignment
Read the value of the fieldalignment
.- Returns:
- The value of the field
alignment
-
writeAlignment
Write a value in the fieldalignment
.- Parameters:
alignment
- The new value for the fieldalignment
-
compare
Returns whether this PathPoint is before or afterpoint2
.- Parameters:
point2
- anotherGskPathPoint
- Returns:
- -1 if this PathPoint is before
point2
, 1 if this PathPoint is afterpoint2
, 0 if they are equal
-
copy
-
equal
Returns whether the two path points refer to the same location on all paths.Note that the start- and endpoint of a closed contour will compare nonequal according to this definition. Use
Path.isClosed()
to find out if the start- and endpoint of a concrete path refer to the same location.- Parameters:
point2
- anotherGskPathPoint
- Returns:
TRUE
if this PathPoint andpoint2
are equal
-
free
public void free()Frees a path point copied bycopy()
. -
getCurvature
Calculates the curvature of the path at the point.Optionally, returns the center of the osculating circle as well. The curvature is the inverse of the radius of the osculating circle.
Lines have a curvature of zero (indicating an osculating circle of infinite radius. In this case, the
center
is not modified.Circles with a radius of zero have
INFINITY
as curvatureNote that certain points on a path may not have a single curvature, such as sharp turns. At such points, there are two curvatures -- the (limit of) the curvature of the path going into the point, and the (limit of) the curvature of the path coming out of it. The
direction
argument lets you choose which one to get.<picture> <source srcset="curvature-dark.png" media="(prefers-color-scheme: dark)"> <img alt="Osculating circle" src="curvature-light.png"> </picture>
- Parameters:
path
- the path that this PathPoint is ondirection
- the direction for which to return the curvaturecenter
- Return location for the center of the osculating circle- Returns:
- The curvature of the path at the given point
-
getDistance
Returns the distance from the beginning of the path to this PathPoint.- Parameters:
measure
- aGskPathMeasure
for the path- Returns:
- the distance of this PathPoint
-
getPosition
-
getRotation
Gets the direction of the tangent at a given point.This is a convenience variant of
getTangent(org.gnome.gsk.Path, org.gnome.gsk.PathDirection, org.gnome.graphene.Vec2)
that returns the angle between the tangent and the X axis. The angle can e.g. be used in gtk_snapshot_rotate().- Parameters:
path
- the path that this PathPoint is ondirection
- the direction for which to return the rotation- Returns:
- the angle between the tangent and the X axis, in degrees
-
getTangent
Gets the tangent of the path at the point.Note that certain points on a path may not have a single tangent, such as sharp turns. At such points, there are two tangents -- the direction of the path going into the point, and the direction coming out of it. The
direction
argument lets you choose which one to get.If the path is just a single point (e.g. a circle with radius zero), then
tangent
is set to0, 0
.If you want to orient something in the direction of the path,
getRotation(org.gnome.gsk.Path, org.gnome.gsk.PathDirection)
may be more convenient to use.- Parameters:
path
- the path that this PathPoint is ondirection
- the direction for which to return the tangenttangent
- Return location for the tangent at the point
-