// File: /workspace/github_cpp_makefile_star2_O2/wrighteagle2d[P]wrighteaglebase/Debug/../src/VisualSystem.cpp
// Function: VisualSystem::VisualRing::GetBestVisualAction(double, double, double)
VisualSystem::VisualAction
VisualSystem::VisualRing::GetBestVisualAction(const AngleDeg left_most,
                                              const AngleDeg right_most,
                                              const AngleDeg interval_length) {
  //区间定义成： [left, right]
  AngleDeg left = left_most;
  AngleDeg right = left;

  double sum = 0.0;

  for (; right < left + interval_length; ++right) {
    sum += Score(right);
  }
  sum += Score(right);

  double max = sum;
  AngleDeg best = (left + right) * 0.5;

  for (; right < right_most; ++right, ++left) {
    AngleDeg in = (Score(right + 1) - Score(left));

    sum += in;

    if (in < FLOAT_EPS)
      continue;

    if (sum > max) {
      max = sum;

      AngleDeg alpha = left + 1;
      while (Score(alpha) < FLOAT_EPS && alpha < right_most)
        alpha++;
      AngleDeg beta = right + 1;
      while (Score(beta) < FLOAT_EPS && beta > alpha)
        beta--;
      best = (alpha + beta) * 0.5;
    }
  }

  return VisualAction(best, max);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x50, %rsp
movsd %xmm1, -0x60(%rbp)
movq %rdi, %rbx
movsd %xmm0, -0x50(%rbp)
addsd %xmm0, %xmm2
movsd %xmm2, -0x58(%rbp)
xorpd %xmm1, %xmm1
movsd %xmm1, -0x28(%rbp)
leaq -0x38(%rbp), %r14
movsd %xmm0, -0x40(%rbp)
movapd %xmm0, %xmm4
movsd %xmm4, -0x30(%rbp)
movsd %xmm4, -0x38(%rbp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4beb4
movsd -0x58(%rbp), %xmm0
ucomisd -0x30(%rbp), %xmm0
movsd -0x28(%rbp), %xmm0
addsd (%rax), %xmm0
movsd %xmm0, -0x28(%rbp)
movsd -0x38(%rbp), %xmm4
jbe 0x4b835
addsd 0xb815(%rip), %xmm4     # 0x57048
jmp 0x4b7f7
movsd -0x40(%rbp), %xmm2
addsd %xmm4, %xmm2
mulsd 0xc002(%rip), %xmm2     # 0x57848
leaq -0x48(%rbp), %r14
leaq -0x50(%rbp), %r15
leaq -0x68(%rbp), %r12
movsd -0x28(%rbp), %xmm3
movsd -0x60(%rbp), %xmm0
ucomisd %xmm4, %xmm0
jbe 0x4b99b
movsd %xmm2, -0x40(%rbp)
addsd 0xb7d5(%rip), %xmm4     # 0x57048
movsd %xmm4, -0x48(%rbp)
movq %rbx, %rdi
movq %r14, %rsi
movsd %xmm3, -0x30(%rbp)
callq 0x4beb4
movsd (%rax), %xmm0
movsd %xmm0, -0x58(%rbp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4beb4
movsd -0x30(%rbp), %xmm3
movsd -0x58(%rbp), %xmm1
subsd (%rax), %xmm1
addsd %xmm1, %xmm3
movsd 0xb78a(%rip), %xmm0     # 0x57040
ucomisd %xmm1, %xmm0
ja 0x4b96d
ucomisd -0x28(%rbp), %xmm3
movsd -0x40(%rbp), %xmm2
jbe 0x4b972
movsd %xmm3, -0x30(%rbp)
movsd -0x50(%rbp), %xmm0
addsd 0xb766(%rip), %xmm0     # 0x57048
movsd %xmm0, -0x48(%rbp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4beb4
movsd 0xb746(%rip), %xmm0     # 0x57040
ucomisd (%rax), %xmm0
jbe 0x4b910
movsd -0x48(%rbp), %xmm0
movsd -0x60(%rbp), %xmm1
ucomisd %xmm0, %xmm1
ja 0x4b8da
movsd -0x38(%rbp), %xmm2
addsd 0xb72b(%rip), %xmm2     # 0x57048
movsd %xmm2, -0x68(%rbp)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x4beb4
movsd 0xb70b(%rip), %xmm0     # 0x57040
ucomisd (%rax), %xmm0
movsd -0x68(%rbp), %xmm2
movsd -0x48(%rbp), %xmm0
jbe 0x4b955
ucomisd %xmm0, %xmm2
jbe 0x4b955
addsd 0xb71d(%rip), %xmm2     # 0x57070
jmp 0x4b91d
addsd %xmm0, %xmm2
mulsd 0xbee7(%rip), %xmm2     # 0x57848
movsd -0x30(%rbp), %xmm3
movsd %xmm3, -0x28(%rbp)
jmp 0x4b972
movsd -0x40(%rbp), %xmm2
movsd -0x38(%rbp), %xmm4
movsd 0xb6c9(%rip), %xmm1     # 0x57048
addsd %xmm1, %xmm4
movsd %xmm4, -0x38(%rbp)
movsd -0x50(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
jmp 0x4b857
movapd %xmm2, %xmm0
movsd -0x28(%rbp), %xmm1
addq $0x50, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nop