aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile1
-rw-r--r--demo.c21
-rw-r--r--librifunktionsteckensnittsglyfrasteriseringsprogrambiblioteket.h7
-rw-r--r--rtgrpblib_draw_circular_arc.c48
4 files changed, 75 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index 1db2138..322c783 100644
--- a/Makefile
+++ b/Makefile
@@ -21,6 +21,7 @@ OBJ =\
lines.o\
sorting.o\
rtgrpblib_create_raster.o\
+ rtgrpblib_draw_circular_arc.o\
rtgrpblib_draw_linear_bezier.o\
rtgrpblib_draw_quadratic_bezier.o\
rtgrpblib_draw_cubic_bezier.o\
diff --git a/demo.c b/demo.c
index 76473e7..6157fbd 100644
--- a/demo.c
+++ b/demo.c
@@ -26,11 +26,16 @@ main(void)
{35, 15},
{20, 25},
{5, 15}
-#else
+#elif 0
{5.25, 5.25},
{35.75, 5.25},
{35.75, 25.75},
{5.25, 25.75}
+#else
+ /* for circular arch*/
+ {20, 15},
+ {15, 10},
+ {100 * M_PI/180, 400 * M_PI/180}
#endif
};
@@ -46,9 +51,21 @@ main(void)
#elif 0
rtgrpblib_draw_quadratic_bezier(raster, P(2), P(3), P(0));
rtgrpblib_draw_linear_bezier(raster, P(0), P(2));
-#else
+#elif 0
rtgrpblib_draw_cubic_bezier(raster, P(0), P(1), P(2), P(3));
rtgrpblib_draw_linear_bezier(raster, P(3), P(0));
+#else
+ rtgrpblib_draw_circular_arc(raster, P(0), P(1), P(2));
+ rtgrpblib_draw_linear_bezier(raster,
+ points[0].x + points[1].x * cos(points[2].y),
+ points[0].y + points[1].y * sin(points[2].y),
+ points[0].x,
+ points[0].y);
+ rtgrpblib_draw_linear_bezier(raster,
+ points[0].x,
+ points[0].y,
+ points[0].x + points[1].x * cos(points[2].x),
+ points[0].y + points[1].y * sin(points[2].x));
#endif
rtgrpblib_fill_shapes(image, width, raster);
diff --git a/librifunktionsteckensnittsglyfrasteriseringsprogrambiblioteket.h b/librifunktionsteckensnittsglyfrasteriseringsprogrambiblioteket.h
index 0fceece..fffeae7 100644
--- a/librifunktionsteckensnittsglyfrasteriseringsprogrambiblioteket.h
+++ b/librifunktionsteckensnittsglyfrasteriseringsprogrambiblioteket.h
@@ -30,4 +30,11 @@ void rtgrpblib_draw_cubic_bezier(RTGRPBLIB_RASTER *restrict raster,
double x3, double y3,
double x4, double y4);
+void rtgrpblib_draw_circular_arc(RTGRPBLIB_RASTER *restrict raster,
+ double x0, double y0,
+ double semiwidth, double semiheight,
+ double start, double end);
+
+/* TODO add support for outlining */
+
#endif
diff --git a/rtgrpblib_draw_circular_arc.c b/rtgrpblib_draw_circular_arc.c
new file mode 100644
index 0000000..f30fde7
--- /dev/null
+++ b/rtgrpblib_draw_circular_arc.c
@@ -0,0 +1,48 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+#ifndef TEST
+
+
+void
+rtgrpblib_draw_circular_arc(RASTER *restrict raster, double x0, double y0,
+ double semiwidth, double semiheight, double start, double end)
+{
+ double inc, v, x, y, prevX, prevY;
+
+ if (start == end)
+ return;
+
+ /* TODO precalculate intersection with raster box */
+
+ inc = fmax(semiwidth, semiheight);
+ inc *= 2 * M_PI;
+ inc *= end - start;
+ inc = raster->draftness / inc;
+
+ v = start;
+ prevX = x0 + semiwidth * cos(start);
+ prevY = y0 + semiheight * sin(start);
+
+ for (; (v += inc) < end; prevX = x, prevY = y) {
+ x = x0 + semiwidth * cos(v);
+ y = y0 + semiheight * sin(v);
+ rtgrpblib_draw_linear_bezier(raster, prevX, prevY, x, y);
+ }
+
+ x = x0 + semiwidth * cos(end);
+ y = y0 + semiheight * sin(end);
+ rtgrpblib_draw_linear_bezier(raster, prevX, prevY, x, y);
+}
+
+
+#else
+
+
+int
+main(void)
+{
+ return 0; /* TODO add test */
+}
+
+
+#endif