Edge *bisect(Site * s1, Site * s2) { double dx, dy, adx, ady; Edge *newedge; newedge = (Edge *) getfree(&efl); newedge->reg[0] = s1; newedge->reg[1] = s2; ref(s1); ref(s2); newedge->ep[0] = (Site *) NULL; newedge->ep[1] = (Site *) NULL; dx = s2->coord.x - s1->coord.x; dy = s2->coord.y - s1->coord.y; adx = dx > 0 ? dx : -dx; ady = dy > 0 ? dy : -dy; newedge->c = s1->coord.x * dx + s1->coord.y * dy + (dx * dx + dy * dy) * 0.5; if (adx > ady) { newedge->a = 1.0; newedge->b = dy / dx; newedge->c /= dx; } else { newedge->b = 1.0; newedge->a = dx / dy; newedge->c /= dy; }; newedge->edgenbr = nedges; #ifdef STANDALONE out_bisector(newedge); #endif nedges += 1; return (newedge); }
struct Edge * VoronoiDiagramGenerator::bisect(struct Site *s1,struct Site *s2) { float dx,dy,adx,ady; struct Edge *newedge; newedge = (struct Edge *) getfree(&efl); newedge -> reg[0] = s1; //store the sites that this edge is bisecting newedge -> reg[1] = s2; ref(s1); ref(s2); newedge -> ep[0] = (struct Site *) NULL; //to begin with, there are no endpoints on the bisector - it goes to infinity newedge -> ep[1] = (struct Site *) NULL; dx = s2->coord.x - s1->coord.x; //get the difference in x dist between the sites dy = s2->coord.y - s1->coord.y; adx = dx>0 ? dx : -dx; //make sure that the difference in positive ady = dy>0 ? dy : -dy; newedge -> c = (float)(s1->coord.x * dx + s1->coord.y * dy + (dx*dx + dy*dy)*0.5);//get the slope of the line if (adx>ady) { newedge -> a = 1.0; newedge -> b = dy/dx; newedge -> c /= dx;//set formula of line, with x fixed to 1 } else { newedge -> b = 1.0; newedge -> a = dx/dy; newedge -> c /= dy;//set formula of line, with y fixed to 1 }; newedge -> edgenbr = nedges; //printf("\nbisect(%d) ((%f,%f) and (%f,%f)",nedges,s1->coord.x,s1->coord.y,s2->coord.x,s2->coord.y); out_bisector(newedge); nedges += 1; return(newedge); }