Updated script to make calc_edge function more abstract with geometry optimization.