CGPoint

struct CGPoint
  • SwifterSwift: Distance from another CGPoint.

    let point1 = CGPoint(x: 10, y: 10)
    let point2 = CGPoint(x: 30, y: 30)
    let distance = point1.distance(from: point2)
    //distance = 28.28
    

    Declaration

    Swift

    public func distance(from point: CGPoint) -> CGFloat

    Parameters

    point

    CGPoint to get distance from.

    Return Value

    Distance between self and given CGPoint.

  • SwifterSwift: Distance between two CGPoints.

    let point1 = CGPoint(x: 10, y: 10)
    let point2 = CGPoint(x: 30, y: 30)
    let distance = CGPoint.distance(from: point2, to: point1)
    //Distance = 28.28
    

    Declaration

    Swift

    public static func distance(from point1: CGPoint, to point2: CGPoint) -> CGFloat

    Parameters

    point1

    first CGPoint.

    point2

    second CGPoint.

    Return Value

    distance between the two given CGPoints.

  • SwifterSwift: Add two CGPoints.

    let point1 = CGPoint(x: 10, y: 10)
    let point2 = CGPoint(x: 30, y: 30)
    let point = point1 + point2
    //point = CGPoint(x: 40, y: 40)
    

    Declaration

    Swift

    public static func + (lhs: CGPoint, rhs: CGPoint) -> CGPoint

    Parameters

    lhs

    CGPoint to add to.

    rhs

    CGPoint to add.

    Return Value

    result of addition of the two given CGPoints.

  • SwifterSwift: Add a CGPoints to self.

    let point1 = CGPoint(x: 10, y: 10)
    let point2 = CGPoint(x: 30, y: 30)
    point1 += point2
    //point1 = CGPoint(x: 40, y: 40)
    

    Declaration

    Swift

    public static func += (lhs: inout CGPoint, rhs: CGPoint)

    Parameters

    lhs

    self

    rhs

    CGPoint to add.

  • SwifterSwift: Subtract two CGPoints.

    let point1 = CGPoint(x: 10, y: 10)
    let point2 = CGPoint(x: 30, y: 30)
    let point = point1 - point2
    //point = CGPoint(x: -20, y: -20)
    

    Declaration

    Swift

    public static func - (lhs: CGPoint, rhs: CGPoint) -> CGPoint

    Parameters

    lhs

    CGPoint to subtract from.

    rhs

    CGPoint to subtract.

    Return Value

    result of subtract of the two given CGPoints.

  • SwifterSwift: Subtract a CGPoints from self.

    let point1 = CGPoint(x: 10, y: 10)
    let point2 = CGPoint(x: 30, y: 30)
    point1 -= point2
    //point1 = CGPoint(x: -20, y: -20)
    

    Declaration

    Swift

    public static func -= (lhs: inout CGPoint, rhs: CGPoint)

    Parameters

    lhs

    self

    rhs

    CGPoint to subtract.

  • SwifterSwift: Multiply a CGPoint with a scalar

    let point1 = CGPoint(x: 10, y: 10)
    let scalar = point1 * 5
    //scalar = CGPoint(x: 50, y: 50)
    

    Declaration

    Swift

    public static func * (point: CGPoint, scalar: CGFloat) -> CGPoint

    Parameters

    point

    CGPoint to multiply.

    scalar

    scalar value.

    Return Value

    result of multiplication of the given CGPoint with the scalar.

  • SwifterSwift: Multiply self with a scalar

    let point1 = CGPoint(x: 10, y: 10)
    point *= 5
    //point1 = CGPoint(x: 50, y: 50)
    

    Declaration

    Swift

    public static func *= (point: inout CGPoint, scalar: CGFloat)

    Parameters

    point

    self.

    scalar

    scalar value.

    Return Value

    result of multiplication of the given CGPoint with the scalar.

  • SwifterSwift: Multiply a CGPoint with a scalar

    let point1 = CGPoint(x: 10, y: 10)
    let scalar = 5 * point1
    //scalar = CGPoint(x: 50, y: 50)
    

    Declaration

    Swift

    public static func * (scalar: CGFloat, point: CGPoint) -> CGPoint

    Parameters

    scalar

    scalar value.

    point

    CGPoint to multiply.

    Return Value

    result of multiplication of the given CGPoint with the scalar.