001         package com.croftsoft.core.math.geom;
002    
003         import java.awt.Shape;
004         import java.awt.geom.RectangularShape;
005    
006         /*********************************************************************
007         * A static method library for manipulating Shape instances.
008         *
009         * @version
010         *   2003-04-17
011         * @since
012         *   2003-04-13
013         * @author
014         *   <a href="https://www.croftsoft.com/">David Wallace Croft</a>
015         *********************************************************************/
016    
017         public final class  ShapeLib
018         //////////////////////////////////////////////////////////////////////
019         //////////////////////////////////////////////////////////////////////
020         {
021    
022         public static Point2DD  getCenter (
023           Shape     shape,
024           Point2DD  center )
025         //////////////////////////////////////////////////////////////////////
026         {
027           if ( shape instanceof Circle )
028           {
029             Circle  circle = ( Circle ) shape;
030    
031             center.setXY ( circle.getCenter ( ) );
032           }
033           else if ( shape instanceof RectangularShape )
034           {
035             RectangularShape  rectangularShape = ( RectangularShape ) shape;
036    
037             center.setXY (
038               rectangularShape.getCenterX ( ),
039               rectangularShape.getCenterY ( ) );
040           }
041           else
042           {
043             getCenter ( shape.getBounds2D ( ), center );
044           }
045    
046           return center;
047         }
048    
049         public static boolean  intersects (
050           Shape  aShape,
051           Shape  bShape )
052         //////////////////////////////////////////////////////////////////////
053         {
054           if ( aShape instanceof Circle )
055           {
056             return ( ( Circle ) aShape ).intersectsShape ( bShape );
057           }
058          
059           if ( bShape instanceof Circle )
060           {
061             return ( ( Circle ) bShape ).intersectsShape ( aShape );
062           }
063          
064           return aShape.intersects ( bShape.getBounds2D ( ) );
065         }
066    
067         //////////////////////////////////////////////////////////////////////
068         //////////////////////////////////////////////////////////////////////
069    
070         private  ShapeLib ( ) { }
071    
072         //////////////////////////////////////////////////////////////////////
073         //////////////////////////////////////////////////////////////////////
074         }