Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- *
- */
- package geometry;
- import java.awt.Color;
- import java.awt.Graphics;
- import java.awt.Point;
- import java.util.ArrayList;
- /**
- * @author Meli
- *
- */
- public class Polygon extends GraphicPrimitive
- {
- ArrayList<Point> a = new ArrayList<Point>();
- int xcoord[];
- int ycoord[];
- int nPoints[];
- int x;
- int y;
- Color color;
- int counter;
- public Polygon(Color color)
- {
- this.color = color;
- }
- public void AddPoint(int x, int y)
- {
- Point p = new Point(x, y);
- a.add(p);
- xcoord = new int[a.size()];
- ycoord = new int[a.size()];
- for (int i = 0; i < a.size(); i++)
- {
- a.get(i).x = xcoord[i];
- a.get(i).y = ycoord[i];
- }
- }
- public void draw(Graphics g)
- {
- g.drawPolygon(xcoord, ycoord, xcoord.length);
- }
- @Override
- public BoundingBox getBoundingBox()
- {
- Point pos = new Point(a.get(0));
- Point size = new Point(a.get(0));
- for (int i = 1; i < a.size(); i++)
- {
- Point temp = a.get(0);
- pos.x = Math.min(pos.x, temp.x);
- pos.y = Math.min(pos.y, temp.y);
- size.x = Math.max(size.x, temp.x);
- size.y = Math.max(size.y, temp.y);
- }
- size.x = size.x - pos.x + 2;
- size.y = size.y - pos.y + 2;
- pos.x--;
- pos.y--;
- return new BoundingBox(pos.x, pos.y, size.x, size.y);
- }
- @Override
- public void move(int dx, int dy)
- {
- for (int i = 0; i < a.size(); i++)
- {
- a.get(i).x += dx;
- a.get(i).y += dy;
- }
- }
- @Override
- public void setDrawPoint(int x, int y)
- {
- // TODO Auto-generated method stub
- }
- @Override
- public String toString()
- {
- return null;
- }
- @Override
- public void setColor()
- {
- // TODO Auto-generated method stub
- }
- @Override
- public GraphicPrimitive clone()
- {
- // TODO Auto-generated method stub
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement