Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public class Draw implements Visitor<Void> {
private final Paint paint;

public Draw(final Canvas canvas, final Paint paint) {
this.canvas = null; // FIXME
this.paint = null; // FIXME
this.canvas = canvas; // FIXED CONSTRUCTOR TO PROVIDED CANVAS
this.paint = paint; // FIXED CONSTRUCTOR TO PROVIDED PAINT
paint.setStyle(Style.STROKE);
}

Expand All @@ -30,37 +30,37 @@ public Void onCircle(final Circle c) {

@Override
public Void onStrokeColor(final StrokeColor c) {

//canvas.draw
return null;
}

@Override
public Void onFill(final Fill f) {

//canvas.draw
return null;
}

@Override
public Void onGroup(final Group g) {

//canvas.draw
return null;
}

@Override
public Void onLocation(final Location l) {

//canvas.draw
return null;
}

@Override
public Void onRectangle(final Rectangle r) {

canvas.drawRect(0, 0 , r.getHeight(), r.getWidth(), paint);
return null;
}

@Override
public Void onOutline(Outline o) {

//canvas.draw
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec
@Override
@SuppressLint("DrawAllocation")
protected void onDraw(final Canvas canvas) {
final var shape = Fixtures.simpleCircle;
final var shape = Fixtures.complexGroup;
final var b = shape.accept(new BoundingBox());
canvas.translate(-b.getX(), -b.getY());
b.accept(new Draw(canvas, paint));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,81 @@ public Location onCircle(final Circle c) {

@Override
public Location onFill(final Fill f) {
return null;
return f.getShape().accept(this);
}

@Override
public Location onGroup(final Group g) {
if (g.getShapes().isEmpty()) {
return new Location(0, 0, new Rectangle(0, 0));
}

return null;
int minX = Integer.MAX_VALUE;
int minY = Integer.MAX_VALUE;
int maxX = Integer.MIN_VALUE;
int maxY = Integer.MIN_VALUE;

for (Shape shape : g.getShapes()) {
Location bbox = shape.accept(this);
Rectangle rect = (Rectangle) bbox.getShape();

int x1 = bbox.getX();
int y1 = bbox.getY();
int x2 = x1 + rect.getWidth();
int y2 = y1 + rect.getHeight();

minX = Math.min(minX, x1);
minY = Math.min(minY, y1);
maxX = Math.max(maxX, x2);
maxY = Math.max(maxY, y2);
}

return new Location(minX, minY, new Rectangle(maxX - minX, maxY - minY));
}

@Override
public Location onLocation(final Location l) {

return null;
Location bbox = l.getShape().accept(this);
Rectangle rect = (Rectangle) bbox.getShape();
return new Location(l.getX() + bbox.getX(), l.getY() + bbox.getY(), rect);
}

@Override
public Location onRectangle(final Rectangle r) {
return null;
return new Location(0, 0, new Rectangle(r.getWidth(), r.getHeight()));
}

@Override
public Location onStrokeColor(final StrokeColor c) {
return null;
return c.getShape().accept(this);
}

@Override
public Location onOutline(final Outline o) {
return null;
return o.getShape().accept(this);
}

@Override
public Location onPolygon(final Polygon s) {
return null;
if (s.getPoints().isEmpty()) {
return new Location(0, 0, new Rectangle(0, 0));
}

int minX = Integer.MAX_VALUE;
int minY = Integer.MAX_VALUE;
int maxX = Integer.MIN_VALUE;
int maxY = Integer.MIN_VALUE;

for (Point point : s.getPoints()) {
int x = point.getX();
int y = point.getY();

minX = Math.min(minX, x);
minY = Math.min(minY, y);
maxX = Math.max(maxX, x);
maxY = Math.max(maxY, y);
}

return new Location(minX, minY, new Rectangle(maxX - minX, maxY - minY));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,45 @@ public class Count implements Visitor<Integer> {

@Override
public Integer onPolygon(final Polygon p) {
return -1;
return 1;
}

@Override
public Integer onCircle(final Circle c) {
return -1;
return 1;
}

@Override
public Integer onGroup(final Group g) {
return -1;
int count = 0;
for (Shape shape : g.getShapes()) {
count += shape.accept(this);
}
return count;
}

@Override
public Integer onRectangle(final Rectangle q) {
return -1;
return 1;
}

@Override
public Integer onOutline(final Outline o) {
return -1;
return o.getShape().accept(this);
}

@Override
public Integer onFill(final Fill c) {
return -1;
return c.getShape().accept(this);
}

@Override
public Integer onLocation(final Location l) {
return -1;
return l.getShape().accept(this);
}

@Override
public Integer onStrokeColor(final StrokeColor c) {
return -1;
return c.getShape().accept(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public Shape getShape() {

@Override
public <Result> Result accept(final Visitor<Result> v) {
// TODO your job
return null;
return v.onOutline(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@
*/
public class Point extends Location {

// TODO your job
// HINT: use a circle with radius 0 as the shape!

public Point(final int x, final int y) {
super(-1, -1, null);
assert x >= 0;
assert y >= 0;
super(x, y, new Circle(0));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public List<? extends Point> getPoints() {

@Override
public <Result> Result accept(final Visitor<Result> v) {
// TODO your job
return null;
return v.onPolygon(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,24 @@
*/
public final class StrokeColor implements Shape {

// TODO entirely your job
protected final int color;
protected final Shape shape;

public StrokeColor(final int color, final Shape shape) {
this.color = color;
this.shape = shape;
}

public int getColor() {
return -1;
return color;
}

public Shape getShape() {
return null;
return shape;
}

@Override
public <Result> Result accept(Visitor<Result> v) {
return null;
return v.onStrokeColor(this);
}
}
Binary file added doc/Screenshot 2025-09-29 at 2.08.18 PM.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/Screenshot 2025-10-17 at 8.04.44 PM.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.