fn split_arc(arc: usize, pt: Point, beachline: &mut BeachLine, dcel: &mut DCEL) -> usize {
    trace!("Splitting arc {}", arc);
    let parent = beachline.nodes[arc].parent;

    let mut arc_pt = Point::new(0.0, 0.0);
    if let BeachItem::Leaf(ref this_arc) = beachline.nodes[arc].item {
        arc_pt = this_arc.site;
    }

    let (twin1, twin2) = dcel.add_twins();

    let breakpoint_AB = BreakPoint::new(arc_pt, pt, twin1);
    let breakpoint_BA = BreakPoint::new(pt, arc_pt, twin2);

    let internal_AB = BeachItem::Internal(breakpoint_AB);
    let internal_BA = BeachItem::Internal(breakpoint_BA);

    let arc_A1 = Arc::new(arc_pt, None);
    let arc_A2 = Arc::new(arc_pt, None);
    let arc_B = Arc::new(pt, None);

    let leaf_A1 = BeachItem::Leaf(arc_A1);
    let leaf_A2 = BeachItem::Leaf(arc_A2);
    let leaf_B = BeachItem::Leaf(arc_B);

    let ind_AB = beachline.nodes.len();
    let ind_BA = ind_AB + 1;
    let ind_A1 = ind_AB + 2;
    let ind_B = ind_AB + 3;
    let ind_A2 = ind_AB + 4;

    let node_AB = BeachNode {
        parent,
        left_child: Some(ind_A1),
        right_child: Some(ind_BA),
        item: internal_AB,
    };
    beachline.nodes.push(node_AB);
    if let Some(parent_ind) = parent {
        let parent_node = &mut beachline.nodes[parent_ind];
        if parent_node.right_child.is_some() && parent_node.right_child.unwrap() == arc {
            parent_node.right_child = Some(ind_AB);
        } else if parent_node.left_child.is_some() && parent_node.left_child.unwrap() == arc {
            parent_node.left_child = Some(ind_AB);
        } else {
            panic!("tree is borked");
        }
    } else {
        beachline.root = ind_AB;
    }

    let node_BA = BeachNode {
        parent: Some(ind_AB),
        left_child: Some(ind_B),
        right_child: Some(ind_A2),
        item: internal_BA,
    };
    beachline.nodes.push(node_BA);

    let node_A1 = BeachNode::make_arc(Some(ind_AB), leaf_A1);
    beachline.nodes.push(node_A1);

    let node_B = BeachNode::make_arc(Some(ind_BA), leaf_B);
    beachline.nodes.push(node_B);

    let node_A2 = BeachNode::make_arc(Some(ind_BA), leaf_A2);
    beachline.nodes.push(node_A2);

    ind_B
}
// return: the index of the node for the new arc
the index of the node for the new arc
the index of the node for the new arc
fn split_arc(arc: usize, pt: Point, beachline: &mut BeachLine, dcel: &mut DCEL) -> usize {
    trace!("Splitting arc {}", arc);
    let parent = beachline.nodes[arc].parent;
    let mut arc_pt = Point::new(0.0, 0.0);
    if let BeachItem::Leaf(ref this_arc) = beachline.nodes[arc].item {
        arc_pt = this_arc.site;
    }
    let (twin1, twin2) = dcel.add_twins();
    let breakpoint_AB = BreakPoint::new(arc_pt, pt, twin1);
    let breakpoint_BA = BreakPoint::new(pt, arc_pt, twin2);
    let internal_AB = BeachItem::Internal(breakpoint_AB);
    let internal_BA = BeachItem::Internal(breakpoint_BA);
    let arc_A1 = Arc::new(arc_pt, None);
    let arc_A2 = Arc::new(arc_pt, None);
    let arc_B = Arc::new(pt, None);
    let leaf_A1 = BeachItem::Leaf(arc_A1);
    let leaf_A2 = BeachItem::Leaf(arc_A2);
    let leaf_B = BeachItem::Leaf(arc_B);
    let ind_AB = beachline.nodes.len();
    let ind_BA = ind_AB + 1;
    let ind_A1 = ind_AB + 2;
    let ind_B = ind_AB + 3;
    let ind_A2 = ind_AB + 4;
    let node_AB = BeachNode {
        parent,
        left_child: Some(ind_A1),
        right_child: Some(ind_BA),
        item: internal_AB,
    };
    beachline.nodes.push(node_AB);
    if let Some(parent_ind) = parent {
        let parent_node = &mut beachline.nodes[parent_ind];
        if parent_node.right_child.is_some() && parent_node.right_child.unwrap() == arc {
            parent_node.right_child = Some(ind_AB);
        } else if parent_node.left_child.is_some() && parent_node.left_child.unwrap() == arc {
            parent_node.left_child = Some(ind_AB);
        } else {
            panic!("tree is borked");
        }
    } else {
        beachline.root = ind_AB;
    }
    let node_BA = BeachNode {
        parent: Some(ind_AB),
        left_child: Some(ind_B),
        right_child: Some(ind_A2),
        item: internal_BA,
    };
    beachline.nodes.push(node_BA);
    let node_A1 = BeachNode::make_arc(Some(ind_AB), leaf_A1);
    beachline.nodes.push(node_A1);
    let node_B = BeachNode::make_arc(Some(ind_BA), leaf_B);
    beachline.nodes.push(node_B);
    let node_A2 = BeachNode::make_arc(Some(ind_BA), leaf_A2);
    beachline.nodes.push(node_A2);
    ind_B
}
fn split_arc ( arc : usize , pt : Point , beachline : & mut BeachLine , dcel : & mut DCEL ) -> usize { trace ! ( " " arc ) ; let parent = beachline . nodes [ arc ] . parent ; let mut arc_pt = Point :: new ( 0.0 , 0.0 ) ; if let BeachItem :: Leaf ( ref this_arc ) = beachline . nodes [ arc ] . item { arc_pt = this_arc . site ; } let ( twin1 , twin2 ) = dcel . add_twins ( ) ; let breakpoint_AB = BreakPoint :: new ( arc_pt , pt , twin1 ) ; let breakpoint_BA = BreakPoint :: new ( pt , arc_pt , twin2 ) ; let internal_AB = BeachItem :: Internal ( breakpoint_AB ) ; let internal_BA = BeachItem :: Internal ( breakpoint_BA ) ; let arc_A1 = Arc :: new ( arc_pt , None ) ; let arc_A2 = Arc :: new ( arc_pt , None ) ; let arc_B = Arc :: new ( pt , None ) ; let leaf_A1 = BeachItem :: Leaf ( arc_A1 ) ; let leaf_A2 = BeachItem :: Leaf ( arc_A2 ) ; let leaf_B = BeachItem :: Leaf ( arc_B ) ; let ind_AB = beachline . nodes . len ( ) ; let ind_BA = ind_AB + 1 ; let ind_A1 = ind_AB + 2 ; let ind_B = ind_AB + 3 ; let ind_A2 = ind_AB + 4 ; let node_AB = BeachNode { parent , left_child : Some ( ind_A1 ) , right_child : Some ( ind_BA ) , item : internal_AB , } ; beachline . nodes . push ( node_AB ) ; if let Some ( parent_ind ) = parent { let parent_node = & mut beachline . nodes [ parent_ind ] ; if parent_node . right_child . is_some ( ) && parent_node . right_child . unwrap ( ) == arc { parent_node . right_child = Some ( ind_AB ) ; } else if parent_node . left_child . is_some ( ) && parent_node . left_child . unwrap ( ) == arc { parent_node . left_child = Some ( ind_AB ) ; } else { panic ! ( " " ) ; } } else { beachline . root = ind_AB ; } let node_BA = BeachNode { parent : Some ( ind_AB ) , left_child : Some ( ind_B ) , right_child : Some ( ind_A2 ) , item : internal_BA , } ; beachline . nodes . push ( node_BA ) ; let node_A1 = BeachNode :: make_arc ( Some ( ind_AB ) , leaf_A1 ) ; beachline . nodes . push ( node_A1 ) ; let node_B = BeachNode :: make_arc ( Some ( ind_BA ) , leaf_B ) ; beachline . nodes . push ( node_B ) ; let node_A2 = BeachNode :: make_arc ( Some ( ind_BA ) , leaf_A2 ) ; beachline . nodes . push ( node_A2 ) ; ind_B }
return: the index of the node for the new arc
return : the index of the node for the new arc
arc
usize
pt
Point
beachline
&mut BeachLine
dcel
&mut DCEL
arc
usize
pt
Point
beachline
&mut BeachLine
dcel
&mut DCEL