Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
Size2.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.Size"/>.
32  /// </summary>
33  [DataContract("!Size2")]
34  [DataStyle(DataStyle.Compact)]
35  [StructLayout(LayoutKind.Sequential)]
36  public struct Size2 : IEquatable<Size2>
37  {
38  /// <summary>
39  /// A zero size with (width, height) = (0,0)
40  /// </summary>
41  public static readonly Size2 Zero = new Size2(0, 0);
42 
43  /// <summary>
44  /// A zero size with (width, height) = (0,0)
45  /// </summary>
46  public static readonly Size2 Empty = Zero;
47 
48  /// <summary>
49  /// Initializes a new instance of the <see cref="Size2"/> struct.
50  /// </summary>
51  /// <param name="width">The x.</param>
52  /// <param name="height">The y.</param>
53  public Size2(int width, int height)
54  {
55  Width = width;
56  Height = height;
57  }
58 
59  /// <summary>
60  /// Width.
61  /// </summary>
62  [DataMember(0)]
63  public int Width;
64 
65  /// <summary>
66  /// Height.
67  /// </summary>
68  [DataMember(1)]
69  public int Height;
70 
71  /// <summary>
72  /// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
73  /// </summary>
74  /// <param name="other">The <see cref="System.Object"/> to compare with this instance.</param>
75  /// <returns>
76  /// <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
77  /// </returns>
78  public bool Equals(Size2 other)
79  {
80  return other.Width == Width && other.Height == Height;
81  }
82 
83  /// <inheritdoc/>
84  public override bool Equals(object obj)
85  {
86  if (ReferenceEquals(null, obj)) return false;
87  if (obj.GetType() != typeof(Size2)) return false;
88  return Equals((Size2)obj);
89  }
90 
91  /// <inheritdoc/>
92  public override int GetHashCode()
93  {
94  unchecked
95  {
96  return (Width*397) ^ Height;
97  }
98  }
99 
100  /// <summary>
101  /// Implements the operator ==.
102  /// </summary>
103  /// <param name="left">The left.</param>
104  /// <param name="right">The right.</param>
105  /// <returns>
106  /// The result of the operator.
107  /// </returns>
108  public static bool operator ==(Size2 left, Size2 right)
109  {
110  return left.Equals(right);
111  }
112 
113  /// <summary>
114  /// Implements the operator !=.
115  /// </summary>
116  /// <param name="left">The left.</param>
117  /// <param name="right">The right.</param>
118  /// <returns>
119  /// The result of the operator.
120  /// </returns>
121  public static bool operator !=(Size2 left, Size2 right)
122  {
123  return !left.Equals(right);
124  }
125 
126  public override string ToString()
127  {
128  return string.Format("({0},{1})", Width, Height);
129  }
130  }
131 }
bool Equals(Size2 other)
Determines whether the specified System.Object is equal to this instance.
Definition: Size2.cs:78
override string ToString()
Definition: Size2.cs:126
Size2(int width, int height)
Initializes a new instance of the Size2 struct.
Definition: Size2.cs:53
Structure using the same layout than System.Drawing.Size.
Definition: Size2.cs:36
override bool Equals(object obj)
Definition: Size2.cs:84
DataStyle
Specifies the style used for textual serialization when an array/list or a dictionary/map must be ser...
Definition: DataStyle.cs:9