sub.rs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. use crate::Point;
  2. use std::ops::{Sub, SubAssign};
  3. use num::Integer;
  4. /*
  5. P - T
  6. P - (T, T)
  7. P - P
  8. P - &P
  9. P - &mP
  10. &P - T
  11. &P - (T, T)
  12. &P - P
  13. &P - &P
  14. &P - &mP
  15. &mP - T
  16. &mP - (T, T)
  17. &mP - P
  18. &mP - &P
  19. &mP - &mP
  20. P -= T
  21. P -= (T, T)
  22. P -= P
  23. P -= &P
  24. P -= &mP
  25. */
  26. impl<T: Integer + Copy> Sub<T> for Point<T> {
  27. type Output = Self;
  28. fn sub(self, rhs: T) -> Self::Output {
  29. Self::from((self.x-rhs, self.y-rhs))
  30. }
  31. }
  32. impl<T: Integer> Sub<(T, T)> for Point<T> {
  33. type Output = Self;
  34. fn sub(self, rhs: (T, T)) -> Self::Output {
  35. Self::from((self.x-rhs.0, self.y-rhs.1))
  36. }
  37. }
  38. impl<T: Integer> Sub<Point<T>> for Point<T> {
  39. type Output = Self;
  40. fn sub(self, rhs: Point<T>) -> Self::Output {
  41. Self::from((self.x-rhs.x, self.y-rhs.y))
  42. }
  43. }
  44. impl<T: Integer + Copy> Sub<&Point<T>> for Point<T> {
  45. type Output = Self;
  46. fn sub(self, rhs: &Point<T>) -> Self::Output {
  47. Self::from((self.x-rhs.x, self.y-rhs.y))
  48. }
  49. }
  50. impl<T: Integer + Copy> Sub<&mut Point<T>> for Point<T> {
  51. type Output = Self;
  52. fn sub(self, rhs: &mut Point<T>) -> Self::Output {
  53. Self::from((self.x-rhs.x, self.y-rhs.y))
  54. }
  55. }
  56. impl<T: Integer + Copy> Sub<T> for &Point<T> {
  57. type Output = Point<T>;
  58. fn sub(self, rhs: T) -> Self::Output {
  59. Point::from((self.x-rhs, self.y-rhs))
  60. }
  61. }
  62. impl<T: Integer + Copy> Sub<(T, T)> for &Point<T> {
  63. type Output = Point<T>;
  64. fn sub(self, rhs: (T, T)) -> Self::Output {
  65. Point::from((self.x-rhs.0, self.y-rhs.1))
  66. }
  67. }
  68. impl<T: Integer + Copy> Sub<Point<T>> for &Point<T> {
  69. type Output = Point<T>;
  70. fn sub(self, rhs: Point<T>) -> Self::Output {
  71. Point::from((self.x-rhs.x, self.y-rhs.y))
  72. }
  73. }
  74. impl<T: Integer + Copy> Sub<&Point<T>> for &Point<T> {
  75. type Output = Point<T>;
  76. fn sub(self, rhs: &Point<T>) -> Self::Output {
  77. Point::from((self.x-rhs.x, self.y-rhs.y))
  78. }
  79. }
  80. impl<T: Integer + Copy> Sub<&mut Point<T>> for &Point<T> {
  81. type Output = Point<T>;
  82. fn sub(self, rhs: &mut Point<T>) -> Self::Output {
  83. Point::from((self.x-rhs.x, self.y-rhs.y))
  84. }
  85. }
  86. impl<T: Integer + Copy> Sub<T> for &mut Point<T> {
  87. type Output = Point<T>;
  88. fn sub(self, rhs: T) -> Self::Output {
  89. Point::from((self.x-rhs, self.y-rhs))
  90. }
  91. }
  92. impl<T: Integer + Copy> Sub<(T, T)> for &mut Point<T> {
  93. type Output = Point<T>;
  94. fn sub(self, rhs: (T, T)) -> Self::Output {
  95. Point::from((self.x-rhs.0, self.y-rhs.1))
  96. }
  97. }
  98. impl<T: Integer + Copy> Sub<Point<T>> for &mut Point<T> {
  99. type Output = Point<T>;
  100. fn sub(self, rhs: Point<T>) -> Self::Output {
  101. Point::from((self.x-rhs.x, self.y-rhs.y))
  102. }
  103. }
  104. impl<T: Integer + Copy> Sub<&Point<T>> for &mut Point<T> {
  105. type Output = Point<T>;
  106. fn sub(self, rhs: &Point<T>) -> Self::Output {
  107. Point::from((self.x-rhs.x, self.y-rhs.y))
  108. }
  109. }
  110. impl<T: Integer + Copy> Sub<&mut Point<T>> for &mut Point<T> {
  111. type Output = Point<T>;
  112. fn sub(self, rhs: &mut Point<T>) -> Self::Output {
  113. Point::from((self.x-rhs.x, self.y-rhs.y))
  114. }
  115. }
  116. impl<T: Integer + SubAssign + Copy> SubAssign<T> for Point<T> {
  117. fn sub_assign(&mut self, rhs: T) {
  118. self.x -= rhs;
  119. self.y -= rhs;
  120. }
  121. }
  122. impl<T: Integer + SubAssign> SubAssign<(T, T)> for Point<T> {
  123. fn sub_assign(&mut self, rhs: (T, T)) {
  124. self.x -= rhs.0;
  125. self.y -= rhs.1;
  126. }
  127. }
  128. impl<T: Integer + SubAssign + Copy> SubAssign<Point<T>> for Point<T> {
  129. fn sub_assign(&mut self, rhs: Point<T>) {
  130. self.x -= rhs.x;
  131. self.y -= rhs.y;
  132. }
  133. }
  134. impl<T: Integer + SubAssign + Copy> SubAssign<&Point<T>> for Point<T> {
  135. fn sub_assign(&mut self, rhs: &Point<T>) {
  136. self.x -= rhs.x;
  137. self.y -= rhs.y;
  138. }
  139. }
  140. impl<T: Integer + SubAssign + Copy> SubAssign<&mut Point<T>> for Point<T> {
  141. fn sub_assign(&mut self, rhs: &mut Point<T>) {
  142. self.x -= rhs.x;
  143. self.y -= rhs.y;
  144. }
  145. }