** find a point on a shape. check if it fits in image ** returns ** MS_SUCCESS and point coordinates in 'p' if chart fits in image ** MS_FAILURE if no point could be found */
| 48 | ** MS_FAILURE if no point could be found |
| 49 | */ |
| 50 | int findChartPoint(mapObj *map, shapeObj *shape, int width, int height, pointObj *center) { |
| 51 | int middle,numpoints,idx,offset; |
| 52 | double invcellsize = 1.0/map->cellsize; /*speed up MAP2IMAGE_X/Y_IC_DBL*/ |
| 53 | switch(shape->type) { |
| 54 | case MS_SHAPE_POINT: |
| 55 | center->x=MS_MAP2IMAGE_X_IC_DBL(shape->line[0].point[0].x, map->extent.minx, invcellsize); |
| 56 | center->y=MS_MAP2IMAGE_Y_IC_DBL(shape->line[0].point[0].y, map->extent.maxy, invcellsize); |
| 57 | |
| 58 | if(MS_CHART_FITS(center->x,center->y,width,height,map->width,map->height)) |
| 59 | return MS_SUCCESS; |
| 60 | else |
| 61 | return MS_FAILURE; |
| 62 | break; |
| 63 | case MS_SHAPE_LINE: |
| 64 | /*loop through line segments starting from middle (alternate between before and after middle point) |
| 65 | **first segment that fits is chosen |
| 66 | */ |
| 67 | middle=shape->line[0].numpoints/2; /*start with middle segment of line*/ |
| 68 | numpoints=shape->line[0].numpoints; |
| 69 | for(offset=1;offset<=middle;offset++) { |
| 70 | idx=middle+offset; |
| 71 | if(idx<numpoints) { |
| 72 | center->x=(shape->line[0].point[idx-1].x+shape->line[0].point[idx].x)/2.; |
| 73 | center->y=(shape->line[0].point[idx-1].y+shape->line[0].point[idx].y)/2.; |
| 74 | center->x=MS_MAP2IMAGE_X_IC_DBL(center->x, map->extent.minx, invcellsize); |
| 75 | center->y=MS_MAP2IMAGE_Y_IC_DBL(center->y, map->extent.maxy, invcellsize); |
| 76 | |
| 77 | if(MS_CHART_FITS(center->x,center->y,width,height,map->width,map->height)) |
| 78 | return MS_SUCCESS; |
| 79 | |
| 80 | break; |
| 81 | } |
| 82 | idx=middle-offset; |
| 83 | if(idx>=0) { |
| 84 | center->x=(shape->line[0].point[idx].x+shape->line[0].point[idx+1].x)/2; |
| 85 | center->y=(shape->line[0].point[idx].y+shape->line[0].point[idx+1].y)/2; |
| 86 | center->x=MS_MAP2IMAGE_X_IC_DBL(center->x, map->extent.minx, invcellsize); |
| 87 | center->y=MS_MAP2IMAGE_Y_IC_DBL(center->y, map->extent.maxy, invcellsize); |
| 88 | |
| 89 | if(MS_CHART_FITS(center->x,center->y,width,height,map->width,map->height)) |
| 90 | return MS_SUCCESS; |
| 91 | break; |
| 92 | } |
| 93 | } |
| 94 | return MS_FAILURE; |
| 95 | break; |
| 96 | case MS_SHAPE_POLYGON: |
| 97 | msPolygonLabelPoint(shape, center, -1); |
| 98 | center->x=MS_MAP2IMAGE_X_IC_DBL(center->x, map->extent.minx, invcellsize); |
| 99 | center->y=MS_MAP2IMAGE_Y_IC_DBL(center->y, map->extent.maxy, invcellsize); |
| 100 | |
| 101 | if(MS_CHART_FITS(center->x,center->y,width,height,map->width,map->height)) |
| 102 | return MS_SUCCESS; |
| 103 | else |
| 104 | return MS_FAILURE; |
| 105 | break; |
| 106 | default: |
| 107 | return MS_FAILURE; |
no test coverage detected