move basisVector() to member function

This commit is contained in:
Paul Zabelin
2016-02-20 23:21:17 -08:00
parent 0098fcab2c
commit b90a82f6cb
2 changed files with 13 additions and 14 deletions

View File

@@ -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
}
}

View File

@@ -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
}