CS 345: Spring 2025

Programming Assignment 3

Round and round we go

We generalize colors to an object (GShader) and add a matrix to the canvas.
    class GShader {
    public:
        virtual ~GShader() {}
        
        virtual bool isOpaque() = 0;
        virtual bool setContext(const GMatrix& ctm) = 0;
        virtual void shadeRow(int x, int y, int count, GPixel row[]) = 0;
    };
    std::shared_ptr<GShader> GCreateBitmapShader(const GBitmap&, const GMatrix&);

    class GMatrix {
    public:
        GMatrix();
        static GMatrix Translate(float tx, float ty);
        static GMatrix Scale(float sx, float sy);
        static GMatrix Rotate(float radians);
        static GMatrix Concat(const GMatrix& secundo, const GMatrix& primo);
        std::optional invert() const;
        void mapPoints(GPoint dst[], const GPoint src[], int count) const;
        ...
    };

    class GCanvas {
    public:
        virtual void save() = 0;
        virtual void restore() = 0;
        virtual void concat(const GMatrix&) = 0;
        ...
    };
    
You task is to extend the subclass of GCanvas you created in PA3, subclass GShader, and implement GMatrix.