formZ SDK | 5.0 API Reference | System | Math

# fz_math_2d_clip_line_seg_with_polygon

Description

Clips a line segment (defined by it's start and end points) 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 lines 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 arrays. They must be preallocated by the calling routine and must be at least as large as the points array + 1 (i.e. sindx[ncurves-1] + 2).
clip_lines_start and clip_lines_end are arrays with the start and end points (respectively) of the clipped line fragments.
in_out is a marker array which specifies whether a clipped line segment is outside the polygon (-1), on the polygon edge (0), or inside the polygon (1). It contains (n_int_pts - 1) entries.
n_clip_lines specifies how many clipped line fragments there are. Note : n_int_pts is always at least 1. If it is, clip_lines contains the original line segment.

Plugin Prototype

fzrt_error_td fz_math_2d_clip_line_seg_with_polygon(

fz_xy_td * | line_start,
fz_xy_td * | line_end,
fz_xy_td * | poly_pts,
fzrt_int * | sindx,
fzrt_int | ncurves,
double * | edge_equs_a,
double * | edge_equs_c,
fz_xy_td * | clip_lines_start,
fz_xy_td * | clip_lines_end,
fzrt_int * | in_out,
fzrt_int * | n_clip_lines )

Parameters

line_start [Input]

start point of 2d line segment to clip

line_end [Input]

end point of 2d line segment to clip

poly_pts [Input]

polygon points array

sindx [Input]

array containing the index of the last point for a curve

ncurves [Input]

number of curves in polygon

edge_equs_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

edge_equs_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

clip_lines_start [Result]

array of the start points of the clipped line fragments
must be preallocated to store sindx[ncurves-1] + 2 values

clip_lines_end [Result]

array of the end points of the clipped line fragments
must be preallocated to store sindx[ncurves-1] + 2 values

in_out [Result]

array indicating the location of the clipped line segment in relation to the polygon
must be preallocated to store sindx[ncurves-1] + 2 values

n_clip_lines [Result]

number of clipped line fragments

Returns

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

Availability

5.0.0.0

Example Files

util_math_2d.fsl

See Also

,, fz_math_2d_area_of_polygon,

Function Set

fz_math_fset

Defined in

fz_math_api.h