source: 2013/30/MiskaK/MW2(My Warfare 2)/Paranneltu Jypeli/AdvanceMath/Geometry2D/Ray.cs @ 4507

Revision 4507, 5.0 KB checked in by anlakane, 6 years ago (diff)

Talletus.

Line 
1
2#region MIT License
3/*
4 * Copyright (c) 2005-2008 Jonathan Mark Porter. http://physics2d.googlepages.com/
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights to
9 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10 * the Software, and to permit persons to whom the Software is furnished to do so,
11 * subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
17 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
18 * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 * OTHER DEALINGS IN THE SOFTWARE.
22 */
23#endregion
24
25
26
27
28#if UseDouble
29using Scalar = System.Double;
30#else
31using Scalar = System.Single;
32#endif
33using System;
34using System.Runtime.InteropServices;
35using AdvanceMath.Design;
36namespace AdvanceMath.Geometry2D
37{
38    [StructLayout(LayoutKind.Sequential, Size = Ray.Size)]
39#if !CompactFramework && !WindowsCE && !PocketPC && !XBOX360 && !SILVERLIGHT && !WINDOWS_PHONE
40    [Serializable]
41    [System.ComponentModel.TypeConverter(typeof(AdvTypeConverter<Ray>))]
42#endif
43    [AdvBrowsableOrder("Origin,Direction")]
44    public struct Ray : IEquatable<Ray>
45    {
46        public const int Size = Vector2D.Size * 2;
47
48        [AdvBrowsable]
49        public Vector2D Origin;
50        [AdvBrowsable]
51        public Vector2D Direction;
52
53        [InstanceConstructor("Origin,Direction")]
54        public Ray(Vector2D origin, Vector2D direction)
55        {
56            this.Origin = origin;
57            this.Direction = direction;
58        }
59
60        public Scalar Intersects(BoundingRectangle rect)
61        {
62            Scalar result;
63            rect.Intersects(ref this, out result);
64            return result;
65        }
66        public Scalar Intersects(Line line)
67        {
68            Scalar result;
69            line.Intersects(ref this, out result);
70            return result;
71        }
72        public Scalar Intersects(LineSegment line)
73        {
74            Scalar result;
75            line.Intersects(ref this, out result);
76            return result;
77        }
78        public Scalar Intersects(BoundingCircle circle)
79        {
80            Scalar result;
81            circle.Intersects(ref this, out result);
82            return result;
83        }
84        public Scalar Intersects(BoundingPolygon polygon)
85        {
86            if (polygon == null) { throw new ArgumentNullException("polygon"); }
87            Scalar result;
88            polygon.Intersects(ref this, out result);
89            return result;
90        }
91
92        public void Intersects(ref BoundingRectangle rect, out Scalar result)
93        {
94            rect.Intersects(ref this, out result);
95        }
96        public void Intersects(ref Line line, out Scalar result)
97        {
98            line.Intersects(ref this, out result);
99        }
100        public void Intersects(ref LineSegment line, out Scalar result)
101        {
102            line.Intersects(ref this, out result);
103        }
104        public void Intersects(ref BoundingCircle circle, out Scalar result)
105        {
106            circle.Intersects(ref this, out result);
107        }
108        public void Intersects(ref BoundingPolygon polygon, out Scalar result)
109        {
110            if (polygon == null) { throw new ArgumentNullException("polygon"); }
111            polygon.Intersects(ref this, out result);
112        }
113
114        public override string ToString()
115        {
116            return string.Format("O: {0} D: {1}", Origin, Direction);
117        }
118        public override int GetHashCode()
119        {
120            return Origin.GetHashCode() ^ Direction.GetHashCode();
121        }
122        public override bool Equals(object obj)
123        {
124            return obj is Ray && Equals((Ray)obj);
125        }
126        public bool Equals(Ray other)
127        {
128            return Equals(ref this, ref other);
129        }
130        public static bool Equals(Ray ray1, Ray ray2)
131        {
132            return Equals(ref ray1, ref ray2);
133        }
134        [CLSCompliant(false)]
135        public static bool Equals(ref Ray ray1, ref Ray ray2)
136        {
137            return Vector2D.Equals(ref ray1.Origin, ref ray2.Origin) && Vector2D.Equals(ref ray1.Direction, ref ray2.Direction);
138        }
139
140        public static bool operator ==(Ray ray1, Ray ray2)
141        {
142            return Equals(ref ray1, ref ray2);
143        }
144        public static bool operator !=(Ray ray1, Ray ray2)
145        {
146            return !Equals(ref ray1, ref ray2);
147        }
148    }
149}
Note: See TracBrowser for help on using the repository browser.