Nevron Open Vision Documentation
Graphics Paths

A graphics path is a sequence of points, that represent a collection of line segments and/or cubic bezier curves. The line and bezier segments inside a single graphics path can form multiple closed and open figures. There is an additional type parameter assigned to each point of the graphics path, that determines whether the point is a point from line segment, from a bezier segment, whether the point closes the current figure etc.

In NOV the graphics path is represented by the NGraphicsPath class. The graphics path is a multi-point geometry object, an as such shares a number of common features with polylines and polygons - see Multipoint Geometries.
Following is a brief overview of the most common operations that you can perform with a graphics path:


 
Plotter Operations

The most common way to fill a graphics path with figures is to use its plotter commands. The usage of plotter commands follows these steps:

  1. A new figure must first be started by calling the StartFigure method and passing the first point of the figure.
  2. Once you have started a figure you can call the Plotter Drawing Commands that all draw a segment from the last point in the path to a new location specified in the command. The plotter commands all have a To or Tos suffix - for example: LineTo, LineTos (performs multiple LineTo), CubicBezierTo, CircularArcTo and EllipticalArcTo.
  3. When you are finished filling the current figure you can call CloseFigure() to close it or do nothing if you intend the figure to remain open.

The following example renders a line and a triangle inside a graphics path:

Plotter Commands
Copy Code
NGraphicsPath path = new NGraphicsPath();
// draw a simple line (open figure)
path.StartFigure(10, 10);
path.LineTo(100, 100);
// add a triangle (closed figure)
path.StartFigure(10, 10);
path.LineTo(100, 10);
path.LineTo(10, 100);
path.CloseFigure();
Figure Operations

The NGraphicsPath provides a wealth of methods that help you add geometry objects to the path, such as rectangles, ellipses, triangles etc. These methods can be called at any stage of the graphics path construction. Based on type of figure being added to the graphics path, the methods are divided as follows:

The following code sample adds a rectangle and two line segments to a path:

Adding Basic Figures to a Path
Copy Code
// AddRectangle adds an entiry closed figure
path.AddRectangle(new NRectangle(0, 0, 100, 100));
// AddLineSegment sees that the current figure is closed and starts a new one (20, 20).
path.AddLineSegment(new NLineSegment(20, 20, 40, 30));
// AddLineSegment sees that the current figure is open and emits a new line to connect with it
path.AddLineSegment(new NLineSegment(30, 100, 25, 35));
// At this point the path has one closed rectangle figure, and open open figure that has the following points:
// (START:(20,20),LINETO(40,30),LINETO(30,100),LINETO(25,35)

You can get the count of figures contained inside a graphics via the GetFiguresCount() method. You can get information about the figure at a specific index via the GetFigure method. The following code sample iterates the figures of a path:

Iterate the Figures of a Path
Copy Code
int count = path.GetFigureCount();
for (int i = 0; i < count; i++)
{
 NGraphicsPathFigure figure = path.GetFigure(i);
 
 // determine whether figure is closed.
 bool isClosed = figure.Closed;
 // get figure bounds
 NRectangle figureBounds = path.GetFigureBounds(figure);
 // get figure path
 NGraphicsPath figurePath = path.GetFigurePath(figure);
}
Flattening

A graphics path is said to be flat, if it contains only line segments (i.e. does not contain cubic bezier segments). You can query whether a path is flat via the IsFlat property. The conversion of a non-flat graphics path to a flat one is called flattening and results in a graphics path, in which bezier curves from the original path are approximated with line segments. You can flatten a graphics path via the Flatten method.

Widening
The process of widening produces a graphics path, that encloses the area that is filled by the original path when drawn by the specified stroke. You can widen a graphics path via the Widen method.
Corner Rounding
The process of corner rounding replaces sharp corners (corners formed by adjacent line segments) with rounded ones (circle arcs). The bezier-line and bezier-bezier corners are not rounded. Corner rounding is performed by the RoundCorners method.
Containment (Hit Test)

You can query whether a point hits the filled area of the path via the Contains method. You can query whether a point hits the stroked outline of a path via the ContainsOnOutline method.

Send Feedback