public static List<ShapeRecord> rectangle(double startx,double starty,double width,double height,double radiusX,double radiusY,double topLeftRadiusX,double topLeftRadiusY,double topRightRadiusX,double topRightRadiusY,double bottomLeftRadiusX,double bottomLeftRadiusY,double bottomRightRadiusX,double bottomRightRadiusY){
  List<ShapeRecord> shapeRecords=new ArrayList<ShapeRecord>();
  if (radiusX == 0.0) {
    radiusY=radiusX=0;
  }
 else   if (radiusY == 0.0) {
    radiusY=radiusX;
  }
  if (radiusX > width / 2.0)   radiusX=width / 2.0;
  if (radiusY > height / 2.0)   radiusY=height / 2.0;
  double[] topLeftRadius=getCornerRadius(topLeftRadiusX,topLeftRadiusY,radiusX,radiusY,width,height);
  topLeftRadiusX=topLeftRadius[0];
  topLeftRadiusY=topLeftRadius[1];
  double[] topRightRadius=getCornerRadius(topRightRadiusX,topRightRadiusY,radiusX,radiusY,width,height);
  topRightRadiusX=topRightRadius[0];
  topRightRadiusY=topRightRadius[1];
  double[] bottomLeftRadius=getCornerRadius(bottomLeftRadiusX,bottomLeftRadiusY,radiusX,radiusY,width,height);
  bottomLeftRadiusX=bottomLeftRadius[0];
  bottomLeftRadiusY=bottomLeftRadius[1];
  double[] bottomRightRadius=getCornerRadius(bottomRightRadiusX,bottomRightRadiusY,radiusX,radiusY,width,height);
  bottomRightRadiusX=bottomRightRadius[0];
  bottomRightRadiusY=bottomRightRadius[1];
  double c0=0.923879532511;
  double c1=0.382683432365;
  double c3=0.707106781187;
  double rx=bottomRightRadiusX;
  double ry=bottomRightRadiusY;
  double tx=rx / 0.923879532511;
  double ty=ry / 0.923879532511;
  double dx, currentx;
  double dy, currenty;
  dx=startx + width - rx;
  dy=starty + height - ry;
  shapeRecords.add(move((dx + rx),dy));
  currentx=(dx + rx);
  currenty=dy;
  if (bottomRightRadiusX != 0.0) {
    shapeRecords.add(curvedEdge(currentx,currenty,(dx + c0 * tx),(dy + c1 * ty),(dx + c3 * rx),(dy + c3 * ry)));
    shapeRecords.add(curvedEdge((dx + c3 * rx),(dy + c3 * ry),(dx + c1 * tx),(dy + c0 * ty),dx,(dy + ry)));
    currentx=dx;
    currenty=dy + ry;
  }
  rx=bottomLeftRadiusX;
  ry=bottomLeftRadiusY;
  tx=rx / 0.923879532511;
  ty=ry / 0.923879532511;
  dx=startx + rx;
  dy=starty + height - ry;
  shapeRecords.addAll(straightEdge(currentx,currenty,dx,(dy + ry)));
  currentx=dx;
  currenty=dy + ry;
  if (bottomLeftRadiusX != 0.0) {
    shapeRecords.add(curvedEdge(currentx,currenty,(dx - c1 * tx),(dy + c0 * ty),(dx - c3 * rx),(dy + c3 * ry)));
    shapeRecords.add(curvedEdge((dx - c3 * rx),(dy + c3 * ry),(dx - c0 * tx),(dy + c1 * ty),(dx - rx),dy));
    currentx=dx - rx;
    currenty=dy;
  }
  rx=topLeftRadiusX;
  ry=topLeftRadiusY;
  tx=rx / 0.923879532511;
  ty=ry / 0.923879532511;
  dx=startx + rx;
  dy=starty + ry;
  shapeRecords.addAll(straightEdge(currentx,currenty,(dx - rx),dy));
  currentx=dx - rx;
  currenty=dy;
  if (topLeftRadiusX != 0.0) {
    shapeRecords.add(curvedEdge(currentx,currenty,(dx - c0 * tx),(dy - c1 * ty),(dx - c3 * rx),(dy - c3 * ry)));
    shapeRecords.add(curvedEdge((dx - c3 * rx),(dy - c3 * ry),(dx - c1 * tx),(dy - c0 * ty),dx,(dy - ry)));
    currentx=dx;
    currenty=dy - ry;
  }
  rx=topRightRadiusX;
  ry=topRightRadiusY;
  tx=rx / 0.923879532511;
  ty=ry / 0.923879532511;
  dx=startx + width - rx;
  dy=starty + ry;
  shapeRecords.addAll(straightEdge(currentx,currenty,dx,(dy - ry)));
  currentx=dx;
  currenty=dy - ry;
  if (topRightRadiusX != 0.0) {
    shapeRecords.add(curvedEdge(currentx,currenty,(dx + c1 * tx),(dy - c0 * ty),(dx + c3 * rx),(dy - c3 * ry)));
    shapeRecords.add(curvedEdge((dx + c3 * rx),(dy - c3 * ry),(dx + c0 * tx),(dy - c1 * ty),(dx + rx),dy));
    currentx=(dx + rx);
    currenty=dy;
  }
  rx=bottomRightRadiusX;
  ry=bottomRightRadiusY;
  tx=rx / 0.923879532511;
  ty=ry / 0.923879532511;
  dx=startx + width - rx;
  dy=starty + height - ry;
  shapeRecords.addAll(straightEdge(currentx,currenty,(dx + rx),dy));
  return shapeRecords;
}

