1
0
Fork 0

- added snap() function to snap a polygon to a grid

This commit is contained in:
curt 2001-09-18 21:27:54 +00:00
parent afbe4fccbd
commit e5028b5637
2 changed files with 36 additions and 0 deletions

View file

@ -994,6 +994,39 @@ FGPolygon remove_dups( const FGPolygon &poly ) {
}
static inline double
snap (double value, double grid_size)
{
// I have no idea if this really works.
double factor = 1.0 / grid_size;
return double(int(value * factor)) / factor;
}
static inline Point3D
snap (const Point3D &p, double grid_size)
{
Point3D result;
result.setx(snap(p.x(), grid_size));
result.sety(snap(p.y(), grid_size));
result.setz(snap(p.z(), grid_size));
cout << result << endl;
return result;
}
// snap all points in a polygon to the given grid size.
FGPolygon snap (const FGPolygon &poly, double grid_size)
{
FGPolygon result;
for (int contour = 0; contour < poly.contours(); contour++) {
for (int i = 0; i < poly.contour_size(contour); i++) {
result.add_node(contour, snap(poly.get_pt(contour, i), grid_size));
}
result.set_hole_flag(contour, poly.get_hole_flag(contour));
}
return result;
}
// static const double tgAirportEpsilon = SG_EPSILON / 10.0;
static const double tgAirportEpsilon = SG_EPSILON;

View file

@ -73,6 +73,9 @@ Point3D calc_point_inside_old( const FGPolygon& p, const int contour,
// calculate some "arbitrary" point inside each of the polygons contours
void calc_points_inside( FGPolygon& p );
// snap all points to a grid
FGPolygon snap( const FGPolygon &poly, double grid_size );
// remove duplicate nodes in a polygon should they exist. Returns the
// fixed polygon
FGPolygon remove_dups( const FGPolygon &poly );