CS 345: Spring 2025
Programming Assignment 5
Curves and tiling
enum GPathVerb {
kMove, // returns pts[0] from Iter
kLine, // returns pts[0]..pts[1] from Iter and Edger
kQuad, // returns pts[0]..pts[2] from Iter and Edger
kCubic, // returns pts[0]..pts[3] from Iter and Edger
};
class GPathBuilder {
...
/**
* Append a new contour respecting the Direction. The contour should be an approximate
* circle (8 quadratic or 4 cubics) with the specified center and radius.
*/
void addCircle(GPoint center, float radius, GPathDirection);
}
class GPath {
public:
...
...
/**
* Revise your code to compute the tight bounds of each curve segment
*/
GRect bounds() const;
...
static void ChopQuadAt(const GPoint src[3], GPoint dst[5], float t);
static void ChopCubicAt(const GPoint src[4], GPoint dst[7], float t);
};
class GCanvas {
public:
...
// Handle quadratic and cubic curves in the path when drawing.
// Draw curves with a tolerance of 1/4 pixel
virtual void drawPath(const GPath& path, const GPaint&) = 0;
};
enum class GTileMode {
kClamp,
kRepeat,
kMirror,
};
std::unique_ptr<GShader> GCreateBitmapShader(..., TileMode);
std::unique_ptr<GShader> GCreateLinearGradient(..., TileMode);
Your task is to support curves (quadratic and cubic) in paths, and implement tiling modes in your shaders (bitmap and gradient).
- Implement curve utilities
- addCircle()
- bounds()
- ChopQuadAt()
- ChopCubicAt()
- Draw curves in GCanvas::drawPath()
- Handle kQuad and kCubic in GPath::Edger
- Compute segment count for eaching using flatten test
- Generate line segments and app to edge list
- Support GTileMode parameter in Bitmap and Gradient Shaders
Your directory should like something like this:
- apps contains the code for testing your code.
- expected contains sample output from the image tool to compare with your output.
- include contains class headers that your code can use.
- src contains common implementations needed for the tools.
- DO NOT EDIT/ADD/REMOVE anything in these sub-directories. You should only add files to the root of the directory.
- your_files any .cpp or .h files you need for your implementation. All of your work must be here.
To test your code...
> make
> ./image -e expected
> ./tests
> ./dbench
> ./bench
Bench scores the VM
clear 2.39
rects_blend 6.40
rects_opaque 0.75
rect_big 0.47
rect_tiny 0.46
quads_blend 7.18
quads_opaque 1.24
circles_large 5.08
circles_tiny 1.74
modes_0 1.44
modes_x 24.81
modes_1 14.64
bitmap_opaque 8.11
bitmap_alpha 11.73
gradient_1 0.13
gradient_2 4.53
gradient_3 9.44
path_small 0.80
path_big 3.00
path_bigc 1.32
path_unclipped 12.25
path_clipped 2.51
gradient_2_repeat 4.98
gradient_2_mirror 6.45
bitmap_repeat 5.51
bitmap_mirror 7.44