Skip to content

Commit

Permalink
do not use math.Pow to compute ** 99, and only compute p if required
Browse files Browse the repository at this point in the history
  • Loading branch information
kidoman committed Sep 26, 2013
1 parent 527e083 commit 6bc7a2c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions main.go
Expand Up @@ -165,8 +165,6 @@ func sampler(orig, dir vector.Vector) vector.Vector {
sf = 1.0
}

p := math.Pow(l.DotProduct(r.Scale(sf)), 99)

if st == missDownward {
h = h.Scale(0.2)
fc := vector.Vector{X: 3, Y: 3, Z: 3}
Expand All @@ -176,6 +174,15 @@ func sampler(orig, dir vector.Vector) vector.Vector {
return fc.Scale(b*0.2 + 0.1)
}

p := l.DotProduct(r.Scale(sf))
p33 := p * p // p ** 2
p33 = p33 * p33 // p ** 4
p33 = p33 * p33 // p ** 8
p33 = p33 * p33 // p ** 16
p33 = p33 * p33 // p ** 32
p33 = p33 * p // p ** 33
p = p33 * p33 * p33

return vector.Vector{X: p, Y: p, Z: p}.Add(sampler(h, r).Scale(0.5))
}

Expand Down

0 comments on commit 6bc7a2c

Please sign in to comment.