srwiley / rasterx

Rasterx is an SVG 2.0 path compliant rasterizer that can use either scany, the golang vector or a derivative of the freetype anti-aliaser.
BSD 3-Clause "New" or "Revised" License
133 stars 11 forks source link

Please explain the AddArc parameters, e.g. to make a "pie part" #13

Open metal3d opened 2 years ago

metal3d commented 2 years ago

Hi, I spent hours making tests and trying to understand the parameters, and the "points" content and I didn't find my way to make a "pie part". Whatever I do, the path becomes a circle.

Using this

    cx, cy := float64(w/2.0), float64(h/2.0)
    r := float64(w / 3.0)
    angle := 45.0
    rot := angle * math.Pi / 180.0

    // find the point on circle of radius r at angle rot
    px := cx + r*math.Cos(rot)
    py := cy + r*math.Sin(rot)

    points := []float64{r, r, angle, 1, 0, px, py}

    stroker.Start(rasterx.ToFixedP(cx, cy))
    //stroker.Line(rasterx.ToFixedP(cx, cy+r))
    stroker.Start(rasterx.ToFixedP(px, py))
    rasterx.AddArc(points, cx, cy, px, py, stroker)
    //stroker.Stop(false)
    //stroker.Line(rasterx.ToFixedP(cx, cy))
    stroker.Stop(false)
    stroker.Draw()

out

With this:

    stroker.Start(rasterx.ToFixedP(cx, cy))
    stroker.Line(rasterx.ToFixedP(cx, cy+r))
    stroker.Start(rasterx.ToFixedP(px, py))
    rasterx.AddArc(points, cx, cy, px, py, stroker)
    stroker.Line(rasterx.ToFixedP(cx, cy))
    stroker.Stop(false)
    stroker.Draw()

out

I made several other tests to start the path somewhere else, with no idea of how to make a "pie chart element".

This is the wanted shape: image

The goal is to make a pie chart (of course :) ) but (sorry to say this) the code is not well documented... Can you please give a simple example of a pie chart element?