PointF.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. //
  2. // System.Drawing.PointF.cs
  3. //
  4. // Author:
  5. // Mike Kestner ([email protected])
  6. //
  7. // (C) Ximian, Inc. http://www.ximian.com
  8. //
  9. using System;
  10. namespace System.Drawing {
  11. public struct PointF {
  12. // Private x and y coordinate fields.
  13. float cx, cy;
  14. // -----------------------
  15. // Public Shared Members
  16. // -----------------------
  17. /// <summary>
  18. /// Empty Shared Field
  19. /// </summary>
  20. ///
  21. /// <remarks>
  22. /// An uninitialized PointF Structure.
  23. /// </remarks>
  24. public static readonly PointF Empty;
  25. /// <summary>
  26. /// Addition Operator
  27. /// </summary>
  28. ///
  29. /// <remarks>
  30. /// Translates a PointF using the Width and Height
  31. /// properties of the given Size.
  32. /// </remarks>
  33. public static PointF operator + (PointF pt, Size sz)
  34. {
  35. return new PointF (pt.X + sz.Width, pt.Y + sz.Height);
  36. }
  37. /// <summary>
  38. /// Equality Operator
  39. /// </summary>
  40. ///
  41. /// <remarks>
  42. /// Compares two PointF objects. The return value is
  43. /// based on the equivalence of the X and Y properties
  44. /// of the two points.
  45. /// </remarks>
  46. public static bool operator == (PointF pt_a, PointF pt_b)
  47. {
  48. return ((pt_a.X == pt_b.X) && (pt_a.Y == pt_b.Y));
  49. }
  50. /// <summary>
  51. /// Inequality Operator
  52. /// </summary>
  53. ///
  54. /// <remarks>
  55. /// Compares two PointF objects. The return value is
  56. /// based on the equivalence of the X and Y properties
  57. /// of the two points.
  58. /// </remarks>
  59. public static bool operator != (PointF pt_a, PointF pt_b)
  60. {
  61. return ((pt_a.X != pt_b.X) || (pt_a.Y != pt_b.Y));
  62. }
  63. /// <summary>
  64. /// Subtraction Operator
  65. /// </summary>
  66. ///
  67. /// <remarks>
  68. /// Translates a PointF using the negation of the Width
  69. /// and Height properties of the given Size.
  70. /// </remarks>
  71. public static PointF operator - (PointF pt, Size sz)
  72. {
  73. return new PointF (pt.X - sz.Width, pt.Y - sz.Height);
  74. }
  75. // -----------------------
  76. // Public Constructor
  77. // -----------------------
  78. /// <summary>
  79. /// PointF Constructor
  80. /// </summary>
  81. ///
  82. /// <remarks>
  83. /// Creates a PointF from a specified x,y coordinate pair.
  84. /// </remarks>
  85. public PointF (float x, float y)
  86. {
  87. cx = x;
  88. cy = y;
  89. }
  90. // -----------------------
  91. // Public Instance Members
  92. // -----------------------
  93. /// <summary>
  94. /// IsEmpty Property
  95. /// </summary>
  96. ///
  97. /// <remarks>
  98. /// Indicates if both X and Y are zero.
  99. /// </remarks>
  100. public bool IsEmpty {
  101. get {
  102. return ((cx == 0.0) && (cy == 0.0));
  103. }
  104. }
  105. /// <summary>
  106. /// X Property
  107. /// </summary>
  108. ///
  109. /// <remarks>
  110. /// The X coordinate of the PointF.
  111. /// </remarks>
  112. public float X {
  113. get {
  114. return cx;
  115. }
  116. set {
  117. cx = value;
  118. }
  119. }
  120. /// <summary>
  121. /// Y Property
  122. /// </summary>
  123. ///
  124. /// <remarks>
  125. /// The Y coordinate of the PointF.
  126. /// </remarks>
  127. public float Y {
  128. get {
  129. return cy;
  130. }
  131. set {
  132. cy = value;
  133. }
  134. }
  135. /// <summary>
  136. /// Equals Method
  137. /// </summary>
  138. ///
  139. /// <remarks>
  140. /// Checks equivalence of this PointF and another object.
  141. /// </remarks>
  142. public override bool Equals (object o)
  143. {
  144. if (!(o is PointF))
  145. return false;
  146. return (this == (PointF) o);
  147. }
  148. /// <summary>
  149. /// GetHashCode Method
  150. /// </summary>
  151. ///
  152. /// <remarks>
  153. /// Calculates a hashing value.
  154. /// </remarks>
  155. public override int GetHashCode ()
  156. {
  157. return (int) cx ^ (int) cy;
  158. }
  159. /// <summary>
  160. /// ToString Method
  161. /// </summary>
  162. ///
  163. /// <remarks>
  164. /// Formats the PointF as a string in coordinate notation.
  165. /// </remarks>
  166. public override string ToString ()
  167. {
  168. return String.Format ("[{0},{1}]", cx, cy);
  169. }
  170. }
  171. }