// File: ddunbar[P]PDSample/ScallopedSector.cpp
// Function: ScallopedRegion::subtractDisk(Vec2, float)
void ScallopedRegion::subtractDisk(Vec2 C, float r)
{
	std::vector<ScallopedSector> *newRegions = new std::vector<ScallopedSector>;

	area = 0;
	for (unsigned int i=0; i<regions->size(); i++) {
		ScallopedSector &ss = (*regions)[i];
		std::vector<ScallopedSector> *tmp = new std::vector<ScallopedSector>;

		ss.subtractDisk(C, r, tmp);

		for (unsigned int j=0; j<tmp->size(); j++) {
			ScallopedSector &nss = (*tmp)[j];

			if (nss.area>minArea) {
				area += nss.area;

				if (newRegions->size()) {
					ScallopedSector &last = (*newRegions)[newRegions->size()-1];
					if (last.a2==nss.a1 && (last.arcs[0].P==nss.arcs[0].P && last.arcs[0].r==nss.arcs[0].r && last.arcs[0].sign==nss.arcs[0].sign) &&
						(last.arcs[1].P==nss.arcs[1].P && last.arcs[1].r==nss.arcs[1].r && last.arcs[1].sign==nss.arcs[1].sign)) {
						last.a2 = nss.a2;
						last.area = last.calcAreaToAngle(last.a2);
						continue;
					}
				}

				newRegions->push_back(nss);
			}
		}

		delete tmp;
	}

	delete regions;
	regions = newRegions;
}

// Assembly:
subq $0x98, %rsp
movlpd %xmm0, 0x90(%rsp)
movq %rdi, 0x88(%rsp)
movss %xmm1, 0x84(%rsp)
movq 0x88(%rsp), %rax
movq %rax, 0x40(%rsp)
movl $0x18, %edi
callq 0x21a0
movq %rax, %rdi
movq %rdi, 0x38(%rsp)
callq 0x12510
movq 0x38(%rsp), %rcx
movq 0x40(%rsp), %rax
movq %rcx, 0x78(%rsp)
xorps %xmm0, %xmm0
movss %xmm0, 0xc(%rax)
movl $0x0, 0x74(%rsp)
movq 0x40(%rsp), %rax
movl 0x74(%rsp), %ecx
movq %rcx, 0x30(%rsp)
movq (%rax), %rdi
callq 0x80b0
movq %rax, %rcx
movq 0x30(%rsp), %rax
cmpq %rcx, %rax
jae 0x11efa
movq 0x40(%rsp), %rax
movq (%rax), %rdi
movl 0x74(%rsp), %eax
movl %eax, %esi
callq 0x12520
movq %rax, 0x68(%rsp)
movl $0x18, %edi
callq 0x21a0
movq %rax, %rdi
movq %rdi, 0x28(%rsp)
callq 0x12510
movq 0x28(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x68(%rsp), %rdi
movss 0x84(%rsp), %xmm0
movq 0x60(%rsp), %rdx
leaq 0x90(%rsp), %rsi
callq 0x10e60
movl $0x0, 0x5c(%rsp)
movl 0x5c(%rsp), %eax
movq %rax, 0x20(%rsp)
movq 0x60(%rsp), %rdi
callq 0x80b0
movq %rax, %rcx
movq 0x20(%rsp), %rax
cmpq %rcx, %rax
jae 0x11ebf
movq 0x60(%rsp), %rdi
movl 0x5c(%rsp), %eax
movl %eax, %esi
callq 0x12520
movq %rax, %rcx
movq 0x40(%rsp), %rax
movq %rcx, 0x50(%rsp)
movq 0x50(%rsp), %rcx
movss 0x10(%rcx), %xmm0
ucomiss 0x8(%rax), %xmm0
jbe 0x11ead
movq 0x40(%rsp), %rax
movq 0x50(%rsp), %rcx
movss 0x10(%rcx), %xmm0
addss 0xc(%rax), %xmm0
movss %xmm0, 0xc(%rax)
movq 0x78(%rsp), %rdi
callq 0x80b0
cmpq $0x0, %rax
je 0x11e9e
movq 0x78(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x78(%rsp), %rdi
callq 0x80b0
movq 0x18(%rsp), %rdi
movq %rax, %rsi
subq $0x1, %rsi
callq 0x12520
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rax
movss 0xc(%rax), %xmm0
movq 0x50(%rsp), %rax
ucomiss 0x8(%rax), %xmm0
jne 0x11e9c
jp 0x11e9c
movq 0x48(%rsp), %rdi
addq $0x14, %rdi
movq 0x50(%rsp), %rsi
addq $0x14, %rsi
callq 0x125a0
testb $0x1, %al
jne 0x11dd7
jmp 0x11e9c
movq 0x48(%rsp), %rax
movss 0x1c(%rax), %xmm0
movq 0x50(%rsp), %rax
ucomiss 0x1c(%rax), %xmm0
jne 0x11e9c
jp 0x11e9c
movq 0x48(%rsp), %rax
movss 0x20(%rax), %xmm0
movq 0x50(%rsp), %rax
ucomiss 0x20(%rax), %xmm0
jne 0x11e9c
jp 0x11e9c
movq 0x48(%rsp), %rdi
addq $0x14, %rdi
addq $0x24, %rdi
movq 0x50(%rsp), %rsi
addq $0x14, %rsi
addq $0x24, %rsi
callq 0x125a0
testb $0x1, %al
jne 0x11e3a
jmp 0x11e9c
movq 0x48(%rsp), %rax
movss 0x40(%rax), %xmm0
movq 0x50(%rsp), %rax
ucomiss 0x40(%rax), %xmm0
jne 0x11e9c
jp 0x11e9c
movq 0x48(%rsp), %rax
movss 0x44(%rax), %xmm0
movq 0x50(%rsp), %rax
ucomiss 0x44(%rax), %xmm0
jne 0x11e9c
jp 0x11e9c
movq 0x50(%rsp), %rax
movss 0xc(%rax), %xmm0
movq 0x48(%rsp), %rax
movss %xmm0, 0xc(%rax)
movq 0x48(%rsp), %rdi
movq 0x48(%rsp), %rax
movss 0xc(%rax), %xmm0
callq 0x107c0
movq 0x48(%rsp), %rax
movss %xmm0, 0x10(%rax)
jmp 0x11eaf
jmp 0x11e9e
movq 0x78(%rsp), %rdi
movq 0x50(%rsp), %rsi
callq 0x125f0
jmp 0x11eaf
movl 0x5c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x5c(%rsp)
jmp 0x11cec
movq 0x60(%rsp), %rax
movq %rax, 0x10(%rsp)
cmpq $0x0, %rax
je 0x11ee8
movq 0x10(%rsp), %rdi
callq 0x12540
movq 0x10(%rsp), %rdi
movl $0x18, %esi
callq 0x21b0
jmp 0x11eea
movl 0x74(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x74(%rsp)
jmp 0x11c64
movq 0x40(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x11f26
movq 0x8(%rsp), %rdi
callq 0x12540
movq 0x8(%rsp), %rdi
movl $0x18, %esi
callq 0x21b0
movq 0x40(%rsp), %rax
movq 0x78(%rsp), %rcx
movq %rcx, (%rax)
addq $0x98, %rsp
retq
nopl (%rax,%rax)