diff --git a/Example/PerspectiveTransform/Visual.playground/Pages/Ovelay.xcplaygroundpage/Contents.swift b/Example/PerspectiveTransform/Visual.playground/Pages/Ovelay.xcplaygroundpage/Contents.swift index ffe1617..9591d62 100644 --- a/Example/PerspectiveTransform/Visual.playground/Pages/Ovelay.xcplaygroundpage/Contents.swift +++ b/Example/PerspectiveTransform/Visual.playground/Pages/Ovelay.xcplaygroundpage/Contents.swift @@ -43,13 +43,37 @@ for (index, point) in points.enumerated() { label.center = anchorView.center } +let transform = start.projectiveTransform(destination: destination) + UIView.animate(withDuration:1.0, delay: 0, options: [.repeat, .autoreverse], animations: { - overlayView.layer.transform = start.projectiveTransform(destination: destination) + overlayView.layer.transform = transform }, completion:nil) +print(transform) +transform.m13 == 0 +transform.m23 == 0 +transform.m31 == 0 +transform.m32 == 0 +transform.m34 == 0 +transform.m43 == 0 +transform.m33 == 1 +transform.m44 == 1 +transform.m41.rounded() == points[0].x.rounded() +transform.m42 == points[0].y +transform.m43 == 0 +transform.m44 == 1 + +transform.m11.isEqual(to: 16.6798123042149) +print(transform.m11) +print(transform.m11.rounded()) +print(transform.m11.rounded(FloatingPointRoundingRule.towardZero)) +transform.m11.magnitude +transform.m11.magnitude.isEqual(to: CGFloat(16.6798123042149).magnitude) +transform.m11.significand.isEqual(to: CGFloat(16.6798123042149).significand) +transform.m11.significand //: [Next](@next) diff --git a/Example/Tests/MatrixSpec.swift b/Example/Tests/MatrixSpec.swift index 2a412ff..2170afb 100644 --- a/Example/Tests/MatrixSpec.swift +++ b/Example/Tests/MatrixSpec.swift @@ -36,6 +36,23 @@ class MatrixSpec: QuickSpec { expect(m.determinant) == -1 expect(m.inverse.determinant) == -1 } + + it("should match math word 2x2 example") { + // http://www.mathwords.com/d/determinant.htm + // | 1 2 | + // | | = 1*4-2*3 = -2 + // | 3 4 | + expect(float2x2([float2(1,2), float2(3,4)]).determinant) == -2 + } + + it("should match math word 3x3 example") { + // http://www.mathwords.com/d/determinant.htm + // | 1 2 3 | + // | 4 5 6 | = (1*5*9+2*6*7+3*4*8)-(3*5*7+2*4*9+1*6*8) = 0 + // | 7 8 9 | + // See: https://www.google.com/search?client=safari&rls=en&q=(1*5*9%2B2*6*7%2B3*4*8)-(3*5*7%2B2*4*9%2B1*6*8)+=&ie=UTF-8&oe=UTF-8 + expect(Matrix3x3Type([1,2,3,4,5,6,7,8,9]).determinant) == 0 + } } } }