mirror of
git://projects.qi-hardware.com/cae-tools.git
synced 2024-12-22 23:26:27 +02:00
poly2d/: automatically switch between clockwise and counter-clockwise polygons
The only functions that care about this at the moment are from CGAL, and there we can determine from context what to do.
This commit is contained in:
parent
dfa85075e8
commit
46c8f8653c
@ -16,23 +16,22 @@ operation in cameo. Later, poly2d could replace more parts of
|
||||
cameo.
|
||||
|
||||
poly2d puts more emphasis on simplicity than on performance. Some
|
||||
functions expect clockwise closed polygons that don't self-intersect.
|
||||
functions expect closed polygons that don't self-intersect. For now,
|
||||
it doesn't matter whether polygons are clockwise or counter-clockwise.
|
||||
The table below shows the capabilities
|
||||
|
||||
Open Counter-clockwise
|
||||
| Concave Min. vertices
|
||||
Open Min. vertices
|
||||
| Concave
|
||||
| | Self-intersect
|
||||
| | | | |
|
||||
Y Y Y Y 0 p2d_contains_poly(b), p2d_free, p2d_free_all,
|
||||
p2d_is_closed, p2d_copy, p2d_reverse, p2d_vertices,
|
||||
p2d_write_gnuplog, p2d_write_gnuplot_all
|
||||
Y Y Y Y 1 p2d_read_gnuplot
|
||||
- Y Y Y 0 p2d_simplify
|
||||
- Y - Y 3 p2d_is_cw
|
||||
- Y - - 3 p2d_contains_point, p2d_contains_poly (a),
|
||||
- Y - # 3 p2d_area*, p2d_offset*
|
||||
|
||||
# CGAL uses ccw, poly2d uses cw. Need to switch.
|
||||
| | | |
|
||||
Y Y Y 0 p2d_contains_poly(b), p2d_copy, p2d_free, p2d_free_all,
|
||||
p2d_is_closed, p2d_no_intersect, p2d_reverse,
|
||||
p2d_vertices, p2d_write_gnuplot, p2d_write_gnuplot_all
|
||||
Y Y Y 1 p2d_read_gnuplot
|
||||
- Y Y 0 p2d_simplify
|
||||
- Y - 3 p2d_is_cw
|
||||
- Y - 3 p2d_contains_point, p2d_contains_poly (a),
|
||||
- Y - 3 p2d_area*, p2d_offset*
|
||||
|
||||
Not yet implemented:
|
||||
- p2d_simplify (low priority - the offsetting from CGAL already covers
|
||||
@ -43,8 +42,6 @@ Not yet specified:
|
||||
|
||||
Other:
|
||||
- change the license from GPL to LGPL
|
||||
- change ccw to cw
|
||||
- make sure CGAL is only fed ccw ploygons and cw holes
|
||||
- transform CGAL's idea of outer polygons into something we can use
|
||||
- use more meaningful offset/overlap model for area fill
|
||||
- check for memory leaks
|
||||
|
@ -35,7 +35,7 @@ typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
|
||||
typedef CGAL::Polygon_2<K> Polygon_2;
|
||||
|
||||
|
||||
static inline Polygon_2 p2d_to_P2(const struct p2d *p)
|
||||
static inline Polygon_2 p2d_to_P2(const struct p2d *p, int ccw)
|
||||
{
|
||||
const struct v2d *v;
|
||||
Polygon_2 np;
|
||||
@ -46,6 +46,8 @@ static inline Polygon_2 p2d_to_P2(const struct p2d *p)
|
||||
v = v->next;
|
||||
}
|
||||
while (v != p->v);
|
||||
if (p2d_is_cw(p) == ccw)
|
||||
np.reverse_orientation();
|
||||
return np;
|
||||
}
|
||||
|
||||
|
@ -80,11 +80,11 @@ extern "C" void p2d_area_holes_append(const struct p2d *p,
|
||||
const struct p2d *h;
|
||||
|
||||
assert(p2d_is_closed(p));
|
||||
Polygon_with_holes poly(p2d_to_P2(p));
|
||||
Polygon_with_holes poly(p2d_to_P2(p, 1));
|
||||
|
||||
for (h = holes; h; h = h->next) {
|
||||
assert(p2d_is_closed(h));
|
||||
poly.add_hole(p2d_to_P2(h));
|
||||
poly.add_hole(p2d_to_P2(h, 0));
|
||||
}
|
||||
|
||||
recurse_area(poly, offset, offset-overlap, last);
|
||||
|
@ -50,11 +50,11 @@ extern "C" struct p2d *p2d_offset_holes(const struct p2d *p,
|
||||
struct p2d *res = NULL, **last = &res;
|
||||
|
||||
assert(p2d_is_closed(p));
|
||||
Polygon_with_holes poly(p2d_to_P2(p));
|
||||
Polygon_with_holes poly(p2d_to_P2(p, 1));
|
||||
|
||||
for (h = holes; h; h = h->next) {
|
||||
assert(p2d_is_closed(h));
|
||||
poly.add_hole(p2d_to_P2(h));
|
||||
poly.add_hole(p2d_to_P2(h, 0));
|
||||
}
|
||||
|
||||
PolygonPtrVector tmp = off > 0 ?
|
||||
|
@ -49,4 +49,28 @@ expect <<EOF
|
||||
|
||||
EOF
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
tst "inner offset, polygon cw" <<EOF
|
||||
struct p2d *p = p2d_new();
|
||||
struct p2d *q;
|
||||
|
||||
p2d_append(p, v2d_new(0, 0));
|
||||
p2d_append(p, v2d_new(0, 1));
|
||||
p2d_append(p, v2d_new(2, 1));
|
||||
p2d_append(p, v2d_new(2, 0));
|
||||
p2d_close(p);
|
||||
q = p2d_offset(p, -0.1);
|
||||
p2d_write_gnuplot(stdout, q);
|
||||
EOF
|
||||
|
||||
expect <<EOF
|
||||
0.1 0.1
|
||||
1.9 0.1
|
||||
1.9 0.9
|
||||
0.1 0.9
|
||||
0.1 0.1
|
||||
|
||||
EOF
|
||||
|
||||
###############################################################################
|
||||
|
Loading…
Reference in New Issue
Block a user