// File: micahcc[P]polygon_skeleton/voronoi.cpp
// Function: Voronoi::Implementation::processPoint(Vector const&)
void Voronoi::Implementation::processPoint(const Point& pt)
{
    std::cerr << "<----------------------" << std::endl;
    std::cerr << "<Processing point: " << pt << std::endl;

    // Update sweep location in beach line so that insertion takes place at the
    // right location

    *m_beach_compare.sweep_y = pt.y;

    // insert two new intersections in between existing intersections
    Intersection dummy{&pt, &pt};
    bool success;
    BeachLineT::iterator it1, it2, it_new;
    const Point* ptA = nullptr;
    const Point* ptB = nullptr;
    const Point* ptC = nullptr;
    const Point* ptD = nullptr;
    if(m_beach.empty()) {
        std::cerr << "<<<Beach empty, inserting special" << std::endl;
        // add null intersection
        // no intersections to erase
        m_beach.emplace(nullptr, &pt);
        m_beach.emplace(&pt, nullptr);
    } else {
        // In between two previous intersections, on the parabolar for the
        // shared point
        //
        //  iterator:      it1       it2
        //  struct:        pt_left pt_right   pt_left pt_right
        //  points:         A   B     B   C
        //  new inter:          B  D  B
        // intersection >= so take the first point
        std::cerr << "<<Finding beach location" << std::endl;
        it1 = m_beach.lower_bound(dummy);
        std::cerr << "<<Lower bound: (" << it1->pt_left << " -- "
            << it1->pt_right << ")" << std::endl;
        if(it1->pt_left) {
            std::cerr << "<<pt_left: " << *it1->pt_left << std::endl;
        }
        if(it1->pt_right) {
            std::cerr << "<<pt_right: " << *it1->pt_right << std::endl;
        }
        std::cerr << "<<Done" << std::endl;
        it2 = it1; it1--;
        ptB = it1->pt_right;
        ptD = &pt;

        std::cerr << "B: " << ptB << std::endl
            << "D: " << ptD << std::endl;
        // Insert new intersection into beach, then create an event for the old
        // left and the new intersection point
        std::cerr << "Inserting " << ptB << ", " << ptD << " into beach" << std::endl;
        std::tie(it_new, success) = m_beach.emplace(ptB, ptD);
        assert(success);
        if(it1->pt_left != nullptr)
            m_events.insert(*m_beach_compare.sweep_y, *it1, *it_new);

        // Insert new intersection int beach, then create a new event for the
        // old upper intersection and the new one
        std::cerr << "Inserting " << ptD << ", " << ptB << " into beach" << std::endl;
        std::tie(it_new, success) = m_beach.emplace(ptD, ptB);
        assert(success);
        if(it2->pt_right != nullptr)
            m_events.insert(*m_beach_compare.sweep_y, *it_new, *it2);

        // Erase the event that involved the meeting of our previous left and
        // right intersections (since we got in the middle)
        if(it1->pt_left != nullptr && it2->pt_right != nullptr) {
            m_events.erase(*it1, *it2);
        }
    }


    std::cerr << "<......................" << std::endl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x190, %rsp            # imm = 0x190
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x118(%rbp)
movq 0x2636b(%rip), %rdi     # 0x32ff0
leaq 0x16b17(%rip), %rsi     # 0x237a3
callq 0x3250
movq %rax, %rdi
movq 0x26325(%rip), %rsi     # 0x32fc0
callq 0x3290
movq 0x26349(%rip), %rdi     # 0x32ff0
leaq 0x16b0d(%rip), %rsi     # 0x237bb
callq 0x3250
movq %rax, %rdi
movq -0x10(%rbp), %rsi
callq 0xa320
movq %rax, %rdi
movq 0x262f7(%rip), %rsi     # 0x32fc0
callq 0x3290
movq -0x118(%rbp), %rax
movq -0x10(%rbp), %rcx
movss 0x4(%rcx), %xmm0
movq 0x8(%rax), %rax
movss %xmm0, (%rax)
movq -0x10(%rbp), %rsi
movq -0x10(%rbp), %rdx
leaq -0x20(%rbp), %rdi
callq 0x11520
leaq -0x30(%rbp), %rdi
callq 0x109f0
leaq -0x38(%rbp), %rdi
callq 0x109f0
leaq -0x40(%rbp), %rdi
callq 0x109f0
movq -0x118(%rbp), %rdi
movq $0x0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
addq $0x10, %rdi
callq 0x11550
testb $0x1, %al
jne 0xcd4b
jmp 0xcde2
movq 0x2629e(%rip), %rdi     # 0x32ff0
leaq 0x16a76(%rip), %rsi     # 0x237cf
callq 0x3250
movq %rax, %rdi
movq 0x26258(%rip), %rsi     # 0x32fc0
callq 0x3290
movq -0x118(%rbp), %rdi
addq $0x10, %rdi
movq $0x0, -0x68(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x70(%rbp)
leaq -0x68(%rbp), %rsi
leaq -0x70(%rbp), %rdx
callq 0x11570
movq -0x118(%rbp), %rdi
movq %rax, -0x80(%rbp)
movb %dl, -0x78(%rbp)
addq $0x10, %rdi
movq -0x10(%rbp), %rax
movq %rax, -0x88(%rbp)
movq $0x0, -0x90(%rbp)
leaq -0x88(%rbp), %rsi
leaq -0x90(%rbp), %rdx
callq 0x115d0
movq %rax, -0xa0(%rbp)
movb %dl, -0x98(%rbp)
jmp 0xd31b
movq 0x26207(%rip), %rdi     # 0x32ff0
leaq 0x16a01(%rip), %rsi     # 0x237f1
callq 0x3250
movq %rax, %rdi
movq 0x261c1(%rip), %rsi     # 0x32fc0
callq 0x3290
movq -0x118(%rbp), %rdi
addq $0x10, %rdi
leaq -0x20(%rbp), %rsi
callq 0x11630
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rax
movq %rax, -0x30(%rbp)
movq 0x261bf(%rip), %rdi     # 0x32ff0
leaq 0x169d2(%rip), %rsi     # 0x2380a
callq 0x3250
movq %rax, -0x128(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x109a0
movq -0x128(%rbp), %rdi
movq (%rax), %rsi
callq 0x31e0
movq %rax, %rdi
leaq 0x166dc(%rip), %rsi     # 0x23542
callq 0x3250
movq %rax, -0x120(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x109a0
movq -0x120(%rbp), %rdi
movq 0x8(%rax), %rsi
callq 0x31e0
movq %rax, %rdi
leaq 0x16b24(%rip), %rsi     # 0x239b9
callq 0x3250
movq %rax, %rdi
movq 0x2611c(%rip), %rsi     # 0x32fc0
callq 0x3290
leaq -0x30(%rbp), %rdi
callq 0x109a0
cmpq $0x0, (%rax)
je 0xcef9
movq 0x26131(%rip), %rdi     # 0x32ff0
leaq 0x16955(%rip), %rsi     # 0x2381b
callq 0x3250
movq %rax, -0x130(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x109a0
movq -0x130(%rbp), %rdi
movq (%rax), %rsi
callq 0xa320
movq %rax, %rdi
movq 0x260cc(%rip), %rsi     # 0x32fc0
callq 0x3290
leaq -0x30(%rbp), %rdi
callq 0x109a0
cmpq $0x0, 0x8(%rax)
je 0xcf4b
movq 0x260e0(%rip), %rdi     # 0x32ff0
leaq 0x16910(%rip), %rsi     # 0x23827
callq 0x3250
movq %rax, -0x138(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x109a0
movq -0x138(%rbp), %rdi
movq 0x8(%rax), %rsi
callq 0xa320
movq %rax, %rdi
movq 0x2607a(%rip), %rsi     # 0x32fc0
callq 0x3290
movq 0x2609e(%rip), %rdi     # 0x32ff0
movq %rdi, -0x148(%rbp)
leaq 0x168d4(%rip), %rsi     # 0x23834
callq 0x3250
movq %rax, %rdi
movq 0x26051(%rip), %rsi     # 0x32fc0
movq %rsi, -0x140(%rbp)
callq 0x3290
movq -0x30(%rbp), %rax
movq %rax, -0x38(%rbp)
leaq -0x30(%rbp), %rdi
movq %rdi, -0x150(%rbp)
xorl %esi, %esi
callq 0x10a50
movq -0x150(%rbp), %rdi
movq %rax, -0xb0(%rbp)
callq 0x109a0
movq -0x148(%rbp), %rdi
movq 0x8(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x60(%rbp)
leaq 0x16875(%rip), %rsi     # 0x2383b
callq 0x3250
movq %rax, %rdi
movq -0x50(%rbp), %rsi
callq 0x31e0
movq -0x140(%rbp), %rsi
movq %rax, %rdi
callq 0x3290
movq %rax, %rdi
leaq 0x1684f(%rip), %rsi     # 0x2383f
callq 0x3250
movq %rax, %rdi
movq -0x60(%rbp), %rsi
callq 0x31e0
movq -0x140(%rbp), %rsi
movq %rax, %rdi
callq 0x3290
movq -0x148(%rbp), %rdi
leaq 0x16825(%rip), %rsi     # 0x23843
callq 0x3250
movq %rax, %rdi
movq -0x50(%rbp), %rsi
callq 0x31e0
movq %rax, %rdi
leaq 0x1603e(%rip), %rsi     # 0x23077
callq 0x3250
movq %rax, %rdi
movq -0x60(%rbp), %rsi
callq 0x31e0
movq %rax, %rdi
leaq 0x167fa(%rip), %rsi     # 0x2384e
callq 0x3250
movq -0x140(%rbp), %rsi
movq %rax, %rdi
callq 0x3290
movq -0x118(%rbp), %rdi
addq $0x10, %rdi
leaq -0x50(%rbp), %rsi
leaq -0x60(%rbp), %rdx
callq 0x11670
movb %dl, -0xc8(%rbp)
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rax
movq %rax, -0xc0(%rbp)
movb -0xc8(%rbp), %al
movb %al, -0xb8(%rbp)
leaq -0xe0(%rbp), %rdi
leaq -0x40(%rbp), %rsi
leaq -0x21(%rbp), %rdx
callq 0x10db0
leaq -0xe0(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x10df0
testb $0x1, -0x21(%rbp)
je 0xd0d6
jmp 0xd0f5
leaq 0x16636(%rip), %rdi     # 0x23713
leaq 0x161ea(%rip), %rsi     # 0x232ce
movl $0x352, %edx            # imm = 0x352
leaq 0x1676a(%rip), %rcx     # 0x2385a
callq 0x3170
leaq -0x30(%rbp), %rdi
callq 0x109a0
cmpq $0x0, (%rax)
je 0xd164
movq -0x118(%rbp), %rax
movq %rax, %rcx
addq $0x40, %rcx
movq %rcx, -0x168(%rbp)
movq 0x8(%rax), %rax
movss (%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x160(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x10970
movq %rax, -0x158(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x10970
movq -0x168(%rbp), %rdi
movsd -0x160(%rbp), %xmm0
movq -0x158(%rbp), %rsi
movq %rax, %rdx
callq 0x10ed0
movq 0x25e85(%rip), %rdi     # 0x32ff0
leaq 0x166d1(%rip), %rsi     # 0x23843
callq 0x3250
movq %rax, %rdi
movq -0x60(%rbp), %rsi
callq 0x31e0
movq %rax, %rdi
leaq 0x15eea(%rip), %rsi     # 0x23077
callq 0x3250
movq %rax, %rdi
movq -0x50(%rbp), %rsi
callq 0x31e0
movq %rax, %rdi
leaq 0x166a6(%rip), %rsi     # 0x2384e
callq 0x3250
movq %rax, %rdi
movq 0x25e09(%rip), %rsi     # 0x32fc0
callq 0x3290
movq -0x118(%rbp), %rdi
addq $0x10, %rdi
leaq -0x60(%rbp), %rsi
leaq -0x50(%rbp), %rdx
callq 0x11670
movb %dl, -0xf8(%rbp)
movq %rax, -0x100(%rbp)
movq -0x100(%rbp), %rax
movq %rax, -0xf0(%rbp)
movb -0xf8(%rbp), %al
movb %al, -0xe8(%rbp)
leaq -0x110(%rbp), %rdi
leaq -0x40(%rbp), %rsi
leaq -0x21(%rbp), %rdx
callq 0x10db0
leaq -0x110(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x10df0
testb $0x1, -0x21(%rbp)
je 0xd22a
jmp 0xd249
leaq 0x164e2(%rip), %rdi     # 0x23713
leaq 0x16096(%rip), %rsi     # 0x232ce
movl $0x35a, %edx            # imm = 0x35A
leaq 0x16616(%rip), %rcx     # 0x2385a
callq 0x3170
leaq -0x38(%rbp), %rdi
callq 0x109a0
cmpq $0x0, 0x8(%rax)
je 0xd2b9
movq -0x118(%rbp), %rax
movq %rax, %rcx
addq $0x40, %rcx
movq %rcx, -0x180(%rbp)
movq 0x8(%rax), %rax
movss (%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x178(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x10970
movq %rax, -0x170(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x10970
movq -0x180(%rbp), %rdi
movsd -0x178(%rbp), %xmm0
movq -0x170(%rbp), %rsi
movq %rax, %rdx
callq 0x10ed0
leaq -0x30(%rbp), %rdi
callq 0x109a0
cmpq $0x0, (%rax)
je 0xd319
leaq -0x38(%rbp), %rdi
callq 0x109a0
cmpq $0x0, 0x8(%rax)
je 0xd319
movq -0x118(%rbp), %rax
addq $0x40, %rax
movq %rax, -0x190(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x10970
movq %rax, -0x188(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x10970
movq -0x190(%rbp), %rdi
movq -0x188(%rbp), %rsi
movq %rax, %rdx
callq 0x10a90
jmp 0xd31b
movq 0x25cce(%rip), %rdi     # 0x32ff0
leaq 0x1656b(%rip), %rsi     # 0x23894
callq 0x3250
movq %rax, %rdi
movq 0x25c88(%rip), %rsi     # 0x32fc0
callq 0x3290
addq $0x190, %rsp            # imm = 0x190
popq %rbp
retq
nopw %cs:(%rax,%rax)