// File: ddunbar[P]PDSample/PDSampling.cpp
// Function: PDSampler::PDSampler(float, bool, bool)
PDSampler::PDSampler(float _radius, bool _isTiled, bool usesGrid) :
	m_rng((unsigned long) (timeInSeconds()*1000)),
	radius(_radius),
	isTiled(_isTiled)
{
	if (usesGrid) {
			// grid size is chosen so that 4*radius search only 
			// requires searching adjacent cells, this also
			// determines max points per cell
		m_gridSize = (int) ceil(2./(4.*_radius));
		if (m_gridSize<2) m_gridSize = 2;

		m_gridCellSize = 2.0f/m_gridSize;
		m_grid = new int[m_gridSize*m_gridSize][kMaxPointsPerCell];

		for (int y=0; y<m_gridSize; y++) {
			for (int x=0; x<m_gridSize; x++) {
				for (int k=0; k<kMaxPointsPerCell; k++) {
					m_grid[y*m_gridSize + x][k] = -1;
				}
			}
		}
	} else {
		m_gridSize = 0;
		m_gridCellSize = 0;
		m_grid = 0;
	}
}

// Assembly:
subq $0x58, %rsp
movb %dl, %al
movb %sil, %cl
movq %rdi, 0x50(%rsp)
movss %xmm0, 0x4c(%rsp)
andb $0x1, %cl
movb %cl, 0x4b(%rsp)
andb $0x1, %al
movb %al, 0x4a(%rsp)
movq 0x50(%rsp), %rax
movq %rax, 0x28(%rsp)
leaq 0x1c166(%rip), %rcx     # 0x1fb48
movq %rcx, (%rax)
addq $0x8, %rax
movq %rax, 0x10(%rsp)
callq 0x2e70
movq 0x10(%rsp), %rdi
movsd 0x12a38(%rip), %xmm1    # 0x16438
mulsd %xmm1, %xmm0
movaps %xmm0, %xmm1
cvttsd2si %xmm1, %rsi
movq %rsi, %rcx
sarq $0x3f, %rcx
movsd 0x12a25(%rip), %xmm1    # 0x16440
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
andq %rcx, %rax
orq %rax, %rsi
callq 0x26e0
movq 0x28(%rsp), %rdi
addq $0x1390, %rdi           # imm = 0x1390
movq %rdi, 0x18(%rsp)
callq 0x6a80
movq 0x28(%rsp), %rdi
addq $0x13b8, %rdi           # imm = 0x13B8
movq %rdi, 0x20(%rsp)
callq 0x6a90
movq 0x28(%rsp), %rax
movss 0x4c(%rsp), %xmm0
movss %xmm0, 0x13d0(%rax)
movb 0x4b(%rsp), %cl
andb $0x1, %cl
movb %cl, 0x13d4(%rax)
testb $0x1, 0x4a(%rsp)
je 0x3bf4
movss 0x4c(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x129b8(%rip), %xmm1    # 0x16450
mulsd %xmm0, %xmm1
movsd 0x129a4(%rip), %xmm0    # 0x16448
divsd %xmm1, %xmm0
callq 0x2060
movq 0x28(%rsp), %rax
cvttsd2si %xmm0, %ecx
movl %ecx, 0x13b0(%rax)
cmpl $0x2, 0x13b0(%rax)
jge 0x3ad4
movq 0x28(%rsp), %rax
movl $0x2, 0x13b0(%rax)
movq 0x28(%rsp), %rax
cvtsi2ssl 0x13b0(%rax), %xmm1
movss 0x129d7(%rip), %xmm0    # 0x164c0
divss %xmm1, %xmm0
movss %xmm0, 0x13b4(%rax)
movl 0x13b0(%rax), %eax
imull %eax, %eax
shlq $0x2, %rax
leaq (%rax,%rax,8), %rdi
callq 0x2030
movq %rax, 0x8(%rsp)
jmp 0x3b12
movq 0x28(%rsp), %rax
movq 0x8(%rsp), %rcx
movq %rcx, 0x13a8(%rax)
movl $0x0, 0x38(%rsp)
movq 0x28(%rsp), %rcx
movl 0x38(%rsp), %eax
cmpl 0x13b0(%rcx), %eax
jge 0x3bf2
movl $0x0, 0x34(%rsp)
movq 0x28(%rsp), %rcx
movl 0x34(%rsp), %eax
cmpl 0x13b0(%rcx), %eax
jge 0x3be0
movl $0x0, 0x30(%rsp)
cmpl $0x9, 0x30(%rsp)
jge 0x3bce
movq 0x28(%rsp), %rdx
movq 0x13a8(%rdx), %rax
movl 0x38(%rsp), %ecx
imull 0x13b0(%rdx), %ecx
addl 0x34(%rsp), %ecx
movslq %ecx, %rcx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movslq 0x30(%rsp), %rcx
movl $0xffffffff, (%rax,%rcx,4) # imm = 0xFFFFFFFF
movl 0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x30(%rsp)
jmp 0x3b65
movq 0x20(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x40(%rsp)
movl %eax, 0x3c(%rsp)
callq 0x6aa0
movq 0x18(%rsp), %rdi
callq 0x6b00
jmp 0x3c1e
jmp 0x3bd0
movl 0x34(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x34(%rsp)
jmp 0x3b48
jmp 0x3be2
movl 0x38(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
jmp 0x3b2b
jmp 0x3c19
movq 0x28(%rsp), %rax
movl $0x0, 0x13b0(%rax)
xorps %xmm0, %xmm0
movss %xmm0, 0x13b4(%rax)
movq $0x0, 0x13a8(%rax)
addq $0x58, %rsp
retq
movq 0x40(%rsp), %rdi
callq 0x22f0
nopl (%rax,%rax)