Advertisement
Guest User

Untitled

a guest
May 27th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.78 KB | None | 0 0
  1. /**
  2.  *
  3.  */
  4. package geometry;
  5.  
  6. import java.awt.Color;
  7. import java.awt.Graphics;
  8. import java.awt.Point;
  9. import java.util.ArrayList;
  10.  
  11. /**
  12.  * @author Meli
  13.  *
  14.  */
  15. public class Polygon extends GraphicPrimitive
  16. {
  17.  
  18.     ArrayList<Point> a = new ArrayList<Point>();
  19.     int xcoord[];
  20.     int ycoord[];
  21.     int nPoints[];
  22.     int x;
  23.     int y;
  24.     Color color;
  25.     int counter;
  26.    
  27.     public Polygon(Color color)
  28.     {
  29.         this.color = color;
  30.     }
  31.  
  32.     public void AddPoint(int x, int y)
  33.     {
  34.         Point p = new Point(x, y);
  35.         a.add(p);
  36.        
  37.         xcoord = new int[a.size()];
  38.         ycoord = new int[a.size()];
  39.        
  40.         for (int i = 0; i < a.size(); i++)
  41.         {
  42.             a.get(i).x = xcoord[i];
  43.             a.get(i).y = ycoord[i];
  44.         }
  45.     }
  46.  
  47.     public void draw(Graphics g)
  48.     {
  49.         g.drawPolygon(xcoord, ycoord, xcoord.length);
  50.     }
  51.  
  52.     @Override
  53.     public BoundingBox getBoundingBox()
  54.     {
  55.         Point pos = new Point(a.get(0));
  56.         Point size = new Point(a.get(0));
  57.  
  58.         for (int i = 1; i < a.size(); i++)
  59.         {
  60.             Point temp = a.get(0);
  61.             pos.x = Math.min(pos.x, temp.x);
  62.             pos.y = Math.min(pos.y, temp.y);
  63.  
  64.             size.x = Math.max(size.x, temp.x);
  65.             size.y = Math.max(size.y, temp.y);
  66.         }
  67.         size.x = size.x - pos.x + 2;
  68.         size.y = size.y - pos.y + 2;
  69.         pos.x--;
  70.         pos.y--;
  71.  
  72.         return new BoundingBox(pos.x, pos.y, size.x, size.y);
  73.     }
  74.  
  75.     @Override
  76.     public void move(int dx, int dy)
  77.     {
  78.         for (int i = 0; i < a.size(); i++)
  79.         {
  80.             a.get(i).x += dx;
  81.             a.get(i).y += dy;
  82.         }
  83.  
  84.     }
  85.  
  86.     @Override
  87.     public void setDrawPoint(int x, int y)
  88.     {
  89.         // TODO Auto-generated method stub
  90.  
  91.     }
  92.  
  93.     @Override
  94.     public String toString()
  95.     {
  96.         return null;
  97.     }
  98.  
  99.     @Override
  100.     public void setColor()
  101.     {
  102.         // TODO Auto-generated method stub
  103.  
  104.     }
  105.  
  106.     @Override
  107.     public GraphicPrimitive clone()
  108.     {
  109.         // TODO Auto-generated method stub
  110.         return null;
  111.     }
  112.  
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement