mirror of
https://github.com/zhigang1992/PerspectiveTransform.git
synced 2026-05-07 00:42:03 +08:00
lint
This commit is contained in:
@@ -23,13 +23,13 @@ jobs:
|
||||
command: |
|
||||
curl https://cocoapods-specs.circleci.com/fetch-cocoapods-repo-from-s3.sh | bash -s cf
|
||||
pod install --project-directory=Example
|
||||
- run:
|
||||
name: Build and run tests
|
||||
command: xcodebuild -workspace Example/PerspectiveTransform.xcworkspace -scheme Example test -destination "$DESTINATION" | xcpretty -r junit
|
||||
- save_cache:
|
||||
key: 2-pods-{{ checksum "Example/Podfile.lock" }}
|
||||
paths:
|
||||
- Example/Pods
|
||||
- run:
|
||||
name: Build and run tests
|
||||
command: xcodebuild -workspace Example/PerspectiveTransform.xcworkspace -scheme Example test -destination "$DESTINATION" | xcpretty -r junit
|
||||
- store_test_results:
|
||||
path: build/reports
|
||||
- store_artifacts:
|
||||
|
||||
3
.swiftlint.yml
Normal file
3
.swiftlint.yml
Normal file
@@ -0,0 +1,3 @@
|
||||
excluded:
|
||||
- Carthage
|
||||
- Pods
|
||||
@@ -25,7 +25,7 @@ class CompareTransformSpecConfiguration: QuickConfiguration {
|
||||
CGPoint(x: 108.315837, y: 80.1687782),
|
||||
CGPoint(x: 377.282671, y: 41.4352201),
|
||||
CGPoint(x: 193.321418, y: 330.023027),
|
||||
CGPoint(x: 459.781253, y: 251.836131),
|
||||
CGPoint(x: 459.781253, y: 251.836131)
|
||||
]
|
||||
let frame = CGRect(origin: CGPoint.zero,
|
||||
size: CGSize(width: 20, height: 10))
|
||||
|
||||
@@ -379,6 +379,7 @@
|
||||
607FACCD1AFB9204008FA782 /* Frameworks */,
|
||||
607FACCE1AFB9204008FA782 /* Resources */,
|
||||
125261E66BB239DB9C4C2C55 /* [CP] Embed Pods Frameworks */,
|
||||
4BD29D3B21F6E985009729A5 /* ShellScript */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
@@ -576,6 +577,23 @@
|
||||
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Application Specs/Pods-Application Specs-frameworks.sh\"\n";
|
||||
showEnvVarsInLog = 0;
|
||||
};
|
||||
4BD29D3B21F6E985009729A5 /* ShellScript */ = {
|
||||
isa = PBXShellScriptBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
inputFileListPaths = (
|
||||
);
|
||||
inputPaths = (
|
||||
);
|
||||
outputFileListPaths = (
|
||||
);
|
||||
outputPaths = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
shellPath = "/bin/bash -l";
|
||||
shellScript = "if which swiftlint >/dev/null; then\n /usr/local/bin/swiftlint autocorrect\nelse\n echo \"warning: SwiftLint not installed\"\n echo \"brew install swiftlint\"\nfi\n";
|
||||
};
|
||||
70CD543F2A946479825D6587 /* [CP] Embed Pods Frameworks */ = {
|
||||
isa = PBXShellScriptBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
|
||||
@@ -34,4 +34,3 @@ class FittingPolygon {
|
||||
return FittingPolygon(svgPointsString: loader.loadPoints())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ let points = [
|
||||
CGPoint(x: 108.315837, y: 80.1687782),
|
||||
CGPoint(x: 377.282671, y: 41.4352201),
|
||||
CGPoint(x: 193.321418, y: 330.023027),
|
||||
CGPoint(x: 459.781253, y: 251.836131),
|
||||
CGPoint(x: 459.781253, y: 251.836131)
|
||||
]
|
||||
|
||||
let destination = QuadrilateralCalc()
|
||||
@@ -62,8 +62,6 @@ CATransform3DEqualToTransform(matrix, toPlace)
|
||||
overlayView.layer.transform = toPlace
|
||||
overlayView2.layer.transform = matrix
|
||||
|
||||
|
||||
|
||||
//: Single point rect should produce identity matrix
|
||||
|
||||
let q = QuadrilateralCalc()
|
||||
|
||||
@@ -49,4 +49,3 @@ transform.m33 == 1
|
||||
transform.m41 == 100
|
||||
transform.m42 == 100
|
||||
transform.m43 == 0
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ let points = [
|
||||
CGPoint(x: 108.315837, y: 80.1687782),
|
||||
CGPoint(x: 377.282671, y: 41.4352201),
|
||||
CGPoint(x: 193.321418, y: 330.023027),
|
||||
CGPoint(x: 459.781253, y: 251.836131),
|
||||
CGPoint(x: 459.781253, y: 251.836131)
|
||||
]
|
||||
let destination = Perspective(points)
|
||||
|
||||
|
||||
@@ -43,4 +43,3 @@ public extension CATransform3D {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ public class QuadrilateralCalc {
|
||||
let kEpsilon = CGFloat(0.0001)
|
||||
|
||||
if abs(i) < kEpsilon {
|
||||
i = kEpsilon * (i > 0 ? 1.0 : -1.0);
|
||||
i = kEpsilon * (i > 0 ? 1.0 : -1.0)
|
||||
}
|
||||
|
||||
return CATransform3D(m11: a/i, m12: d/i, m13: 0, m14: g/i,
|
||||
|
||||
@@ -67,8 +67,6 @@ class CALayerTransformSpec: QuickSpec {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ class CATransform3Dfrom2DSpec: QuickSpec {
|
||||
let projection2D = Matrix3x3Type([
|
||||
Vector3Type(11, 12, 13),
|
||||
Vector3Type(21, 22, 23),
|
||||
Vector3Type(31,32,1),
|
||||
Vector3Type(31, 32, 1)
|
||||
])
|
||||
let projection3D = CATransform3D(
|
||||
m11: 11, m12: 12, m13: 0, m14: 13,
|
||||
|
||||
@@ -57,4 +57,3 @@ class MatrixSpec: QuickSpec {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -205,7 +205,6 @@ class ProjectionSpec: QuickSpec {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
context("affine 2D") {
|
||||
var scale2D: CGAffineTransform!
|
||||
var translate2D: CGAffineTransform!
|
||||
|
||||
@@ -8,9 +8,9 @@ class VectorProjectionSpec: QuickSpec {
|
||||
it("should be 0 orthogonally") {
|
||||
let v12 = vector_float2(1, 0)
|
||||
let v23 = vector_float2(0, 1)
|
||||
let p = project(v12, v23)
|
||||
expect(p.x) == 0
|
||||
expect(p.y) == 0
|
||||
let projection = project(v12, v23)
|
||||
expect(projection.x) == 0
|
||||
expect(projection.y) == 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,7 +92,6 @@ class AccelerateSolvePerfTest: XCTestCase {
|
||||
XCTAssertEqual(solution[7], 0, accuracy: accuracy)
|
||||
}
|
||||
|
||||
|
||||
func testSolvePerformance() {
|
||||
preparePerspective()
|
||||
measure {
|
||||
|
||||
@@ -13,7 +13,7 @@ class CompareTransformSpecConfiguration: QuickConfiguration {
|
||||
CGPoint(x: 108.315837, y: 80.1687782),
|
||||
CGPoint(x: 377.282671, y: 41.4352201),
|
||||
CGPoint(x: 193.321418, y: 330.023027),
|
||||
CGPoint(x: 459.781253, y: 251.836131),
|
||||
CGPoint(x: 459.781253, y: 251.836131)
|
||||
]
|
||||
let frame = CGRect(origin: CGPoint.zero,
|
||||
size: CGSize(width: 20, height: 10))
|
||||
|
||||
@@ -16,7 +16,7 @@ extension CATransform3D {
|
||||
m11, m12, m13, m14,
|
||||
m21, m22, m23, m24,
|
||||
m31, m32, m33, m34,
|
||||
m41, m42, m43, m44,
|
||||
m41, m42, m43, m44
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ class PerformanceTest: XCTestCase {
|
||||
CGPoint(x: 108.315837, y: 80.1687782),
|
||||
CGPoint(x: 377.282671, y: 41.4352201),
|
||||
CGPoint(x: 193.321418, y: 330.023027),
|
||||
CGPoint(x: 459.781253, y: 251.836131),
|
||||
CGPoint(x: 459.781253, y: 251.836131)
|
||||
]
|
||||
|
||||
let destination = QuadrilateralCalc()
|
||||
|
||||
@@ -87,7 +87,7 @@ public class QuadrilateralCalc {
|
||||
let kEpsilon = CGFloat(0.0001)
|
||||
|
||||
if abs(i) < kEpsilon {
|
||||
i = kEpsilon * (i > 0 ? 1.0 : -1.0);
|
||||
i = kEpsilon * (i > 0 ? 1.0 : -1.0)
|
||||
}
|
||||
|
||||
return CATransform3D(m11: a/i, m12: d/i, m13: 0, m14: g/i,
|
||||
|
||||
@@ -55,10 +55,8 @@ extension Matrix3x3Type {
|
||||
}
|
||||
|
||||
private var normalizationFactor: ScalarType {
|
||||
get {
|
||||
let zScale = self[Vector3Type.lastIndex, Vector3Type.lastIndex]
|
||||
assert(zScale.isZero == false, "since we use homogenized vectors, z != 0")
|
||||
return ScalarType.one / zScale
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,15 +14,15 @@ import simd
|
||||
public final class Perspective {
|
||||
let vectors: [Vector3Type]
|
||||
|
||||
init(_ q: Quadrilateral) {
|
||||
vectors = q.corners.map{$0.homogeneous3dvector}
|
||||
init(_ quad: Quadrilateral) {
|
||||
vectors = quad.corners.map {$0.homogeneous3dvector}
|
||||
}
|
||||
|
||||
internal lazy var basisVectorsToPointsMap = calculateBasisVectorsToPointsMap()
|
||||
internal lazy var pointsToBasisVectorsMap = basisVectorsToPointsMap.inverse
|
||||
|
||||
internal func projection(to:Perspective) -> Matrix3x3Type {
|
||||
return to.basisVectorsToPointsMap * pointsToBasisVectorsMap
|
||||
internal func projection(to destination: Perspective) -> Matrix3x3Type {
|
||||
return destination.basisVectorsToPointsMap * pointsToBasisVectorsMap
|
||||
}
|
||||
|
||||
private func calculateBasisVectorsToPointsMap() -> Matrix3x3Type {
|
||||
|
||||
Reference in New Issue
Block a user