// File: 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
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movss %xmm0, -0x24(%rbp)
movq 0x1672a9(%rip), %rdi    # 0x272fc0
leaq 0xf152a(%rip), %rsi     # 0x1fd248
callq 0x5540
movq %rax, -0x90(%rbp)
movq -0x8(%rbp), %rdi
addq $0x48, %rdi
callq 0xf270
movq -0x90(%rbp), %rdi
movq %rax, %rsi
callq 0x5160
movq %rax, %rdi
movq 0x167248(%rip), %rsi    # 0x272f98
callq 0x55b0
movq -0x10(%rbp), %rdi
addq $0x48, %rdi
callq 0x25230
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rdi
addq $0x48, %rdi
callq 0x250b0
movq %rax, -0x38(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x599b0
testb $0x1, %al
jne 0x10bd8d
jmp 0x10bf1f
movq $0x0, -0x40(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x599f0
movsd (%rax), %xmm0
movsd %xmm0, -0x48(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x599f0
movsd 0x8(%rax), %xmm0
movsd %xmm0, -0x50(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x599f0
movsd 0x10(%rax), %xmm0
movsd %xmm0, -0x58(%rbp)
movq -0x8(%rbp), %rdi
addq $0x48, %rdi
callq 0x25230
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rdi
addq $0x48, %rdi
callq 0x250b0
movq %rax, -0x68(%rbp)
leaq -0x60(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x599b0
testb $0x1, %al
jne 0x10be05
jmp 0x10bed3
leaq -0x60(%rbp), %rdi
callq 0x599f0
movsd (%rax), %xmm0
movsd %xmm0, -0x70(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x599f0
movsd 0x8(%rax), %xmm0
movsd %xmm0, -0x78(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x599f0
movsd 0x10(%rax), %xmm0
movsd %xmm0, -0x80(%rbp)
movq -0x18(%rbp), %rdi
movsd -0x70(%rbp), %xmm0
movsd -0x78(%rbp), %xmm1
movsd -0x80(%rbp), %xmm2
movsd -0x48(%rbp), %xmm3
movsd -0x50(%rbp), %xmm4
movsd -0x58(%rbp), %xmm5
callq 0x97a10
movsd %xmm0, -0x88(%rbp)
movsd -0x88(%rbp), %xmm1
movss -0x24(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jb 0x10bec3
cmpq $0x0, -0x40(%rbp)
jne 0x10be99
leaq -0x60(%rbp), %rdi
callq 0xaed90
movq %rax, -0x40(%rbp)
jmp 0x10bec1
leaq -0x60(%rbp), %rdi
callq 0x599f0
movsd 0x18(%rax), %xmm0
movq -0x40(%rbp), %rax
ucomisd 0x18(%rax), %xmm0
jbe 0x10bebf
leaq -0x60(%rbp), %rdi
callq 0xaed90
movq %rax, -0x40(%rbp)
jmp 0x10bec1
jmp 0x10bec3
jmp 0x10bec5
leaq -0x60(%rbp), %rdi
callq 0xb4bd0
jmp 0x10bdde
cmpq $0x0, -0x40(%rbp)
je 0x10beed
movq -0x20(%rbp), %rdi
addq $0x48, %rdi
movq -0x40(%rbp), %rsi
callq 0xf440
jmp 0x10bf0f
movq 0x1670cc(%rip), %rdi    # 0x272fc0
leaq 0xf135a(%rip), %rsi     # 0x1fd255
callq 0x5540
movq %rax, %rdi
movq 0x16708e(%rip), %rsi    # 0x272f98
callq 0x55b0
jmp 0x10bf11
leaq -0x30(%rbp), %rdi
callq 0xb4bd0
jmp 0x10bd66
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax,%rax)