// File: /workspace/github_cpp_makefile_star2_O2/Luthaf[P]zeopp/cluster.cc
// Function: nearest_largest_diameter_ha_vornet(VORONOI_NETWORK*, VORONOI_NETWORK*, ATOM_NETWORK*, VORONOI_NETWORK*, float)
void nearest_largest_diameter_ha_vornet(VORONOI_NETWORK* ha_vornet, VORONOI_NETWORK* vornet, 
        ATOM_NETWORK* atmnet, VORONOI_NETWORK* red_vornet, float cutoff)
{
    cout << "vornet size " << ha_vornet->nodes.size() << endl;
    for (VnIt vit = vornet->nodes.begin(); vit != vornet->nodes.end(); ++vit){
        VOR_NODE* biggest_near_vornode = NULL;
        double x2 = vit->x;
        double y2 = vit->y;
        double z2 = vit->z;
        for (VnIt vh_it = ha_vornet->nodes.begin(); vh_it != ha_vornet->nodes.end(); ++vh_it){
            double x1 = vh_it->x;
            double y1 = vh_it->y;
            double z1 = vh_it->z;
            double dist = atmnet->calcDistanceXYZ(x1,y1,z1,x2,y2,z2);
            //cout << dist << endl;
            if (dist <= cutoff){
                if (!biggest_near_vornode)
                    biggest_near_vornode = &*vh_it;
                else{
                    if (vh_it->rad_stat_sphere > biggest_near_vornode->rad_stat_sphere) {
                        biggest_near_vornode = &*vh_it;
                    }
                }
                //cout << "Size of vornode " << sizeof(biggest_near_vornode) << endl;
            }
        }
        //cout << "Reduced vornet nodes size " << red_vornet->nodes.size() << endl;
        //cout << "Size of vornode " << sizeof(biggest_near_vornode) << endl;
        if (biggest_near_vornode){
            red_vornet->nodes.push_back(*biggest_near_vornode);
        }
        else{
            cout << "Not able to find closest ha node" << endl;
            //throw 10;
        }
        //cout << "Size of vornode " << sizeof(biggest_near_vornode) << endl;
    }

    /* Ignoring edges at the moment as they are not needed */
    // Now that the voronoi nodes in reduced voronoi network are in the order 
    // of low accuracy vornet, generate the edges connecting the nodes in the order corresponding
    // to that in the low accuracy voronoi network. 
    // Adjust parameters of edges such as length, radius etc
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movss %xmm0, (%rsp)
movq %rcx, %rbx
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %r12
movq 0xdb9fe(%rip), %rdi     # 0x14ffc0
leaq 0x90f5f(%rip), %rsi     # 0x105528
callq 0x4480
movq 0x50(%r12), %rsi
subq 0x48(%r12), %rsi
sarq $0x6, %rsi
movq %rax, %rdi
callq 0x42e0
movq %rax, %rdi
callq 0x4230
movq 0x48(%r15), %rbp
cvtss2sd (%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
addq $0x48, %rbx
movq %rbx, 0x8(%rsp)
cmpq 0x50(%r15), %rbp
je 0x746d1
movsd (%rbp), %xmm0
movsd %xmm0, (%rsp)
movsd 0x8(%rbp), %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x10(%rbp), %xmm0
movsd %xmm0, 0x18(%rsp)
movq 0x48(%r12), %rbx
xorl %r13d, %r13d
cmpq 0x50(%r12), %rbx
je 0x74699
movsd (%rbx), %xmm0
movsd 0x8(%rbx), %xmm1
movsd 0x10(%rbx), %xmm2
movq %r14, %rdi
movsd (%rsp), %xmm3
movsd 0x20(%rsp), %xmm4
movsd 0x18(%rsp), %xmm5
callq 0x3f636
movsd 0x10(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jae 0x74675
movq %r13, %rax
jmp 0x74690
movq %rbx, %rax
testq %r13, %r13
je 0x74690
movsd 0x18(%rbx), %xmm0
ucomisd 0x18(%r13), %xmm0
movq %r13, %rax
jbe 0x74690
movq %rbx, %rax
addq $0x40, %rbx
movq %rax, %r13
jmp 0x74636
testq %r13, %r13
je 0x746ad
movq 0x8(%rsp), %rdi
movq %r13, %rsi
callq 0xa89e
jmp 0x746c8
movq 0xdb90c(%rip), %rdi     # 0x14ffc0
leaq 0x90e7a(%rip), %rsi     # 0x105535
callq 0x4480
movq %rax, %rdi
callq 0x4230
addq $0x40, %rbp
jmp 0x74604
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq