001package armyc2.c5isr.renderer.utilities;
002
003import android.graphics.Path;
004import android.graphics.Path.Direction;
005import android.graphics.RectF;
006
007public class PathUtilities {
008
009        public static RectF makeRectF(float x, float y, float w, float h)
010        {
011                return new RectF(x, y, x + w, y + h);
012        }
013        
014        public static void addLine(Path path, float x1, float y1, float x2, float y2)
015        {
016                path.moveTo(x1,y1);
017        path.lineTo(x2,y2);
018        }
019        
020        public static void addEllipse(Path path, float x, float y, float w, float h)
021        {
022                path.addOval(new RectF(x, y, x + w, y + h), Direction.CW);
023        }
024        
025        public static void addEllipse(Path path, float x, float y, float w, float h, Direction dir)
026        {
027                path.addOval(new RectF(x, y, x + w, y + h), dir);
028        }
029        /*
030        public static void addEllipse(Path path, int x, int y, int w, int h)
031        {
032                path.addOval(new RectF(x, y, x + w, y + h), Direction.CW);
033        }
034        
035        public static void addEllipse(Path path, int x, int y, int w, int h, Direction dir)
036        {
037                path.addOval(new RectF(x, y, x + w, y + h), dir);
038        }//*/
039        
040        /**
041         * 
042         * @param path
043         * @param x
044         * @param y
045         * @param r radius
046         * @param sAngle start angle in degrees
047         * @param eAngle how many degrees relative to sAngle
048         */
049        public static void arc(Path path, float x, float y, float r, float sAngle, float eAngle)
050        {
051                RectF oval = new RectF(x-r, y-r, x+r, y+r);
052                path.arcTo(oval, sAngle, eAngle, true);
053        }
054        
055        /**
056         * 
057         * @param path
058         * @param x
059         * @param y
060         * @param r radius
061         * @param sAngle start angle in degrees
062         * @param eAngle how many degrees relative to sAngle
063         * @param moveTo If true, begin a new contour
064         */
065        public static void arc(Path path, float x, float y, float r, float sAngle, float eAngle, boolean moveTo)
066        {
067                RectF oval = new RectF(x-r, y-r, x+r, y+r);
068                path.arcTo(oval, sAngle, eAngle, moveTo);
069        }
070
071        /**
072         *
073         * @param path
074         * @param x
075         * @param y
076         * @param r radius
077         * @param sAngle start angle in degrees
078         * @param eAngle how many degrees relative to sAngle
079         */
080        public static void addArc(Path path, float x, float y, float r, float sAngle, float eAngle)
081        {
082                RectF oval = new RectF(x-r, y-r, x+r, y+r);
083                path.addArc(oval, sAngle, eAngle);
084        }
085        
086        public static void addRoundedRect(Path path, float x, float y, float w, float h, float rw, float rh)
087        {
088                path.addRoundRect(PathUtilities.makeRectF(x, y, w, h),rw, rh,Direction.CW);
089        }
090        
091        public static void addRoundedRect(Path path, float x, float y, float w, float h, float rw, float rh, Direction dir)
092        {
093                path.addRoundRect(PathUtilities.makeRectF(x, y, w, h),rw, rh, dir);
094        }
095        
096
097}