Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
Half2.cs
Go to the documentation of this file.
1 // Copyright (c) 2011 Silicon Studio
2 // Copyright (c) 2010-2011 SharpDX - Alexandre Mutel
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining a copy
5 // of this software and associated documentation files (the "Software"), to deal
6 // in the Software without restriction, including without limitation the rights
7 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 // copies of the Software, and to permit persons to whom the Software is
9 // furnished to do so, subject to the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 // THE SOFTWARE.
21 
22 using System;
23 using System.ComponentModel;
24 using System.Runtime.InteropServices;
25 using SiliconStudio.Core.Serialization;
26 
27 namespace SiliconStudio.Core.Mathematics
28 {
29  /// <summary>
30  /// Defines a two component vector, using half precision floating point coordinates.
31  /// </summary>
32  [DataContract]
33  [StructLayout(LayoutKind.Sequential, Pack = 2)]
34  public struct Half2 : IEquatable<Half2>
35  {
36  /// <summary>
37  /// Gets or sets the X component of the vector.
38  /// </summary>
39  /// <value>The X component of the vector.</value>
40  public Half X;
41  /// <summary>
42  /// Gets or sets the Y component of the vector.
43  /// </summary>
44  /// <value>The Y component of the vector.</value>
45  public Half Y;
46  /// <summary>
47  /// Initializes a new instance of the <see cref="T:SiliconStudio.Core.Mathematics.Half2" /> structure.
48  /// </summary>
49  /// <param name="x">The X component.</param>
50  /// <param name="y">The Y component.</param>
51  public Half2(Half x, Half y)
52  {
53  this.X = x;
54  this.Y = y;
55  }
56 
57  /// <summary>
58  /// Initializes a new instance of the <see cref="T:SiliconStudio.Core.Mathematics.Half2" /> structure.
59  /// </summary>
60  /// <param name="value">The value to set for both the X and Y components.</param>
61  public Half2(Half value)
62  {
63  this.X = value;
64  this.Y = value;
65  }
66 
67  /// <summary>
68  /// Initializes a new instance of the <see cref="T:SiliconStudio.Core.Mathematics.Half2" /> structure.
69  /// </summary>
70  /// <param name="x">The X component.</param>
71  /// <param name="y">The Y component.</param>
72  public Half2(float x, float y)
73  {
74  this.X = (Half)x;
75  this.Y = (Half)y;
76  }
77 
78  /// <summary>
79  /// Initializes a new instance of the <see cref="T:SiliconStudio.Core.Mathematics.Half2" /> structure.
80  /// </summary>
81  /// <param name="value">The value to set for both the X and Y components.</param>
82  public Half2(float value)
83  {
84  this.X = (Half)value;
85  this.Y = (Half)value;
86  }
87 
88  /// <summary>
89  /// Tests for equality between two objects.
90  /// </summary>
91  /// <param name="left">The first value to compare.</param>
92  /// <param name="right">The second value to compare.</param>
93  /// <returns>
94  /// <c>true</c> if <paramref name="left" /> has the same value as <paramref name="right" />; otherwise, <c>false</c>.</returns>
95  public static bool operator ==(Half2 left, Half2 right)
96  {
97  return Equals(ref left, ref right);
98  }
99 
100  /// <summary>
101  /// Tests for inequality between two objects.
102  /// </summary>
103  /// <param name="left">The first value to compare.</param>
104  /// <param name="right">The second value to compare.</param>
105  /// <returns>
106  /// <c>true</c> if <paramref name="left" /> has a different value than <paramref name="right" />; otherwise, <c>false</c>.</returns>
107  [return: MarshalAs(UnmanagedType.U1)]
108  public static bool operator !=(Half2 left, Half2 right)
109  {
110  return !Equals(ref left, ref right);
111  }
112 
113  /// <summary>
114  /// Returns the hash code for this instance.
115  /// </summary>
116  /// <returns>A 32-bit signed integer hash code.</returns>
117  public override int GetHashCode()
118  {
119  return (this.Y.GetHashCode() + this.X.GetHashCode());
120  }
121 
122  /// <summary>
123  /// Determines whether the specified object instances are considered equal.
124  /// </summary>
125  /// <param name="value1" />
126  /// <param name="value2" />
127  /// <returns>
128  /// <c>true</c> if <paramref name="value1" /> is the same instance as <paramref name="value2" /> or
129  /// if both are <c>null</c> references or if <c>value1.Equals(value2)</c> returns <c>true</c>; otherwise, <c>false</c>.</returns>
130  public static bool Equals(ref Half2 value1, ref Half2 value2)
131  {
132  return ((value1.X == value2.X) && (value1.Y == value2.Y));
133  }
134 
135  /// <summary>
136  /// Returns a value that indicates whether the current instance is equal to the specified object.
137  /// </summary>
138  /// <param name="other">Object to make the comparison with.</param>
139  /// <returns>
140  /// <c>true</c> if the current instance is equal to the specified object; <c>false</c> otherwise.</returns>
141  public bool Equals(Half2 other)
142  {
143  return ((this.X == other.X) && (this.Y == other.Y));
144  }
145 
146  /// <summary>
147  /// Returns a value that indicates whether the current instance is equal to a specified object.
148  /// </summary>
149  /// <param name="obj">Object to make the comparison with.</param>
150  /// <returns>
151  /// <c>true</c> if the current instance is equal to the specified object; <c>false</c> otherwise.</returns>
152  public override bool Equals(object obj)
153  {
154  if (obj == null)
155  {
156  return false;
157  }
158  if (obj.GetType() != base.GetType())
159  {
160  return false;
161  }
162  return this.Equals((Half2)obj);
163  }
164 
165  /// <summary>
166  /// Performs an explicit conversion from <see cref="Vector3"/> to <see cref="Half3"/>.
167  /// </summary>
168  /// <param name="value">The value.</param>
169  /// <returns>The result of the conversion.</returns>
170  public static explicit operator Half2(Vector2 value)
171  {
172  return new Half2((Half)value.X, (Half)value.Y);
173  }
174 
175  /// <summary>
176  /// Performs an explicit conversion from <see cref="Vector3"/> to <see cref="Half3"/>.
177  /// </summary>
178  /// <param name="value">The value.</param>
179  /// <returns>The result of the conversion.</returns>
180  public static explicit operator Vector2(Half2 value)
181  {
182  return new Vector2(value.X, value.Y);
183  }
184  }
185 }
SiliconStudio.Paradox.Games.Mathematics.Vector2 Vector2
Half2(float x, float y)
Initializes a new instance of the T:SiliconStudio.Core.Mathematics.Half2 structure.
Definition: Half2.cs:72
Represents a two dimensional mathematical vector.
Definition: Vector2.cs:42
Half X
Gets or sets the X component of the vector.
Definition: Half2.cs:40
bool Equals(Half2 other)
Returns a value that indicates whether the current instance is equal to the specified object...
Definition: Half2.cs:141
_In_ size_t _In_ DXGI_FORMAT _In_ size_t _In_ float size_t y
Definition: DirectXTexP.h:191
static bool Equals(ref Half2 value1, ref Half2 value2)
Determines whether the specified object instances are considered equal.
Definition: Half2.cs:130
A half precision (16 bit) floating point value.
Definition: Half.cs:37
Half2(float value)
Initializes a new instance of the T:SiliconStudio.Core.Mathematics.Half2 structure.
Definition: Half2.cs:82
float Y
The Y component of the vector.
Definition: Vector2.cs:79
SiliconStudio.Paradox.Games.Mathematics.Half Half
Half2(Half x, Half y)
Initializes a new instance of the T:SiliconStudio.Core.Mathematics.Half2 structure.
Definition: Half2.cs:51
float X
The X component of the vector.
Definition: Vector2.cs:73
Defines a two component vector, using half precision floating point coordinates.
Definition: Half2.cs:34
Half2(Half value)
Initializes a new instance of the T:SiliconStudio.Core.Mathematics.Half2 structure.
Definition: Half2.cs:61
Half Y
Gets or sets the Y component of the vector.
Definition: Half2.cs:45
override int GetHashCode()
Returns the hash code for this instance.
Definition: Half2.cs:117
override bool Equals(object obj)
Returns a value that indicates whether the current instance is equal to a specified object...
Definition: Half2.cs:152