// File: /workspace/github_cpp_makefile_star2_O2/intheswim[P]FractalTubes/m3d.cpp
// Function: M3DDrawer::SetGlobals(ShapeParams*, DrawParams*)
long M3DDrawer::SetGlobals (struct ShapeParams *sp, struct DrawParams *dp)
{
    //double k = 1.414213562373095048801688724209698078;
	double k = sqrt (2.0) ;

	double incircle = (floor)(k * (2 * M_PI * sp->l) + 0.5);
	double cycles = k * hypot ((sp->r + sp->l) * sp->alpha_range, sp->y_range);
    
    exposed_y_range = sp->y_range / sp->r;
    
	//double cycles_in2pi = 2 * M_PI * cycles / sp->alpha_range;
    
    // Jan 2015 we need this for the mesh:
    m_points_in_cycle = (int)incircle;
    
    /*  if ((m_points_in_cycle & 1) != 0)
    {
        m_points_in_cycle++;
        incircle = m_points_in_cycle;
    } */
    
	sp->total_points = incircle * cycles;
    
	sp->delta_y = sp->y_range / sp->total_points;
	sp->delta_alpha = sp->alpha_range / sp->total_points;
	//sp->coef = hypot (2*PI * (sp->r + sp->l), sp->y_range * (2 * PI/sp->alpha_range)) ;
    
	//sp->coef = 2 * PI * (sp->l + sp->r);
	sp->coef = 2 * M_PI * cycles / sp->alpha_range;
	//sp->coef = cycles * PI * 2 * sp->l/ sp->alpha_range; //cycles_in2pi;
    
	if (dp->method == 0)
    {
		if (dp->max_radius < 0)
			dp->max_radius = dp->xRadius / (pow ((double)POWER_BASE, (double)(POWER_RANGE + POWER_ADD) * dp->stretchRatio));
		else //f (dp->stretchRatio == 0)
        {
			double t = log (dp->max_radius / dp->xRadius);
			dp->stretchRatio = (t / log (1/POWER_BASE)) / (POWER_RANGE + POWER_ADD);
        }
    }
    
	if (dp->method == 1) // two points
    {
		dp->steps1 = log (dp->max_radius / dp->xRadius) / log (1/POWER_BASE) - POWER_ADD;
		dp->steps2 = log (dp->max_radius / dp->xRadius2) / log (1/POWER_BASE) - POWER_ADD;
    }
    
    m_total_points = sp->total_points;
    
	return sp->total_points;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x60, %rsp
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %rbx
movsd 0x10(%rsi), %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0x48(%rsi), %xmm0
movsd %xmm0, 0x20(%rsp)
mulsd 0x2a44(%rip), %xmm0     # 0x94b0
mulsd 0x2a44(%rip), %xmm0     # 0x94b8
addsd 0x27dc(%rip), %xmm0     # 0x9258
callq 0x35a0
movsd %xmm0, 0x28(%rsp)
movsd 0x20(%rsp), %xmm0
addsd 0x40(%r14), %xmm0
mulsd 0x18(%r14), %xmm0
movsd 0x10(%rsp), %xmm1
callq 0x3100
movsd 0x10(%r14), %xmm1
movapd %xmm1, %xmm2
divsd 0x40(%r14), %xmm2
cvtsd2ss %xmm2, %xmm2
mulsd 0x29f8(%rip), %xmm0     # 0x94b8
movss %xmm2, 0x28(%rbx)
movsd 0x28(%rsp), %xmm2
cvttsd2si %xmm2, %eax
movl %eax, 0x60(%rbx)
mulsd %xmm0, %xmm2
cvttsd2si %xmm2, %rax
movq %rax, (%r14)
cvtsi2sd %rax, %xmm2
divsd %xmm2, %xmm1
movsd %xmm1, 0x58(%rsp)
fldl 0x58(%rsp)
fstpt 0x20(%r14)
movsd 0x18(%r14), %xmm1
mulsd 0x29ad(%rip), %xmm0     # 0x94b0
divsd %xmm1, %xmm0
divsd %xmm2, %xmm1
movsd %xmm1, 0x48(%rsp)
fldl 0x48(%rsp)
fstpt 0x30(%r14)
movsd %xmm0, 0x50(%rsp)
fldl 0x50(%rsp)
fstpt 0x50(%r14)
movl 0xb8(%r15), %eax
testl %eax, %eax
jne 0x6bc4
movsd 0xb0(%r15), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
jbe 0x6b83
fldt 0x70(%r15)
fstpt 0x10(%rsp)
cvtss2sd 0x30(%r15), %xmm1
mulsd 0x2969(%rip), %xmm1     # 0x94c8
movsd 0x2969(%rip), %xmm0     # 0x94d0
callq 0x35b0
movsd %xmm0, 0x30(%rsp)
fldt 0x10(%rsp)
fdivl 0x30(%rsp)
fstpl 0xb0(%r15)
jmp 0x6bbd
movsd %xmm0, 0x40(%rsp)
fldt 0x70(%r15)
fdivrl 0x40(%rsp)
fstpt (%rsp)
callq 0x3170
fstpl 0x38(%rsp)
movsd 0x38(%rsp), %xmm0
divsd 0x2915(%rip), %xmm0     # 0x94c0
divsd 0x2915(%rip), %xmm0     # 0x94c8
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x30(%r15)
movl 0xb8(%r15), %eax
cmpl $0x1, %eax
jne 0x6c14
fldt 0x70(%r15)
fdivrl 0xb0(%r15)
fstpt (%rsp)
callq 0x3170
fldl 0x28de(%rip)            # 0x94c0
fld %st(0)
fstpt 0x10(%rsp)
fdivrp %st, %st(1)
fstps 0xbc(%r15)
fldt 0xa0(%r15)
fdivrl 0xb0(%r15)
fstpt (%rsp)
callq 0x3170
fldt 0x10(%rsp)
fdivrp %st, %st(1)
fstps 0xc0(%r15)
movq (%r14), %rax
movq %rax, 0x58(%rbx)
addq $0x60, %rsp
popq %rbx
popq %r14
popq %r15
retq
nop