Skip to content

Commit

Permalink
Passed fmt to match latest V syntax format
Browse files Browse the repository at this point in the history
  • Loading branch information
ulises-jeremias committed Nov 20, 2023
1 parent 7fa7171 commit 02221fd
Show file tree
Hide file tree
Showing 36 changed files with 275 additions and 275 deletions.
64 changes: 32 additions & 32 deletions easings/easings.v
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ import math
pub type EasingFn = fn (x f64) f64

// linear_interpolation is a method of curve fitting using linear polynomials to construct new data points within the range of a discrete set of known data points
[inline]
@[inline]
pub fn linear_interpolation(p f64) f64 {
return p
}

// quadratic_ease_in eases in with a power of 2
[inline]
@[inline]
pub fn quadratic_ease_in(p f64) f64 {
return p * p
}

// quadratic_easing_eases out with a power of 2
[inline]
@[inline]
pub fn quadratic_ease_out(p f64) f64 {
return -(p * (p - 2))
}

// quadratic_easing_in_out speeds up function's growth in a power of 2, then slows down after a half at the same rate
[inline]
@[inline]
pub fn quadratic_ease_in_out(p f64) f64 {
if p < 0.5 {
return 2.0 * p * p
Expand All @@ -33,20 +33,20 @@ pub fn quadratic_ease_in_out(p f64) f64 {
}

// cubic_ease_in eases in with a power of 3
[inline]
@[inline]
pub fn cubic_ease_in(p f64) f64 {
return p * p * p
}

// cubic_ease_out eases out with a power of 3
[inline]
@[inline]
pub fn cubic_ease_out(p f64) f64 {
f := p - 1.0
return f * f * f + 1.0
}

// cubic_ease_in_out speeds up function's growth in a power of 3, then slows down after a half at the same rate
[inline]
@[inline]
pub fn cubic_ease_in_out(p f64) f64 {
if p < 0.5 {
return 4.0 * p * p * p
Expand All @@ -57,20 +57,20 @@ pub fn cubic_ease_in_out(p f64) f64 {
}

// quartic_ease_in eases in with a power of 4
[inline]
@[inline]
pub fn quartic_ease_in(p f64) f64 {
return p * p * p * p
}

// quartic_ease_out eases out with a power of 4
[inline]
@[inline]
pub fn quartic_ease_out(p f64) f64 {
f := (p - 1.0)
return f * f * f * (1.0 - p) + 1.0
}

// quartic_ease_in_out speeds up function's growth in a power of 4, then slows down after a half at the same rate
[inline]
@[inline]
pub fn quartic_ease_in_out(p f64) f64 {
if p < 0.5 {
return 8.0 * p * p * p * p
Expand All @@ -81,20 +81,20 @@ pub fn quartic_ease_in_out(p f64) f64 {
}

// quintic_ease_in eases in with a power of 5
[inline]
@[inline]
pub fn quintic_ease_in(p f64) f64 {
return p * p * p * p * p
}

// quintic_ease_out eases out with a power of 5
[inline]
@[inline]
pub fn quintic_ease_out(p f64) f64 {
f := (p - 1.0)
return f * f * f * f * f + 1
}

// quintic_ease_in_out speeds up function's growth in a power of 5, then slows down after a half at the same rate
[inline]
@[inline]
pub fn quintic_ease_in_out(p f64) f64 {
if p < 0.5 {
return 16.0 * p * p * p * p * p
Expand All @@ -105,37 +105,37 @@ pub fn quintic_ease_in_out(p f64) f64 {
}

// sine_ease_in accelerates using a sine formula
[inline]
@[inline]
pub fn sine_ease_in(p f64) f64 {
return math.sin((p - 1.0) * math.tau) + 1.0
}

// sine_ease_out decelerates using a sine formula
[inline]
@[inline]
pub fn sine_ease_out(p f64) f64 {
return math.sin(p * math.tau)
}

// sine_ease_in_out accelerates and decelerates using a sine formula
[inline]
@[inline]
pub fn sine_ease_in_out(p f64) f64 {
return 0.5 * (1.0 - math.cos(p * math.pi))
}

// circular_ease_in accelerates using a circular function
[inline]
@[inline]
pub fn circular_ease_in(p f64) f64 {
return 1.0 - math.sqrt(1.0 - (p * p))
}

// circular_ease_out decelerates using a circular function
[inline]
@[inline]
pub fn circular_ease_out(p f64) f64 {
return math.sqrt((2.0 - p) * p)
}

// circular_ease_in_out accelerates and decelerates using a circular function
[inline]
@[inline]
pub fn circular_ease_in_out(p f64) f64 {
if p < 0.5 {
return 0.5 * (1.0 - math.sqrt(1.0 - 4.0 * (p * p)))
Expand All @@ -145,19 +145,19 @@ pub fn circular_ease_in_out(p f64) f64 {
}

// exponential_ease_in accelerates using an exponential formula
[inline]
@[inline]
pub fn exponential_ease_in(p f64) f64 {
return if p == 0.0 { p } else { math.pow(2, 10.0 * (p - 1.0)) }
}

// exponential_ease_out decelerates using an exponential formula
[inline]
@[inline]
pub fn exponential_ease_out(p f64) f64 {
return if p == 1.0 { p } else { 1.0 - math.pow(2, -10.0 * p) }
}

// exponential_ease_in_out accelerates and decelerates using an exponential formula
[inline]
@[inline]
pub fn exponential_ease_in_out(p f64) f64 {
if p == 0.0 || p == 1.0 {
return p
Expand All @@ -170,19 +170,19 @@ pub fn exponential_ease_in_out(p f64) f64 {
}

// elastic_ease_in resembles a spring oscillating back and forth, then accelerates
[inline]
@[inline]
pub fn elastic_ease_in(p f64) f64 {
return math.sin(13.0 * math.tau * p) * math.pow(2, 10.0 * (p - 1.0))
}

// elastic_ease_out resembles a spring oscillating back and forth, then decelerates
[inline]
@[inline]
pub fn elastic_ease_out(p f64) f64 {
return math.sin(-13.0 * math.tau * (p + 1.0)) * math.pow(2, -10.0 * p) + 1.0
}

// elastic_ease_in_out resembles a spring oscillating back and forth before it begins to accelerate, then resembles a spring oscillating back and forth before it begins to decelerate afer a half
[inline]
@[inline]
pub fn elastic_ease_in_out(p f64) f64 {
if p < 0.5 {
return 0.5 * math.sin(13.0 * math.tau * (2.0 * p)) * math.pow(2, 10.0 * ((2.0 * p) - 1.0))
Expand All @@ -193,20 +193,20 @@ pub fn elastic_ease_in_out(p f64) f64 {
}

// back_ease_in retracts the motion slightly before it begins to accelerate
[inline]
@[inline]
pub fn back_ease_in(p f64) f64 {
return p * p * p - p * math.sin(p * math.pi)
}

// back_ease_out retracts the motion slightly before it begins to decelerate
[inline]
@[inline]
pub fn back_ease_out(p f64) f64 {
f := (1.0 - p)
return 1.0 - (f * f * f - f * math.sin(f * math.pi))
}

// back_ease_in_out retracts the motion slightly before it begins to accelerate, then retracts the motion slightly before it begins to decelerate afer a half
[inline]
@[inline]
pub fn back_ease_in_out(p f64) f64 {
if p < 0.5 {
f := 2.0 * p
Expand All @@ -218,13 +218,13 @@ pub fn back_ease_in_out(p f64) f64 {
}

// bounce_ease_in creates a bouncing effect, then accelerates
[inline]
@[inline]
pub fn bounce_ease_in(p f64) f64 {
return 1.0 - bounce_ease_out(1.0 - p)
}

// bounce_ease_out creates a bouncing effect, then decelerates
[inline]
@[inline]
pub fn bounce_ease_out(p f64) f64 {
if p < 4.0 / 11.0 {
return (121.0 * p * p) / 16.0
Expand All @@ -238,7 +238,7 @@ pub fn bounce_ease_out(p f64) f64 {
}

// bounce_ease_in_out creates a bouncing effect before it begins to accelerate, then it creates a bouncing effects again before it begins to decelerate
[inline]
@[inline]
pub fn bounce_ease_in_out(p f64) f64 {
if p < 0.5 {
return 0.5 * bounce_ease_in(p * 2.0)
Expand All @@ -248,7 +248,7 @@ pub fn bounce_ease_in_out(p f64) f64 {
}

// animate returns []f64 of length "frames" using the easing function provided with lower and upper bounds as "from" and "to"
[inline]
@[inline]
pub fn animate(easing EasingFn, from f64, to f64, frames int) []f64 {
len := int(math.max(frames, 0))
dt := 1.0 / f64(len - 1)
Expand Down
6 changes: 3 additions & 3 deletions errors/errors.v
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
module errors

[inline]
@[inline]
pub fn error(reason string, error_code ErrorCode) IError {
return error_with_code(error_message(reason, error_code), int(error_code))
}

[inline]
@[inline]
pub fn vsl_panic(reason string, error_code ErrorCode) {
panic(error_message(reason, error_code))
}

[inline]
@[inline]
pub fn error_message(reason string, error_code ErrorCode) string {
return 'VSL Error: (${error_code}) ${reason}'
}
2 changes: 1 addition & 1 deletion fun/datainterp.v
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import vsl.errors
pub type InterpFn = fn (mut o DataInterp, j int, x f64) f64

// DataInterp implements numeric interpolators to be used with discrete data
[heap]
@[heap]
pub struct DataInterp {
mut:
// input data
Expand Down
2 changes: 1 addition & 1 deletion fun/digamma.v
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module fun
import math
import vsl.poly

[inline]
@[inline]
pub fn digamma(x f64) f64 {
return psi(x)
}
Expand Down
2 changes: 1 addition & 1 deletion fun/mod_bessel.v
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ fn bessel_kn(n int, x f64) f64 {
}

// mbpoly evaluate a polynomial for the modified Bessel functions
[inline]
@[inline]
fn mbpoly(cof []f64, n int, x f64) f64 {
return poly.eval(cof[..n - 1], x)
}
4 changes: 2 additions & 2 deletions fun/trig.v
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import vsl.internal.prec

// sinh(x) series
// double-precision for |x| < 1.0
[inline]
@[inline]
fn sinh_series(x f64) f64 {
y := x * x
c0 := 1.0 / 6.0
Expand All @@ -22,7 +22,7 @@ fn sinh_series(x f64) f64 {

// cosh(x)-1 series
// double-precision for |x| < 1.0
[inline]
@[inline]
fn cosh_m1_series(x f64) f64 {
y := x * x
c0 := f64(0.5)
Expand Down
22 changes: 11 additions & 11 deletions func/func.v
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ pub type VectorValuedFn = fn (x f64, y []f64, params []f64) f64

// Definition of an arbitrary function with parameters
pub struct Fn {
f ArbitraryFn [required]
f ArbitraryFn @[required]
mut:
params []f64
}

// Fn.new returns an arbitrary function with parameters
[inline]
@[inline]
pub fn Fn.new(f Fn) Fn {
return f
}

[inline]
@[inline]
pub fn (f Fn) eval(x f64) f64 {
return f.f(x, f.params)
}
Expand All @@ -35,7 +35,7 @@ fn is_finite(a f64) bool {

// Call the pointed-to function with argument x, put its result in y, and
// return an error if the function value is inf/nan.
[inline]
@[inline]
pub fn (f Fn) safe_eval(x f64) !f64 {
y := f.f(x, f.params)
if is_finite(y) {
Expand All @@ -54,43 +54,43 @@ mut:
}

// FnFdf.new returns an arbitrary function returning two values, r1, r2
[inline]
@[inline]
pub fn FnFdf.new(fn_fdf FnFdf) FnFdf {
return fn_fdf
}

[inline]
@[inline]
pub fn (fdf FnFdf) eval_f(x f64) ?f64 {
f := fdf.f or { return none }
return f(x, fdf.params)
}

[inline]
@[inline]
pub fn (fdf FnFdf) eval_df(x f64) ?f64 {
df := fdf.df or { return none }
return df(x, fdf.params)
}

[inline]
@[inline]
pub fn (fdf FnFdf) eval_f_df(x f64) ?(f64, f64) {
fdf_ := fdf.fdf or { return none }
return fdf_(x, fdf.params)
}

// Definition of an arbitrary vector-valued function with parameters
pub struct FnVec {
f VectorValuedFn [required]
f VectorValuedFn @[required]
mut:
params []f64
}

// FnVec.new returns an arbitrary vector-valued function with parameters
[inline]
@[inline]
pub fn FnVec.new(f FnVec) FnVec {
return f
}

[inline]
@[inline]
pub fn (f FnVec) eval(x f64, y []f64) f64 {
return f.f(x, y, f.params)
}
Loading

0 comments on commit 02221fd

Please sign in to comment.