// File: /workspace/github_cpp_makefile_star2_O1/Hybryd[P]HyRoadGenerator/Polygon.cpp
// Function: Polygon::split()
std::pair< Polygon,Polygon > Polygon::split()
{
  std::pair<int,Point> pair = randPoint();
  int ed=pair.first; // indice de l'arete contenant le point aleatoire
  Point p=pair.second; // le point aleatoire
  Point v(poly[ed].second.x()-poly[ed].first.x(), poly[ed].second.y()-poly[ed].first.y()); // vecteur arete
  double c=-(v.x()*p.x() + v.y()*p.y()); // le c de l'equation de la droite ax + bx + c =0
  int i=0;
  bool bb=true;
  while (i<size() && bb)
  {
    if(i!=ed)
    {
      // on regarde si pour chaque arete les deux points sont du meme coté de la droite, ie meme signe
      bb = (poly[i].first.x()*v.x() + poly[i].first.y()*v.y() + c)*(poly[i].second.x()*v.x() + poly[i].second.y()*v.y() + c) > 0;
    }
    if(bb)
    {
      ++i;
    }
  }
  double denom=(v.x()*(poly[i].second.x()-poly[i].first.x()) + v.y()*(poly[i].second.y()-poly[i].first.y()));
  double t=0;
  if(denom != 0)
  {
    t=-(v.x()*poly[i].first.x() + v.y()*poly[i].first.y() + c)/denom;
  }
  else
  {
    std::cerr << " PROBLEME DENOMINATEUR NUL " << std::endl; // impossible to get here
  }
  
  
  Point intersec(poly[i].first.x() + t*(poly[i].second.x() - poly[i].first.x() ), poly[i].first.y() + t*(poly[i].second.y() - poly[i].first.y() )  );
  
  
  Polygon p1,p2;
  
  // split de l'arete de depart
  std::pair< Point,Point > ed1(p,poly[ed].second);
  std::pair< Point,Point > ed2(poly[ed].first,p);
  
  // split de l'arete d'intersection
  std::pair< Point,Point > edd1(poly[i].first,intersec);
  std::pair< Point,Point > edd2(intersec,poly[i].second);
  
  // creation du segment [intersec,p] (a inverser pour p2)
  std::pair< Point,Point > pont(intersec,p);
  
  p1.push_back(ed1);
  
  int k=ed;
  if(k==size()-1)
    k=0;
  else
    ++k;
  
  while(k<size() && k != i)
  {
    p1.push_back(poly[k]);
    ++k;
  }
  if(k==size())
  {
    k=0;
    while(k<size() && k != i)
    {
      p1.push_back(poly[k]);
      ++k;
    }
  }
  // on est arrivé en i
  p1.push_back(edd1);
  p1.push_back(pont); // p1 est defini
  

  // on commence p2
  if(k==size()-1)
    k=0;
  else
    ++k;
  
  p2.push_back(edd2);
  while(k<size() && k != ed)
  {
    p2.push_back(poly[k]);
    ++k;
  }
  if(k==size())
  {
    k=0;
    while(k<size() && k != ed)
    {
      p2.push_back(poly[k]);
      ++k;
    }
  }
  // on arrive en ed
  p2.push_back(ed2);
  // on inverse pont
  std::pair< Point,Point > tnop(pont.second,pont.first);
  p2.push_back(tnop);
  
  return std::pair< Polygon,Polygon >(p1,p2);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %rsi, %rbx
movq %rdi, -0xc8(%rbp)
leaq -0xd4(%rbp), %r15
movq %r15, %rdi
callq 0x1984
movslq (%r15), %r12
movss 0x4(%r15), %xmm7
movss 0x8(%r15), %xmm8
movq (%rbx), %rax
movq %r12, %r13
shlq $0x4, %r13
movss 0x8(%rax,%r13), %xmm1
movss 0xc(%rax,%r13), %xmm2
subss (%rax,%r13), %xmm1
subss 0x4(%rax,%r13), %xmm2
movq %rbx, -0x60(%rbp)
movq 0x8(%rbx), %rcx
movaps %xmm8, %xmm0
mulss %xmm2, %xmm0
movaps %xmm1, %xmm3
mulss %xmm7, %xmm3
addss %xmm0, %xmm3
xorps 0x2567(%rip), %xmm3     # 0x4020
xorps %xmm0, %xmm0
cvtss2sd %xmm3, %xmm0
subq %rax, %rcx
shrq $0x4, %rcx
testl %ecx, %ecx
jle 0x1b44
movb $0x1, %dl
xorl %ebx, %ebx
xorps %xmm3, %xmm3
cmpl %r12d, %ebx
je 0x1b2d
movl %ebx, %edx
shlq $0x4, %rdx
movss 0x4(%rax,%rdx), %xmm4
mulss %xmm2, %xmm4
movss (%rax,%rdx), %xmm5
mulss %xmm1, %xmm5
addss %xmm4, %xmm5
xorps %xmm4, %xmm4
cvtss2sd %xmm5, %xmm4
addsd %xmm0, %xmm4
movss 0xc(%rax,%rdx), %xmm5
mulss %xmm2, %xmm5
movss 0x8(%rax,%rdx), %xmm6
mulss %xmm1, %xmm6
addss %xmm5, %xmm6
xorps %xmm5, %xmm5
cvtss2sd %xmm6, %xmm5
addsd %xmm0, %xmm5
mulsd %xmm4, %xmm5
ucomisd %xmm3, %xmm5
seta %dl
movl %edx, %esi
andb $0x1, %sil
movzbl %sil, %esi
addl %esi, %ebx
cmpl %ecx, %ebx
jge 0x1b46
testb $0x1, %dl
jne 0x1ad2
jmp 0x1b46
xorl %ebx, %ebx
movslq %ebx, %r15
shlq $0x4, %r15
movss 0x8(%rax,%r15), %xmm5
movss (%rax,%r15), %xmm3
movss 0x4(%rax,%r15), %xmm4
subss %xmm3, %xmm5
movss 0xc(%rax,%r15), %xmm6
subss %xmm4, %xmm6
mulss %xmm2, %xmm6
mulss %xmm1, %xmm5
addss %xmm6, %xmm5
xorps %xmm6, %xmm6
ucomiss %xmm6, %xmm5
jne 0x1b86
jnp 0x1bac
cvtss2sd %xmm5, %xmm5
mulss %xmm4, %xmm2
mulss %xmm3, %xmm1
addss %xmm2, %xmm1
cvtss2sd %xmm1, %xmm1
addsd %xmm1, %xmm0
xorpd 0x248a(%rip), %xmm0     # 0x4030
divsd %xmm5, %xmm0
jmp 0x1c08
movq 0x543d(%rip), %r14      # 0x6ff0
leaq 0x249e(%rip), %rsi      # 0x4058
movl $0x1b, %edx
movq %r14, %rdi
movss %xmm7, -0x2c(%rbp)
movss %xmm8, -0x38(%rbp)
callq 0x1120
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x10f0
movsbl %al, %esi
movq %r14, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1090
movss -0x38(%rbp), %xmm8
movss -0x2c(%rbp), %xmm7
xorpd %xmm0, %xmm0
movq -0x60(%rbp), %r14
movq (%r14), %rax
movss (%rax,%r15), %xmm1
movss 0x4(%rax,%r15), %xmm2
xorps %xmm3, %xmm3
cvtss2sd %xmm1, %xmm3
movss 0x8(%rax,%r15), %xmm4
subss %xmm1, %xmm4
xorps %xmm1, %xmm1
cvtss2sd %xmm4, %xmm1
mulsd %xmm0, %xmm1
addsd %xmm3, %xmm1
cvtsd2ss %xmm1, %xmm1
xorps %xmm3, %xmm3
cvtss2sd %xmm2, %xmm3
movss 0xc(%rax,%r15), %xmm4
subss %xmm2, %xmm4
xorps %xmm2, %xmm2
cvtss2sd %xmm4, %xmm2
mulsd %xmm0, %xmm2
addsd %xmm3, %xmm2
xorps %xmm0, %xmm0
cvtsd2ss %xmm2, %xmm0
xorl %ecx, %ecx
leaq -0x90(%rbp), %rdi
movq %rcx, 0x10(%rdi)
xorps %xmm2, %xmm2
movaps %xmm2, (%rdi)
movq %rcx, -0x40(%rbp)
movaps %xmm2, -0x50(%rbp)
leaq -0xf4(%rbp), %rsi
movss %xmm7, (%rsi)
movss %xmm8, 0x4(%rsi)
movss 0x8(%rax,%r13), %xmm2
movss %xmm2, 0x8(%rsi)
movss 0xc(%rax,%r13), %xmm2
movss %xmm2, 0xc(%rsi)
movss (%rax,%r13), %xmm2
movss %xmm2, -0xc0(%rbp)
movss 0x4(%rax,%r13), %xmm2
movss %xmm2, -0xbc(%rbp)
movss %xmm7, -0xb8(%rbp)
movss %xmm8, -0xb4(%rbp)
movss (%rax,%r15), %xmm2
movss %xmm2, -0xb0(%rbp)
movss 0x4(%rax,%r15), %xmm2
movss %xmm2, -0xac(%rbp)
movss %xmm1, -0xa8(%rbp)
movss %xmm0, -0xa4(%rbp)
movss %xmm1, -0xa0(%rbp)
movss %xmm0, -0x9c(%rbp)
movss 0x8(%rax,%r15), %xmm2
movss %xmm2, -0x98(%rbp)
movss 0xc(%rax,%r15), %xmm2
movss %xmm2, -0x94(%rbp)
movss %xmm1, -0x70(%rbp)
movss %xmm0, -0x6c(%rbp)
movss %xmm7, -0x68(%rbp)
movss %xmm8, -0x64(%rbp)
callq 0x217c
movl %r12d, %edx
movq (%r14), %rsi
movq 0x8(%r14), %rax
subq %rsi, %rax
shrq $0x4, %rax
leal -0x1(%rax), %ecx
leal 0x1(%r12), %r13d
movq %rdx, -0x38(%rbp)
cmpl %ecx, %edx
movl $0x0, %ecx
cmovel %ecx, %r13d
cmpl %ebx, %r13d
movq %r12, -0x58(%rbp)
je 0x1ddc
cmpl %eax, %r13d
jge 0x1ddc
movslq %r13d, %r14
movq %r14, %r15
shlq $0x4, %r15
incq %r14
leal -0x1(%rbx), %eax
movl %eax, -0x2c(%rbp)
addq %r15, %rsi
leaq -0x90(%rbp), %rdi
callq 0x217c
movq -0x60(%rbp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rax
subq %rsi, %rax
shrq $0x4, %rax
leal 0x1(%r13), %r12d
cmpl %r13d, -0x2c(%rbp)
je 0x1ddf
movslq %eax, %rcx
addq $0x10, %r15
leaq 0x1(%r14), %rdx
movl %r12d, %r13d
cmpq %rcx, %r14
movq %rdx, %r14
jl 0x1d99
jmp 0x1ddf
movl %r13d, %r12d
cmpl %eax, %r12d
movq -0x60(%rbp), %r13
jne 0x1e3f
xorl %r12d, %r12d
testl %ebx, %ebx
je 0x1e3f
movq (%r13), %rax
movq 0x8(%r13), %rcx
subq %rax, %rcx
shrq $0x4, %rcx
testl %ecx, %ecx
jle 0x1e3f
movl %ebx, %ebx
xorl %r12d, %r12d
leaq -0x90(%rbp), %r15
movq %r12, %rsi
shlq $0x4, %rsi
addq %rax, %rsi
movq %r15, %rdi
callq 0x217c
incq %r12
cmpq %rbx, %r12
je 0x1e3f
movq (%r13), %rax
movq 0x8(%r13), %rcx
subq %rax, %rcx
shrq $0x4, %rcx
movslq %ecx, %rcx
cmpq %rcx, %r12
jl 0x1e0e
leaq -0x90(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x217c
leaq -0x90(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x217c
movq (%r13), %rbx
movq 0x8(%r13), %r14
leaq -0x50(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x217c
subq %rbx, %r14
shrq $0x4, %r14
decl %r14d
leal 0x1(%r12), %eax
xorl %ebx, %ebx
cmpl %r14d, %r12d
cmovnel %eax, %ebx
movq (%r13), %rsi
movq 0x8(%r13), %rax
subq %rsi, %rax
shrq $0x4, %rax
movq -0x38(%rbp), %r14
cmpl %r14d, %ebx
je 0x1f05
cmpl %eax, %ebx
jge 0x1f05
movslq %ebx, %r14
movq %r14, %r12
shlq $0x4, %r12
incq %r14
movq -0x58(%rbp), %rax
decl %eax
movq %rax, -0x58(%rbp)
leaq -0x50(%rbp), %r15
addq %r12, %rsi
movq %r15, %rdi
callq 0x217c
movq (%r13), %rsi
movq 0x8(%r13), %rax
subq %rsi, %rax
shrq $0x4, %rax
leal 0x1(%rbx), %ecx
cmpl %ebx, -0x58(%rbp)
je 0x1eff
movslq %eax, %rdx
addq $0x10, %r12
leaq 0x1(%r14), %rdi
movl %ecx, %ebx
cmpq %rdx, %r14
movq %rdi, %r14
jl 0x1ec8
movq -0x38(%rbp), %r14
jmp 0x1f07
movl %ebx, %ecx
cmpl %eax, %ecx
jne 0x1f5a
testq %r14, %r14
je 0x1f5a
movq (%r13), %rax
movq 0x8(%r13), %rcx
subq %rax, %rcx
shrq $0x4, %rcx
testl %ecx, %ecx
jle 0x1f5a
xorl %ebx, %ebx
leaq -0x50(%rbp), %r15
movq %rbx, %rsi
shlq $0x4, %rsi
addq %rax, %rsi
movq %r15, %rdi
callq 0x217c
incq %rbx
cmpq %r14, %rbx
je 0x1f5a
movq (%r13), %rax
movq 0x8(%r13), %rcx
subq %rax, %rcx
shrq $0x4, %rcx
movslq %ecx, %rcx
cmpq %rcx, %rbx
jl 0x1f29
leaq -0x50(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x217c
movq -0x70(%rbp), %rax
movq -0x68(%rbp), %rcx
leaq -0xe4(%rbp), %rsi
movq %rcx, (%rsi)
movq %rax, 0x8(%rsi)
leaq -0x50(%rbp), %rdi
callq 0x217c
movq -0xc8(%rbp), %rbx
leaq -0x90(%rbp), %rsi
leaq -0x50(%rbp), %rdx
movq %rbx, %rdi
callq 0x213a
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x1fb8
movq -0x40(%rbp), %rsi
subq %rdi, %rsi
callq 0x1110
movq -0x90(%rbp), %rdi
testq %rdi, %rdi
je 0x1fd0
movq -0x80(%rbp), %rsi
subq %rdi, %rsi
callq 0x1110
movq %rbx, %rax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1ff1
jmp 0x1ff1
jmp 0x1ff1
jmp 0x1ff1
jmp 0x1ff1
jmp 0x1ff1
movq %rax, %rbx
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x2009
movq -0x40(%rbp), %rsi
subq %rdi, %rsi
callq 0x1110
movq -0x90(%rbp), %rdi
testq %rdi, %rdi
je 0x2021
movq -0x80(%rbp), %rsi
subq %rdi, %rsi
callq 0x1110
movq %rbx, %rdi
callq 0x1180