memononen / nanosvg

Simple stupid SVG parser
zlib License
1.69k stars 357 forks source link

Question on nsvg__xformInverse for gradient colors #186

Open chenwu054 opened 4 years ago

chenwu054 commented 4 years ago

One question on "nsvgxformInverse(shape->fill.gradient->xform, t);" for gradient paints in nsvgscaleToViewbox function. I wonder why do we need to do inverse in the "scale" function? Is there any math formula to reference? Thank you!

memononen commented 4 years ago

The gradient transform is stored as inverse so that passing a point to it will return a point in gradient space. In retrospect sound wierd, but made sense at the time as I working on the rasterizer.