M_Polygon
—
Agar-Math polygon structure
#include <agar/core.h>
#include <agar/gui.h>
#include <agar/math/m.h>
The M_Polygon structure describes a simple
polygon. The polygon may be convex or concave. Self-intersections and holes
are not allowed.
typedef struct m_polygon {
M_Vector2 *v; /* Vertices */
Uint n; /* Vertex count */
} M_Polygon;
int
M_PolygonAddVertex
(M_Polygon
*P, M_Vector2
v);
int
M_PolygonAddLine
(M_Polygon
*P, M_Line2 L);
int
M_PolygonDelVertex
(M_Polygon
*P, int v);
int
M_PolygonCopy
(M_Polygon
*Pdst, const M_Polygon
*Psrc);
void
M_PolygonScale
(M_Polygon
*P, M_Real xScale,
M_Real yScale);
void
M_PolygonOffset
(M_Polygon
*P, M_Real xOffs,
M_Real yOffs);
int
M_PointInPolygon
(const
M_Polygon *P, M_Vector2
p);
int
M_PolygonIsConvex
(const
M_Polygon *P);
The
M_PolygonAddVertex
()
function adds a new vertex to a polygon. Returns index of new vertex on
success, -1 on failure. The M_PolygonAddLine
()
variant accepts a
M_Line(3)
argument instead of a vector.
M_PolygonDelVertex
()
removes the vertex at given index v.
The
M_PolygonCopy
()
function copies the vertices of a source polygon Psrc
to a destination polygon Pdst. The destination
structure does not need to be initialized. Any existing vertices in
Pdst will be overwritten. The function returns 0 on
success or -1 if insufficient memory is available.
M_PolygonScale
()
multiplies all vertices of a polygon with the given scaling factors
xScale, yScale.
M_PolygonOffset
() translates all vertices against
xOffs, yOffs.
The
M_PointInPolygon
()
function returns 1 if the point p lies inside the
polygon.
M_PolygonIsConvex
()
returns 1 if the polygon is convex.
AG_DataSource(3),
AG_Intro(3),
M_Circle(3),
M_Geometry(3),
M_Plane(3),
M_PointSet(3),
M_Polygon(3),
M_Rectangle(3),
M_Sphere(3),
M_Triangle(3),
M_Vector(3)
The M_Polygon
structure first appeared in
Agar 1.3.4.