transform warps the image to align with non-linear axes.
(p *plot.Plot)
| 79 | |
| 80 | // transform warps the image to align with non-linear axes. |
| 81 | func (img *Image) transformFor(p *plot.Plot) image.Image { |
| 82 | _, xLinear := p.X.Scale.(plot.LinearScale) |
| 83 | _, yLinear := p.Y.Scale.(plot.LinearScale) |
| 84 | if xLinear && yLinear { |
| 85 | return img.img |
| 86 | } |
| 87 | b := img.img.Bounds() |
| 88 | o := image.NewNRGBA64(b) |
| 89 | for c := range img.cols { |
| 90 | // Find the equivalent image column after applying axis transforms. |
| 91 | cTrans := int(p.X.Norm(img.x(c)) * float64(img.cols)) |
| 92 | // Find the equivalent column of the previous image column after applying |
| 93 | // axis transforms. |
| 94 | cPrevTrans := int(p.X.Norm(img.x(max(c-1, 0))) * float64(img.cols)) |
| 95 | for r := range img.rows { |
| 96 | // Find the equivalent image row after applying axis transforms. |
| 97 | rTrans := int(p.Y.Norm(img.y(r)) * float64(img.rows)) |
| 98 | // Find the equivalent row of the previous image row after applying |
| 99 | // axis transforms. |
| 100 | rPrevTrans := int(p.Y.Norm(img.y(max(r-1, 0))) * float64(img.rows)) |
| 101 | crColor := img.img.At(c, img.rows-r-1) |
| 102 | // Set all the pixels in the new image between (cPrevTrans, rPrevTrans) |
| 103 | // and (cTrans, rTrans) to the color at (c,r) in the original image. |
| 104 | // TODO: Improve interpolation. |
| 105 | for cPrime := cPrevTrans; cPrime <= cTrans; cPrime++ { |
| 106 | for rPrime := rPrevTrans; rPrime <= rTrans; rPrime++ { |
| 107 | o.Set(cPrime, img.rows-rPrime-1, crColor) |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | return o |
| 113 | } |
| 114 | |
| 115 | func (img *Image) x(c int) float64 { |
| 116 | if c >= img.cols || c < 0 { |