Skip to content

Commit

Permalink
Expose Apply operation and add documentation to it (#26)
Browse files Browse the repository at this point in the history
- Exposed the `Apply` operation as it was starting with a lower case
letter for some reason
- Added short documentation comments
- Function passed to the `Apply` now needs to additionally accept an
index of a component. This is to allow differentiation between
processing X Y and Z
  • Loading branch information
Xkonti authored Sep 15, 2023
1 parent 3ffb0e4 commit 710b83c
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions apply.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
package govec

func (v V2F[T]) apply(f func(T) T) V2F[T] {
return V2F[T]{X: f(v.X), Y: f(v.Y)}
// Apply applies a function to each component of a vector.
// The function passed to Apply takes the component value and index as arguments.
func (v V2F[T]) Apply(f func(compVal T, compIdx int8) T) V2F[T] {
return V2F[T]{X: f(v.X, 0), Y: f(v.Y, 1)}
}

func (v V3F[T]) apply(f func(T) T) V3F[T] {
return V3F[T]{X: f(v.X), Y: f(v.Y), Z: f(v.Z)}
// Apply applies a function to each component of a vector.
// The function passed to Apply takes the component value and index as arguments.
func (v V3F[T]) Apply(f func(compVal T, compIdx int8) T) V3F[T] {
return V3F[T]{X: f(v.X, 0), Y: f(v.Y, 1), Z: f(v.Z, 2)}
}

func (v V2I[T]) apply(f func(T) T) V2I[T] {
return V2I[T]{X: f(v.X), Y: f(v.Y)}
// Apply applies a function to each component of a vector.
// The function passed to Apply takes the component value and index as arguments.
func (v V2I[T]) Apply(f func(compVal T, compIdx int8) T) V2I[T] {
return V2I[T]{X: f(v.X, 0), Y: f(v.Y, 1)}
}

func (v V3I[T]) apply(f func(T) T) V3I[T] {
return V3I[T]{X: f(v.X), Y: f(v.Y), Z: f(v.Z)}
// Apply applies a function to each component of a vector.
// The function passed to Apply takes the component value and index as arguments.
func (v V3I[T]) Apply(f func(compVal T, compIdx int8) T) V3I[T] {
return V3I[T]{X: f(v.X, 0), Y: f(v.Y, 1), Z: f(v.Z, 2)}
}

0 comments on commit 710b83c

Please sign in to comment.