001/* 002 * To change this template, choose Tools | Templates 003 * and open the template in the editor. 004 */ 005package armyc2.c5isr.graphics2d; 006import android.graphics.Path; 007import android.graphics.RectF; 008//import android.graphics.Region; 009import armyc2.c5isr.JavaLineArray.POINT2; 010import java.util.ArrayList; 011/** 012 * 013* 014 */ 015public class GeneralPath implements Shape 016{ 017 private Path _path=null; 018 private PathIterator _pathIterator=null; 019 public GeneralPath() 020 { 021 _path=new Path(); 022 _pathIterator=new PathIterator(null); 023 } 024 public void lineTo(double x, double y) 025 { 026 _path.lineTo((float)x, (float)y); 027 _pathIterator.lineTo(x, y); 028 } 029 public void moveTo(double x, double y) 030 { 031 _path.moveTo((float)x, (float)y); 032 _pathIterator.moveTo(x, y); 033 } 034 public void quadTo(double x1, double y1, double x2, double y2) 035 { 036 _path.quadTo((float)x1, (float)y1, (float)x2, (float)y2); 037 _pathIterator.quadTo(x1, y1, x2, y2); 038 } 039 public void cubicTo(double x1, double y1, double x2, double y2, double x3, double y3) 040 { 041 _path.cubicTo((float)x1, (float)y1, (float)x2, (float)y2, (float)x3, (float)y3); 042 _pathIterator.cubicTo(x1, y1, x2, y2, x3, y3); 043 } 044 public void curveTo(double x1, double y1, double x2, double y2, double x3, double y3) 045 { 046 _path.cubicTo((float)x1, (float)y1, (float)x2, (float)y2, (float)x3, (float)y3); 047 _pathIterator.cubicTo(x1, y1, x2, y2, x3, y3); 048 } 049 public void computeBounds(Rectangle2D rect) 050 { 051 RectF rectf=new RectF(); 052 _path.computeBounds(rectf, true); 053 rect.x=rectf.left; 054 rect.y=rectf.top; 055 rect.width=rectf.bottom-rectf.top; 056 rect.setRect(rectf.left, rectf.top, rectf.width(), rectf.height()); 057 } 058 public void closePath() 059 { 060 if(_path != null) 061 _path.close(); 062 } 063 public boolean contains (int x, int y) 064 { 065 return false; 066 } 067 public boolean contains (Point2D pt) 068 { 069 return false; 070 } 071 public boolean contains (int x, int y, int width, int height) 072 { 073 Rectangle rect2=this.getBounds(); 074 return rect2.contains(x, y, width, height); 075 } 076 077 public boolean contains(Rectangle2D r) { 078 Rectangle rect=new Rectangle((int)r.x,(int)r.y,(int)r.width,(int)r.height); 079 Rectangle rect2=this.getBounds(); 080 return rect2.contains(rect.x, rect.y, rect.width, rect.height); 081 } 082 public Rectangle2D getBounds2D() 083 { 084 return _pathIterator.getBounds(); 085 } 086 public Rectangle getBounds() 087 { 088 Rectangle2D rect = _pathIterator.getBounds(); 089 return new Rectangle((int)rect.x,(int)rect.y,(int)rect.width,(int)rect.height); 090 } 091 /** 092 * Only tests against the bounds, used only when the GeneralPath is a rectangle 093 * @param x 094 * @param y 095 * @param w 096 * @param h 097 * @return 098 */ 099 public boolean intersects(double x, double y, double w, double h) 100 { 101 return this.getBounds().intersects(x, y, w, h); 102 } 103 /** 104 * called only when the GeneralPath is a rectangle 105 * @param rect 106 * @return 107 */ 108 public boolean intersects(Rectangle2D rect) 109 { 110 return this.getBounds().intersects(rect.x, rect.y, rect.width, rect.height); 111 } 112 public void append(Shape shape,boolean connect) 113 { 114 GeneralPath gp=(GeneralPath)shape; 115 ArrayList<POINT2>pts=gp._pathIterator.getPoints(); 116 int j=0; 117 POINT2 pt=null; 118 POINT2 pt1=null; 119 POINT2 pt2=null; 120 int n=pts.size(); 121 //for(j=0;j<pts.size();j++) 122 for(j=0;j<n;j++) 123 { 124 pt=pts.get(j); 125 switch(pt.style) 126 { 127 case IPathIterator.SEG_MOVETO: 128 _path.moveTo((float)pt.x, (float)pt.y); 129 _pathIterator.moveTo(pt.x, pt.y); 130 break; 131 case IPathIterator.SEG_LINETO: 132 _path.lineTo((float)pt.x, (float)pt.y); 133 _pathIterator.lineTo(pt.x, pt.y); 134 break; 135 case IPathIterator.SEG_CUBICTO: 136 pt1=pts.get(j+1);j++; 137 pt2=pts.get(j+2);j++; 138 _path.cubicTo((float)pt.x, (float)pt.y, (float)pt1.x, (float)pt1.y, (float)pt2.x, (float)pt2.y); 139 _pathIterator.cubicTo((float)pt.x, (float)pt.y, (float)pt1.x, (float)pt1.y, (float)pt2.x, (float)pt2.y); 140 break; 141 default: 142 break; 143 } 144 } 145 } 146 public Path getPath() 147 { 148 return _path; 149 } 150 public PathIterator getPathIterator(AffineTransform tx) 151 { 152 _pathIterator.reset(); 153 return _pathIterator; 154 } 155}