Geometric Primitives.playground/Sources/Support.swift
/* |
Copyright (C) 2016 Apple Inc. All Rights Reserved. |
See LICENSE.txt for this sample’s licensing information |
Abstract: |
Support code for the `simd` geometric primitive playground. |
*/ |
import simd |
/// Enum for possible results of an incircle test. |
public enum IncircleResult { |
case insideCircle |
case onCircle |
case outsideCircle |
case nan |
/// Initialize incircle result from a floating-point value. |
public init<T: FloatingPoint>(_ value: T) { |
if value < T(0) { self = .outsideCircle } |
else if value > T(0) { self = .insideCircle } |
else if value == T(0) { self = .onCircle } |
else { self = .nan } |
} |
} |
/// Enum for possible results of an orientation test. |
public enum Orientation { |
case positivelyOriented |
case degenerate |
case negativelyOriented |
case nan |
/// Initialize orientation result from a floating-point value. |
public init<T: FloatingPoint>(_ value: T) { |
if value < T(0) { self = .negativelyOriented } |
else if value > T(0) { self = .positivelyOriented } |
else if value == T(0) { self = .degenerate } |
else { self = .nan } |
} |
} |
public extension float2x2 { |
/// Determinant of `self`. |
var determinant: Float { return matrix_determinant(self.cmatrix) } |
} |
public extension float3x3 { |
/// Determinant of `self`. |
var determinant: Float { return matrix_determinant(self.cmatrix) } |
} |
public extension float4x4 { |
/// Determinant of `self`. |
var determinant: Float { return matrix_determinant(self.cmatrix) } |
} |
Copyright © 2016 Apple Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2016-09-28