Class

NSBezier​Path

An NSBezier​Path object allows you to create paths using PostScript-style commands. Paths consist of straight and curved line segments joined together. Paths can form recognizable shapes such as rectangles, ovals, arcs, and glyphs; they can also form complex polygons using either straight or curved line segments. A single path can be closed by connecting its two endpoints, or it can be left open.

Overview

An NSBezier​Path object can contain multiple disconnected paths, whether they are closed or open. Each of these paths is referred to as a subpath. The subpaths of an NSBezier​Path object must be manipulated as a group. The only way to manipulate subpaths individually is to create separate NSBezier​Path objects for each.

For a given NSBezier​Path object, you can stroke the path’s outline or fill the region occupied by the path. You can also use the path as a clipping region for views or other regions. Using methods of NSBezier​Path, you can also perform hit detection on the filled or stroked path. Hit detection is needed to implement interactive graphics, as in rubber banding and dragging operations.

The current graphics context is automatically saved and restored for all drawing operations involving NSBezier​Path objects, so your application does not need to worry about the graphics settings changing across invocations.

Symbols

Creating an NSBezierPath Object

init(oval​In:​ NSRect)

Creates and returns a new NSBezier​Path object initialized with an oval path inscribed in the specified rectangle.

init(rect:​ NSRect)

Creates and returns a new NSBezier​Path object initialized with a rectangular path.

init(rounded​Rect:​ NSRect, x​Radius:​ CGFloat, y​Radius:​ CGFloat)

Creates and returns a new NSBezier​Path object initialized with a rounded rectangular path.

var flattened:​ NSBezier​Path

A flattened version of the path object.

var reversed:​ NSBezier​Path

A path containing the reversed contents of the current path object.

Constructing Paths

func move(to:​ NSPoint)

Moves the receiver’s current point to the specified location.

func line(to:​ NSPoint)

Appends a straight line to the receiver’s path

func close()

Closes the most recently added subpath.

func relative​Move(to:​ NSPoint)

Moves the receiver’s current point to a new point whose location is the specified distance from the current point.

func relative​Line(to:​ NSPoint)

Appends a straight line segment to the receiver’s path starting at the current point and moving towards the specified point, relative to the current location.

func relative​Curve(to:​ NSPoint, control​Point1:​ NSPoint, control​Point2:​ NSPoint)

Adds a Bezier cubic curve to the receiver’s path from the current point to a new location, which is specified as a relative distance from the current point.

Appending Common Shapes to a Path

func append(NSBezier​Path)

Appends the contents of the specified path object to the receiver’s path.

func append​Points(NSPoint​Array, count:​ Int)

Appends a series of line segments to the receiver’s path.

func append​Oval(in:​ NSRect)

Appends an oval path to the receiver, inscribing the oval in the specified rectangle.

func append​Glyph(NSGlyph, in:​ NSFont)

Appends an outline of the specified glyph to the receiver’s path.

func append​Glyphs(Unsafe​Mutable​Pointer<NSGlyph>, count:​ Int, in:​ NSFont)

Appends the outlines of the specified glyphs to the receiver’s path.

func append​Packed​Glyphs(Unsafe​Pointer<Int8>)

Appends an array of packed glyphs to the receiver’s path.

func append​Rect(NSRect)

Appends a rectangular path to the receiver’s path.

func append​Rounded​Rect(NSRect, x​Radius:​ CGFloat, y​Radius:​ CGFloat)

Appends a rounded rectangular path to the receiver’s path.

Accessing the Path Attributes

var winding​Rule:​ NSWinding​Rule

The winding rule used to fill the path.

var line​Cap​Style:​ NSLine​Cap​Style

The line cap style for the path.

var line​Join​Style:​ NSLine​Join​Style

The line join style for the path.

var line​Width:​ CGFloat

The width of stroked path lines.

var miter​Limit:​ CGFloat

The limit at which miter joins are converted to bevel joins.

var flatness:​ CGFloat

The accuracy with which curves are rendered.

Configuring the Default Path Attributes

class func default​Winding​Rule()

Returns the default winding rule used to fill all paths.

class func set​Default​Winding​Rule(NSWinding​Rule)

Sets the default winding rule used to fill all paths.

class func default​Line​Cap​Style()

Returns the default line cap style for all paths.

class func set​Default​Line​Cap​Style(NSLine​Cap​Style)

Sets the default line cap style for all paths.

class func default​Line​Join​Style()

Returns the default line join style for all paths.

class func set​Default​Line​Join​Style(NSLine​Join​Style)

Sets the default line join style for all paths.

class func default​Line​Width()

Returns the default line width for the all paths.

class func set​Default​Line​Width(CGFloat)

Sets the default line width for all paths.

class func default​Miter​Limit()

Returns the default miter limit for all paths.

class func set​Default​Miter​Limit(CGFloat)

Sets the default miter limit for all paths.

class func default​Flatness()

Returns the default flatness value for all paths.

class func set​Default​Flatness(CGFloat)

Sets the default flatness value for all paths.

Drawing Paths

func stroke()

Draws a line along the receiver’s path using the current stroke color and drawing attributes.

func fill()

Paints the region enclosed by the receiver’s path.

class func fill(NSRect)

Fills the specified rectangular path with the current fill color.

class func stroke(NSRect)

Strokes the path of the specified rectangle using the current stroke color and the default drawing attributes.

class func stroke​Line(from:​ NSPoint, to:​ NSPoint)

Strokes a line between two points using the current stroke color and the default drawing attributes.

class func draw​Packed​Glyphs(Unsafe​Pointer<Int8>, at:​ NSPoint)

Draws a set of packed glyphs at the specified point in the current coordinate system.

Clipping Paths

func add​Clip()

Intersects the area enclosed by the receiver's path with the clipping path of the current graphics context and makes the resulting shape the current clipping path.

func set​Clip()

Replaces the clipping path of the current graphics context with the area inside the receiver's path.

class func clip(NSRect)

Intersects the specified rectangle with the clipping path of the current graphics context and makes the resulting shape the current clipping path

Hit Detection

func contains(NSPoint)

Returns a Boolean value indicating whether the receiver contains the specified point.

Querying Paths

var bounds:​ NSRect

The bounding box of the receiver’s path

var control​Point​Bounds:​ NSRect

The bounding box of the receiver’s path, including any control points

var current​Point:​ NSPoint

The receiver’s current point (the trailing point or ending point in the most recently added segment).

var is​Empty:​ Bool

A Boolean value indicating whether the path is empty.

Applying Transformations

func transform(using:​ Affine​Transform)

Transforms all points in the receiver using the specified transform.

Accessing Elements of a Path

var element​Count:​ Int

The total number of path elements in the receiver's path.

func element(at:​ Int)

Returns the type of path element at the specified index.

func element(at:​ Int, associated​Points:​ NSPoint​Array?)

Gets the element type and (and optionally) the associated points for the path element at the specified index.

func remove​All​Points()

Removes all path elements from the receiver, effectively clearing the path.

func set​Associated​Points(NSPoint​Array?, at:​ Int)

Changes the points associated with the specified path element.

Constants

NSBezier​Path​Element

Basic path element commands.

NSLine​Join​Style

These constants specify the shape of the joints between connected segments of a stroked path.

NSLine​Cap​Style

These constants specify the shape of endpoints for an open path when stroked.

NSWinding​Rule

These constants are used to specify the winding rule a Bezier path should use.

Relationships

Inherits From