// File: sunweilun[P]Delaunay/Mesh.cpp
// Function: Mesh::locateTriangleWalking(unsigned int, unsigned int) const
unsigned Mesh::locateTriangleWalking(unsigned startEdgeIndex, unsigned vIndex) const
{
    const vec3& pos = vertices[vIndex].pos;
    unsigned eIndex = startEdgeIndex;
    vec3 searchPos = getMidPoint(eIndex);
    while(!inTriangle(halfEdges[eIndex].tIndex, pos))
    {
        unsigned exitIndex = halfEdges[eIndex].nextIndex;
        real r = intersectRatio(exitIndex, searchPos, pos);
        if(r < 0 || r > 1)
        {
            exitIndex = halfEdges[exitIndex].nextIndex;
            r = intersectRatio(exitIndex, searchPos, pos);
        }

        const vec3& v0 = vertices[halfEdges[exitIndex].vIndices[0]].pos;
        const vec3& v1 = vertices[halfEdges[exitIndex].vIndices[1]].pos;
        searchPos = v0+r*(v1-v0);
        eIndex = halfEdges[exitIndex].neighborIndex;
    }
    return halfEdges[eIndex].tIndex;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0xa8(%rbp)
addq $0x10, %rdi
movl -0x10(%rbp), %eax
movl %eax, %esi
callq 0x4240
movq -0xa8(%rbp), %rsi
addq $0x8, %rax
movq %rax, -0x18(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %edx
leaq -0x38(%rbp), %rdi
callq 0x24f0
movq -0xa8(%rbp), %rdi
addq $0x40, %rdi
movl -0x1c(%rbp), %eax
movl %eax, %esi
callq 0x4260
movq -0xa8(%rbp), %rdi
movl 0x8(%rax), %esi
movq -0x18(%rbp), %rdx
callq 0x2130
xorb $-0x1, %al
testb $0x1, %al
jne 0x2632
jmp 0x27ae
movq -0xa8(%rbp), %rdi
addq $0x40, %rdi
movl -0x1c(%rbp), %eax
movl %eax, %esi
callq 0x4260
movq -0xa8(%rbp), %rdi
movl 0xc(%rax), %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %esi
movq -0x18(%rbp), %rcx
leaq -0x38(%rbp), %rdx
callq 0x2350
movsd %xmm0, -0x48(%rbp)
xorps %xmm0, %xmm0
ucomisd -0x48(%rbp), %xmm0
ja 0x2686
movsd -0x48(%rbp), %xmm0
movsd 0x10988(%rip), %xmm1    # 0x13008
ucomisd %xmm1, %xmm0
jbe 0x26bd
movq -0xa8(%rbp), %rdi
addq $0x40, %rdi
movl -0x3c(%rbp), %eax
movl %eax, %esi
callq 0x4260
movq -0xa8(%rbp), %rdi
movl 0xc(%rax), %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %esi
movq -0x18(%rbp), %rcx
leaq -0x38(%rbp), %rdx
callq 0x2350
movsd %xmm0, -0x48(%rbp)
movq -0xa8(%rbp), %rdi
movq %rdi, %rax
addq $0x10, %rax
movq %rax, -0xc0(%rbp)
addq $0x40, %rdi
movl -0x3c(%rbp), %eax
movl %eax, %esi
callq 0x4260
movq -0xc0(%rbp), %rdi
movl (%rax), %eax
movl %eax, %esi
callq 0x4240
movq -0xa8(%rbp), %rdi
addq $0x8, %rax
movq %rax, -0x50(%rbp)
movq %rdi, %rax
addq $0x10, %rax
movq %rax, -0xb8(%rbp)
addq $0x40, %rdi
movl -0x3c(%rbp), %eax
movl %eax, %esi
callq 0x4260
movq -0xb8(%rbp), %rdi
movl 0x4(%rax), %eax
movl %eax, %esi
callq 0x4240
addq $0x8, %rax
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
leaq -0xa0(%rbp), %rdi
callq 0x4650
leaq -0x88(%rbp), %rdi
leaq -0x48(%rbp), %rsi
leaq -0xa0(%rbp), %rdx
callq 0x5580
movq -0xb0(%rbp), %rsi
leaq -0x70(%rbp), %rdi
leaq -0x88(%rbp), %rdx
callq 0x46d0
leaq -0x38(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x4790
movq -0xa8(%rbp), %rdi
addq $0x40, %rdi
movl -0x3c(%rbp), %eax
movl %eax, %esi
callq 0x4260
movl 0x14(%rax), %eax
movl %eax, -0x1c(%rbp)
jmp 0x25ff
movq -0xa8(%rbp), %rdi
addq $0x40, %rdi
movl -0x1c(%rbp), %eax
movl %eax, %esi
callq 0x4260
movl 0x8(%rax), %eax
addq $0xc0, %rsp
popq %rbp
retq
nop