Skip to content

Commit

Permalink
fix option to result in fun (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyi98 authored Mar 2, 2023
1 parent 1fec7c8 commit ff01045
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions fun/interpcubic.v
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub fn (o InterpCubic) critical() (f64, f64, f64, bool, bool, bool) {
// (x1, y1) -- second point
// (x2, y2) -- third point
// (x3, y3) -- fourth point
pub fn (mut o InterpCubic) fit_4points(x0 f64, y0 f64, x1 f64, y1 f64, x2 f64, y2 f64, x3 f64, y3 f64) ? {
pub fn (mut o InterpCubic) fit_4points(x0 f64, y0 f64, x1 f64, y1 f64, x2 f64, y2 f64, x3 f64, y3 f64) ! {
z0, z1, z2, z3 := x0 * x0, x1 * x1, x2 * x2, x3 * x3
w0, w1, w2, w3 := z0 * x0, z1 * x1, z2 * x2, z3 * x3
den := w0 * ((x2 - x3) * z1 + x3 * z2 - x2 * z3 + x1 * (z3 - z2)) + w1 * (x2 * z3 - x3 * z2) +
Expand Down Expand Up @@ -97,7 +97,7 @@ pub fn (mut o InterpCubic) fit_4points(x0 f64, y0 f64, x1 f64, y1 f64, x2 f64, y
// (x1, y1) -- second point
// (x2, y2) -- third point
// (x3, d3) -- derivative @ x3
pub fn (mut o InterpCubic) fit_3points_d(x0 f64, y0 f64, x1 f64, y1 f64, x2 f64, y2 f64, x3 f64, d3 f64) ? {
pub fn (mut o InterpCubic) fit_3points_d(x0 f64, y0 f64, x1 f64, y1 f64, x2 f64, y2 f64, x3 f64, d3 f64) ! {
z0, z1, z2, z3 := x0 * x0, x1 * x1, x2 * x2, x3 * x3
w0, w1, w2 := z0 * x0, z1 * x1, z2 * x2
den := x0 * (2 * w1 * x3 - 2 * w2 * x3 - 3 * z1 * z3 + 3 * z2 * z3) +
Expand Down
8 changes: 4 additions & 4 deletions fun/interpcubic_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn test_interp_cubic_01() {

// intepolator
mut interp := new_interp_cubic()
interp.fit_4points(x0, y0, x1, y1, x2, y2, x3, y3)?
interp.fit_4points(x0, y0, x1, y1, x2, y2, x3, y3)!

// check model and derivatives
for x in [-10.0, 0.0, 1.0, 8.0] {
Expand Down Expand Up @@ -50,7 +50,7 @@ fn test_interp_cubic_02() {

// intepolator
mut interp := new_interp_cubic()
interp.fit_4points(x0, y0, x1, y1, x2, y2, x3, y3)?
interp.fit_4points(x0, y0, x1, y1, x2, y2, x3, y3)!

// check model and derivatives
for x in [-10.0, 0.0, 5.0, 100.0] {
Expand Down Expand Up @@ -81,7 +81,7 @@ fn test_interp_cubic_03() {

// intepolator
mut interp := new_interp_cubic()
interp.fit_4points(x0, y0, x1, y1, x2, y2, x3, y3)?
interp.fit_4points(x0, y0, x1, y1, x2, y2, x3, y3)!

// check model and derivatives
for x in [-10.0, 0.0, 5.0, 100.0] {
Expand Down Expand Up @@ -113,7 +113,7 @@ fn test_interp_cubic_04() {

// intepolator
mut interp := new_interp_cubic()
interp.fit_3points_d(x0, y0, x1, y1, x2, y2, x3, d3)?
interp.fit_3points_d(x0, y0, x1, y1, x2, y2, x3, d3)!

// check model and derivatives
for x in [-10.0, 0.0, 1.0, 8.0] {
Expand Down
4 changes: 2 additions & 2 deletions fun/interpquad.v
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub fn (o InterpQuad) optimum() (f64, f64) {
// (x0, y0) -- first point
// (x1, y1) -- second point
// (x2, y2) -- third point
pub fn (mut o InterpQuad) fit_3points(x0 f64, y0 f64, x1 f64, y1 f64, x2 f64, y2 f64) ? {
pub fn (mut o InterpQuad) fit_3points(x0 f64, y0 f64, x1 f64, y1 f64, x2 f64, y2 f64) ! {
z0, z1, z2 := x0 * x0, x1 * x1, x2 * x2
den := x0 * (z2 - z1) - x1 * z2 + x2 * z1 + (x1 - x2) * z0
if math.abs(den) < o.tol_den {
Expand All @@ -64,7 +64,7 @@ pub fn (mut o InterpQuad) fit_3points(x0 f64, y0 f64, x1 f64, y1 f64, x2 f64, y2
// (x0, y0) -- first point
// (x1, y1) -- second point
// (x2, d2) -- derivate @ x2
pub fn (mut o InterpQuad) fit_2points_d(x0 f64, y0 f64, x1 f64, y1 f64, x2 f64, d2 f64) ? {
pub fn (mut o InterpQuad) fit_2points_d(x0 f64, y0 f64, x1 f64, y1 f64, x2 f64, d2 f64) ! {
z0, z1 := x0 * x0, x1 * x1
den := -z1 + z0 + 2 * x1 * x2 - 2 * x0 * x2
if math.abs(den) < o.tol_den {
Expand Down
8 changes: 4 additions & 4 deletions fun/interpquad_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn test_interp_quad_01() {

// intepolator
mut interp := new_interp_quad()
interp.fit_3points(x0, y0, x1, y1, x2, y2)?
interp.fit_3points(x0, y0, x1, y1, x2, y2)!

// check model and derivatives
for x in [-10.0, 0.0, 1.0, 8.0] {
Expand Down Expand Up @@ -46,7 +46,7 @@ fn test_interp_quad_02() {

// intepolator
mut interp := new_interp_quad()
interp.fit_3points(x0, y0, x1, y1, x2, y2)?
interp.fit_3points(x0, y0, x1, y1, x2, y2)!

// check model and derivatives
for x in [-10.0, 0.0, 1.0, 8.0] {
Expand Down Expand Up @@ -76,7 +76,7 @@ fn test_interp_quad_03() {

// intepolator
mut interp := new_interp_quad()
interp.fit_2points_d(x0, y0, x1, y1, x2, d2)?
interp.fit_2points_d(x0, y0, x1, y1, x2, d2)!

// check model and derivatives
for x in [-10.0, 0.0, 1.0, 8.0] {
Expand Down Expand Up @@ -106,7 +106,7 @@ fn test_interp_quad_04() {

// intepolator
mut interp := new_interp_quad()
interp.fit_2points_d(x0, y0, x1, y1, x2, d2)?
interp.fit_2points_d(x0, y0, x1, y1, x2, d2)!

// check model and derivatives
for x in [-10.0, 0.0, 1.0, 8.0] {
Expand Down

0 comments on commit ff01045

Please sign in to comment.