public static List < ShapeRecord > rectangle ( double startx , double starty , double width , double height , double radiusX , double radiusY , double topLeftRadiusX , double topLeftRadiusY , double topRightRadiusX , double topRightRadiusY , double bottomLeftRadiusX , double bottomLeftRadiusY , double bottomRightRadiusX , double bottomRightRadiusY ) { List < ShapeRecord > shapeRecords = new ArrayList < ShapeRecord > ( ) ; if ( radiusX == 0.0 ) { radiusY = radiusX = 0 ; } else if ( radiusY == 0.0 ) { radiusY = radiusX ; } if ( radiusX > width / 2.0 ) radiusX = width / 2.0 ; if ( radiusY > height / 2.0 ) radiusY = height / 2.0 ; double [ ] topLeftRadius = getCornerRadius ( topLeftRadiusX , topLeftRadiusY , radiusX , radiusY , width , height ) ; topLeftRadiusX = topLeftRadius [ 0 ] ; topLeftRadiusY = topLeftRadius [ 1 ] ; double [ ] topRightRadius = getCornerRadius ( topRightRadiusX , topRightRadiusY , radiusX , radiusY , width , height ) ; topRightRadiusX = topRightRadius [ 0 ] ; topRightRadiusY = topRightRadius [ 1 ] ; double [ ] bottomLeftRadius = getCornerRadius ( bottomLeftRadiusX , bottomLeftRadiusY , radiusX , radiusY , width , height ) ; bottomLeftRadiusX = bottomLeftRadius [ 0 ] ; bottomLeftRadiusY = bottomLeftRadius [ 1 ] ; double [ ] bottomRightRadius = getCornerRadius ( bottomRightRadiusX , bottomRightRadiusY , radiusX , radiusY , width , height ) ; bottomRightRadiusX = bottomRightRadius [ 0 ] ; bottomRightRadiusY = bottomRightRadius [ 1 ] ; double c0 = 0.923879532511 ; double c1 = 0.382683432365 ; double c3 = 0.707106781187 ; double rx = bottomRightRadiusX ; double ry = bottomRightRadiusY ; double tx = rx / 0.923879532511 ; double ty = ry / 0.923879532511 ; double dx , currentx ; double dy , currenty ; dx = startx + width - rx ; dy = starty + height - ry ; shapeRecords . add ( move ( ( dx + rx ) , dy ) ) ; currentx = ( dx + rx ) ; currenty = dy ; if ( bottomRightRadiusX != 0.0 ) { shapeRecords . add ( curvedEdge ( currentx , currenty , ( dx + c0 * tx ) , ( dy + c1 * ty ) , ( dx + c3 * rx ) , ( dy + c3 * ry ) ) ) ; shapeRecords . add ( curvedEdge ( ( dx + c3 * rx ) , ( dy + c3 * ry ) , ( dx + c1 * tx ) , ( dy + c0 * ty ) , dx , ( dy + ry ) ) ) ; currentx = dx ; currenty = dy + ry ; } rx = bottomLeftRadiusX ; ry = bottomLeftRadiusY ; tx = rx / 0.923879532511 ; ty = ry / 0.923879532511 ; dx = startx + rx ; dy = starty + height - ry ; shapeRecords . addAll ( straightEdge ( currentx , currenty , dx , ( dy + ry ) ) ) ; currentx = dx ; currenty = dy + ry ; if ( bottomLeftRadiusX != 0.0 ) { shapeRecords . add ( curvedEdge ( currentx , currenty , ( dx - c1 * tx ) , ( dy + c0 * ty ) , ( dx - c3 * rx ) , ( dy + c3 * ry ) ) ) ; shapeRecords . add ( curvedEdge ( ( dx - c3 * rx ) , ( dy + c3 * ry ) , ( dx - c0 * tx ) , ( dy + c1 * ty ) , ( dx - rx ) , dy ) ) ; currentx = dx - rx ; currenty = dy ; } rx = topLeftRadiusX ; ry = topLeftRadiusY ; tx = rx / 0.923879532511 ; ty = ry / 0.923879532511 ; dx = startx + rx ; dy = starty + ry ; shapeRecords . addAll ( straightEdge ( currentx , currenty , ( dx - rx ) , dy ) ) ; currentx = dx - rx ; currenty = dy ; if ( topLeftRadiusX != 0.0 ) { shapeRecords . add ( curvedEdge ( currentx , currenty , ( dx - c0 * tx ) , ( dy - c1 * ty ) , ( dx - c3 * rx ) , ( dy - c3 * ry ) ) ) ; shapeRecords . add ( curvedEdge ( ( dx - c3 * rx ) , ( dy - c3 * ry ) , ( dx - c1 * tx ) , ( dy - c0 * ty ) , dx , ( dy - ry ) ) ) ; currentx = dx ; currenty = dy - ry ; } rx = topRightRadiusX ; ry = topRightRadiusY ; tx = rx / 0.923879532511 ; ty = ry / 0.923879532511 ; dx = startx + width - rx ; dy = starty + ry ; shapeRecords . addAll ( straightEdge ( currentx , currenty , dx , ( dy - ry ) ) ) ; currentx = dx ; currenty = dy - ry ; if ( topRightRadiusX != 0.0 ) { shapeRecords . add ( curvedEdge ( currentx , currenty , ( dx + c1 * tx ) , ( dy - c0 * ty ) , ( dx + c3 * rx ) , ( dy - c3 * ry ) ) ) ; shapeRecords . add ( curvedEdge ( ( dx + c3 * rx ) , ( dy - c3 * ry ) , ( dx + c0 * tx ) , ( dy - c1 * ty ) , ( dx + rx ) , dy ) ) ; currentx = ( dx + rx ) ; currenty = dy ; } rx = bottomRightRadiusX ; ry = bottomRightRadiusY ; tx = rx / 0.923879532511 ; ty = ry / 0.923879532511 ; dx = startx + width - rx ; dy = starty + height - ry ; shapeRecords . addAll ( straightEdge ( currentx , currenty , ( dx + rx ) , dy ) ) ; return shapeRecords ; }
creates a list of shaperecord to draw a rectangle from the given origin ( startx , starty ) for the specified width and height ( in pixels ) and radiusx and radiusy for rounded corners .
