painter.go: Optimize isTick function
This reduces the loop frequency to one or two iterations in all cases. I have been unable to find any single line equation that can produce this same behavior, but one likely exists.
This commit is contained in:
parent
e7a49c2c21
commit
19173dfd37
1 changed files with 5 additions and 3 deletions
|
|
@ -617,10 +617,12 @@ func (p *Painter) TextFit(body string, x, y, width int, textAligns ...string) ch
|
||||||
|
|
||||||
func isTick(totalRange int, numTicks int, index int) bool {
|
func isTick(totalRange int, numTicks int, index int) bool {
|
||||||
step := float64(totalRange-1) / float64(numTicks-1)
|
step := float64(totalRange-1) / float64(numTicks-1)
|
||||||
for i := 0; i < numTicks; i++ {
|
for i := int(float64(index) / step); i < numTicks; i++ {
|
||||||
value := float64(i) * step
|
value := int((float64(i) * step) + 0.5)
|
||||||
if int(value + 0.5) == index {
|
if value == index {
|
||||||
return true
|
return true
|
||||||
|
} else if value > index {
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue