mirror of
https://github.com/zhigang1992/PerspectiveTransform.git
synced 2026-04-29 04:35:14 +08:00
move basisVector() to member function
This commit is contained in:
@@ -13,7 +13,6 @@ class BasisSpec: QuickSpec {
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
context("multiply adj by vector") {
|
||||
it("should match expected") {
|
||||
let adjM = float3x3([-122, -152, 18544, 122, 0, 0, 0, 152, 0])
|
||||
@@ -27,13 +26,13 @@ class BasisSpec: QuickSpec {
|
||||
context("basis") {
|
||||
it("should match fiddle") {
|
||||
let startBasis = normalize(float3x3([0, 2818688, 0, 0, 0, 2262368, -18544, 18544, 18544]))
|
||||
let result = basis(start)
|
||||
let result = start.basisVector()
|
||||
expect(result) ≈ startBasis ± 0.5
|
||||
}
|
||||
|
||||
it("should work for destination") {
|
||||
let destBasis = normalize(float3x3([-4000000, 12000000, 4000000, -4000000, 4000000, 12000000, -40000, 40000, 40000]))
|
||||
let result = basis(destination)
|
||||
let result = destination.basisVector()
|
||||
expect(result) ≈ destBasis ± 0.5
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,10 +10,19 @@ import UIKit
|
||||
import simd
|
||||
|
||||
public extension Quadrilateral {
|
||||
func basisVector() -> float3x3 {
|
||||
let m = first3(self)
|
||||
let v4 = float3(p4)
|
||||
let v = m.inverse * v4
|
||||
let diag = float3x3(diagonal: v)
|
||||
let result = m * diag
|
||||
return result
|
||||
}
|
||||
|
||||
func general2DProjection(to:Quadrilateral) -> float3x3 {
|
||||
var source = basis(self)
|
||||
var source = basisVector()
|
||||
source = normalize(source)
|
||||
var destination = basis(to)
|
||||
var destination = to.basisVector()
|
||||
destination = normalize(destination)
|
||||
var result = destination * source.inverse
|
||||
result = normalize(result)
|
||||
@@ -80,15 +89,6 @@ func first3(quad:Quadrilateral) -> float3x3 {
|
||||
return float3x3([v1, v2, v3])
|
||||
}
|
||||
|
||||
func basis(quad:Quadrilateral) -> float3x3 {
|
||||
let m = first3(quad)
|
||||
let v4 = float3(quad.p4)
|
||||
let v = m.inverse * v4
|
||||
let diag = float3x3(diagonal: v)
|
||||
let result = m * diag
|
||||
return result
|
||||
}
|
||||
|
||||
func normalize(input:float3x3) -> float3x3 {
|
||||
return (Float(1) / input[2,2]) * input
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user