0

How to draw outline rectangle on shapes ? I have many shapes, I want to surround them with outline rectangle? I drew first fill() then draw()

public void paint(Graphics g){
      Graphics2D g2d = (Graphics2D) g; 
            Rectangle2D R = getRect();
            g2d.setColor(Color.blue);
            g2d.fill(path);
            g2d.setColor(Color.red);                    
            g2d.draw(R);                    
      }

getRect() method :

public Rectangle2D getRect(){
      return new Rectangle2D.Double(MinX(),MinY(),MaxX(),MaxY());
  }

MaxX() and MaxY() methods are same thing except changing in Y instead of X:

public double MaxX(){ 
     double max = Double.MIN_VALUE;//check the smallest double value
     double maxPathEntry=0.0;
     Paths01 p=new Paths01();
     for ( int i = 0 ; i < PathsList.size() ; i++ ) {
        maxPathEntry = PathsList.get(i).MaxX();
         if (maxPathEntry > max ){
             max = maxPathEntry;
         }
     else if (p.MoveToX > maxPathEntry){ 
         max = p.MoveToX;
     }
     }
     return max;
  }

MinX() and MinY() methods are:

public double MinX(){ 
     double min = Double.MAX_VALUE;//check the biggest double value
     double minPathEntry=0.0;
     Paths01 p=new Paths01();
     for ( int i = 0 ; i < PathsList.size() ; i++ ) {
        minPathEntry = PathsList.get(i).MinX();
         if (minPathEntry < min ){
             min = minPathEntry;
         }
     else if (p.MoveToX < minPathEntry){ 
         min= p.MoveToX;
     }
     }
     return min;
  }

But when it worked, it didn't display exact outline rectangle on the shape, it displayed inappropriate outline rectangle on the shape

a14
  • 31
  • 15
  • 2
    might i ask why you don't use the methode java.awt.geom.Rectangle2D r = java.awt.Shape.getBounds2D()? – Martin Frank Mar 04 '14 at 11:25
  • `java.awt.geom.Rectangle2D r = java.awt.Shape.getBounds2D()` same as `Rectangle2D R = getRect();` i got the outline rectangle but the same problem as before not fit on the shape – a14 Mar 05 '14 at 07:04
  • looking at http://docs.oracle.com/javase/7/docs/api/java/awt/Shape.html or http://docs.oracle.com/javase/7/docs/api/java/awt/Rectangle.html it says "getBounds2D() Returns a high precision and more accurate bounding box of the Shape than the getBounds method" – Martin Frank Mar 05 '14 at 07:14
  • can you define what you mean by 'inappropriate' ? maybe we're talking of different problems? – Martin Frank Mar 05 '14 at 07:16
  • inappropriate i mean not drawing the outline rectangle on the boundary of shape, but it's drawing big rectangle, just one side is drawing and other 3 sides are out of boundaries – a14 Mar 05 '14 at 07:26
  • in my case when i mentioned shape i mean `MinX(),MinY(),MaxX(),MaxY()` my shape is set of curves 'Bezier curves' – a14 Mar 05 '14 at 07:34
  • 1
    wow thanks for that info, that is quite important ... have you read the article about http://stackoverflow.com/questions/2587751/an-algorithm-to-find-bounding-box-of-closed-bezier-curves – Martin Frank Mar 05 '14 at 07:39
  • Are you trying to draw an outline of _each_ shape? or all of them together? – Paul Samsotha Mar 06 '14 at 07:42
  • @peeskillet yes,i am trying to draw an outline of each shape – a14 Mar 06 '14 at 10:57

0 Answers0