// Use of the windingnumber for simple curves (NON CROSSED) // The most fast and robust with Asymptote. // Utilisation du nombre d'enroulement pour des courbes NON CROISÉES // Le plus rapide et robuste avec Asymptote. size(6cm,0, false); import math; import roundedpath; bool counterclockwise(path g) { // Return "true" if "g" (SIMPLE CURVE i.e. NON CROSSED) is counterclockwise // Retounre "true" si "g" (NON CROISÉ) est dans le sens contraire des aiguilles d'une montre return windingnumber(g,inside(g)) > 0; } path counterclockdirected(path g) { if (counterclockwise(g)) return g; else return reverse(g); } path p = (0,1)..(.8,1)..(.8,.6)..(.4,.6)..(.4,.2)..(.8,.2)..(.8,-.2)..(.4,-.2)..(.4,-.6)..(.8,-.6)..(.8,-1)..(0,-1)..cycle; draw(counterclockdirected(reverse(p)), Arrow(Relative(.1)), BeginBar); draw(counterclockdirected(p), Arrow(position=Relative(.2),FillDraw(red)), BeginBar);