MCPcopy Index your code
hub / github.com/MapServer/MapServer / msRotateVectorSymbol

Function msRotateVectorSymbol

mapsymbol.c:887–943  ·  view source on GitHub ↗

** msRotateSymbol - Clockwise rotation of a symbol definition. Contributed ** by MapMedia, with clean up by SDL. Currently only type VECTOR and PIXMAP ** symbols are handled. */

Source from the content-addressed store, hash-verified

885 ** symbols are handled.
886 */
887symbolObj *msRotateVectorSymbol(symbolObj *symbol, double angle)
888{
889 double angle_rad=0.0;
890 double cos_a, sin_a;
891 double minx=0.0, miny=0.0, maxx=0.0, maxy=0.0;
892 symbolObj *newSymbol = NULL;
893 double dp_x, dp_y, xcor, ycor;
894 double TOL=0.00000000001;
895 int i;
896
897 //assert(symbol->type == MS_SYMBOL_VECTOR);
898
899 newSymbol = (symbolObj *) malloc(sizeof(symbolObj));
900 msCopySymbol(newSymbol, symbol, NULL); /* TODO: do we really want to do this for all symbol types? */
901
902 angle_rad = (MS_DEG_TO_RAD*angle);
903
904
905 sin_a = sin(angle_rad);
906 cos_a = cos(angle_rad);
907
908 dp_x = symbol->sizex * .5; /* get the shift vector at 0,0 */
909 dp_y = symbol->sizey * .5;
910
911 /* center at 0,0 and rotate; then move back */
912 for( i=0;i < symbol->numpoints;i++) {
913 /* don't rotate PENUP commands (TODO: should use a constant here) */
914 if ((symbol->points[i].x == -99.0) || (symbol->points[i].x == -99.0) ) {
915 newSymbol->points[i].x = -99.0;
916 newSymbol->points[i].y = -99.0;
917 continue;
918 }
919
920 newSymbol->points[i].x = dp_x + ((symbol->points[i].x-dp_x)*cos_a - (symbol->points[i].y-dp_y)*sin_a);
921 newSymbol->points[i].y = dp_y + ((symbol->points[i].x-dp_x)*sin_a + (symbol->points[i].y-dp_y)*cos_a);
922 }
923
924 /* get the new bbox of the symbol, because we need it to get the new dimensions of the new symbol */
925 get_bbox(newSymbol->points, newSymbol->numpoints, &minx, &miny, &maxx, &maxy);
926 if ( (fabs(minx)>TOL) || (fabs(miny)>TOL) ) {
927 xcor = minx*-1.0; /* symbols always start at 0,0 so get the shift vector */
928 ycor = miny*-1.0;
929 for( i=0;i < newSymbol->numpoints;i++) {
930 if ((newSymbol->points[i].x == -99.0) || (newSymbol->points[i].x == -99.0))
931 continue;
932 newSymbol->points[i].x = newSymbol->points[i].x + xcor;
933 newSymbol->points[i].y = newSymbol->points[i].y + ycor;
934 }
935
936 /* update the bbox to get the final dimension values for the symbol */
937 get_bbox(newSymbol->points, newSymbol->numpoints, &minx, &miny, &maxx, &maxy);
938 }
939
940 newSymbol->sizex = maxx;
941 newSymbol->sizey = maxy;
942 return newSymbol;
943}
944

Callers

nothing calls this directly

Calls 2

msCopySymbolFunction · 0.85
get_bboxFunction · 0.70

Tested by

no test coverage detected