// File: 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
subq $0x90, %rsp
movq %rdi, -0x18(%rbp)
movsd %xmm0, -0x20(%rbp)
movsd %xmm1, -0x28(%rbp)
movsd %xmm2, -0x30(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x80(%rbp)
movsd -0x20(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x40(%rbp), %xmm1
movsd -0x38(%rbp), %xmm0
addsd -0x30(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0xa86b6
movq -0x80(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0xa9500
movsd (%rax), %xmm0
addsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
movsd 0x18966(%rip), %xmm0    # 0xc1010
addsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
jmp 0xa8672
movq -0x80(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0xa9500
movsd (%rax), %xmm0
addsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
movsd -0x38(%rbp), %xmm0
addsd -0x40(%rbp), %xmm0
movsd 0x18933(%rip), %xmm1    # 0xc1020
mulsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x40(%rbp), %xmm1
movsd -0x28(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0xa88b0
movq -0x80(%rbp), %rdi
movsd 0x188fa(%rip), %xmm0    # 0xc1010
addsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
leaq -0x68(%rbp), %rsi
callq 0xa9500
movq -0x80(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x88(%rbp)
leaq -0x38(%rbp), %rsi
callq 0xa9500
movsd -0x88(%rbp), %xmm0
subsd (%rax), %xmm0
movsd %xmm0, -0x60(%rbp)
movsd -0x60(%rbp), %xmm0
addsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
movsd 0x1889e(%rip), %xmm0    # 0xc1008
ucomisd -0x60(%rbp), %xmm0
jbe 0xa8776
jmp 0xa8887
movsd -0x48(%rbp), %xmm0
ucomisd -0x50(%rbp), %xmm0
jbe 0xa8885
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
movsd 0x18878(%rip), %xmm0    # 0xc1010
addsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0xa9500
movq %rax, %rcx
xorl %eax, %eax
movsd 0x1884c(%rip), %xmm0    # 0xc1008
ucomisd (%rcx), %xmm0
movb %al, -0x89(%rbp)
jbe 0xa87df
movsd -0x70(%rbp), %xmm1
movsd -0x28(%rbp), %xmm0
ucomisd %xmm1, %xmm0
seta %al
movb %al, -0x89(%rbp)
movb -0x89(%rbp), %al
testb $0x1, %al
jne 0xa87eb
jmp 0xa87ff
movsd 0x1881d(%rip), %xmm0    # 0xc1010
addsd -0x70(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
jmp 0xa87a2
movsd 0x18809(%rip), %xmm0    # 0xc1010
addsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x78(%rbp)
movq -0x80(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0xa9500
movq %rax, %rcx
xorl %eax, %eax
movsd 0x187dd(%rip), %xmm0    # 0xc1008
ucomisd (%rcx), %xmm0
movb %al, -0x8a(%rbp)
jbe 0xa884a
movsd -0x78(%rbp), %xmm0
ucomisd -0x70(%rbp), %xmm0
seta %al
movb %al, -0x8a(%rbp)
movb -0x8a(%rbp), %al
testb $0x1, %al
jne 0xa8856
jmp 0xa886a
movsd 0x18fca(%rip), %xmm0    # 0xc1828
addsd -0x78(%rbp), %xmm0
movsd %xmm0, -0x78(%rbp)
jmp 0xa8811
movsd -0x70(%rbp), %xmm0
addsd -0x78(%rbp), %xmm0
movsd 0x187a4(%rip), %xmm1    # 0xc1020
mulsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
jmp 0xa8887
movsd 0x18781(%rip), %xmm0    # 0xc1010
addsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movsd 0x1876f(%rip), %xmm0    # 0xc1010
addsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
jmp 0xa86f6
movsd -0x58(%rbp), %xmm0
movsd -0x50(%rbp), %xmm1
leaq -0x10(%rbp), %rdi
callq 0xa8e50
movsd -0x10(%rbp), %xmm0
movsd -0x8(%rbp), %xmm1
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)