Skip to content

Commit

Permalink
Replace custom expandRect rectangle function with insert(
Browse files Browse the repository at this point in the history
  • Loading branch information
Boris-Em committed Jun 12, 2018
1 parent 0db548c commit 657817b
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 28 deletions.
2 changes: 1 addition & 1 deletion WeScan/Common/EditScanCornerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ final class EditScanCornerView: UIView {
override func draw(_ rect: CGRect) {
super.draw(rect)

let bezierPath = UIBezierPath(ovalIn: rect.expandRect(byOffset: -circleLayer.lineWidth))
let bezierPath = UIBezierPath(ovalIn: rect.insetBy(dx: circleLayer.lineWidth, dy: circleLayer.lineWidth))
circleLayer.frame = rect
circleLayer.path = bezierPath.cgPath

Expand Down
9 changes: 0 additions & 9 deletions WeScan/Extensions/CGRect+Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,4 @@ extension CGRect {
return translatedRect
}

/// Returns a new `CGRect` instance with the same center, with its width and height offset by the passed in value.
///
/// - Parameters:
/// - offset: The number of points the rect should be shrinked or expanded by
/// - Returns: A new instanec of `CGRect` shrinked or expanded by the number of points passed in.
func expandRect(byOffset offset: CGFloat) -> CGRect {
return CGRect(x: origin.x - offset / 2.0, y: origin.y - offset / 2.0, width: width + offset, height: height + offset)
}

}
18 changes: 1 addition & 17 deletions WeScanTests/CGRectTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,5 @@ final class CGRectTests: XCTestCase {

XCTAssert(rect == expectedRect)
}

func testExpandRect() {
var originalRect = CGRect(x: 0.0, y: 0.0, width: 100.0, height: 100.0)
var expandedRect = originalRect.expandRect(byOffset: 2)
var expectedRect = CGRect(x: -1.0, y: -1.0, width: 102.0, height: 102.0)

XCTAssert(expandedRect == expectedRect)
XCTAssert(CGPoint(x: originalRect.midX, y: originalRect.midY) == CGPoint(x: expandedRect.midX, y: expandedRect.midY))

originalRect = CGRect(x: 100.0, y: 100.0, width: 200.0, height: 200.0)
expandedRect = originalRect.expandRect(byOffset: -1)
expectedRect = CGRect(x: 100.5, y: 100.5, width: 199.0, height: 199.0)

XCTAssert(expandedRect == expectedRect)
XCTAssert(CGPoint(x: originalRect.midX, y: originalRect.midY) == CGPoint(x: expandedRect.midX, y: expandedRect.midY))
}


}
2 changes: 1 addition & 1 deletion WeScanTests/RectangleFeaturesFunnelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ final class RectangleFeaturesFunnelTests: XCTestCase {
let rectangleFeatureType2 = ImageFeatureTestHelpers.getRectangleFeature(from: .rect2)

for i in 0 ..< rectangleFeaturesType1.count {
funnel.add(rectangleFeaturesType1[i], currentlyDisplayedRectangle: nil, completion: { (rectange) in
funnel.add(rectangleFeaturesType1[i], currentlyDisplayedRectangle: nil, completion: { _ in
})
}

Expand Down

0 comments on commit 657817b

Please sign in to comment.