1
0
mirror of git://projects.qi-hardware.com/cae-tools.git synced 2024-12-23 19:24:36 +02:00
cae-tools/poly2d/cgal_helper.h

68 lines
1.4 KiB
C
Raw Normal View History

/*
* cgal_helper.h - Conversions between poly2d and CGAL
*
* Written 2012 by Werner Almesberger
* Copyright 2012 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 CGAL_HELPER_H
#define CGAL_HELPER_H
/*
* References:
* http://www.cgal.org/Manual/latest/examples/Straight_skeleton_2/
* Create_saop_from_polygon_with_holes_2.cpp
* http://www.cgal.org/Manual/latest/examples/Straight_skeleton_2/print.h
*/
extern "C" {
#include "poly2d.h"
}
#include <vector>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Polygon_with_holes_2.h>
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, int ccw)
{
const struct v2d *v;
Polygon_2 np;
v = p->v;
do {
np.push_back(K::Point_2(v->x, v->y));
v = v->next;
}
while (v != p->v);
if (p2d_is_cw(p) == ccw)
np.reverse_orientation();
return np;
}
static inline struct p2d *P2_to_p2d(Polygon_2 p)
{
struct p2d *np;
np = p2d_new();
for (Polygon_2::Vertex_iterator vit = p.vertices_begin();
vit != p.vertices_end(); ++vit)
p2d_append(np, v2d_new(vit->x(), vit->y()));
p2d_close(np);
return np;
}
#endif /* !CGAL_HELPER_H */