diff --git a/ptrude/Makefile b/ptrude/Makefile index 8b92aae..c85c38a 100644 --- a/ptrude/Makefile +++ b/ptrude/Makefile @@ -1,13 +1,66 @@ -CFLAGS = -Wall -g +# +# Makefile - Makefile of ptrude +# +# Written 2011 by Werner Almesberger +# Copyright 2011 by Werner Almesberger +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# + +SHELL = /bin/bash + +MAIN = ptrude +OBJS = $(MAIN).o path.o + +CFLAGS = -Wall -g -Wshadow -Wmissing-prototypes \ + -Wmissing-declarations -Wno-format-zero-length LDFLAGS = -lm -OBJS = ptrude.o path.o -.PHONY: clean try +# ----- Verbosity control ----------------------------------------------------- -ptrude: $(OBJS) +CC_normal := $(CC) +DEPEND_normal := $(CPP) $(CFLAGS) -MM -MG -try: ptrude - ./ptrude $*.d; \ + [ "$${PIPESTATUS[*]}" = "0 0" ] || { rm -f $*.d; exit 1; } + +-include $(OBJS:.o=.d) diff --git a/ptrude/path.c b/ptrude/path.c index e7b8476..a9f14f8 100644 --- a/ptrude/path.c +++ b/ptrude/path.c @@ -1,3 +1,15 @@ +/* + * path.c - 2D path operations + * + * Written 2011 by Werner Almesberger + * Copyright 2011 by Werner Almesberger + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + #include #include #include @@ -92,6 +104,13 @@ static const struct vertex *add_vertex(struct path *path, double x, double y, } +/* + * "corner" replaces a corner with a ploygon if the corner is too sharp to + * be within distance "d" of the bend radius. This may change the point from + * where we resume drawing (originally the corner point, "b"). "corner" + * therefore returns the new end of the arc. + */ + static const struct vertex *corner(struct path *path, const struct vertex *a, const struct vertex *b, const struct vertex *c, double r, double d) { @@ -230,17 +249,29 @@ static const struct vertex *corner(struct path *path, const struct vertex *a, n = (int) ceil((t2-2*(p+q))/(2*q)); /* - * @@@ We should evenly distribute the slack and try to pick a + * We could evenly distribute the slack and try to pick a * smaller value for d, but that seems difficult. * + * A drawback of reducing p would be that we may make the + * corner unnecessarily sharp, possibly even turning against + * the general direction of the turn. We'd still respect the + * bend radius and the tolerance, but the result may look weird + * anyway. + * * For now, we just center the polygon. */ q = (t2/2-p)/(n+1); if (n) ang = p+q; - else + else { ang = t2/2; + /* + * @@@ To do: adjust the radius such that we always hug + * the r-d circle (see arc.fig) and usually not the + * r+d circle. Right now, it's just the opposite. + */ + } u = tan(p)*(r-d); v = tan(q)*(r-d); diff --git a/ptrude/path.h b/ptrude/path.h index 8215298..5410c27 100644 --- a/ptrude/path.h +++ b/ptrude/path.h @@ -1,3 +1,15 @@ +/* + * path.h - 2D path operations + * + * Written 2011 by Werner Almesberger + * Copyright 2011 by Werner Almesberger + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + #ifndef PATH_H #define PATH_H diff --git a/ptrude/ptrude.c b/ptrude/ptrude.c index 6df85ff..dff3533 100644 --- a/ptrude/ptrude.c +++ b/ptrude/ptrude.c @@ -1,3 +1,15 @@ +/* + * ptrude.c - Extrusion of a 2D path along a perpendicular 2D path + * + * Written 2011 by Werner Almesberger + * Copyright 2011 by Werner Almesberger + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + #include #include "path.h"