make Quadrilateral internal

This commit is contained in:
Paul Zabelin
2018-03-12 02:09:54 -07:00
parent 2dc825524b
commit 6dd8da7dd2
3 changed files with 16 additions and 10 deletions

View File

@@ -8,15 +8,18 @@
import simd
/**
3D Perspective represented on 2D by 4 corners polygon
*/
public final class Perspective {
let vectors : [Vector3Type]
public init(_ q: Quadrilateral) {
init(_ q: Quadrilateral) {
vectors = q.corners.map{$0.homogeneous3dvector}
}
lazy var basisVectorsToPointsMap: Matrix3x3Type = calculateBasisVectorsToPointsMap()
lazy var pointsToBasisVectorsMap: Matrix3x3Type = basisVectorsToPointsMap.inverse
internal lazy var basisVectorsToPointsMap = calculateBasisVectorsToPointsMap()
internal lazy var pointsToBasisVectorsMap = basisVectorsToPointsMap.inverse
internal func projection(to:Perspective) -> Matrix3x3Type {
return to.basisVectorsToPointsMap * pointsToBasisVectorsMap
@@ -32,6 +35,9 @@ public final class Perspective {
}
extension Perspective: CustomDebugStringConvertible {
/**
returns String listing perspective vectors
*/
public var debugDescription: String {
return "Perspective: [\n" +
vectors.map {String(describing: $0)}.joined(separator: "\n") +

View File

@@ -8,8 +8,8 @@
import CoreGraphics
public final class Quadrilateral {
public var corners : [CGPoint] {
final class Quadrilateral {
var corners : [CGPoint] {
return [topLeft, topRight, bottomLeft, bottomRight]
}
@@ -18,18 +18,18 @@ public final class Quadrilateral {
private let bottomLeft: CGPoint
private let bottomRight: CGPoint
public init(_ topLeft:CGPoint, _ topRight:CGPoint, _ bottomLeft:CGPoint, _ bottomRight:CGPoint) {
init(_ topLeft:CGPoint, _ topRight:CGPoint, _ bottomLeft:CGPoint, _ bottomRight:CGPoint) {
self.topLeft = topLeft
self.topRight = topRight
self.bottomLeft = bottomLeft
self.bottomRight = bottomRight
}
public convenience init(_ points:[CGPoint]) {
convenience init(_ points:[CGPoint]) {
self.init(points[0], points[1], points[2], points[3])
}
public convenience init(_ origin:CGPoint, _ size:CGSize) {
convenience init(_ origin:CGPoint, _ size:CGSize) {
let stayPut = CGAffineTransform.identity
let shiftRight = CGAffineTransform(translationX: size.width, y: 0)
let shiftDown = CGAffineTransform(translationX: 0, y: size.height)
@@ -43,7 +43,7 @@ public final class Quadrilateral {
self.init(originToCornerTransform.map{origin.applying($0)})
}
public convenience init(_ rect:CGRect) {
convenience init(_ rect:CGRect) {
self.init(rect.origin, rect.size)
}
}