Utilities

public struct Utilities

Contains common helper methods.

  • Checks whether the segments defined by the specified point pairs intersect and returns the intersection point.

    Declaration

    Swift

    public static func segmentIntersect(_ s1: Point, s2: Point, l1: Point, l2: Point, pt: inout Point) -> Bool

    Parameters

    s1

    The first point of the first segment.

    s2

    The second point of the first segment.

    l1

    The first point of the second segment.

    l2

    The second point of the second segment.

    pt

    The intersection point if any.

    Return Value

    true if the segments intersect; otherwise false.

  • Finds the intersection point of the lines defined by the specified point pairs.

    Declaration

    Swift

    public static func lineIntersect(_ m1: Point, m2: Point, n1: Point, n2: Point) -> Point?

    Parameters

    s1

    The first point of the first line.

    s2

    The second point of the first line.

    l1

    The first point of the second line.

    l2

    The second point of the second line.

    Return Value

    The intersection point or nil if none is found.

  • Gets the point from the specified bezier curve, corresponding to the specified parameter t [0, 1].

    Declaration

    Swift

    public static func getBezierPt(_ points: [Point], segment: Int, t: Double) -> Point

    Parameters

    points

    An array with the control point-s of the Bezier curve.

    segment

    The index of the segment.

    t

    The parameter. Values range from [0, 1].

    Return Value

    A point.

  • Calculate the intersection point between the ellipse with the specified bounds and the line segment defined by the specified points.

    Declaration

    Swift

    public static func getEllipseIntr(_ rcBox: Rect, pt1: Point, pt2: Point, pt: inout Point)

    Parameters

    rcBox

    The bounding rectangle of the ellipse.

    pt1

    The first point of the line segment.

    pt2

    The second point of the line segment.

    pt

    The intersection point.

  • Normalizes the specified rectangle ensuring its height and width are non-negative numbers.

    Declaration

    Swift

    public static func normalizeRect(_ rc: Rect) -> Rect

    Parameters

    rc

    The rectangle to normalize.

    Return Value

    The normalized rectangle.

  • Approximates the specified Bézier curve with a polyline. The specified quality parameter varies in the interval [1, …) and is proportional to the number of points in the resulting polyline.

    Declaration

    Swift

    public static func approxBezier(_ points: [Point], startIdx: Int, quality: Int) -> [Point]

    Parameters

    points

    An array of Point objects, which defines the Bézier curve.

    startIdx

    The index of the first point to be processed in points.

    quality

    The quality of the produced approximation.

    Return Value

    A list with Point objects, which contain the calculated approximation.

  • Returns the smallest possible rectangle containing both of the specified rectangles if they are not empty.

    Declaration

    Swift

    public static func unionRects(_ rc1: Rect!, rc2: Rect!) -> Rect?

    Parameters

    rc1

    The first rectangle.

    rc2

    The second rectangle.

    Return Value

    A rectangle that represents the union of the specified arguments.

  • Inflates the specified rectangle with the specified amount on all sides.

    Declaration

    Swift

    public static func inflate(_ rc: inout Rect, size: Double)

    Parameters

    rc

    The rectangle to inflate.

    size

    The amount with which rc is inflated.

  • Inflates the specified rectangle with the specified horizontal and vertical amount.

    Declaration

    Swift

    public static func inflate(_ rc: inout Rect, sx: Double, sy: Double)

    Parameters

    rc

    The rectangle to inflate.

    sx

    The amount with which rc is inflated horizontally.

    sy

    The amount with which rc is inflated vertically.

  • Checks whether the specified rectangle contains the specified point.

    Declaration

    Swift

    public static func pointInRect(_ pt: Point, rc: Rect) -> Bool

    Parameters

    pt

    The point to check.

    rc

    The rectangle.

    Return Value

    true if the point is in the rectangle; otherwise false.

  • Gets the point where the specified rectangle is crossed by the specified line.

    Declaration

    Swift

    public static func getRectIntr(_ rcBox: Rect, pt1: Point, pt2: Point, pt: inout Point)

    Parameters

    rcBox
    pt1

    The first point of the line.

    pt2

    The second point of the line.

    pt

    The intersection point.