// File: ddunbar[P]PDSample/PDSampling.cpp
// Function: LinearPureSampler::complete()
void LinearPureSampler::complete()
{
	IntVector candidates;

	addPoint(randomPoint());
	candidates.push_back((int) points.size()-1);

	while (candidates.size()) {
		int c = m_rng.getInt32()%candidates.size();
		int index = candidates[c];
		Vec2 candidate = points[index];
		candidates[c] = candidates[candidates.size()-1];
		candidates.pop_back();

		ScallopedRegion sr(candidate, radius*2, radius*4);
		findNeighbors(candidate, radius*8);
		
		for (IntVector::const_iterator it=m_neighbors.begin(); it!=m_neighbors.end(); it++) {
			int nIdx = *it;
			Vec2 &n = points[nIdx];
			Vec2 nClose = candidate + getTiled(n-candidate);

			if (nIdx<index) {
				sr.subtractDisk(nClose, radius*4);
			} else {
				sr.subtractDisk(nClose, radius*2);
			}
		}

		while (!sr.isEmpty()) {
			Vec2 p = sr.sample(m_rng);
			Vec2 pt = getTiled(p);

			addPoint(pt);
			candidates.push_back((int) points.size()-1);

			sr.subtractDisk(p, radius*2);
		}
	}
}

