import { IClone } from "./IClone" ; import { Vector3 } from "./Vector3" ; /**
 * Represents a plane in three dimensional space.
 */ export class Plane implements IClone { param p param out static normalize ( p , out ) { const { normal } = p ; const factor = 1.0 / normal . length ( ) ; const outNormal = out . normal ; outNormal . x = normal . x * factor ; outNormal . y = normal . y * factor ; outNormal . z = normal . z * factor ; out . distance = p . distance * factor ; } param point0 param point1 param point2 param out static fromPoints ( point0 , point1 , point2 , out ) { const x0 = point0 . x ; const y0 = point0 . y ; const z0 = point0 . z ; const x1 = point1 . x - x0 ; const y1 = point1 . y - y0 ; const z1 = point1 . z - z0 ; const x2 = point2 . x - x0 ; const y2 = point2 . y - y0 ; const z2 = point2 . z - z0 ; const yz = y1 * z2 - z1 * y2 ; const xz = z1 * x2 - x1 * z2 ; const xy = x1 * y2 - y1 * x2 ; const invPyth = 1.0 / Math . sqrt ( yz * yz + xz * xz + xy * xy ) ; const x = yz * invPyth ; const y = xz * invPyth ; const z = xy * invPyth ; const { normal } = out ; normal . x = x ; normal . y = y ; normal . z = z ; out . distance = - ( x * x0 + y * y0 + z * z0 ) ; } /** The normal of the plane. */ public readonly normal : Vector3 = new Vector3 ( ) ; /** The distance of the plane along its normal to the origin. */ public distance : number = 0 ; param normal param distance constructor ( normal = null , distance = 0 ) { normal && normal . cloneTo ( this . normal ) ; this . distance = distance ; } returns normalize ( ) { Plane . normalize ( this , this ) ; return this ; } returns clone ( ) { const out = new Plane ( ) ; this . cloneTo ( out ) ; return out ; } param out returns cloneTo ( out ) { this . normal . cloneTo ( out . normal ) ; out . distance = this . distance ; return out ; } }