| 967 | } |
| 968 | |
| 969 | int msHatchPolygon(imageObj *img, shapeObj *poly, double spacing, double width, double angle, colorObj *color) { |
| 970 | assert(MS_RENDERER_PLUGIN(img->format)); |
| 971 | msComputeBounds(poly); |
| 972 | int pw=(int)(poly->bounds.maxx-poly->bounds.minx+width*2)+1; |
| 973 | int ph=(int)(poly->bounds.maxy-poly->bounds.miny+width*2)+1; |
| 974 | mapserver::path_storage lines = createHatch(pw,ph, angle, spacing); |
| 975 | lines.transform(mapserver::trans_affine_translation(poly->bounds.minx-width,poly->bounds.miny-width)); |
| 976 | polygon_adaptor polygons(poly); |
| 977 | shapeObj shape; |
| 978 | msInitShape(&shape); |
| 979 | int allocated = 20; |
| 980 | lineObj line; |
| 981 | shape.line = &line; |
| 982 | shape.numlines = 1; |
| 983 | shape.line[0].point = (pointObj*)msSmallCalloc(allocated,sizeof(pointObj)); |
| 984 | shape.line[0].numpoints = 0; |
| 985 | mapserver::conv_stroke<mapserver::path_storage> stroke(lines); |
| 986 | stroke.width(width); |
| 987 | stroke.line_cap(mapserver::butt_cap); |
| 988 | //mapserver::conv_clipper<mapserver::path_storage,polygon_adaptor> clipper(*lines,polygons, mapserver::clipper_and); |
| 989 | //mapserver::conv_clipper<polygon_adaptor,mapserver::path_storage> clipper(polygons,lines, mapserver::clipper_and); |
| 990 | mapserver::conv_clipper<polygon_adaptor,mapserver::conv_stroke<mapserver::path_storage> > clipper(polygons,stroke, mapserver::clipper_and); |
| 991 | clipper.rewind(0); |
| 992 | |
| 993 | double x=0,y=0; |
| 994 | unsigned int cmd, prevCmd=-1; |
| 995 | while((cmd = clipper.vertex(&x,&y)) != mapserver::path_cmd_stop) { |
| 996 | switch(cmd) { |
| 997 | case mapserver::path_cmd_line_to: |
| 998 | if(shape.line[0].numpoints == allocated) { |
| 999 | allocated *= 2; |
| 1000 | shape.line[0].point = (pointObj*)msSmallRealloc(shape.line[0].point, allocated*sizeof(pointObj)); |
| 1001 | } |
| 1002 | shape.line[0].point[shape.line[0].numpoints].x = x; |
| 1003 | shape.line[0].point[shape.line[0].numpoints].y = y; |
| 1004 | shape.line[0].numpoints++; |
| 1005 | break; |
| 1006 | case mapserver::path_cmd_move_to: |
| 1007 | //assert(shape.line[0].numpoints <= 1 || prevCmd == mapserver::path_cmd_line_to); |
| 1008 | shape.line[0].point[0].x = x; |
| 1009 | shape.line[0].point[0].y = y; |
| 1010 | shape.line[0].numpoints = 1; |
| 1011 | break; |
| 1012 | case mapserver::path_cmd_end_poly|mapserver::path_flags_close: |
| 1013 | if(shape.line[0].numpoints > 2) { |
| 1014 | MS_IMAGE_RENDERER(img)->renderPolygon(img,&shape,color); |
| 1015 | } |
| 1016 | break; |
| 1017 | default: |
| 1018 | assert(0); //WTF? |
| 1019 | } |
| 1020 | prevCmd = cmd; |
| 1021 | } |
| 1022 | free(shape.line[0].point); |
| 1023 | //assert(prevCmd == mapserver::path_cmd_line_to); |
| 1024 | //delete lines; |
| 1025 | return MS_SUCCESS; |
| 1026 | } |
no test coverage detected