// Assembly:
subq $0x178, %rsp            # imm = 0x178
movq %rdi, 0x170(%rsp)
movq 0x170(%rsp), %rax
movq %rax, 0x78(%rsp)
leaq 0x158(%rsp), %rdi
callq 0x6a80
movq 0x78(%rsp), %rdi
callq 0x3cb0
movaps %xmm0, 0x80(%rsp)
jmp 0x62fd
movq 0x78(%rsp), %rdi
movaps 0x80(%rsp), %xmm0
movlpd %xmm0, 0x150(%rsp)
movsd 0x150(%rsp), %xmm0
callq 0x3f10
jmp 0x6323
movq 0x78(%rsp), %rdi
addq $0x13b8, %rdi           # imm = 0x13B8
callq 0x3970
decl %eax
movl %eax, 0x140(%rsp)
leaq 0x158(%rsp), %rdi
leaq 0x140(%rsp), %rsi
callq 0x6ed0
jmp 0x6354
jmp 0x6356
leaq 0x158(%rsp), %rdi
callq 0x6d30
cmpq $0x0, %rax
je 0x67d6
movq 0x78(%rsp), %rdi
addq $0x8, %rdi
callq 0x29e0
movq %rax, 0x70(%rsp)
jmp 0x6382
leaq 0x158(%rsp), %rdi
movq %rdi, 0x68(%rsp)
callq 0x6d30
movq 0x68(%rsp), %rdi
movq %rax, %rcx
movq 0x70(%rsp), %rax
xorl %edx, %edx
divq %rcx
movl %edx, %eax
movl %eax, 0x13c(%rsp)
movslq 0x13c(%rsp), %rsi
callq 0x6f00
movq 0x78(%rsp), %rdi
movl (%rax), %eax
movl %eax, 0x138(%rsp)
addq $0x13b8, %rdi           # imm = 0x13B8
movslq 0x138(%rsp), %rsi
callq 0x3990
movq 0x68(%rsp), %rdi
movq (%rax), %rax
movq %rax, 0x130(%rsp)
callq 0x6d30
movq 0x68(%rsp), %rdi
movq %rax, %rsi
decq %rsi
callq 0x6f00
movq 0x68(%rsp), %rdi
movl (%rax), %eax
movl %eax, 0x64(%rsp)
movslq 0x13c(%rsp), %rsi
callq 0x6f00
movl 0x64(%rsp), %ecx
movq 0x68(%rsp), %rdi
movl %ecx, (%rax)
callq 0x6f20
movq 0x78(%rsp), %rax
movss 0x13d0(%rax), %xmm1
movaps %xmm1, %xmm0
addss %xmm0, %xmm0
movss 0x10085(%rip), %xmm2    # 0x164cc
mulss %xmm2, %xmm1
leaq 0x120(%rsp), %rdi
leaq 0x130(%rsp), %rsi
movss 0x1007d(%rip), %xmm2    # 0x164e0
callq 0x11ac0
jmp 0x646a
movq 0x78(%rsp), %rdi
movss 0x13d0(%rdi), %xmm0
movss 0x10065(%rip), %xmm1    # 0x164e4
mulss %xmm1, %xmm0
leaq 0x130(%rsp), %rsi
callq 0x4010
jmp 0x6492
movq 0x78(%rsp), %rdi
addq $0x1390, %rdi           # imm = 0x1390
callq 0x7480
movq %rax, 0x110(%rsp)
leaq 0x118(%rsp), %rdi
leaq 0x110(%rsp), %rsi
callq 0x74b0
movq 0x78(%rsp), %rdi
addq $0x1390, %rdi           # imm = 0x1390
callq 0x7530
movq %rax, 0x108(%rsp)
leaq 0x118(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x74f0
testb $0x1, %al
jne 0x64f7
jmp 0x66ab
leaq 0x118(%rsp), %rdi
callq 0x7560
movq 0x78(%rsp), %rdi
movl (%rax), %eax
movl %eax, 0x104(%rsp)
addq $0x13b8, %rdi           # imm = 0x13B8
movslq 0x104(%rsp), %rsi
callq 0x3990
movq %rax, 0xf8(%rsp)
movq 0xf8(%rsp), %rdi
movq 0x130(%rsp), %rax
movq %rax, 0xd8(%rsp)
movsd 0xd8(%rsp), %xmm0
callq 0x6d70
movaps %xmm0, 0x50(%rsp)
jmp 0x655b
movq 0x78(%rsp), %rdi
movaps 0x50(%rsp), %xmm0
movlpd %xmm0, 0xe0(%rsp)
movsd 0xe0(%rsp), %xmm0
callq 0x3d20
movaps %xmm0, 0x40(%rsp)
jmp 0x6583
movaps 0x40(%rsp), %xmm0
movlpd %xmm0, 0xe8(%rsp)
movsd 0xe8(%rsp), %xmm0
leaq 0x130(%rsp), %rdi
callq 0x7570
movaps %xmm0, 0x30(%rsp)
jmp 0x65ae
movaps 0x30(%rsp), %xmm0
movlpd %xmm0, 0xf0(%rsp)
movl 0x104(%rsp), %eax
cmpl 0x138(%rsp), %eax
jge 0x6652
movq 0x78(%rsp), %rax
movq 0xf0(%rsp), %rcx
movq %rcx, 0xd0(%rsp)
movss 0x13d0(%rax), %xmm1
movss 0xfed7(%rip), %xmm0     # 0x164cc
mulss %xmm0, %xmm1
movsd 0xd0(%rsp), %xmm0
leaq 0x120(%rsp), %rdi
callq 0x11c00
jmp 0x6611
jmp 0x668d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x148(%rsp)
movl %eax, 0x144(%rsp)
jmp 0x67eb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x148(%rsp)
movl %eax, 0x144(%rsp)
leaq 0x120(%rsp), %rdi
callq 0x11bc0
jmp 0x67eb
movq 0x78(%rsp), %rax
movq 0xf0(%rsp), %rcx
movq %rcx, 0xc8(%rsp)
movss 0x13d0(%rax), %xmm1
addss %xmm1, %xmm1
movsd 0xc8(%rsp), %xmm0
leaq 0x120(%rsp), %rdi
callq 0x11c00
jmp 0x668b
jmp 0x668d
jmp 0x668f
leaq 0x118(%rsp), %rdi
xorl %esi, %esi
callq 0x7960
movq %rax, 0xc0(%rsp)
jmp 0x64c0
jmp 0x66ad
leaq 0x120(%rsp), %rdi
callq 0x7610
movb %al, 0x2f(%rsp)
jmp 0x66c0
movb 0x2f(%rsp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x66cf
jmp 0x67c4
movq 0x78(%rsp), %rsi
addq $0x8, %rsi
leaq 0x120(%rsp), %rdi
callq 0x11f40
movaps %xmm0, 0x10(%rsp)
jmp 0x66ec
movq 0x78(%rsp), %rdi
movaps 0x10(%rsp), %xmm0
movlpd %xmm0, 0xb8(%rsp)
movq 0xb8(%rsp), %rax
movq %rax, 0xa8(%rsp)
movsd 0xa8(%rsp), %xmm0
callq 0x3d20
movaps %xmm0, (%rsp)
jmp 0x6723
movq 0x78(%rsp), %rdi
movaps (%rsp), %xmm0
movlpd %xmm0, 0xb0(%rsp)
movq 0xb0(%rsp), %rax
movq %rax, 0xa0(%rsp)
movsd 0xa0(%rsp), %xmm0
callq 0x3f10
jmp 0x6755
movq 0x78(%rsp), %rdi
addq $0x13b8, %rdi           # imm = 0x13B8
callq 0x3970
decl %eax
movl %eax, 0x9c(%rsp)
leaq 0x158(%rsp), %rdi
leaq 0x9c(%rsp), %rsi
callq 0x6ed0
jmp 0x6786
movq 0x78(%rsp), %rax
movq 0xb8(%rsp), %rcx
movq %rcx, 0x90(%rsp)
movss 0x13d0(%rax), %xmm1
addss %xmm1, %xmm1
movsd 0x90(%rsp), %xmm0
leaq 0x120(%rsp), %rdi
callq 0x11c00
jmp 0x67bf
jmp 0x66ad
leaq 0x120(%rsp), %rdi
callq 0x11bc0
jmp 0x6356
leaq 0x158(%rsp), %rdi
callq 0x6b00
addq $0x178, %rsp            # imm = 0x178
retq
leaq 0x158(%rsp), %rdi
callq 0x6b00
movq 0x148(%rsp), %rdi
callq 0x22f0
nopw %cs:(%rax,%rax)