summaryrefslogtreecommitdiff
path: root/src/rotrect.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/rotrect.c')
-rw-r--r--src/rotrect.c28
1 files changed, 22 insertions, 6 deletions
diff --git a/src/rotrect.c b/src/rotrect.c
index 5abae13..6721d10 100644
--- a/src/rotrect.c
+++ b/src/rotrect.c
@@ -15,8 +15,8 @@ rotate(double *x, double *y, double angle)
*y = ox * s + oy * c;
}
-void
-rotrect(double x, double y, double width, double height, double angle)
+Rect
+rotrect_create(double width, double height, double angle)
{
double xs[4] = {
width / 2.0,
@@ -30,14 +30,30 @@ rotrect(double x, double y, double width, double height, double angle)
height / 2.0,
-height / 2.0,
};
- for (int i = 0; i < 4; i++) {
+ for (int i = 0; i < 4; i++)
rotate(&xs[i], &ys[i], angle);
- xs[i] = round(xs[i] + x);
- ys[i] = round(ys[i] + y);
- }
+ return (Rect){ xs[0], ys[0], xs[1], ys[1], xs[2], ys[2], xs[3], ys[3] };
+}
+
+void
+rotrect_draw(Rect rect, double x, double y)
+{
+ const int xs[4] = {
+ round(rect.x0 + x), round(rect.x1) + x,
+ round(rect.x2 + x), round(rect.x3) + x
+ };
+ const int ys[4] = {
+ round(rect.y0 + y), round(rect.y1) + y,
+ round(rect.y2 + y), round(rect.y3) + y,
+ };
LZY_DrawLine(xs[0], ys[0], xs[1], ys[1]);
LZY_DrawLine(xs[1], ys[1], xs[2], ys[2]);
LZY_DrawLine(xs[2], ys[2], xs[3], ys[3]);
LZY_DrawLine(xs[3], ys[3], xs[0], ys[0]);
}
+void
+rotrect(double x, double y, double width, double height, double angle)
+{
+ rotrect_draw(rotrect_create(width, height, angle), x, y);
+}