// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved. // ----------------------------------------------------------------------------- // Original code from SharpDX project. https://github.com/sharpdx/SharpDX/ // Greetings to Alexandre Mutel. Original code published with the following license: // ----------------------------------------------------------------------------- // Copyright (c) 2010-2014 SharpDX - Alexandre Mutel // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. // ----------------------------------------------------------------------------- // Original code from SlimMath project. http://code.google.com/p/slimmath/ // Greetings to SlimDX Group. Original code published with the following license: // ----------------------------------------------------------------------------- /* * Copyright (c) 2007-2011 SlimDX Group * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ using System; using System.Globalization; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace FlaxEngine { [Serializable] partial struct Plane : IEquatable, IFormattable { /// /// Initializes a new instance of the struct. /// /// The value that will be assigned to all components. public Plane(float value) { Normal.X = Normal.Y = Normal.Z = D = value; } /// /// Initializes a new instance of the struct. /// /// The X component of the normal. /// The Y component of the normal. /// The Z component of the normal. /// The distance of the plane along its normal from the origin. public Plane(float a, float b, float c, float d) { Normal.X = a; Normal.Y = b; Normal.Z = c; D = d; } /// /// Initializes a new instance of the class. /// /// Any point that lies along the plane. /// The normal vector to the plane. public Plane(Vector3 point, Vector3 normal) { Normal = normal; D = -Vector3.Dot(normal, point); } /// /// Initializes a new instance of the struct. /// /// The normal of the plane. /// The distance of the plane along its normal from the origin public Plane(Vector3 value, float d) { Normal = value; D = d; } /// /// Initializes a new instance of the struct. /// /// First point of a triangle defining the plane. /// Second point of a triangle defining the plane. /// Third point of a triangle defining the plane. public Plane(Vector3 point1, Vector3 point2, Vector3 point3) { float x1 = point2.X - point1.X; float y1 = point2.Y - point1.Y; float z1 = point2.Z - point1.Z; float x2 = point3.X - point1.X; float y2 = point3.Y - point1.Y; float z2 = point3.Z - point1.Z; float yz = y1 * z2 - z1 * y2; float xz = z1 * x2 - x1 * z2; float xy = x1 * y2 - y1 * x2; float invPyth = 1.0f / (float)Math.Sqrt(yz * yz + xz * xz + xy * xy); Normal.X = yz * invPyth; Normal.Y = xz * invPyth; Normal.Z = xy * invPyth; D = -(Normal.X * point1.X + Normal.Y * point1.Y + Normal.Z * point1.Z); } /// /// Initializes a new instance of the struct. /// /// /// The values to assign to the A, B, C, and D components of the plane. This must be an array with /// four elements. /// /// Thrown when is null. /// /// Thrown when contains more or less than four /// elements. /// public Plane(float[] values) { if (values == null) throw new ArgumentNullException(nameof(values)); if (values.Length != 4) throw new ArgumentOutOfRangeException(nameof(values), "There must be four and only four input values for Plane."); Normal.X = values[0]; Normal.Y = values[1]; Normal.Z = values[2]; D = values[3]; } /// /// Gets or sets the component at the specified index. /// /// The value of the A, B, C, or D component, depending on the index. /// /// The index of the component to access. Use 0 for the A component, 1 for the B component, 2 for the C /// component, and 3 for the D component. /// /// The value of the component at the specified index. /// /// Thrown when the is out of the range [0, /// 3]. /// public float this[int index] { get { switch (index) { case 0: return Normal.X; case 1: return Normal.Y; case 2: return Normal.Z; case 3: return D; } throw new ArgumentOutOfRangeException(nameof(index), "Indices for Plane run from 0 to 3, inclusive."); } set { switch (index) { case 0: Normal.X = value; break; case 1: Normal.Y = value; break; case 2: Normal.Z = value; break; case 3: D = value; break; default: throw new ArgumentOutOfRangeException(nameof(index), "Indices for Plane run from 0 to 3, inclusive."); } } } /// /// Changes the coefficients of the normal vector of the plane to make it of unit length. /// public void Normalize() { float magnitude = 1.0f / (float)Math.Sqrt(Normal.X * Normal.X + Normal.Y * Normal.Y + Normal.Z * Normal.Z); Normal.X *= magnitude; Normal.Y *= magnitude; Normal.Z *= magnitude; D *= magnitude; } /// /// Creates an array containing the elements of the plane. /// /// A four-element array containing the components of the plane. public float[] ToArray() { return new[] { Normal.X, Normal.Y, Normal.Z, D }; } /// /// Determines if there is an intersection between the current object and a point. /// /// The point to test. /// Whether the two objects intersected. public PlaneIntersectionType Intersects(ref Vector3 point) { return CollisionsHelper.PlaneIntersectsPoint(ref this, ref point); } /// /// Determines if there is an intersection between the current object and a . /// /// The ray to test. /// Whether the two objects intersected. public bool Intersects(ref Ray ray) { float distance; return CollisionsHelper.RayIntersectsPlane(ref ray, ref this, out distance); } /// /// Determines if there is an intersection between the current object and a . /// /// The ray to test. /// /// When the method completes, contains the distance of the intersection, /// or 0 if there was no intersection. /// /// Whether the two objects intersected. public bool Intersects(ref Ray ray, out float distance) { return CollisionsHelper.RayIntersectsPlane(ref ray, ref this, out distance); } /// /// Determines if there is an intersection between the current object and a . /// /// The ray to test. /// /// When the method completes, contains the point of intersection, /// or if there was no intersection. /// /// Whether the two objects intersected. public bool Intersects(ref Ray ray, out Vector3 point) { return CollisionsHelper.RayIntersectsPlane(ref ray, ref this, out point); } /// /// Determines if there is an intersection between the current object and a . /// /// The plane to test. /// Whether the two objects intersected. public bool Intersects(ref Plane plane) { return CollisionsHelper.PlaneIntersectsPlane(ref this, ref plane); } /// /// Determines if there is an intersection between the current object and a . /// /// The plane to test. /// /// When the method completes, contains the line of intersection /// as a , or a zero ray if there was no intersection. /// /// Whether the two objects intersected. public bool Intersects(ref Plane plane, out Ray line) { return CollisionsHelper.PlaneIntersectsPlane(ref this, ref plane, out line); } /// /// Determines if there is an intersection between the current object and a triangle. /// /// The first vertex of the triangle to test. /// The second vertex of the triangle to test. /// The third vertex of the triangle to test. /// Whether the two objects intersected. public PlaneIntersectionType Intersects(ref Vector3 vertex1, ref Vector3 vertex2, ref Vector3 vertex3) { return CollisionsHelper.PlaneIntersectsTriangle(ref this, ref vertex1, ref vertex2, ref vertex3); } /// /// Determines if there is an intersection between the current object and a . /// /// The box to test. /// Whether the two objects intersected. public PlaneIntersectionType Intersects(ref BoundingBox box) { return CollisionsHelper.PlaneIntersectsBox(ref this, ref box); } /// /// Determines if there is an intersection between the current object and a . /// /// The sphere to test. /// Whether the two objects intersected. public PlaneIntersectionType Intersects(ref BoundingSphere sphere) { return CollisionsHelper.PlaneIntersectsSphere(ref this, ref sphere); } /// /// Builds a matrix that can be used to reflect vectors about a plane. /// /// When the method completes, contains the reflection matrix. public void Reflection(out Matrix result) { float x = Normal.X; float y = Normal.Y; float z = Normal.Z; float x2 = -2.0f * x; float y2 = -2.0f * y; float z2 = -2.0f * z; result.M11 = x2 * x + 1.0f; result.M12 = y2 * x; result.M13 = z2 * x; result.M14 = 0.0f; result.M21 = x2 * y; result.M22 = y2 * y + 1.0f; result.M23 = z2 * y; result.M24 = 0.0f; result.M31 = x2 * z; result.M32 = y2 * z; result.M33 = z2 * z + 1.0f; result.M34 = 0.0f; result.M41 = x2 * D; result.M42 = y2 * D; result.M43 = z2 * D; result.M44 = 1.0f; } /// /// Builds a matrix that can be used to reflect vectors about a plane. /// /// The reflection matrix. public Matrix Reflection() { Matrix result; Reflection(out result); return result; } /// /// Creates a matrix that flattens geometry into a shadow from this the plane onto which to project the geometry as a /// shadow. /// This plane is assumed to be normalized /// /// /// The light direction. If the W component is 0, the light is directional light; if the /// W component is 1, the light is a point light. /// /// When the method completes, contains the shadow matrix. public void Shadow(ref Vector4 light, out Matrix result) { float dot = Normal.X * light.X + Normal.Y * light.Y + Normal.Z * light.Z + D * light.W; float x = -Normal.X; float y = -Normal.Y; float z = -Normal.Z; float d = -D; result.M11 = x * light.X + dot; result.M21 = y * light.X; result.M31 = z * light.X; result.M41 = d * light.X; result.M12 = x * light.Y; result.M22 = y * light.Y + dot; result.M32 = z * light.Y; result.M42 = d * light.Y; result.M13 = x * light.Z; result.M23 = y * light.Z; result.M33 = z * light.Z + dot; result.M43 = d * light.Z; result.M14 = x * light.W; result.M24 = y * light.W; result.M34 = z * light.W; result.M44 = d * light.W + dot; } /// /// Creates a matrix that flattens geometry into a shadow from this the plane onto which to project the geometry as a /// shadow. /// This plane is assumed to be normalized /// /// /// The light direction. If the W component is 0, the light is directional light; if the /// W component is 1, the light is a point light. /// /// The shadow matrix. public Matrix Shadow(Vector4 light) { Matrix result; Shadow(ref light, out result); return result; } /// /// Builds a Matrix3x3 that can be used to reflect vectors about a plane for which the reflection occurs. /// This plane is assumed to be normalized /// /// When the method completes, contains the reflection Matrix3x3. public void Reflection(out Matrix3x3 result) { float x = Normal.X; float y = Normal.Y; float z = Normal.Z; float x2 = -2.0f * x; float y2 = -2.0f * y; float z2 = -2.0f * z; result.M11 = x2 * x + 1.0f; result.M12 = y2 * x; result.M13 = z2 * x; result.M21 = x2 * y; result.M22 = y2 * y + 1.0f; result.M23 = z2 * y; result.M31 = x2 * z; result.M32 = y2 * z; result.M33 = z2 * z + 1.0f; } /// /// Builds a Matrix3x3 that can be used to reflect vectors about a plane for which the reflection occurs. /// This plane is assumed to be normalized /// /// The reflection Matrix3x3. public Matrix3x3 Reflection3x3() { Matrix3x3 result; Reflection(out result); return result; } /// /// Creates a Matrix3x3 that flattens geometry into a shadow. /// /// /// The light direction. If the W component is 0, the light is directional light; if the /// W component is 1, the light is a point light. /// /// /// The plane onto which to project the geometry as a shadow. This parameter is assumed to be /// normalized. /// /// When the method completes, contains the shadow Matrix3x3. public static void Shadow(ref Vector4 light, ref Plane plane, out Matrix3x3 result) { float dot = plane.Normal.X * light.X + plane.Normal.Y * light.Y + plane.Normal.Z * light.Z + plane.D * light.W; float x = -plane.Normal.X; float y = -plane.Normal.Y; float z = -plane.Normal.Z; float d = -plane.D; result.M11 = x * light.X + dot; result.M21 = y * light.X; result.M31 = z * light.X; result.M12 = x * light.Y; result.M22 = y * light.Y + dot; result.M32 = z * light.Y; result.M13 = x * light.Z; result.M23 = y * light.Z; result.M33 = z * light.Z + dot; } /// /// Creates a Matrix3x3 that flattens geometry into a shadow. /// /// /// The light direction. If the W component is 0, the light is directional light; if the /// W component is 1, the light is a point light. /// /// /// The plane onto which to project the geometry as a shadow. This parameter is assumed to be /// normalized. /// /// The shadow Matrix3x3. public static Matrix3x3 Shadow(Vector4 light, Plane plane) { Matrix3x3 result; Shadow(ref light, ref plane, out result); return result; } /// /// Scales the plane by the given scaling factor. /// /// The plane to scale. /// The amount by which to scale the plane. /// When the method completes, contains the scaled plane. public static void Multiply(ref Plane value, float scale, out Plane result) { result.Normal.X = value.Normal.X * scale; result.Normal.Y = value.Normal.Y * scale; result.Normal.Z = value.Normal.Z * scale; result.D = value.D * scale; } /// /// Scales the plane by the given scaling factor. /// /// The plane to scale. /// The amount by which to scale the plane. /// The scaled plane. public static Plane Multiply(Plane value, float scale) { return new Plane(value.Normal.X * scale, value.Normal.Y * scale, value.Normal.Z * scale, value.D * scale); } /// /// Calculates the dot product of the specified vector and plane. /// /// The source plane. /// The source vector. /// When the method completes, contains the dot product of the specified plane and vector. public static void Dot(ref Plane left, ref Vector4 right, out float result) { result = left.Normal.X * right.X + left.Normal.Y * right.Y + left.Normal.Z * right.Z + left.D * right.W; } /// /// Calculates the dot product of the specified vector and plane. /// /// The source plane. /// The source vector. /// The dot product of the specified plane and vector. public static float Dot(Plane left, Vector4 right) { return left.Normal.X * right.X + left.Normal.Y * right.Y + left.Normal.Z * right.Z + left.D * right.W; } /// /// Calculates the dot product of a specified vector and the normal of the plane plus the distance value of the plane. /// /// The source plane. /// The source vector. /// /// When the method completes, contains the dot product of a specified vector and the normal of the /// Plane plus the distance value of the plane. /// public static void DotCoordinate(ref Plane left, ref Vector3 right, out float result) { result = left.Normal.X * right.X + left.Normal.Y * right.Y + left.Normal.Z * right.Z + left.D; } /// /// Calculates the dot product of a specified vector and the normal of the plane plus the distance value of the plane. /// /// The source plane. /// The source vector. /// The dot product of a specified vector and the normal of the Plane plus the distance value of the plane. public static float DotCoordinate(Plane left, Vector3 right) { return left.Normal.X * right.X + left.Normal.Y * right.Y + left.Normal.Z * right.Z + left.D; } /// /// Calculates the dot product of the specified vector and the normal of the plane. /// /// The source plane. /// The source vector. /// /// When the method completes, contains the dot product of the specified vector and the normal of the /// plane. /// public static void DotNormal(ref Plane left, ref Vector3 right, out float result) { result = left.Normal.X * right.X + left.Normal.Y * right.Y + left.Normal.Z * right.Z; } /// /// Calculates the dot product of the specified vector and the normal of the plane. /// /// The source plane. /// The source vector. /// The dot product of the specified vector and the normal of the plane. public static float DotNormal(Plane left, Vector3 right) { return left.Normal.X * right.X + left.Normal.Y * right.Y + left.Normal.Z * right.Z; } /// /// Changes the coefficients of the normal vector of the plane to make it of unit length. /// /// The source plane. /// When the method completes, contains the normalized plane. public static void Normalize(ref Plane plane, out Plane result) { float magnitude = 1.0f / (float)Math.Sqrt(plane.Normal.X * plane.Normal.X + plane.Normal.Y * plane.Normal.Y + plane.Normal.Z * plane.Normal.Z); result.Normal.X = plane.Normal.X * magnitude; result.Normal.Y = plane.Normal.Y * magnitude; result.Normal.Z = plane.Normal.Z * magnitude; result.D = plane.D * magnitude; } /// /// Changes the coefficients of the normal vector of the plane to make it of unit length. /// /// The source plane. /// The normalized plane. public static Plane Normalize(Plane plane) { float magnitude = 1.0f / (float)Math.Sqrt(plane.Normal.X * plane.Normal.X + plane.Normal.Y * plane.Normal.Y + plane.Normal.Z * plane.Normal.Z); return new Plane(plane.Normal.X * magnitude, plane.Normal.Y * magnitude, plane.Normal.Z * magnitude, plane.D * magnitude); } /// /// Transforms a normalized plane by a quaternion rotation. /// /// The normalized source plane. /// The quaternion rotation. /// When the method completes, contains the transformed plane. public static void Transform(ref Plane plane, ref Quaternion rotation, out Plane result) { float x2 = rotation.X + rotation.X; float y2 = rotation.Y + rotation.Y; float z2 = rotation.Z + rotation.Z; float wx = rotation.W * x2; float wy = rotation.W * y2; float wz = rotation.W * z2; float xx = rotation.X * x2; float xy = rotation.X * y2; float xz = rotation.X * z2; float yy = rotation.Y * y2; float yz = rotation.Y * z2; float zz = rotation.Z * z2; float x = plane.Normal.X; float y = plane.Normal.Y; float z = plane.Normal.Z; result.Normal.X = x * (1.0f - yy - zz) + y * (xy - wz) + z * (xz + wy); result.Normal.Y = x * (xy + wz) + y * (1.0f - xx - zz) + z * (yz - wx); result.Normal.Z = x * (xz - wy) + y * (yz + wx) + z * (1.0f - xx - yy); result.D = plane.D; } /// /// Transforms a normalized plane by a quaternion rotation. /// /// The normalized source plane. /// The quaternion rotation. /// The transformed plane. public static Plane Transform(Plane plane, Quaternion rotation) { Plane result; float x2 = rotation.X + rotation.X; float y2 = rotation.Y + rotation.Y; float z2 = rotation.Z + rotation.Z; float wx = rotation.W * x2; float wy = rotation.W * y2; float wz = rotation.W * z2; float xx = rotation.X * x2; float xy = rotation.X * y2; float xz = rotation.X * z2; float yy = rotation.Y * y2; float yz = rotation.Y * z2; float zz = rotation.Z * z2; float x = plane.Normal.X; float y = plane.Normal.Y; float z = plane.Normal.Z; result.Normal.X = x * (1.0f - yy - zz) + y * (xy - wz) + z * (xz + wy); result.Normal.Y = x * (xy + wz) + y * (1.0f - xx - zz) + z * (yz - wx); result.Normal.Z = x * (xz - wy) + y * (yz + wx) + z * (1.0f - xx - yy); result.D = plane.D; return result; } /// /// Transforms an array of normalized planes by a quaternion rotation. /// /// The array of normalized planes to transform. /// The quaternion rotation. /// Thrown when is null. public static void Transform(Plane[] planes, ref Quaternion rotation) { if (planes == null) throw new ArgumentNullException(nameof(planes)); float x2 = rotation.X + rotation.X; float y2 = rotation.Y + rotation.Y; float z2 = rotation.Z + rotation.Z; float wx = rotation.W * x2; float wy = rotation.W * y2; float wz = rotation.W * z2; float xx = rotation.X * x2; float xy = rotation.X * y2; float xz = rotation.X * z2; float yy = rotation.Y * y2; float yz = rotation.Y * z2; float zz = rotation.Z * z2; for (var i = 0; i < planes.Length; ++i) { float x = planes[i].Normal.X; float y = planes[i].Normal.Y; float z = planes[i].Normal.Z; /* * Note: * Factor common arithmetic out of loop. */ planes[i].Normal.X = x * (1.0f - yy - zz) + y * (xy - wz) + z * (xz + wy); planes[i].Normal.Y = x * (xy + wz) + y * (1.0f - xx - zz) + z * (yz - wx); planes[i].Normal.Z = x * (xz - wy) + y * (yz + wx) + z * (1.0f - xx - yy); } } /// /// Transforms a normalized plane by a matrix. /// /// The normalized source plane. /// The transformation matrix. /// When the method completes, contains the transformed plane. public static void Transform(ref Plane plane, ref Matrix transformation, out Plane result) { float x = plane.Normal.X; float y = plane.Normal.Y; float z = plane.Normal.Z; float d = plane.D; Matrix inverse; Matrix.Invert(ref transformation, out inverse); result.Normal.X = x * inverse.M11 + y * inverse.M12 + z * inverse.M13 + d * inverse.M14; result.Normal.Y = x * inverse.M21 + y * inverse.M22 + z * inverse.M23 + d * inverse.M24; result.Normal.Z = x * inverse.M31 + y * inverse.M32 + z * inverse.M33 + d * inverse.M34; result.D = x * inverse.M41 + y * inverse.M42 + z * inverse.M43 + d * inverse.M44; } /// /// Transforms a normalized plane by a matrix. /// /// The normalized source plane. /// The transformation matrix. /// When the method completes, contains the transformed plane. public static Plane Transform(Plane plane, Matrix transformation) { Plane result; float x = plane.Normal.X; float y = plane.Normal.Y; float z = plane.Normal.Z; float d = plane.D; transformation.Invert(); result.Normal.X = x * transformation.M11 + y * transformation.M12 + z * transformation.M13 + d * transformation.M14; result.Normal.Y = x * transformation.M21 + y * transformation.M22 + z * transformation.M23 + d * transformation.M24; result.Normal.Z = x * transformation.M31 + y * transformation.M32 + z * transformation.M33 + d * transformation.M34; result.D = x * transformation.M41 + y * transformation.M42 + z * transformation.M43 + d * transformation.M44; return result; } /// /// Transforms an array of normalized planes by a matrix. /// /// The array of normalized planes to transform. /// The transformation matrix. /// Thrown when is null. public static void Transform(Plane[] planes, ref Matrix transformation) { if (planes == null) throw new ArgumentNullException(nameof(planes)); Matrix inverse; Matrix.Invert(ref transformation, out inverse); for (var i = 0; i < planes.Length; ++i) Transform(ref planes[i], ref transformation, out planes[i]); } /// /// Scales a plane by the given value. /// /// The amount by which to scale the plane. /// The plane to scale. /// The scaled plane. public static Plane operator *(float scale, Plane plane) { return new Plane(plane.Normal.X * scale, plane.Normal.Y * scale, plane.Normal.Z * scale, plane.D * scale); } /// /// Scales a plane by the given value. /// /// The plane to scale. /// The amount by which to scale the plane. /// The scaled plane. public static Plane operator *(Plane plane, float scale) { return new Plane(plane.Normal.X * scale, plane.Normal.Y * scale, plane.Normal.Z * scale, plane.D * scale); } /// /// Tests for equality between two objects. /// /// The first value to compare. /// The second value to compare. /// /// true if has the same value as ; otherwise, /// false. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Plane left, Plane right) { return left.Equals(ref right); } /// /// Tests for inequality between two objects. /// /// The first value to compare. /// The second value to compare. /// /// true if has a different value than ; otherwise, /// false. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Plane left, Plane right) { return !left.Equals(ref right); } /// /// Returns a that represents this instance. /// /// /// A that represents this instance. /// public override string ToString() { return string.Format(CultureInfo.CurrentCulture, "A:{0} B:{1} C:{2} D:{3}", Normal.X, Normal.Y, Normal.Z, D); } /// /// Returns a that represents this instance. /// /// The format. /// /// A that represents this instance. /// public string ToString(string format) { return string.Format(CultureInfo.CurrentCulture, "A:{0} B:{1} C:{2} D:{3}", Normal.X.ToString(format, CultureInfo.CurrentCulture), Normal.Y.ToString(format, CultureInfo.CurrentCulture), Normal.Z.ToString(format, CultureInfo.CurrentCulture), D.ToString(format, CultureInfo.CurrentCulture)); } /// /// Returns a that represents this instance. /// /// The format provider. /// /// A that represents this instance. /// public string ToString(IFormatProvider formatProvider) { return string.Format(formatProvider, "A:{0} B:{1} C:{2} D:{3}", Normal.X, Normal.Y, Normal.Z, D); } /// /// Returns a that represents this instance. /// /// The format. /// The format provider. /// /// A that represents this instance. /// public string ToString(string format, IFormatProvider formatProvider) { return string.Format(formatProvider, "A:{0} B:{1} C:{2} D:{3}", Normal.X.ToString(format, formatProvider), Normal.Y.ToString(format, formatProvider), Normal.Z.ToString(format, formatProvider), D.ToString(format, formatProvider)); } /// /// Returns a hash code for this instance. /// /// /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. /// public override int GetHashCode() { unchecked { return (Normal.GetHashCode() * 397) ^ D.GetHashCode(); } } /// /// Determines whether the specified is equal to this instance. /// /// The to compare with this instance. /// /// true if the specified is equal to this instance; otherwise, false. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(ref Plane value) { return (Normal == value.Normal) && (D == value.D); } /// /// Determines whether the specified is equal to this instance. /// /// The to compare with this instance. /// /// true if the specified is equal to this instance; otherwise, false. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Plane value) { return Equals(ref value); } /// /// Determines whether the specified is equal to this instance. /// /// The to compare with this instance. /// /// true if the specified is equal to this instance; otherwise, false. /// public override bool Equals(object value) { if (!(value is Plane)) return false; var strongValue = (Plane)value; return Equals(ref strongValue); } } }