Edge* nearestEdgeInModel (Model *m, Edge *start, float x, float y) /***************************************************************************** nearestEdgeInModel - Return pointer to edge in model nearest to specified (x,y) coordinates ****************************************************************************** Input: m model start edge to look at first (NULL to begin looking anywhere) x x-coordinate y y-coordinate Returns: pointer to nearest Edge ****************************************************************************** Author: Dave Hale, Colorado School of Mines, 09/11/90 ******************************************************************************/ { float d,dmin=0.0; Edge *emin=NULL; EdgeUse *eu; Tri *t; /* find triangle containing point */ if (start!=NULL) { t = (start->eu->f!=NULL?start->eu->f:start->eu->euMate->f); t = insideTriInModel(m,t,x,y); } else { t = insideTriInModel(m,NULL,x,y); } /* loop over edges in triangle */ eu = t->eu; do { /* compute distance to edge */ d = distanceToEdge(eu->e,x,y); /* update minimum distance */ if (eu==t->eu || d<dmin) { dmin = d; emin = eu->e; } /* next edge */ eu = eu->euCW; } while (eu!=t->eu); /* return edge corresponding to minimum distance */ return emin; }
Direction getNearestSeparator() { auto smallestDistance = std::max(cellWidth, cellHeight); Direction nearestSeparator; for (auto direction : getAllDirections()) { if (!cellIsOnGridExtremity(direction)) { auto distance = distanceToEdge(direction); if (distance < smallestDistance) { smallestDistance = distance; nearestSeparator = direction; } } } return nearestSeparator; }