// File: /workspace/github_cpp_makefile_star2_O2/icemiliang[P]vot/src/vot/unitcell.cc
// Function: voro::unitcell::unitcell(double, double, double, double, double, double)
unitcell::unitcell(double bx_,double bxy_,double by_,double bxz_,double byz_,double bz_)
	: bx(bx_), bxy(bxy_), by(by_), bxz(bxz_), byz(byz_), bz(bz_) {
	int i,j,l=1;

	// Initialize the Voronoi cell to be a very large rectangular box
	const double ucx=max_unit_voro_shells*bx,ucy=max_unit_voro_shells*by,ucz=max_unit_voro_shells*bz;
	unit_voro.init(-ucx,ucx,-ucy,ucy,-ucz,ucz);

	// Repeatedly cut the cell by shells of periodic image particles
	while(l<2*max_unit_voro_shells) {

		// Check to see if any of the planes from the current shell
		// will cut the cell
		if(unit_voro_intersect(l)) {

			// If they do, apply the plane cuts from the current
			// shell
			unit_voro_apply(l,0,0);
			for(i=1;i<l;i++) {
				unit_voro_apply(l,i,0);
				unit_voro_apply(-l,i,0);
			}
			for(i=-l;i<=l;i++) unit_voro_apply(i,l,0);
			for(i=1;i<l;i++) for(j=-l+1;j<=l;j++) {
				unit_voro_apply(l,j,i);
				unit_voro_apply(-j,l,i);
				unit_voro_apply(-l,-j,i);
				unit_voro_apply(j,-l,i);
			}
			for(i=-l;i<=l;i++) for(j=-l;j<=l;j++) unit_voro_apply(i,j,l);
		} else {

			// Calculate a bound on the maximum y and z coordinates
			// that could possibly cut the cell. This is based upon
			// a geometric result that particles with z>l can't cut
			// a cell lying within the paraboloid
			// z<=(l*l-x*x-y*y)/(2*l). It is always a tighter bound
			// than the one based on computing the maximum radius
			// of a Voronoi cell vertex.
			max_uv_y=max_uv_z=0;
			double y,z,q,*pts=unit_voro.pts,*pp=pts;
			while(pp<pts+3*unit_voro.p) {
				q=*(pp++);y=*(pp++);z=*(pp++);q=sqrt(q*q+y*y+z*z);
				if(y+q>max_uv_y) max_uv_y=y+q;
				if(z+q>max_uv_z) max_uv_z=z+q;
			}
			max_uv_z*=0.5;
			max_uv_y*=0.5;
			return;
		}
		l++;
	}

	// If the routine makes it here, then the unit cell still hasn't been
	// completely bounded by the plane cuts. Give the memory error code,
	// because this is mainly a case of hitting a safe limit, than any
	// inherent problem.
	voro_fatal_error("Periodic cell computation failed",VOROPP_MEMORY_ERROR);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
movsd %xmm0, (%rdi)
movsd %xmm1, 0x8(%rdi)
movsd %xmm2, 0x10(%rdi)
movsd %xmm3, 0x18(%rdi)
movsd %xmm4, 0x20(%rdi)
movsd %xmm5, 0x28(%rdi)
leaq 0x30(%rdi), %r14
movq %r14, %rdi
callq 0xf846
movsd 0xd03a(%rip), %xmm5     # 0x490b8
movsd (%rbx), %xmm1
mulsd %xmm5, %xmm1
movsd 0x10(%rbx), %xmm3
mulsd %xmm5, %xmm3
mulsd 0x28(%rbx), %xmm5
movapd 0x2ac4(%rip), %xmm4     # 0x3eb60
movapd %xmm1, %xmm0
xorpd %xmm4, %xmm0
movapd %xmm3, %xmm2
xorpd %xmm4, %xmm2
xorpd %xmm5, %xmm4
movq %r14, 0x20(%rsp)
movq %r14, %rdi
callq 0x171ca
pushq $0x1
popq %r12
pushq $-0x3
popq %rax
movq %rax, 0x10(%rsp)
pushq $0x2
popq %rax
movl $0x0, 0x4(%rsp)
xorl %r13d, %r13d
movl %eax, 0xc(%rsp)
movl %eax, %r14d
movl %r12d, (%rsp)
cmpl $0x15, %r14d
je 0x3c24f
movq %rbx, %rdi
movl (%rsp), %esi
callq 0x3c350
testb %al, %al
je 0x3c26c
movq %rbx, %rdi
movl (%rsp), %ebp
movl %ebp, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x3ce3a
movl %r14d, 0x8(%rsp)
movl %ebp, %r15d
negl %r15d
movl %r12d, %r14d
leal (%r14,%r13), %eax
cmpl $0x1, %eax
je 0x3c14b
movq %rbx, %rdi
movl %ebp, %esi
movl %r14d, %edx
xorl %ecx, %ecx
callq 0x3ce3a
movq %rbx, %rdi
movl %r15d, %esi
movl %r14d, %edx
xorl %ecx, %ecx
callq 0x3ce3a
incl %r14d
jmp 0x3c11e
pushq $-0x1
popq %rax
movl %eax, %r14d
movq 0x10(%rsp), %rax
addl %r14d, %eax
cmpl $-0x1, %eax
je 0x3c173
leal (%r14,%r13), %esi
movq %rbx, %rdi
movl %ebp, %edx
xorl %ecx, %ecx
callq 0x3ce3a
incl %r14d
jmp 0x3c151
movq %r13, 0x18(%rsp)
cmpl %ebp, %r12d
je 0x3c1e6
xorl %ebp, %ebp
movl 0x4(%rsp), %r13d
cmpl %ebp, 0xc(%rsp)
je 0x3c1de
movq 0x18(%rsp), %rax
leal (%rax,%rbp), %r14d
movq %rbx, %rdi
movl (%rsp), %esi
movl %r14d, %edx
movl %r12d, %ecx
callq 0x3ce3a
movq %rbx, %rdi
movl %r13d, %esi
movl (%rsp), %edx
movl %r12d, %ecx
callq 0x3ce3a
movq %rbx, %rdi
movl %r15d, %esi
movl %r13d, %edx
movl %r12d, %ecx
callq 0x3ce3a
movq %rbx, %rdi
movl %r14d, %esi
movl %r15d, %edx
movl %r12d, %ecx
callq 0x3ce3a
incl %ebp
decl %r13d
jmp 0x3c184
incl %r12d
movl (%rsp), %ebp
jmp 0x3c178
pushq $0x1
popq %r12
movq 0x18(%rsp), %r13
cmpl 0x8(%rsp), %r15d
je 0x3c224
pushq $-0x1
popq %rax
movl %eax, %r14d
movq 0x10(%rsp), %rax
addl %r14d, %eax
cmpl $-0x1, %eax
je 0x3c21f
leal (%r14,%r13), %edx
movq %rbx, %rdi
movl %r15d, %esi
movl %ebp, %ecx
callq 0x3ce3a
incl %r14d
jmp 0x3c1fc
incl %r15d
jmp 0x3c1ef
incl %ebp
movl %ebp, (%rsp)
movl 0x8(%rsp), %r14d
incl %r14d
decl %r13d
movq 0x10(%rsp), %rax
addl $-0x2, %eax
movq %rax, 0x10(%rsp)
addl $0x2, 0xc(%rsp)
incl 0x4(%rsp)
jmp 0x3c0e2
leaq 0xce6a(%rip), %rdi      # 0x490c0
pushq $0x2
popq %rsi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1c1ae
leaq 0xd0(%rbx), %rax
xorpd %xmm0, %xmm0
movupd %xmm0, 0xd0(%rbx)
movq 0x60(%rbx), %rsi
movslq 0x48(%rbx), %rcx
imulq $0x18, %rcx, %rcx
addq %rsi, %rcx
xorpd %xmm1, %xmm1
xorpd %xmm0, %xmm0
cmpq %rcx, %rsi
jae 0x3c301
movq %rsi, %rdx
movsd (%rsi), %xmm4
movsd 0x8(%rsi), %xmm3
movsd 0x10(%rsi), %xmm2
movapd %xmm3, %xmm5
mulsd %xmm3, %xmm5
mulsd %xmm4, %xmm4
addsd %xmm5, %xmm4
movapd %xmm2, %xmm5
mulsd %xmm2, %xmm5
addsd %xmm4, %xmm5
sqrtsd %xmm5, %xmm4
addsd %xmm4, %xmm3
ucomisd %xmm0, %xmm3
jbe 0x3c2de
movsd %xmm3, (%rax)
movapd %xmm3, %xmm0
addsd %xmm4, %xmm2
leaq 0x18(%rdx), %rsi
ucomisd %xmm1, %xmm2
jbe 0x3c296
addq $0x18, %rdx
movsd %xmm2, 0xd8(%rbx)
movapd %xmm2, %xmm1
movq %rdx, %rsi
jmp 0x3c296
movsd 0x81af(%rip), %xmm2     # 0x444b8
mulsd %xmm2, %xmm1
movsd %xmm1, 0xd8(%rbx)
mulsd %xmm2, %xmm0
movsd %xmm0, 0xd0(%rbx)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3c33a
jmp 0x3c33a
jmp 0x3c33a
jmp 0x3c33a
jmp 0x3c33a
movq %rax, %rbx
movq 0x20(%rsp), %rdi
callq 0x16e1a
movq %rbx, %rdi
callq 0x76c0
nop