Point3.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // Point3.cs
  2. //
  3. // Modified MIT License (MIT)
  4. //
  5. // Copyright (c) 2015 Completely Fair Games Ltd.
  6. //
  7. // Permission is hereby granted, free of charge, to any person obtaining a copy
  8. // of this software and associated documentation files (the "Software"), to deal
  9. // in the Software without restriction, including without limitation the rights
  10. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. // copies of the Software, and to permit persons to whom the Software is
  12. // furnished to do so, subject to the following conditions:
  13. //
  14. // The above copyright notice and this permission notice shall be included in
  15. // all copies or substantial portions of the Software.
  16. //
  17. // The following content pieces are considered PROPRIETARY and may not be used
  18. // in any derivative works, commercial or non commercial, without explicit
  19. // written permission from Completely Fair Games:
  20. //
  21. // * Images (sprites, textures, etc.)
  22. // * 3D Models
  23. // * Sound Effects
  24. // * Music
  25. //
  26. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  27. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  28. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  29. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  30. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  31. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  32. // THE SOFTWARE.
  33. using System;
  34. using System.Collections.Generic;
  35. using System.Linq;
  36. using System.Security.Cryptography.X509Certificates;
  37. using System.Text;
  38. using Microsoft.Xna.Framework;
  39. namespace DwarfCorp
  40. {
  41. public struct Point3 : IEquatable<Point3>
  42. {
  43. public int X;
  44. public int Y;
  45. public int Z;
  46. public static readonly Point3 Zero = new Point3(0, 0, 0);
  47. public Point3(int x, int y, int z)
  48. {
  49. X = x;
  50. Y = y;
  51. Z = z;
  52. }
  53. public override int GetHashCode()
  54. {
  55. const int p1 = 4273;
  56. const int p2 = 6247;
  57. return (X * p1 + Y) * p2 + Z;
  58. }
  59. public bool Equals(Point3 other)
  60. {
  61. return other.X == X && other.Y == Y && other.Z == Z;
  62. }
  63. public override bool Equals(object obj)
  64. {
  65. if(!(obj is Point3))
  66. {
  67. return false;
  68. }
  69. Point3 other = (Point3) obj;
  70. return other.X == X && other.Y == Y && other.Z == Z;
  71. }
  72. public static Point3 operator +(Point3 toAdd1, Point3 toAdd2)
  73. {
  74. return new Point3(toAdd1.X + toAdd2.X, toAdd1.Y + toAdd2.Y, toAdd1.Z + toAdd2.Z);
  75. }
  76. public Vector3 ToVector3()
  77. {
  78. return new Vector3(X, Y, Z);
  79. }
  80. public override string ToString()
  81. {
  82. return String.Format("{{{0}, {1}, {2}}}", X, Y, Z);
  83. }
  84. }
  85. }