formZ SDK | 5.0 API Reference | System | Math

fz_math_2d_clip_polygon_with_polygon

Description

Clips a polygon with a polygon.
The polygon is defined as a set of curves. The first curve is the outer boundary. All other curves are assmued to be holes.

The polygon points are ordered sequentially.

The curves are defined via the sindx array. ncurves indicates how many curves make up the polygon. For a given curve i, sindx[i] contains the index of the last point for that curve. That means, the start point of a curve is the index of the last point of the previous curve + 1.

For example a polygon with 2 holes and 4 points per curve would look like this :

poly_pts : sindx : ncurves : 3
0) [ x, y ] 0) [ 3]
1) [ x, y ] 1) [ 7]
2) [ x, y ] 2) [11]
3) [ x, y ]
4) [ x, y ]
5) [ x, y ]
6) [ x, y ]
7) [ x, y ]
8) [ x, y ]
9) [ x, y ]
10) [ x, y ]
11) [ x, y ]

Optionally, the line equations of the polygon edges can be passed in. If this routine is called multiple times, for example, clipping many polygons against the same polygon, it is more efficient to precompute the line equations and reuse them each time. If this routine is called only once, the line equations array may be passed as NULL. The line equations array is parallel to the points array, with a line equation for each point, defining the edge from this point to the next point.

The clipping result is returned in two lists, that must be initialised by the calling routine using fz_type_list_init. The clippee_pts_list contains the points and the clippee_curves_list contains the last indices of points in each curve.

Plugin Prototype

fzrt_error_td fz_math_2d_clip_polygon_with_polygon(

fz_xy_td *

clipper_pts,

fzrt_int

n_clipper_pts,

double *

clipper_a,

double *

clipper_c,

fz_xy_td *

clippee_pts,

fzrt_int

n_clippee_pts,

double *

clippee_a,

double *

clippee_c,

fzrt_int *

clippee_loops,

fzrt_int

n_clippee_loops,

fz_type_list_ptr

clippee_pts_list,

fz_type_list_ptr

clippee_loops_list )

Parameters

clipper_pts [Input]

array of points of the polygon used to clip

n_clipper_pts [Input]

number of points of the polygon used to clip

clipper_a [Input, Optional]

array containing the slopes of the line equations of the polygon

Default Value: the line equations are calculated from the poly_pts array

clipper_c [Input, Optional]

array containing the offsets of the line equations of the polygon

Default Value: the line equations are calculated from the poly_pts array

clippee_pts [Input]

array of points of the polygon to clip

n_clippee_pts [Input]

number of points of the polygon to clip

clippee_a [Input, Optional]

array containing the slopes of the line equations of the polygon

Default Value: the line equations are calculated from the poly_pts array

clippee_c [Input, Optional]

array containing the offsets of the line equations of the polygon

Default Value: the line equations are calculated from the poly_pts array

clippee_loops [Input]

array containing the index of the last point for a curve

n_clippee_loops [Input]

number of curves in the polygon to clip

clippee_pts_list [Result]

List of clipped points

clippee_loops_list [Result]

List of clipped loops

Returns

Error codes
FZ_MATH_ERR_ZERO_LEN_VEC - one of the polygon edges is zero length

Availability

5.0.0.0

Example Files

util_math_2d.fsl

See Also

fz_type_list_init, fz_type_list_count,, ,, fz_math_2d_area_of_polygon,

Function Set

fz_math_fset


Defined in

fz_math_api.h