1. Engineering
  2. Computer Science
  3. package edulucetlcs313androidshapesmodel import javautillist a shape visitor for...

Question: package edulucetlcs313androidshapesmodel import javautillist a shape visitor for...

Question details
Fill on Polygon method.

package edu.luc.etl.cs313.android.shapes.model;

import java.util.List;

/**
 * A shape visitor for calculating the bounding box, that is, the smallest
 * rectangle containing the shape. The resulting bounding box is returned as a
 * rectangle at a specific location.
 */
public class BoundingBox implements Visitor<Location> {

   // TODO entirely your job (except onCircle)

   @Override
   public Location onCircle(final Circle c) {
      final int radius = c.getRadius();
      return new Location(-radius, -radius, new Rectangle(2 * radius, 2 * radius));
   }

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

   @Override
   public Location onGroup(final Group g) {
      // Fill this method
   }

   @Override
   public Location onLocation(final Location l) {
      Location location = l.shape.accept(this);
      return new Location(l.x+location.x, l.y+location.y, location.shape);
   }

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

   @Override
   public Location onStroke(final Stroke c) {
      return c.getShape().accept(this);
   }

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

   @Override
   public Location onPolygon(final Polygon s) {
      // Fill this method
   }
}
Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution