// File: ddunbar[P]PDSample/PDSampling.cpp
// Function: PureSampler::complete()
void PureSampler::complete()
{
	Vec2 pt = randomPoint();
	ScallopedRegion *rgn = new ScallopedRegion(pt, radius*2, radius*4);
	RegionMap regions;
	WeightedDiscretePDF<int> regionsPDF;

	addPoint(pt);
	regions[(int) points.size()-1] = rgn;
	regionsPDF.insert((int) points.size()-1, rgn->area);

	while (regions.size()) {
		int idx = regionsPDF.choose(m_rng.getFloatL());
		
		pt = getTiled(((*regions.find(idx)).second)->sample(m_rng));
		rgn = new ScallopedRegion(pt, radius*2, radius*4);

		findNeighbors(pt, radius*8);
		for (IntVector::const_iterator it=m_neighbors.begin(); it!=m_neighbors.end(); it++) {
			int nIdx = *it;
			Vec2 &n = points[nIdx];
			
			rgn->subtractDisk(pt+getTiled(n-pt), radius*4);

			RegionMap::iterator entry = regions.find(nIdx);
			if (entry!=regions.end()) {
				ScallopedRegion *nRgn = (*entry).second;
				nRgn->subtractDisk(n+getTiled(pt-n), radius*2);

				if (nRgn->isEmpty()) {
					regions.erase(entry);
					regionsPDF.remove(nIdx);
					delete nRgn;
				} else {
					regionsPDF.update(nIdx, nRgn->area);
				}
			}
		}

		addPoint(pt);

		if (!rgn->isEmpty()) {
			regions[(int) points.size()-1] = rgn;
			regionsPDF.insert((int) points.size()-1, rgn->area);
		} else {
			delete rgn;
		}
	}
}

