/trunk/Demo.Mmose.Core/ServerEngine/Common/Point4D.cs

# · C# · 325 lines · 155 code · 42 blank · 128 comment · 51 complexity · 78040fe6885fc264856170086b0e241e MD5 · raw file

  1. #region zh-CHS 2006 - 2008 DemoSoft 团队 | en 2006 - 2008 DemoSoft Team
  2. // NOTES
  3. // ---------------
  4. //
  5. // This file is a part of the MMOSE(Massively Multiplayer Online Server Engine) for .NET.
  6. //
  7. // 2006-2008 DemoSoft Team
  8. //
  9. //
  10. // First Version : by H.Q.Cai - mailto:caihuanqing@hotmail.com
  11. /***************************************************************************
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU Lesser General Public License as published
  15. * by the Free Software Foundation; either version 2.1 of the License, or
  16. * (at your option) any later version.
  17. *
  18. ***************************************************************************/
  19. #region zh-CHS 包含名字空间 | en Include namespace
  20. using System;
  21. #endregion
  22. namespace Demo.Mmose.Core.Common
  23. {
  24. /// <summary>
  25. ///
  26. /// </summary>
  27. public class Point4D : IPoint4D, IComparable, IComparable<Point4D>
  28. {
  29. #region zh-CHS 类常量 | en Class Constants
  30. /// <summary>
  31. ///
  32. /// </summary>
  33. public static readonly Point4D Zero = new Point4D( 0, 0, 0, 0 );
  34. #endregion
  35. #region zh-CHS 构造和初始化和清理 | en Constructors and Initializers and Dispose
  36. /// <summary>
  37. ///
  38. /// </summary>
  39. /// <param name="x"></param>
  40. /// <param name="y"></param>
  41. /// <param name="z"></param>
  42. public Point4D( float x, float y, float z, float orientation )
  43. {
  44. m_X = x;
  45. m_Y = y;
  46. m_Z = z;
  47. m_O = orientation;
  48. }
  49. /// <summary>
  50. ///
  51. /// </summary>
  52. /// <param name="point3D"></param>
  53. public Point4D( IPoint4D point4D )
  54. : this( point4D.X, point4D.Y, point4D.Z, point4D.O )
  55. {
  56. }
  57. /// <summary>
  58. ///
  59. /// </summary>
  60. /// <param name="point3D"></param>
  61. public Point4D( IPoint3D point3D, float orientation )
  62. : this( point3D.X, point3D.Y, point3D.Z, orientation )
  63. {
  64. }
  65. /// <summary>
  66. ///
  67. /// </summary>
  68. /// <param name="point2D"></param>
  69. /// <param name="z"></param>
  70. public Point4D( IPoint2D point2D, float z, float orientation )
  71. : this( point2D.X, point2D.Y, z, orientation )
  72. {
  73. }
  74. #endregion
  75. #region zh-CHS 属性 | en Properties
  76. #region zh-CHS 私有成员变量 | en Private Member Variables
  77. /// <summary>
  78. ///
  79. /// </summary>
  80. private float m_X;
  81. #endregion
  82. /// <summary>
  83. ///
  84. /// </summary>
  85. public float X
  86. {
  87. get { return m_X; }
  88. set { m_X = value; }
  89. }
  90. #region zh-CHS 私有成员变量 | en Private Member Variables
  91. /// <summary>
  92. ///
  93. /// </summary>
  94. private float m_Y;
  95. #endregion
  96. /// <summary>
  97. ///
  98. /// </summary>
  99. public float Y
  100. {
  101. get { return m_Y; }
  102. set { m_Y = value; }
  103. }
  104. #region zh-CHS 私有成员变量 | en Private Member Variables
  105. /// <summary>
  106. ///
  107. /// </summary>
  108. private float m_Z;
  109. #endregion
  110. /// <summary>
  111. ///
  112. /// </summary>
  113. public float Z
  114. {
  115. get { return m_Z; }
  116. set { m_Z = value; }
  117. }
  118. #region zh-CHS 私有成员变量 | en Private Member Variables
  119. /// <summary>
  120. ///
  121. /// </summary>
  122. private float m_O;
  123. #endregion
  124. /// <summary>
  125. ///
  126. /// </summary>
  127. public float O
  128. {
  129. get { return m_O; }
  130. set { m_O = value; }
  131. }
  132. #endregion
  133. #region zh-CHS 方法 | en Method
  134. /// <summary>
  135. ///
  136. /// </summary>
  137. /// <param name="value"></param>
  138. /// <returns></returns>
  139. public static Point4D Parse( string value )
  140. {
  141. int iStart = value.IndexOf( '(' );
  142. int iEnd = value.IndexOf( ',', iStart + 1 );
  143. string strParam1 = value.Substring( iStart + 1, iEnd - ( iStart + 1 ) ).Trim();
  144. iStart = iEnd;
  145. iEnd = value.IndexOf( ',', iStart + 1 );
  146. string strParam2 = value.Substring( iStart + 1, iEnd - ( iStart + 1 ) ).Trim();
  147. iStart = iEnd;
  148. iEnd = value.IndexOf( ',', iStart + 1 );
  149. string strParam3 = value.Substring( iStart + 1, iEnd - ( iStart + 1 ) ).Trim();
  150. iStart = iEnd;
  151. iEnd = value.IndexOf( ')', iStart + 1 );
  152. string strParam4 = value.Substring( iStart + 1, iEnd - ( iStart + 1 ) ).Trim();
  153. return new Point4D( Convert.ToSingle( strParam1 ), Convert.ToSingle( strParam2 ), Convert.ToSingle( strParam3 ), Convert.ToSingle( strParam4 ) );
  154. }
  155. /// <summary>
  156. ///
  157. /// </summary>
  158. /// <param name="l"></param>
  159. /// <param name="r"></param>
  160. /// <returns></returns>
  161. public static bool operator ==( Point4D xCompare, Point4D yCompare )
  162. {
  163. return xCompare.m_X == yCompare.m_X && xCompare.m_Y == yCompare.m_Y && xCompare.m_Z == yCompare.m_Z && xCompare.m_O == yCompare.O;
  164. }
  165. /// <summary>
  166. ///
  167. /// </summary>
  168. /// <param name="l"></param>
  169. /// <param name="r"></param>
  170. /// <returns></returns>
  171. public static bool operator ==( Point4D xCompare, IPoint4D yCompare )
  172. {
  173. if ( object.ReferenceEquals( yCompare, null ) )
  174. return false;
  175. return xCompare.m_X == yCompare.X && xCompare.m_Y == yCompare.Y && xCompare.m_Z == yCompare.Z && xCompare.m_O == yCompare.O;
  176. }
  177. /// <summary>
  178. ///
  179. /// </summary>
  180. /// <param name="l"></param>
  181. /// <param name="r"></param>
  182. /// <returns></returns>
  183. public static bool operator !=( Point4D xCompare, Point4D yCompare )
  184. {
  185. return xCompare.m_X != yCompare.m_X || xCompare.m_Y != yCompare.m_Y || xCompare.m_Z != yCompare.m_Z || xCompare.m_O != yCompare.O;
  186. }
  187. /// <summary>
  188. ///
  189. /// </summary>
  190. /// <param name="l"></param>
  191. /// <param name="r"></param>
  192. /// <returns></returns>
  193. public static bool operator !=( Point4D xCompare, IPoint4D yCompare )
  194. {
  195. if ( object.ReferenceEquals( yCompare, null ) )
  196. return false;
  197. return xCompare.m_X != yCompare.X || xCompare.m_Y != yCompare.Y || xCompare.m_Z != yCompare.Z || xCompare.m_O != yCompare.O;
  198. }
  199. /// <summary>
  200. ///
  201. /// </summary>
  202. /// <param name="iSerial"></param>
  203. /// <returns></returns>
  204. public static explicit operator Point2D( Point4D point4D )
  205. {
  206. return new Point2D( point4D );
  207. }
  208. /// <summary>
  209. ///
  210. /// </summary>
  211. /// <param name="iSerial"></param>
  212. /// <returns></returns>
  213. public static explicit operator Point3D( Point4D point4D )
  214. {
  215. return new Point3D( point4D );
  216. }
  217. /// <summary>
  218. ///
  219. /// </summary>
  220. /// <param name="xObject"></param>
  221. /// <returns></returns>
  222. public override bool Equals( object xObject )
  223. {
  224. if ( xObject == null )
  225. return false;
  226. IPoint4D point4D = xObject as IPoint4D;
  227. if ( point4D == null )
  228. return false;
  229. return m_X == point4D.X && m_Y == point4D.Y && m_Z == point4D.Z && m_O == point4D.O;
  230. }
  231. /// <summary>
  232. ///
  233. /// </summary>
  234. /// <returns></returns>
  235. public override int GetHashCode()
  236. {
  237. return (int)m_X ^ (int)m_Y ^ (int)m_Z ^ (int)m_O;
  238. }
  239. /// <summary>
  240. ///
  241. /// </summary>
  242. /// <returns></returns>
  243. public override string ToString()
  244. {
  245. return String.Format( "({0}, {1}, {2}, {3} )", m_X, m_Y, m_Z, m_O );
  246. }
  247. /// <summary>
  248. ///
  249. /// </summary>
  250. /// <param name="other"></param>
  251. /// <returns></returns>
  252. public int CompareTo( Point4D other )
  253. {
  254. int iCompare = ( m_X.CompareTo( other.m_X ) );
  255. if ( iCompare == 0 )
  256. {
  257. iCompare = ( m_Y.CompareTo( other.m_Y ) );
  258. if ( iCompare == 0 )
  259. {
  260. iCompare = ( m_Z.CompareTo( other.m_Z ) );
  261. if ( iCompare == 0 )
  262. iCompare = ( m_O.CompareTo( other.m_O ) );
  263. }
  264. }
  265. return iCompare;
  266. }
  267. /// <summary>
  268. ///
  269. /// </summary>
  270. /// <param name="other"></param>
  271. /// <returns></returns>
  272. public int CompareTo( object other )
  273. {
  274. if ( other == null )
  275. return 1;
  276. if ( other is Point4D == false )
  277. return 1;
  278. return CompareTo( (Point4D)other );
  279. }
  280. #endregion
  281. }
  282. }
  283. #endregion