mirror of
git://projects.qi-hardware.com/cae-tools.git
synced 2024-12-22 18:08:59 +02:00
cameo/: move conversion between poly2d and "struct path" from area-poly2d.c to poly2d.c
Untested.
This commit is contained in:
parent
f48754e067
commit
7b54293bff
@ -15,8 +15,8 @@ PREFIX ?= /usr/local
|
||||
SHELL=/bin/bash
|
||||
|
||||
MAIN=cameo
|
||||
OBJS=cameo.o excellon.o area-poly2d.o gerber.o gnuplot.o ops.o path.o shape.o \
|
||||
lex.yy.o y.tab.o
|
||||
OBJS=cameo.o excellon.o area-poly2d.o gerber.o gnuplot.o ops.o path.o \
|
||||
poly2d.o shape.o lex.yy.o y.tab.o
|
||||
|
||||
CFLAGS_WARN=-Wall -Wshadow -Wmissing-prototypes \
|
||||
-Wmissing-declarations -Wno-format-zero-length
|
||||
|
@ -12,7 +12,7 @@
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include <poly2d.h>
|
||||
#include "poly2d.h"
|
||||
|
||||
#include "path.h"
|
||||
#include "area.h"
|
||||
@ -22,46 +22,22 @@ static void fill_path(const struct path *paths, double z, double overlap,
|
||||
struct path ***res)
|
||||
{
|
||||
const struct path *path;
|
||||
const struct point *p;
|
||||
double r_tool;
|
||||
struct p2d *polys = NULL, *poly, *last = NULL;
|
||||
double r_tool = 0;
|
||||
struct p2d *polys;
|
||||
struct p2d *fill;
|
||||
const struct v2d *v;
|
||||
|
||||
for (path = paths; path; path = path->next) {
|
||||
if (path->first->z != z)
|
||||
continue;
|
||||
if (!path->first || !path->first->next)
|
||||
continue;
|
||||
r_tool = path->r_tool;
|
||||
for (path = paths; path; path = path->next)
|
||||
if (path->first && path->first->z == z)
|
||||
r_tool = path->r_tool;
|
||||
|
||||
poly = p2d_new();
|
||||
if (last)
|
||||
last->next = poly;
|
||||
else
|
||||
polys = poly;
|
||||
last = poly;
|
||||
for (p = path->first; p && p->next; p = p->next)
|
||||
p2d_append(poly, v2d_new(p->x, p->y));
|
||||
p2d_close(poly);
|
||||
}
|
||||
polys = paths_to_polys_z(paths, z, z);
|
||||
|
||||
fill = p2d_area(polys, r_tool, 2*r_tool-overlap);
|
||||
p2d_free_all(polys);
|
||||
|
||||
for (poly = fill; poly; poly = poly->next) {
|
||||
**res = path_new(r_tool, "");
|
||||
v = poly->v;
|
||||
while (v) {
|
||||
path_add(**res, v->x, v->y, z);
|
||||
v = v->next;
|
||||
if (v == poly->v)
|
||||
break;
|
||||
}
|
||||
if (v)
|
||||
path_add(**res, v->x, v->y, z);
|
||||
**res = polys_to_paths(fill, r_tool, z);
|
||||
while (**res)
|
||||
*res = &(**res)->next;
|
||||
}
|
||||
p2d_free_all(fill);
|
||||
}
|
||||
|
||||
|
90
cameo/poly2d.c
Normal file
90
cameo/poly2d.c
Normal file
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* poly2d.c - Poly2D interface functions
|
||||
*
|
||||
* Written 2012 by Werner Almesberger
|
||||
* Copyright 2012 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 <math.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "path.h"
|
||||
#include "poly2d.h"
|
||||
|
||||
|
||||
struct p2d *path_to_poly(const struct path *path)
|
||||
{
|
||||
struct p2d *poly;
|
||||
const struct point *p;
|
||||
|
||||
if (!path->first || !path->first->next)
|
||||
return NULL;
|
||||
|
||||
poly = p2d_new();
|
||||
for (p = path->first; p && p->next; p = p->next)
|
||||
p2d_append(poly, v2d_new(p->x, p->y));
|
||||
if (path_is_closed(path))
|
||||
p2d_close(poly);
|
||||
return poly;
|
||||
}
|
||||
|
||||
|
||||
struct p2d *paths_to_polys_z(const struct path *paths,
|
||||
double zmin, double zmax)
|
||||
{
|
||||
struct p2d *polys = NULL, **last = &polys;
|
||||
const struct path *path;
|
||||
|
||||
assert(zmin <= zmax);
|
||||
for (path = paths; path; path = path->next) {
|
||||
if (path->first->z < zmin || path->first->z > zmax)
|
||||
continue;
|
||||
*last = path_to_poly(path);
|
||||
last = &(*last)->next;
|
||||
}
|
||||
return polys;
|
||||
}
|
||||
|
||||
|
||||
struct p2d *paths_to_polys(const struct path *paths)
|
||||
{
|
||||
return paths_to_polys_z(paths, -HUGE_VAL, HUGE_VAL);
|
||||
}
|
||||
|
||||
|
||||
struct path *poly_to_path(const struct p2d *poly, double r_tool, double z)
|
||||
{
|
||||
struct path *path;
|
||||
const struct v2d *v;
|
||||
|
||||
path = path_new(r_tool, "");
|
||||
v = poly->v;
|
||||
while (v) {
|
||||
path_add(path, v->x, v->y, z);
|
||||
v = v->next;
|
||||
if (v == poly->v)
|
||||
break;
|
||||
}
|
||||
if (v)
|
||||
path_add(path, v->x, v->y, z);
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
struct path *polys_to_paths(const struct p2d *polys, double r_tool, double z)
|
||||
{
|
||||
struct path *paths = NULL, **last = &paths;
|
||||
const struct p2d *poly;
|
||||
|
||||
for (poly = polys; poly; poly = poly->next) {
|
||||
*last = poly_to_path(poly, r_tool, z);
|
||||
last = &(*last)->next;
|
||||
}
|
||||
return paths;
|
||||
}
|
29
cameo/poly2d.h
Normal file
29
cameo/poly2d.h
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* poly2d.h - Poly2D interface functions
|
||||
*
|
||||
* Written 2012 by Werner Almesberger
|
||||
* Copyright 2012 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 POLY2D_H
|
||||
|
||||
#include <poly2d.h>
|
||||
|
||||
#include "path.h"
|
||||
|
||||
|
||||
struct p2d *path_to_poly(const struct path *path);
|
||||
struct p2d *paths_to_polys_z(const struct path *paths,
|
||||
double zmin, double zmax);
|
||||
struct p2d *paths_to_polys(const struct path *paths);
|
||||
|
||||
struct path *poly_to_path(const struct p2d *poly, double r_tool, double z);
|
||||
struct path *polys_to_paths(const struct p2d *polys, double r_tool, double z);
|
||||
|
||||
#endif /* !POLY2D_H */
|
Loading…
Reference in New Issue
Block a user