fact: Fixpoint check_curve_element_and_repair (fuel : nat) (cells : seq cell) (e : curve_element) : seq curve_element := match e with | straight p1 p2 => straight p1 p2 :: nil | bezier p1 p2 p3 => if Nat.eqb (List.length (cell_indices p2)) 2 then let i1 := nth 0 (cell_indices p2) 0%nat in let i2 := nth 1 (cell_indices p2) 0%nat in let vedge := match common_vert_edge (nth i1 cells dummy_cell) (nth i2 cells dummy_cell) with Some v => v | None => dummy_vert_edge end in let e' := (if Qlt_bool (p_x (apt_val p1)) (p_x (apt_val p2)) then bezier p1 p2 p3 else bezier p3 p2 p1) in match e' with |straight _ _ => e' :: nil | bezier p1' p2' p3' => let check_function := if Qlt_bool 0 (pue_formula (apt_val p1') (apt_val p2') (apt_val p3')) then check_bezier_ccw else check_bezier_cw in match check_function 20%nat vedge (apt_val p1')(apt_val p2')(apt_val p3') with | Some true => bezier p1 p2 p3 :: nil | _ => match fuel with | S p => straight p1 (Apt (midpoint (apt_val p1) (apt_val p2)) (cell_indices p1)) :: check_curve_element_and_repair p cells (bezier (Apt (midpoint (apt_val p1) (apt_val p2)) (cell_indices p1)) p2 (Apt (midpoint (apt_val p2) (apt_val p3)) (cell_indices p3))) ++ straight (Apt (midpoint (apt_val p2) (apt_val p3)) (cell_indices p3)) p3 :: nil | _ => straight p1 p2 :: straight p2 p3 :: nil end end end else (bezier p1 p2 p3 :: nil) end.
imports: mathcomp(all_ssreflect) ZArith QArith List String OrderedType OrderedTypeEx FMapAVL