// File: /workspace/github_cpp_makefile_star2_O1/jamesliu516[P]amrdg2d/wall4amrdg2013.cpp
// Function: getWallCurvatureRadius(pointxy const*, pointxy&)
double getWallCurvatureRadius(const PXYZ *pt, PXYZ &ndir)
{
    int ils1;
    double rd1=0.0,rd2=0.0, dis1,dis2;
    PXYZ pp1,pp2,pp3, cen1,cen2, ndir1,ndir2;
    int nb;
    ils1=getIndexAtWallPoint(pt,nb);
    if(ils1==NWallPts[nb]-1)
    {
        pp1.x = MultiCircle[nb][0].x;
        pp1.y = MultiCircle[nb][0].y;
        pp2.x = MultiCircle[nb][ils1].x;
        pp2.y = MultiCircle[nb][ils1].y;
        pp3.x = MultiCircle[nb][ils1-1].x;
        pp3.y = MultiCircle[nb][ils1-1].y;

        rd1=getRadius(&pp1,&pp2,&pp3,cen1);
        dis1=sqrt((pt->x-cen1.x)*(pt->x-cen1.x)+(pt->y-cen1.y)*(pt->y-cen1.y));
        ndir.x=(pt->x-cen1.x)/dis1;
        ndir.y=(pt->y-cen1.y)/dis1;		

        return rd1;
    }
    else if(ils1==NWallPts[nb]-2)
    {
        pp1.x = MultiCircle[nb][0].x;
        pp1.y = MultiCircle[nb][0].y;
        pp2.x = MultiCircle[nb][ils1].x;
        pp2.y = MultiCircle[nb][ils1].y;
        pp3.x = MultiCircle[nb][ils1+1].x;
        pp3.y = MultiCircle[nb][ils1+1].y;

        rd1=getRadius(&pp1,&pp2,&pp3,cen1);
        dis1=sqrt((pt->x-cen1.x)*(pt->x-cen1.x)+(pt->y-cen1.y)*(pt->y-cen1.y));
        ndir1.x=(pt->x-cen1.x)/dis1;
        ndir1.y=(pt->y-cen1.y)/dis1;	

        pp1.x = MultiCircle[nb][ils1+1].x;
        pp1.y = MultiCircle[nb][ils1+1].y;
        pp2.x = MultiCircle[nb][ils1].x;
        pp2.y = MultiCircle[nb][ils1].y;
        pp3.x = MultiCircle[nb][ils1-1].x;
        pp3.y = MultiCircle[nb][ils1-1].y;

        rd2=getRadius(&pp1,&pp2,&pp3, cen2);

        dis2=sqrt((pt->x-cen2.x)*(pt->x-cen2.x)+(pt->y-cen2.y)*(pt->y-cen2.y));
        ndir2.x=(pt->x-cen2.x)/dis2;
        ndir2.y=(pt->y-cen2.y)/dis2;

        ndir.x=0.5*(ndir1.x+ndir2.x);
        ndir.y=0.5*(ndir1.y+ndir2.y);			

        return (0.5*(rd1+rd2));
    }
    else if(ils1==0)
    {
        pp1.x = MultiCircle[nb][0].x;
        pp1.y = MultiCircle[nb][0].y;
        pp2.x = MultiCircle[nb][1].x;
        pp2.y = MultiCircle[nb][1].y;
        pp3.x = MultiCircle[nb][2].x;
        pp3.y = MultiCircle[nb][2].y;
        //	rd1=getRadius(&pp1,&pp2,&pp3);
        rd1=getRadius(&pp1,&pp2,&pp3,cen1);
        dis1=sqrt((pt->x-cen1.x)*(pt->x-cen1.x)+(pt->y-cen1.y)*(pt->y-cen1.y));
        ndir.x=(pt->x-cen1.x)/dis1;
        ndir.y=(pt->y-cen1.y)/dis1;	

        return rd1;
    }
    else
    {
        pp1.x = MultiCircle[nb][ils1+2].x;
        pp1.y = MultiCircle[nb][ils1+2].y;
        pp2.x = MultiCircle[nb][ils1].x;
        pp2.y = MultiCircle[nb][ils1].y;
        pp3.x = MultiCircle[nb][ils1+1].x;
        pp3.y = MultiCircle[nb][ils1+1].y;

        rd1=getRadius(&pp1,&pp2,&pp3,cen1);
        dis1=sqrt((pt->x-cen1.x)*(pt->x-cen1.x)+(pt->y-cen1.y)*(pt->y-cen1.y));
        ndir1.x=(pt->x-cen1.x)/dis1;
        ndir1.y=(pt->y-cen1.y)/dis1;

        pp1.x = MultiCircle[nb][ils1+1].x;
        pp1.y = MultiCircle[nb][ils1+1].y;
        pp2.x = MultiCircle[nb][ils1].x;
        pp2.y = MultiCircle[nb][ils1].y;
        pp3.x = MultiCircle[nb][ils1-1].x;
        pp3.y = MultiCircle[nb][ils1-1].y;

        rd2=getRadius(&pp1,&pp2,&pp3, cen2);

        dis2=sqrt((pt->x-cen2.x)*(pt->x-cen2.x)+(pt->y-cen2.y)*(pt->y-cen2.y));
        ndir2.x=(pt->x-cen2.x)/dis2;
        ndir2.y=(pt->y-cen2.y)/dis2;

        ndir.x=0.5*(ndir1.x+ndir2.x);
        ndir.y=0.5*(ndir1.y+ndir2.y);

        return (0.5*(rd1+rd2));
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa0, %rsp
movq %rsi, %rbx
movq %rdi, %r14
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x90(%rsp)
leaq 0x8c(%rsp), %r15
movq %r15, %rsi
callq 0x11acd
movslq (%r15), %rcx
leaq 0x12cd0(%rip), %rdx     # 0x25200
movl (%rdx,%rcx,4), %edx
leal -0x1(%rdx), %esi
cmpl %esi, %eax
jne 0x125d3
imulq $0x1f40, %rcx, %rcx     # imm = 0x1F40
leaq 0x12e34(%rip), %rdx     # 0x25380
leaq (%rdx,%rcx), %r8
movaps (%rdx,%rcx), %xmm0
leaq 0x50(%rsp), %rdi
movaps %xmm0, (%rdi)
cltq
shlq $0x4, %rax
movaps (%rax,%r8), %xmm0
leaq 0x40(%rsp), %rsi
movaps %xmm0, (%rsi)
movapd -0x10(%rax,%r8), %xmm0
leaq 0x30(%rsp), %rdx
movapd %xmm0, (%rdx)
leaq 0x60(%rsp), %r15
movq %r15, %rcx
callq 0x12218
movapd %xmm0, %xmm3
movsd (%r14), %xmm0
movsd 0x8(%r14), %xmm1
movapd (%r15), %xmm4
subsd %xmm4, %xmm0
movapd %xmm4, %xmm2
unpckhpd %xmm4, %xmm2            # xmm2 = xmm2[1],xmm4[1]
subsd %xmm2, %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x12682
sqrtsd %xmm0, %xmm0
jmp 0x1269f
addl $-0x2, %edx
cmpl %edx, %eax
jne 0x126b9
imulq $0x1f40, %rcx, %rcx     # imm = 0x1F40
leaq 0x12d94(%rip), %rdx     # 0x25380
leaq (%rdx,%rcx), %rsi
movaps (%rdx,%rcx), %xmm0
leaq 0x50(%rsp), %rdi
movaps %xmm0, (%rdi)
cltq
shlq $0x4, %rax
leaq (%rsi,%rax), %r13
leaq (%rax,%rsi), %r12
addq $0x10, %r12
movaps -0x10(%r12), %xmm0
leaq 0x40(%rsp), %rsi
movaps %xmm0, (%rsi)
movaps (%r12), %xmm0
leaq 0x30(%rsp), %rdx
movaps %xmm0, (%rdx)
leaq 0x60(%rsp), %r15
movq %r15, %rcx
callq 0x12218
movaps %xmm0, %xmm3
movsd (%r14), %xmm0
movsd 0x8(%r14), %xmm1
movapd (%r15), %xmm4
subsd %xmm4, %xmm0
movapd %xmm4, %xmm2
unpckhpd %xmm4, %xmm2            # xmm2 = xmm2[1],xmm4[1]
subsd %xmm2, %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
movsd %xmm3, 0x8(%rsp)
jb 0x12761
sqrtsd %xmm0, %xmm0
jmp 0x12772
movsd %xmm3, 0x8(%rsp)
movapd %xmm4, 0x10(%rsp)
callq 0x31b0
movapd 0x10(%rsp), %xmm4
movsd 0x8(%rsp), %xmm3
movupd (%r14), %xmm1
subpd %xmm4, %xmm1
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
divpd %xmm0, %xmm1
movupd %xmm1, (%rbx)
jmp 0x128d5
testl %eax, %eax
je 0x127ac
imulq $0x1f40, %rcx, %rcx     # imm = 0x1F40
addq 0x12901(%rip), %rcx     # 0x24fd0
movslq %eax, %r12
shlq $0x4, %r12
leaq (%r12,%rcx), %r13
addq $0x10, %r13
movaps 0x10(%r13), %xmm0
leaq 0x50(%rsp), %rdi
movaps %xmm0, (%rdi)
addq %rcx, %r12
movaps -0x10(%r13), %xmm0
leaq 0x40(%rsp), %rsi
movaps %xmm0, (%rsi)
movaps (%r13), %xmm0
leaq 0x30(%rsp), %rdx
movaps %xmm0, (%rdx)
leaq 0x60(%rsp), %r15
movq %r15, %rcx
callq 0x12218
movaps %xmm0, %xmm3
movsd (%r14), %xmm0
movsd 0x8(%r14), %xmm1
movapd (%r15), %xmm4
subsd %xmm4, %xmm0
movapd %xmm4, %xmm2
unpckhpd %xmm4, %xmm2            # xmm2 = xmm2[1],xmm4[1]
subsd %xmm2, %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
movsd %xmm3, 0x8(%rsp)
jb 0x127de
sqrtsd %xmm0, %xmm0
jmp 0x127ef
movapd %xmm4, 0x10(%rsp)
callq 0x31b0
movapd 0x10(%rsp), %xmm4
movupd (%r14), %xmm1
subpd %xmm4, %xmm1
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
divpd %xmm0, %xmm1
movapd %xmm1, 0x10(%rsp)
movaps (%r12), %xmm0
leaq 0x50(%rsp), %rdi
movaps %xmm0, (%rdi)
movaps (%r13), %xmm0
leaq 0x40(%rsp), %rsi
movaps %xmm0, (%rsi)
movapd -0x20(%r12), %xmm0
jmp 0x12826
imulq $0x1f40, %rcx, %rax     # imm = 0x1F40
leaq 0x12bc6(%rip), %rcx     # 0x25380
movaps (%rcx,%rax), %xmm0
leaq 0x50(%rsp), %rdi
movaps %xmm0, (%rdi)
movaps 0x10(%rcx,%rax), %xmm0
leaq 0x40(%rsp), %rsi
movaps %xmm0, (%rsi)
movapd 0x20(%rcx,%rax), %xmm0
jmp 0x12576
movapd %xmm4, 0x10(%rsp)
callq 0x31b0
movapd 0x10(%rsp), %xmm4
movupd (%r14), %xmm1
subpd %xmm4, %xmm1
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
divpd %xmm0, %xmm1
movapd %xmm1, 0x10(%rsp)
movaps (%r13), %xmm0
leaq 0x50(%rsp), %rdi
movaps %xmm0, (%rdi)
movaps (%r12), %xmm0
leaq 0x40(%rsp), %rsi
movaps %xmm0, (%rsi)
movapd -0x20(%r13), %xmm0
leaq 0x30(%rsp), %rdx
movapd %xmm0, (%rdx)
leaq 0x90(%rsp), %r15
movq %r15, %rcx
callq 0x12218
movapd %xmm0, %xmm4
movapd (%r15), %xmm5
movsd (%r14), %xmm0
movsd 0x8(%r14), %xmm1
subsd %xmm5, %xmm0
movapd %xmm5, %xmm2
unpckhpd %xmm5, %xmm2            # xmm2 = xmm2[1],xmm5[1]
subsd %xmm2, %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
ucomisd 0xb941(%rip), %xmm0     # 0x1e1b8
jb 0x1287f
sqrtsd %xmm0, %xmm0
jmp 0x1289c
movsd %xmm4, 0x28(%rsp)
movapd %xmm5, 0x70(%rsp)
callq 0x31b0
movapd 0x70(%rsp), %xmm5
movsd 0x28(%rsp), %xmm4
movsd 0x8(%rsp), %xmm3
movupd (%r14), %xmm1
subpd %xmm5, %xmm1
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
divpd %xmm0, %xmm1
movapd 0x10(%rsp), %xmm0
addpd %xmm1, %xmm0
mulpd 0xbd0b(%rip), %xmm0     # 0x1e5d0
movupd %xmm0, (%rbx)
addsd %xmm4, %xmm3
mulsd 0xb873(%rip), %xmm3     # 0x1e148
movapd %xmm3, %xmm0
addq $0xa0, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq