Skip to content

Commit e9d816f

Browse files
committed
AddX, AddY, AddZ, AddW, Fract
1 parent 7d29870 commit e9d816f

3 files changed

Lines changed: 101 additions & 0 deletions

File tree

vector2/vector2.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,28 @@ func (v Vector[T]) Add(other Vector[T]) Vector[T] {
318318
}
319319
}
320320

321+
func (v Vector[T]) AddX(other T) Vector[T] {
322+
return Vector[T]{
323+
x: v.x + other,
324+
y: v.y,
325+
}
326+
}
327+
328+
func (v Vector[T]) AddY(other T) Vector[T] {
329+
return Vector[T]{
330+
x: v.x,
331+
y: v.y + other,
332+
}
333+
}
334+
335+
// Fract returns the fractional part of each component of the vector. This is calculated as x - floor(x).
336+
func (v Vector[T]) Fract() Vector[T] {
337+
return Vector[T]{
338+
x: T(float64(v.x) - math.Floor(float64(v.x))),
339+
y: T(float64(v.y) - math.Floor(float64(v.y))),
340+
}
341+
}
342+
321343
func (v Vector[T]) Sub(other Vector[T]) Vector[T] {
322344
return Vector[T]{
323345
x: v.x - other.x,

vector3/vector3.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,39 @@ func (v Vector[T]) Add(other Vector[T]) Vector[T] {
525525
}
526526
}
527527

528+
func (v Vector[T]) AddX(other T) Vector[T] {
529+
return Vector[T]{
530+
x: v.x + other,
531+
y: v.y,
532+
z: v.z,
533+
}
534+
}
535+
536+
func (v Vector[T]) AddY(other T) Vector[T] {
537+
return Vector[T]{
538+
x: v.x,
539+
y: v.y + other,
540+
z: v.z,
541+
}
542+
}
543+
544+
func (v Vector[T]) AddZ(other T) Vector[T] {
545+
return Vector[T]{
546+
x: v.x,
547+
y: v.y,
548+
z: v.z + other,
549+
}
550+
}
551+
552+
// Fract returns the fractional part of each component of the vector. This is calculated as x - floor(x).
553+
func (v Vector[T]) Fract() Vector[T] {
554+
return Vector[T]{
555+
x: T(float64(v.x) - math.Floor(float64(v.x))),
556+
y: T(float64(v.y) - math.Floor(float64(v.y))),
557+
z: T(float64(v.z) - math.Floor(float64(v.z))),
558+
}
559+
}
560+
528561
func (v Vector[T]) Sub(other Vector[T]) Vector[T] {
529562
return Vector[T]{
530563
x: v.x - other.x,

vector4/vector4.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,52 @@ func (v Vector[T]) Add(other Vector[T]) Vector[T] {
382382
}
383383
}
384384

385+
func (v Vector[T]) AddX(other T) Vector[T] {
386+
return Vector[T]{
387+
x: v.x + other,
388+
y: v.y,
389+
z: v.z,
390+
w: v.w,
391+
}
392+
}
393+
394+
func (v Vector[T]) AddY(other T) Vector[T] {
395+
return Vector[T]{
396+
x: v.x,
397+
y: v.y + other,
398+
z: v.z,
399+
w: v.w,
400+
}
401+
}
402+
403+
func (v Vector[T]) AddZ(other T) Vector[T] {
404+
return Vector[T]{
405+
x: v.x,
406+
y: v.y,
407+
z: v.z + other,
408+
w: v.w,
409+
}
410+
}
411+
412+
func (v Vector[T]) AddW(other T) Vector[T] {
413+
return Vector[T]{
414+
x: v.x,
415+
y: v.y,
416+
z: v.z,
417+
w: v.w + other,
418+
}
419+
}
420+
421+
// Fract returns the fractional part of each component of the vector. This is calculated as x - floor(x).
422+
func (v Vector[T]) Fract() Vector[T] {
423+
return Vector[T]{
424+
x: T(float64(v.x) - math.Floor(float64(v.x))),
425+
y: T(float64(v.y) - math.Floor(float64(v.y))),
426+
z: T(float64(v.z) - math.Floor(float64(v.z))),
427+
w: T(float64(v.w) - math.Floor(float64(v.w))),
428+
}
429+
}
430+
385431
func (v Vector[T]) Sub(other Vector[T]) Vector[T] {
386432
return Vector[T]{
387433
x: v.x - other.x,

0 commit comments

Comments
 (0)