void PolygonRotateShift(RasterPoint *poly, const int n, const PixelScalar xs, const PixelScalar ys, Angle angle, const int scale) { static Angle lastangle = Angle::Native(fixed(-1)); static int cost = 1024, sint = 0; static int last_scale = 0; angle = angle.AsBearing(); if ((angle != lastangle) || (last_scale != scale)) { lastangle = angle; last_scale = scale; if (scale == 100) { cost = FastScale(angle.ifastcosine()); sint = FastScale(angle.ifastsine()); } else { cost = FastScale(angle.ifastcosine() * scale) / 100; sint = FastScale(angle.ifastsine() * scale) / 100; } } RasterPoint *p = poly; const RasterPoint *pe = poly + n; while (p < pe) { int x = p->x; int y = p->y; p->x = roundshift(x * cost - y * sint) + xs; p->y = roundshift(y * cost + x * sint) + ys; p++; } }
/** * Shifts and rotates the given polygon and also sizes it via FastScale() * @param poly Points specifying the polygon * @param n Number of points of the polygon * @param xs Pixels to shift in the x-direction * @param ys Pixels to shift in the y-direction * @param angle Angle of rotation */ void PolygonRotateShift(RasterPoint *poly, const int n, const int xs, const int ys, Angle angle, const bool scale) { static Angle lastangle = Angle::native(-fixed_one); static int cost = 1024, sint = 0; static bool last_scale = false; angle = angle.as_bearing(); if ((angle != lastangle) || (last_scale != scale)) { lastangle = angle; last_scale = scale; if (scale) { cost = Layout::FastScale(angle.ifastcosine()); sint = Layout::FastScale(angle.ifastsine()); } else { cost = Layout::FastScale(angle.ifastcosine()/2); sint = Layout::FastScale(angle.ifastsine()/2); } } RasterPoint *p = poly; const RasterPoint *pe = poly + n; while (p < pe) { int x = p->x; int y = p->y; p->x = roundshift(x * cost - y * sint ) + xs; p->y = roundshift(y * cost + x * sint ) + ys; p++; } }