mirror of
git://projects.qi-hardware.com/cae-tools.git
synced 2024-12-23 04:23:55 +02:00
ptrude/: proper command-line handling; open -d for debug mode
This commit is contained in:
parent
188cf9d9d4
commit
3dcd5cc9aa
@ -42,7 +42,7 @@ endif
|
|||||||
$(MAIN): $(OBJS)
|
$(MAIN): $(OBJS)
|
||||||
|
|
||||||
try: $(MAIN)
|
try: $(MAIN)
|
||||||
./$(MAIN) <try | tee out
|
./$(MAIN) -d try 1 0.1 | tee out
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f $(OBJS) $(OBJS:.o=.d)
|
rm -f $(OBJS) $(OBJS:.o=.d)
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
|
#include "ptrude.h"
|
||||||
#include "path.h"
|
#include "path.h"
|
||||||
|
|
||||||
|
|
||||||
@ -169,13 +170,16 @@ static const struct vertex *corner(struct path *path, const struct vertex *a,
|
|||||||
*/
|
*/
|
||||||
dd = hypot(r, s)-r;
|
dd = hypot(r, s)-r;
|
||||||
|
|
||||||
fprintf(stderr, "a = (%g, %g)-(%g, %g) = (%g, %g); |a| = %g\n",
|
if (debug) {
|
||||||
b->x, b->y, a->x, a->y, ax, ay, aa);
|
fprintf(stderr, "a = (%g, %g)-(%g, %g) = (%g, %g); |a| = %g\n",
|
||||||
fprintf(stderr, "b = (%g, %g)-(%g, %g) = (%g, %g); |b| = %g\n",
|
b->x, b->y, a->x, a->y, ax, ay, aa);
|
||||||
c->x, c->y, b->x, b->y, bx, by, bb);
|
fprintf(stderr, "b = (%g, %g)-(%g, %g) = (%g, %g); |b| = %g\n",
|
||||||
fprintf(stderr, "sin 2t = %g, cos 2t = %g, tan t = %g\n",
|
c->x, c->y, b->x, b->y, bx, by, bb);
|
||||||
cp/aa/bb, dp/aa/bb, tt);
|
fprintf(stderr, "sin 2t = %g, cos 2t = %g, tan t = %g\n",
|
||||||
fprintf(stderr, "r = %g, d = %g, s = %g, dd = %g\n", r, d, s, dd);
|
cp/aa/bb, dp/aa/bb, tt);
|
||||||
|
fprintf(stderr, "r = %g, d = %g, s = %g, dd = %g\n",
|
||||||
|
r, d, s, dd);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We only know how to make a rounded corner if two vectors are
|
* We only know how to make a rounded corner if two vectors are
|
||||||
@ -228,8 +232,9 @@ static const struct vertex *corner(struct path *path, const struct vertex *a,
|
|||||||
|
|
||||||
q = acos((r-d)/(r+d));
|
q = acos((r-d)/(r+d));
|
||||||
|
|
||||||
fprintf(stderr, "t2 = %g, p(max) = %g, q(max) = %g\n",
|
if (debug)
|
||||||
deg(t2), deg(p), deg(q));
|
fprintf(stderr, "t2 = %g, p(max) = %g, q(max) = %g\n",
|
||||||
|
deg(t2), deg(p), deg(q));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Step 4: emit the starting point of the arc
|
* Step 4: emit the starting point of the arc
|
||||||
@ -279,8 +284,9 @@ static const struct vertex *corner(struct path *path, const struct vertex *a,
|
|||||||
for (i = 0; i <= n; i++) {
|
for (i = 0; i <= n; i++) {
|
||||||
x += f*ax*cos(ang-q)-dir*f*ay*sin(ang-q);
|
x += f*ax*cos(ang-q)-dir*f*ay*sin(ang-q);
|
||||||
y += dir*f*ax*sin(ang-q)+f*ay*cos(ang-q);
|
y += dir*f*ax*sin(ang-q)+f*ay*cos(ang-q);
|
||||||
fprintf(stderr, " %d/%d: %g %g @ %g\n", i, n,
|
if (debug)
|
||||||
x, y, deg(ang));
|
fprintf(stderr, " %d/%d: %g %g @ %g\n", i, n,
|
||||||
|
x, y, deg(ang));
|
||||||
add_vertex(path, x, y, 0, 0, NULL);
|
add_vertex(path, x, y, 0, 0, NULL);
|
||||||
ang += 2*q;
|
ang += 2*q;
|
||||||
f = (2*v)/aa;
|
f = (2*v)/aa;
|
||||||
|
@ -10,18 +10,107 @@
|
|||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#include "path.h"
|
#include "path.h"
|
||||||
|
#include "ptrude.h"
|
||||||
|
|
||||||
|
|
||||||
int main(void)
|
int debug = 0;
|
||||||
|
|
||||||
|
|
||||||
|
static FILE *open_file(const char *name, const char *mode)
|
||||||
{
|
{
|
||||||
const struct path *path;
|
FILE *file;
|
||||||
|
|
||||||
path = load_path(stdin);
|
if (!strcmp(name, "-"))
|
||||||
path = round_path(path, 1, 0.1);
|
return strcmp(mode, "r") ? stdout : stdin;
|
||||||
save_path(stdout, path);
|
|
||||||
|
file = fopen(name, mode);
|
||||||
|
if (!file) {
|
||||||
|
perror(name);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void close_file(FILE *file)
|
||||||
|
{
|
||||||
|
if (file == stdin || file == stdout)
|
||||||
|
return;
|
||||||
|
if (fclose(file) == EOF) {
|
||||||
|
perror("fclose");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void usage(const char *name)
|
||||||
|
{
|
||||||
|
fprintf(stderr,
|
||||||
|
"usage: %s shape radius tolerance\n"
|
||||||
|
"%6s %s path shape radius tolerance\n",
|
||||||
|
name, "", name);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
FILE *file;
|
||||||
|
const struct path *path = NULL, *shape;
|
||||||
|
double r, d;
|
||||||
|
char *end;
|
||||||
|
int c;
|
||||||
|
|
||||||
|
while ((c = getopt(argc, argv, "d")) != EOF)
|
||||||
|
switch (c) {
|
||||||
|
case 'd':
|
||||||
|
debug = 1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
usage(*argv);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (argc-optind) {
|
||||||
|
case 3:
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
file = open_file(argv[optind], "r");
|
||||||
|
path = load_path(file);
|
||||||
|
close_file(file);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
usage(*argv);
|
||||||
|
}
|
||||||
|
|
||||||
|
file = open_file(argv[argc-3], "r");
|
||||||
|
shape = load_path(file);
|
||||||
|
close_file(file);
|
||||||
|
|
||||||
|
r = strtod(argv[argc-2], &end);
|
||||||
|
if (*end || r <= 0)
|
||||||
|
usage(*argv);
|
||||||
|
d = strtod(argv[argc-1], &end);
|
||||||
|
if (*end || d <= 0)
|
||||||
|
usage (*argv);
|
||||||
|
|
||||||
|
if (path) {
|
||||||
|
/*
|
||||||
|
* We split the error budget evenly between path and shape.
|
||||||
|
*/
|
||||||
|
path = round_path(path, r, sqrt(d));
|
||||||
|
shape = round_path(shape, r, sqrt(d));
|
||||||
|
/* ... now all that's missing is the extrusion :-) */
|
||||||
|
} else {
|
||||||
|
shape = round_path(shape, r, d);
|
||||||
|
save_path(stdout, shape);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
18
ptrude/ptrude.h
Normal file
18
ptrude/ptrude.h
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
/*
|
||||||
|
* ptrude.h - 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef PTRUDE_H
|
||||||
|
#define PTRUDE_H
|
||||||
|
|
||||||
|
extern int debug;
|
||||||
|
|
||||||
|
#endif /* !PTRUDE_H */
|
Loading…
Reference in New Issue
Block a user