KarthikRIyer/swiftplot

Create single renderer function to draw Rect with fillColor and border

KarthikRIyer opened this issue · 8 comments

Our renderers right now can only draw a filled rectangle separate from a stroked one which is not ideal. Every renderer out there can draw a rectangle with both a fill color and a stroke color at once, instead of having to draw two rectangles one on top of the other with different settings. We should probably replace drawRect and drawSolidRect by a simpler one that accepts a strokeWidth, strokeColor, fillColor and hatchPattern.

Can I work on this ?

public func drawSolidRectWithBorder(_ rect: Rect,
                                        strokeWidth thickness: Float,
                                        fillColor: Color = Color.white,
                                        borderColor: Color = Color.black) {
        var x = [Float]()
        var y = [Float]()

        let pts = getPoints(from: rect)
        x.append(pts.tL.x + xOffset)
        x.append(pts.tR.x + xOffset)
        x.append(pts.bR.x + xOffset)
        x.append(pts.bL.x + xOffset)
        y.append(pts.tL.y + yOffset)
        y.append(pts.tR.y + yOffset)
        y.append(pts.bR.y + yOffset)
        y.append(pts.bL.y + yOffset)

        draw_solid_rect(x,
                        y,
                        fillColor.r,
                        fillColor.g,
                        fillColor.b,
                        fillColor.a,
                        0,
                        agg_object)
        draw_rect(x,
                  y,
                  thickness,
                  borderColor.r,
                  borderColor.g,
                  borderColor.b,
                  borderColor.a,
                  agg_object)
    }

isn't this what is required from this task ?

Yes @boronhub . But you need to add the function to the Renderer protocol first and then add implementations to each Renderer.

And in my PR, do I have to remove the original two rectangle functions or no?

Don't remove those functions. They might come in useful somewhere.

Dosen't drawSolidRectWithBorder fit this criteria ? It's working right now across all three renderers. It also exists in Renderer.swift

@boronhub, I think that we want a function that does the drawRect and drawSolidRect part all at once, as the renderers themselves should support it. You don't use drawRect or drawSolidRect, you replace drawSolidRectWithBorder that uses each renderer's own support of it, instead of overlaying rects which is happening now. Hope this makes some sort of sense.