Skip to content

Commit

Permalink
Merge pull request #8 from koher/dev-0.4.1
Browse files Browse the repository at this point in the history
Develop 0.4.1
  • Loading branch information
koher authored May 4, 2020
2 parents 910ed2e + 9feb2ea commit f6bed1d
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Sources/CGPointVector/CGPoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ extension CGPoint {
}

public var length: CGFloat {
return sqrt(squareLength)
return hypot(x, y)
}

public var squareLength: CGFloat {
Expand Down
2 changes: 1 addition & 1 deletion Sources/CGPointVector/CGSize.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ extension CGSize {
}

public var length: CGFloat {
return sqrt(squareLength)
return hypot(width, height)
}

public var squareLength: CGFloat {
Expand Down
2 changes: 1 addition & 1 deletion Sources/CGPointVector/CGVector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ extension CGVector {
}

public var length: CGFloat {
return sqrt(squareLength)
return hypot(dx, dy)
}

public var squareLength: CGFloat {
Expand Down
2 changes: 2 additions & 0 deletions Tests/CGPointVectorTests/CGPointTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class CGPointTests: XCTestCase {

func testLength() {
XCTAssertEqual(CGPoint(x: 3.0, y: -4.0).length, 5.0, accuracy: torelance)
XCTAssertEqual(CGPoint(x: .greatestFiniteMagnitude, y: 0.0).length, .greatestFiniteMagnitude)
XCTAssertEqual(CGPoint(x: 0.0, y: .leastNonzeroMagnitude).length, .leastNonzeroMagnitude)
}

func testSquareLength() {
Expand Down
2 changes: 2 additions & 0 deletions Tests/CGPointVectorTests/CGSizeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class CGSizeTests: XCTestCase {

func testLength() {
XCTAssertEqual(CGSize(width: 3.0, height: -4.0).length, 5.0, accuracy: torelance)
XCTAssertEqual(CGSize(width: .greatestFiniteMagnitude, height: 0.0).length, .greatestFiniteMagnitude)
XCTAssertEqual(CGSize(width: 0.0, height: .leastNonzeroMagnitude).length, .leastNonzeroMagnitude)
}

func testSquareLength() {
Expand Down
2 changes: 2 additions & 0 deletions Tests/CGPointVectorTests/CGVectorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class CGVectorTests: XCTestCase {

func testLength() {
XCTAssertEqual(CGVector(dx: 3.0, dy: -4.0).length, 5.0, accuracy: torelance)
XCTAssertEqual(CGVector(dx: .greatestFiniteMagnitude, dy: 0.0).length, .greatestFiniteMagnitude)
XCTAssertEqual(CGVector(dx: 0.0, dy: .leastNonzeroMagnitude).length, .leastNonzeroMagnitude)
}

func testSquareLength() {
Expand Down

0 comments on commit f6bed1d

Please sign in to comment.