// Assembly:
subq $0x268, %rsp            # imm = 0x268
movq %rdi, 0x260(%rsp)
movq 0x260(%rsp), %rdi
movq %rdi, 0x128(%rsp)
callq 0x3cb0
movlpd %xmm0, 0x258(%rsp)
movl $0x10, %edi
callq 0x21a0
movq %rax, %rdi
movq 0x128(%rsp), %rax
movq %rdi, %rcx
movq %rcx, 0x130(%rsp)
movss 0x13d0(%rax), %xmm1
movaps %xmm1, %xmm0
addss %xmm0, %xmm0
movss 0x10a48(%rip), %xmm2    # 0x164cc
mulss %xmm2, %xmm1
leaq 0x258(%rsp), %rsi
movss 0x10a48(%rip), %xmm2    # 0x164e0
callq 0x11ac0
jmp 0x5a9f
movq 0x130(%rsp), %rax
movq %rax, 0x250(%rsp)
leaq 0x210(%rsp), %rdi
callq 0x6f40
leaq 0x208(%rsp), %rdi
callq 0x6f50
jmp 0x5acb
movq 0x128(%rsp), %rdi
movq 0x258(%rsp), %rax
movq %rax, 0x200(%rsp)
movsd 0x200(%rsp), %xmm0
callq 0x3f10
jmp 0x5af3
movq 0x128(%rsp), %rdi
movq 0x250(%rsp), %rax
movq %rax, 0x118(%rsp)
addq $0x13b8, %rdi           # imm = 0x13B8
callq 0x3970
decl %eax
movl %eax, 0x1fc(%rsp)
leaq 0x210(%rsp), %rdi
leaq 0x1fc(%rsp), %rsi
callq 0x6f70
movq %rax, 0x120(%rsp)
jmp 0x5b3f
movq 0x128(%rsp), %rdi
movq 0x120(%rsp), %rax
movq 0x118(%rsp), %rcx
movq %rcx, (%rax)
addq $0x13b8, %rdi           # imm = 0x13B8
callq 0x3970
movl %eax, %esi
decl %esi
movq 0x250(%rsp), %rax
movss 0xc(%rax), %xmm0
leaq 0x208(%rsp), %rdi
callq 0x7060
jmp 0x5b86
jmp 0x5b88
leaq 0x210(%rsp), %rdi
callq 0x7240
cmpq $0x0, %rax
je 0x626b
movq 0x128(%rsp), %rdi
addq $0x8, %rdi
callq 0x2d90
movss %xmm0, 0x114(%rsp)
jmp 0x5bbb
movss 0x114(%rsp), %xmm0
leaq 0x208(%rsp), %rdi
callq 0x7250
movl %eax, 0x110(%rsp)
jmp 0x5bda
movl 0x110(%rsp), %eax
movl %eax, 0x1f8(%rsp)
leaq 0x210(%rsp), %rdi
leaq 0x1f8(%rsp), %rsi
callq 0x7430
movq %rax, 0x108(%rsp)
jmp 0x5c07
movq 0x108(%rsp), %rax
movq %rax, 0x1e0(%rsp)
leaq 0x1e0(%rsp), %rdi
callq 0x7460
movq 0x128(%rsp), %rsi
movq 0x8(%rax), %rdi
addq $0x8, %rsi
callq 0x11f40
movaps %xmm0, 0xf0(%rsp)
jmp 0x5c43
movq 0x128(%rsp), %rdi
movaps 0xf0(%rsp), %xmm0
movlpd %xmm0, 0x1e8(%rsp)
movsd 0x1e8(%rsp), %xmm0
callq 0x3d20
movaps %xmm0, 0xe0(%rsp)
jmp 0x5c74
movaps 0xe0(%rsp), %xmm0
movlpd %xmm0, 0x1f0(%rsp)
movq 0x1f0(%rsp), %rax
movq %rax, 0x258(%rsp)
movl $0x10, %edi
callq 0x21a0
movq %rax, 0xd8(%rsp)
jmp 0x5ca9
movq 0xd8(%rsp), %rdi
movq 0x128(%rsp), %rax
movss 0x13d0(%rax), %xmm1
movaps %xmm1, %xmm0
addss %xmm0, %xmm0
movss 0x107fc(%rip), %xmm2    # 0x164cc
mulss %xmm2, %xmm1
leaq 0x258(%rsp), %rsi
movss 0x107fc(%rip), %xmm2    # 0x164e0
callq 0x11ac0
jmp 0x5ceb
movq 0x128(%rsp), %rdi
movq 0xd8(%rsp), %rax
movq %rax, 0x250(%rsp)
movss 0x13d0(%rdi), %xmm0
movss 0x107d1(%rip), %xmm1    # 0x164e4
mulss %xmm1, %xmm0
leaq 0x258(%rsp), %rsi
callq 0x4010
jmp 0x5d26
movq 0x128(%rsp), %rdi
addq $0x1390, %rdi           # imm = 0x1390
callq 0x7480
movq %rax, 0x1d0(%rsp)
leaq 0x1d8(%rsp), %rdi
leaq 0x1d0(%rsp), %rsi
callq 0x74b0
movq 0x128(%rsp), %rdi
addq $0x1390, %rdi           # imm = 0x1390
callq 0x7530
movq %rax, 0x1c8(%rsp)
leaq 0x1d8(%rsp), %rdi
leaq 0x1c8(%rsp), %rsi
callq 0x74f0
testb $0x1, %al
jne 0x5d91
jmp 0x6166
leaq 0x1d8(%rsp), %rdi
callq 0x7560
movq 0x128(%rsp), %rdi
movl (%rax), %eax
movl %eax, 0x1c4(%rsp)
addq $0x13b8, %rdi           # imm = 0x13B8
movslq 0x1c4(%rsp), %rsi
callq 0x3990
movq %rax, 0x1b8(%rsp)
movq 0x250(%rsp), %rax
movq %rax, 0xb8(%rsp)
movq 0x1b8(%rsp), %rdi
movq 0x258(%rsp), %rax
movq %rax, 0x198(%rsp)
movsd 0x198(%rsp), %xmm0
callq 0x6d70
movaps %xmm0, 0xc0(%rsp)
jmp 0x5e0b
movq 0x128(%rsp), %rdi
movaps 0xc0(%rsp), %xmm0
movlpd %xmm0, 0x1a0(%rsp)
movsd 0x1a0(%rsp), %xmm0
callq 0x3d20
movaps %xmm0, 0xa0(%rsp)
jmp 0x5e3c
movaps 0xa0(%rsp), %xmm0
movlpd %xmm0, 0x1a8(%rsp)
movsd 0x1a8(%rsp), %xmm0
leaq 0x258(%rsp), %rdi
callq 0x7570
movaps %xmm0, 0x90(%rsp)
jmp 0x5e6d
movq 0xb8(%rsp), %rdi
movq 0x128(%rsp), %rax
movaps 0x90(%rsp), %xmm0
movlpd %xmm0, 0x1b0(%rsp)
movss 0x13d0(%rax), %xmm1
movss 0x1062e(%rip), %xmm0    # 0x164cc
mulss %xmm0, %xmm1
movsd 0x1b0(%rsp), %xmm0
callq 0x11c00
jmp 0x5eb2
leaq 0x210(%rsp), %rdi
leaq 0x1c4(%rsp), %rsi
callq 0x7430
movq %rax, 0x88(%rsp)
jmp 0x5ed1
movq 0x88(%rsp), %rax
movq %rax, 0x190(%rsp)
leaq 0x210(%rsp), %rdi
callq 0x75e0
movq %rax, 0x188(%rsp)
leaq 0x190(%rsp), %rdi
leaq 0x188(%rsp), %rsi
callq 0x75c0
testb $0x1, %al
jne 0x5f14
jmp 0x6148
leaq 0x190(%rsp), %rdi
callq 0x7460
movq 0x8(%rax), %rax
movq %rax, 0x180(%rsp)
movq 0x180(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x1b8(%rsp), %rax
movq %rax, 0x68(%rsp)
movq (%rax), %rax
movq %rax, 0x160(%rsp)
movsd 0x160(%rsp), %xmm0
leaq 0x258(%rsp), %rdi
callq 0x6d70
movaps %xmm0, 0x70(%rsp)
jmp 0x5f6f
movq 0x128(%rsp), %rdi
movaps 0x70(%rsp), %xmm0
movlpd %xmm0, 0x168(%rsp)
movsd 0x168(%rsp), %xmm0
callq 0x3d20
movaps %xmm0, 0x50(%rsp)
jmp 0x5f9a
movq 0x68(%rsp), %rdi
movaps 0x50(%rsp), %xmm0
movlpd %xmm0, 0x170(%rsp)
movsd 0x170(%rsp), %xmm0
callq 0x7570
movaps %xmm0, 0x40(%rsp)
jmp 0x5fc2
movq 0x60(%rsp), %rdi
movq 0x128(%rsp), %rax
movaps 0x40(%rsp), %xmm0
movlpd %xmm0, 0x178(%rsp)
movss 0x13d0(%rax), %xmm1
addss %xmm1, %xmm1
movsd 0x178(%rsp), %xmm0
callq 0x11c00
jmp 0x5ff9
movq 0x180(%rsp), %rdi
callq 0x7610
movb %al, 0x3f(%rsp)
jmp 0x600c
movb 0x3f(%rsp), %al
testb $0x1, %al
jne 0x6019
jmp 0x6121
movq 0x190(%rsp), %rax
movq %rax, 0x158(%rsp)
movq 0x158(%rsp), %rsi
leaq 0x210(%rsp), %rdi
callq 0x7630
movq %rax, 0x30(%rsp)
jmp 0x6045
movq 0x30(%rsp), %rax
movq %rax, 0x150(%rsp)
movl 0x1c4(%rsp), %esi
leaq 0x208(%rsp), %rdi
callq 0x7670
jmp 0x6068
movq 0x180(%rsp), %rax
movq %rax, 0x28(%rsp)
cmpq $0x0, %rax
je 0x6094
movq 0x28(%rsp), %rdi
callq 0x11bc0
movq 0x28(%rsp), %rdi
movl $0x10, %esi
callq 0x21b0
jmp 0x6146
movq 0x130(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
movl $0x10, %esi
callq 0x21b0
jmp 0x62a7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
jmp 0x629a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
jmp 0x628d
movq 0xd8(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
movl $0x10, %esi
callq 0x21b0
jmp 0x628d
movl 0x1c4(%rsp), %esi
movq 0x180(%rsp), %rax
movss 0xc(%rax), %xmm0
leaq 0x208(%rsp), %rdi
callq 0x7870
jmp 0x6144
jmp 0x6146
jmp 0x6148
jmp 0x614a
leaq 0x1d8(%rsp), %rdi
xorl %esi, %esi
callq 0x7960
movq %rax, 0x148(%rsp)
jmp 0x5d57
movq 0x128(%rsp), %rdi
movq 0x258(%rsp), %rax
movq %rax, 0x140(%rsp)
movsd 0x140(%rsp), %xmm0
callq 0x3f10
jmp 0x618e
movq 0x250(%rsp), %rdi
callq 0x7610
movb %al, 0x27(%rsp)
jmp 0x61a1
movb 0x27(%rsp), %al
testb $0x1, %al
jne 0x6238
jmp 0x61af
movq 0x128(%rsp), %rdi
movq 0x250(%rsp), %rax
movq %rax, 0x10(%rsp)
addq $0x13b8, %rdi           # imm = 0x13B8
callq 0x3970
decl %eax
movl %eax, 0x13c(%rsp)
leaq 0x210(%rsp), %rdi
leaq 0x13c(%rsp), %rsi
callq 0x6f70
movq %rax, 0x18(%rsp)
jmp 0x61f5
movq 0x128(%rsp), %rdi
movq 0x18(%rsp), %rax
movq 0x10(%rsp), %rcx
movq %rcx, (%rax)
addq $0x13b8, %rdi           # imm = 0x13B8
callq 0x3970
movl %eax, %esi
decl %esi
movq 0x250(%rsp), %rax
movss 0xc(%rax), %xmm0
leaq 0x208(%rsp), %rdi
callq 0x7060
jmp 0x6236
jmp 0x6266
movq 0x250(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x6264
movq 0x8(%rsp), %rdi
callq 0x11bc0
movq 0x8(%rsp), %rdi
movl $0x10, %esi
callq 0x21b0
jmp 0x6266
jmp 0x5b88
leaq 0x208(%rsp), %rdi
callq 0x79a0
leaq 0x210(%rsp), %rdi
callq 0x79f0
addq $0x268, %rsp            # imm = 0x268
retq
leaq 0x208(%rsp), %rdi
callq 0x79a0
leaq 0x210(%rsp), %rdi
callq 0x79f0
movq 0x248(%rsp), %rdi
callq 0x22f0
nopw %cs:(%rax,%rax)