Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
Point.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under MIT License. See LICENSE.md for details.
3 //
4 // Copyright (c) 2010-2013 SharpDX - Alexandre Mutel
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
9 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 // copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 // THE SOFTWARE.
23 
24 using System;
25 using System.Runtime.InteropServices;
26 using SiliconStudio.Core.Serialization;
27 
28 namespace SiliconStudio.Core.Mathematics
29 {
30  /// <summary>
31  /// Structure using the same layout than <see cref="System.Drawing.Point"/>.
32  /// </summary>
33  [DataContract]
34  [StructLayout(LayoutKind.Sequential)]
35  public struct Point : IEquatable<Point>
36  {
37  /// <summary>
38  /// A point with (0,0) coordinates.
39  /// </summary>
40  public static readonly Point Zero = new Point(0, 0);
41 
42  /// <summary>
43  /// Initializes a new instance of the <see cref="Point"/> struct.
44  /// </summary>
45  /// <param name="x">The x.</param>
46  /// <param name="y">The y.</param>
47  public Point(int x, int y)
48  {
49  X = x;
50  Y = y;
51  }
52 
53  /// <summary>
54  /// Left coordinate.
55  /// </summary>
56  [DataMember(0)]
57  public int X;
58 
59  /// <summary>
60  /// Top coordinate.
61  /// </summary>
62  [DataMember(1)]
63  public int Y;
64 
65  /// <summary>
66  /// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
67  /// </summary>
68  /// <param name="other">The <see cref="System.Object"/> to compare with this instance.</param>
69  /// <returns>
70  /// <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
71  /// </returns>
72  public bool Equals(Point other)
73  {
74  return other.X == X && other.Y == Y;
75  }
76 
77  /// <inheritdoc/>
78  public override bool Equals(object obj)
79  {
80  if (ReferenceEquals(null, obj)) return false;
81  if (obj.GetType() != typeof(Point)) return false;
82  return Equals((Point)obj);
83  }
84 
85  /// <inheritdoc/>
86  public override int GetHashCode()
87  {
88  unchecked
89  {
90  return (X * 397) ^ Y;
91  }
92  }
93 
94  /// <summary>
95  /// Implements the operator ==.
96  /// </summary>
97  /// <param name="left">The left.</param>
98  /// <param name="right">The right.</param>
99  /// <returns>
100  /// The result of the operator.
101  /// </returns>
102  public static bool operator ==(Point left, Point right)
103  {
104  return left.Equals(right);
105  }
106 
107  /// <summary>
108  /// Implements the operator !=.
109  /// </summary>
110  /// <param name="left">The left.</param>
111  /// <param name="right">The right.</param>
112  /// <returns>
113  /// The result of the operator.
114  /// </returns>
115  public static bool operator !=(Point left, Point right)
116  {
117  return !left.Equals(right);
118  }
119 
120  public override string ToString()
121  {
122  return string.Format("({0},{1})", X, Y);
123  }
124 
125  /// <summary>
126  /// Performs an implicit conversion from <see cref="SharpDX.Vector2"/> to <see cref="Point"/>.
127  /// </summary>
128  /// <param name="value">The value.</param>
129  /// <returns>The result of the conversion.</returns>
130  public static explicit operator Point(Vector2 value)
131  {
132  return new Point((int)value.X, (int)value.Y);
133  }
134 
135  /// <summary>
136  /// Performs an explicit conversion from <see cref="Point"/> to <see cref="SharpDX.Vector2"/>.
137  /// </summary>
138  /// <param name="value">The value.</param>
139  /// <returns>The result of the conversion.</returns>
140  public static implicit operator Vector2(Point value)
141  {
142  return new Vector2(value.X, value.Y);
143  }
144  }
145 }
SiliconStudio.Paradox.Games.Mathematics.Vector2 Vector2
Represents a two dimensional mathematical vector.
Definition: Vector2.cs:42
bool Equals(Point other)
Determines whether the specified System.Object is equal to this instance.
Definition: Point.cs:72
_In_ size_t _In_ DXGI_FORMAT _In_ size_t _In_ float size_t y
Definition: DirectXTexP.h:191
Point(int x, int y)
Initializes a new instance of the Point struct.
Definition: Point.cs:47
override bool Equals(object obj)
Definition: Point.cs:78
override string ToString()
Definition: Point.cs:120
Structure using the same layout than System.Drawing.Point.
Definition: Point.cs:35
float Y
The Y component of the vector.
Definition: Vector2.cs:79
int X
Left coordinate.
Definition: Point.cs:57
int Y
Top coordinate.
Definition: Point.cs:63
float X
The X component of the vector.
Definition: Vector2.cs:73
System.Windows.Point Point
Definition: ColorPicker.cs:15