Skip to content

Commit 669416e

Browse files
committed
Added component-wise division
1 parent e5c856b commit 669416e

File tree

8 files changed

+224
-0
lines changed

8 files changed

+224
-0
lines changed

src/main/scala/vecmatlib/vector/Vec2d.scala

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,33 @@ case class Vec2d(x: Double, y: Double) extends VecDouble[Vec2d] with Double2 {
135135
*/
136136
def angle(x: Double, y: Double): Double = this.angle(Vec2d(x, y))
137137

138+
/**
139+
* Returns a vector whose components are the multiplicative inverse of this vectors components.
140+
*
141+
* @return A vector whose components are the multiplicative inverse of this vectors components
142+
*/
143+
override def inverse: Vec2d = Vec2d(1.0 / this.x, 1.0 / this.y)
144+
145+
/**
146+
* Returns the component-wise division between this vector and the given scalars.
147+
*
148+
* @param x Value by which the X component is divided
149+
* @param y Value by which the Y component is divided
150+
* @return The component-wise division between this vector and the given scalars.
151+
*/
152+
def /(x: Double, y: Double): Vec2d = Vec2d(this.x / x, this.y / y)
153+
154+
/**
155+
* Returns the component-wise division between this vector and the given scalars.
156+
*
157+
* This method can be used in place of the '/' operator for better interoperability with Java.
158+
*
159+
* @param x Value by which the X component is divided
160+
* @param y Value by which the Y component is divided
161+
* @return The component-wise division between this vector and the given scalars.
162+
*/
163+
def divide(x: Double, y: Double): Vec2d = this / (x, y)
164+
138165
/**
139166
* Returns a vector with all components in absolute value.
140167
*

src/main/scala/vecmatlib/vector/Vec2f.scala

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,33 @@ case class Vec2f(x: Float, y: Float) extends VecFloat[Vec2f] with Float2 {
135135
*/
136136
def angle(x: Double, y: Double): Double = this.toDouble.angle(Vec2d(x, y))
137137

138+
/**
139+
* Returns a vector whose components are the multiplicative inverse of this vectors components.
140+
*
141+
* @return A vector whose components are the multiplicative inverse of this vectors components
142+
*/
143+
override def inverse: Vec2f = Vec2f(1.0f / this.x, 1.0f / this.y)
144+
145+
/**
146+
* Returns the component-wise division between this vector and the given scalars.
147+
*
148+
* @param x Value by which the X component is divided
149+
* @param y Value by which the Y component is divided
150+
* @return The component-wise division between this vector and the given scalars.
151+
*/
152+
def /(x: Float, y: Float): Vec2f = Vec2f(this.x / x, this.y / y)
153+
154+
/**
155+
* Returns the component-wise division between this vector and the given scalars.
156+
*
157+
* This method can be used in place of the '/' operator for better interoperability with Java.
158+
*
159+
* @param x Value by which the X component is divided
160+
* @param y Value by which the Y component is divided
161+
* @return The component-wise division between this vector and the given scalars.
162+
*/
163+
def divide(x: Float, y: Float): Vec2f = this / (x, y)
164+
138165
/**
139166
* Returns a vector with all components in absolute value.
140167
*

src/main/scala/vecmatlib/vector/Vec3d.scala

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,35 @@ case class Vec3d(x: Double, y: Double, z: Double) extends VecDouble[Vec3d] with
192192
*/
193193
def angle(x: Double, y: Double, z: Double): Double = this.angle(Vec3d(x, y, z))
194194

195+
/**
196+
* Returns a vector whose components are the multiplicative inverse of this vectors components.
197+
*
198+
* @return A vector whose components are the multiplicative inverse of this vectors components
199+
*/
200+
override def inverse: Vec3d = Vec3d(1.0 / this.x, 1.0 / this.y, 1.0 / this.z)
201+
202+
/**
203+
* Returns the component-wise division between this vector and the given scalars.
204+
*
205+
* @param x Value by which the X component is divided
206+
* @param y Value by which the Y component is divided
207+
* @param z Value by which the Z component is divided
208+
* @return The component-wise division between this vector and the given scalars.
209+
*/
210+
def /(x: Double, y: Double, z: Double): Vec3d = Vec3d(this.x / x, this.y / y, this.z / z)
211+
212+
/**
213+
* Returns the component-wise division between this vector and the given scalars.
214+
*
215+
* This method can be used in place of the '/' operator for better interoperability with Java.
216+
*
217+
* @param x Value by which the X component is divided
218+
* @param y Value by which the Y component is divided
219+
* @param z Value by which the Z component is divided
220+
* @return The component-wise division between this vector and the given scalars.
221+
*/
222+
def divide(x: Double, y: Double, z: Double): Vec3d = this / (x, y, z)
223+
195224
/**
196225
* Returns a vector with all components in absolute value.
197226
*

src/main/scala/vecmatlib/vector/Vec3f.scala

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,35 @@ case class Vec3f(x: Float, y: Float, z: Float) extends VecFloat[Vec3f] with Floa
192192
*/
193193
def angle(x: Double, y: Double, z: Double): Double = this.toDouble.angle(Vec3d(x, y, z))
194194

195+
/**
196+
* Returns a vector whose components are the multiplicative inverse of this vectors components.
197+
*
198+
* @return A vector whose components are the multiplicative inverse of this vectors components
199+
*/
200+
override def inverse: Vec3f = Vec3f(1.0f / this.x, 1.0f / this.y, 1.0f / this.z)
201+
202+
/**
203+
* Returns the component-wise division between this vector and the given scalars.
204+
*
205+
* @param x Value by which the X component is divided
206+
* @param y Value by which the Y component is divided
207+
* @param z Value by which the Z component is divided
208+
* @return The component-wise division between this vector and the given scalars.
209+
*/
210+
def /(x: Float, y: Float, z: Float): Vec3f = Vec3f(this.x / x, this.y / y, this.z / z)
211+
212+
/**
213+
* Returns the component-wise division between this vector and the given scalars.
214+
*
215+
* This method can be used in place of the '/' operator for better interoperability with Java.
216+
*
217+
* @param x Value by which the X component is divided
218+
* @param y Value by which the Y component is divided
219+
* @param z Value by which the Z component is divided
220+
* @return The component-wise division between this vector and the given scalars.
221+
*/
222+
def divide(x: Float, y: Float, z: Float): Vec3f = this / (x, y, z)
223+
195224
/**
196225
* Returns a vector with all components in absolute value.
197226
*

src/main/scala/vecmatlib/vector/Vec4d.scala

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,37 @@ case class Vec4d(x: Double, y: Double, z: Double, w: Double) extends VecDouble[V
231231
*/
232232
def angle(x: Double, y: Double, z: Double, w: Double): Double = this.angle(Vec4d(x, y, z, w))
233233

234+
/**
235+
* Returns a vector whose components are the multiplicative inverse of this vectors components.
236+
*
237+
* @return A vector whose components are the multiplicative inverse of this vectors components
238+
*/
239+
override def inverse: Vec4d = Vec4d(1.0 / this.x, 1.0 / this.y, 1.0 / this.z, 1.0 / this.w)
240+
241+
/**
242+
* Returns the component-wise division between this vector and the given scalars.
243+
*
244+
* @param x Value by which the X component is divided
245+
* @param y Value by which the Y component is divided
246+
* @param z Value by which the Z component is divided
247+
* @param w Value by which the W component is divided
248+
* @return The component-wise division between this vector and the given scalars.
249+
*/
250+
def /(x: Double, y: Double, z: Double, w: Double): Vec4d = Vec4d(this.x / x, this.y / y, this.z / z, this.w / w)
251+
252+
/**
253+
* Returns the component-wise division between this vector and the given scalars.
254+
*
255+
* This method can be used in place of the '/' operator for better interoperability with Java.
256+
*
257+
* @param x Value by which the X component is divided
258+
* @param y Value by which the Y component is divided
259+
* @param z Value by which the Z component is divided
260+
* @param w Value by which the W component is divided
261+
* @return The component-wise division between this vector and the given scalars.
262+
*/
263+
def divide(x: Double, y: Double, z: Double, w: Double): Vec4d = this / (x, y, z, w)
264+
234265
/**
235266
* Returns a vector with all components in absolute value.
236267
*

src/main/scala/vecmatlib/vector/Vec4f.scala

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,37 @@ case class Vec4f(x: Float, y: Float, z: Float, w: Float) extends VecFloat[Vec4f]
231231
*/
232232
def angle(x: Double, y: Double, z: Double, w: Double): Double = this.toDouble.angle(Vec4d(x, y, z, w))
233233

234+
/**
235+
* Returns a vector whose components are the multiplicative inverse of this vectors components.
236+
*
237+
* @return A vector whose components are the multiplicative inverse of this vectors components
238+
*/
239+
override def inverse: Vec4f = Vec4f(1.0f / this.x, 1.0f / this.y, 1.0f / this.z, 1.0f / this.w)
240+
241+
/**
242+
* Returns the component-wise division between this vector and the given scalars.
243+
*
244+
* @param x Value by which the X component is divided
245+
* @param y Value by which the Y component is divided
246+
* @param z Value by which the Z component is divided
247+
* @param w Value by which the W component is divided
248+
* @return The component-wise division between this vector and the given scalars.
249+
*/
250+
def /(x: Float, y: Float, z: Float, w: Float): Vec4f = Vec4f(this.x / x, this.y / y, this.z / z, this.w / w)
251+
252+
/**
253+
* Returns the component-wise division between this vector and the given scalars.
254+
*
255+
* This method can be used in place of the '/' operator for better interoperability with Java.
256+
*
257+
* @param x Value by which the X component is divided
258+
* @param y Value by which the Y component is divided
259+
* @param z Value by which the Z component is divided
260+
* @param w Value by which the W component is divided
261+
* @return The component-wise division between this vector and the given scalars.
262+
*/
263+
def divide(x: Float, y: Float, z: Float, w: Float): Vec4f = this / (x, y, z, w)
264+
234265
/**
235266
* Returns a vector with all components in absolute value.
236267
*

src/main/scala/vecmatlib/vector/VecDouble.scala

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,31 @@ abstract class VecDouble[V <: VecDouble[V]] extends VecAbstract[V] {
8080
*/
8181
override def angle(v: V): Double = math.acos((this dot v) / (this.length * v.length))
8282

83+
/**
84+
* Returns a vector whose components are the multiplicative inverse of this vectors components.
85+
*
86+
* @return A vector whose components are the multiplicative inverse of this vectors components
87+
*/
88+
def inverse: V
89+
90+
/**
91+
* Returns the component-wise division between this vector and the given one.
92+
*
93+
* @param v The second operand of the division
94+
* @return The component-wise multiplication between this vector and the given one
95+
*/
96+
def /(v: V): V = this * v.inverse
97+
98+
/**
99+
* Returns the component-wise division between this vector and the given one.
100+
*
101+
* This method can be used in place of the '/' operator for better interoperability with Java.
102+
*
103+
* @param v The second operand of the division
104+
* @return The component-wise multiplication between this vector and the given one
105+
*/
106+
def divide(v: V): V = this / v
107+
83108
/**
84109
* Returns the normalized vector pointing from this vector to the given one.
85110
*

src/main/scala/vecmatlib/vector/VecFloat.scala

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,31 @@ abstract class VecFloat[V <: VecFloat[V]] extends VecAbstract[V] {
8080
*/
8181
override def angle(v: V): Double = math.acos((this dot v) / (this.length * v.length))
8282

83+
/**
84+
* Returns a vector whose components are the multiplicative inverse of this vectors components.
85+
*
86+
* @return A vector whose components are the multiplicative inverse of this vectors components
87+
*/
88+
def inverse: V
89+
90+
/**
91+
* Returns the component-wise division between this vector and the given one.
92+
*
93+
* @param v The second operand of the division
94+
* @return The component-wise multiplication between this vector and the given one
95+
*/
96+
def /(v: V): V = this * v.inverse
97+
98+
/**
99+
* Returns the component-wise division between this vector and the given one.
100+
*
101+
* This method can be used in place of the '/' operator for better interoperability with Java.
102+
*
103+
* @param v The second operand of the division
104+
* @return The component-wise multiplication between this vector and the given one
105+
*/
106+
def divide(v: V): V = this / v
107+
83108
/**
84109
* Returns the normalized vector pointing from this vector to the given one.
85110
*

0 commit comments

Comments
 (0)