toxi::geom::Vec2D toxi::geom::Polygon2D::getClosestPointTo( Vec2D & p ) { float minD = FLT_MAX; Vec2D q = Vec2D(); for (Line2D l : getEdges()) { Vec2D c = l.closestPointTo(p); float d = static_cast< float > ( c.distanceToSquared( p ) ); if (d < minD) { q = c; minD = d; } } return q; }
toxi::geom::Polygon2D * toxi::geom::Polygon2D::reduceVertices( const float & mel ) { float minEdgeLength = mel * mel; std::vector<Vec2D> reduced; Vec2D prev = vertices.at(0); reduced.push_back(prev); int num = vertices.size() - 1; for (int i = 1; i < num; i++) { Vec2D v = vertices.at(i); if (prev.distanceToSquared( v ) >= minEdgeLength) { reduced.push_back(v); prev = v; } } if (vertices.at(0).distanceToSquared( vertices.at(num)) >= minEdgeLength) { reduced.push_back(vertices.at(num)); } vertices = reduced; return this; }