-
Notifications
You must be signed in to change notification settings - Fork 0
/
axis.go
64 lines (49 loc) · 1.17 KB
/
axis.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package fnplot
import (
"math/big"
"github.com/ALTree/bigfloat"
)
type Axis interface {
Point(*big.Float) float64
SetMaxValue(*big.Float)
}
type StdAxix struct{}
func (StdAxix) Point(p *big.Float) float64 {
fp, _ := p.Float64()
return fp
}
func (*StdAxix) SetMaxValue(*big.Float) {}
type ScaledAxis struct {
Max float64
ratio *big.Float
}
func (sa ScaledAxis) Point(p *big.Float) float64 {
scaled, _ := big.NewFloat(0).Mul(p, sa.ratio).Float64()
return scaled
}
func (sa *ScaledAxis) SetMaxValue(v *big.Float) {
sa.ratio = big.NewFloat(0).Quo(big.NewFloat(sa.Max), v)
}
type LnAxis struct{}
func (la LnAxis) Point(p *big.Float) float64 {
if p.Cmp(big.NewFloat(0)) == 0 {
return 0
}
scaled, _ := bigfloat.Log(p).Float64()
return scaled
}
func (*LnAxis) SetMaxValue(*big.Float) {}
type LnScaledAxis struct {
Max float64
ratio *big.Float
}
func (lsa LnScaledAxis) Point(p *big.Float) float64 {
if p.Cmp(big.NewFloat(0)) == 0 {
return 0
}
scaled, _ := big.NewFloat(0).Mul(bigfloat.Log(p), lsa.ratio).Float64()
return scaled
}
func (lsa *LnScaledAxis) SetMaxValue(v *big.Float) {
lsa.ratio = big.NewFloat(0).Quo(big.NewFloat(lsa.Max), bigfloat.Log(v))
}