// File: /workspace/github_cpp_makefile_star2_O3/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, -0xd0(%rbp)
leaq -0xdc(%rbp), %r15
movq %r15, %rdi
callq 0x17e2
movslq (%r15), %r14
movss 0x4(%r15), %xmm9
movss 0x8(%r15), %xmm10
movq (%rbx), %rax
movq %r14, %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, -0x40(%rbp)
movq 0x8(%rbx), %rcx
movaps %xmm10, %xmm0
mulss %xmm2, %xmm0
movaps %xmm1, %xmm3
mulss %xmm9, %xmm3
addss %xmm0, %xmm3
xorps 0x2708(%rip), %xmm3     # 0x4020
xorps %xmm0, %xmm0
cvtss2sd %xmm3, %xmm0
subq %rax, %rcx
shrq $0x4, %rcx
testl %ecx, %ecx
jle 0x19a3
movb $0x1, %dl
xorl %ebx, %ebx
xorps %xmm3, %xmm3
cmpl %r14d, %ebx
je 0x198c
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 0x19a5
testb $0x1, %dl
jne 0x1931
jmp 0x19a5
xorl %ebx, %ebx
movslq %ebx, %r15
shlq $0x4, %r15
movss 0x8(%rax,%r15), %xmm5
movss (%rax,%r15), %xmm6
movss 0x4(%rax,%r15), %xmm3
subss %xmm6, %xmm5
movss 0xc(%rax,%r15), %xmm4
subss %xmm3, %xmm4
movaps %xmm2, %xmm8
mulss %xmm4, %xmm8
movaps %xmm1, %xmm7
mulss %xmm5, %xmm7
addss %xmm8, %xmm7
xorps %xmm8, %xmm8
ucomiss %xmm8, %xmm7
jne 0x19f0
jnp 0x1a19
cvtss2sd %xmm7, %xmm7
mulss %xmm3, %xmm2
mulss %xmm6, %xmm1
addss %xmm2, %xmm1
cvtss2sd %xmm1, %xmm1
addsd %xmm1, %xmm0
xorpd 0x2620(%rip), %xmm0     # 0x4030
divsd %xmm7, %xmm0
jmp 0x1aa2
movq 0x45d0(%rip), %r12      # 0x5ff0
leaq 0x2631(%rip), %rsi      # 0x4058
movl $0x1b, %edx
movq %r12, %rdi
movss %xmm9, -0x2c(%rbp)
movss %xmm10, -0x38(%rbp)
callq 0x1110
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x10e0
movsbl %al, %esi
movq %r12, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1090
movss -0x38(%rbp), %xmm10
movss -0x2c(%rbp), %xmm9
movq -0x40(%rbp), %rax
movq (%rax), %rax
movss (%rax,%r15), %xmm6
movss 0x4(%rax,%r15), %xmm3
movss 0x8(%rax,%r15), %xmm5
movss 0xc(%rax,%r15), %xmm4
subss %xmm6, %xmm5
subss %xmm3, %xmm4
xorpd %xmm0, %xmm0
xorps %xmm1, %xmm1
cvtss2sd %xmm6, %xmm1
xorps %xmm2, %xmm2
cvtss2sd %xmm5, %xmm2
mulsd %xmm0, %xmm2
addsd %xmm1, %xmm2
xorps %xmm1, %xmm1
cvtsd2ss %xmm2, %xmm1
xorps %xmm2, %xmm2
cvtss2sd %xmm3, %xmm2
xorps %xmm3, %xmm3
cvtss2sd %xmm4, %xmm3
mulsd %xmm0, %xmm3
addsd %xmm2, %xmm3
xorps %xmm0, %xmm0
cvtsd2ss %xmm3, %xmm0
xorps %xmm2, %xmm2
leaq -0x90(%rbp), %rdi
movaps %xmm2, (%rdi)
xorl %r12d, %r12d
movq %r12, 0x10(%rdi)
movq %r12, -0x50(%rbp)
movaps %xmm2, -0x60(%rbp)
leaq -0xfc(%rbp), %rsi
movss %xmm9, (%rsi)
movss %xmm10, 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 %xmm9, -0xb8(%rbp)
movss %xmm10, -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 %xmm9, -0x68(%rbp)
movss %xmm10, -0x64(%rbp)
callq 0x1ff4
movl %r14d, %edi
movq -0x40(%rbp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rax
movq %rax, %rcx
subq %rsi, %rcx
shrq $0x4, %rcx
leal -0x1(%rcx), %edx
leal 0x1(%r14), %r13d
movq %rdi, -0x38(%rbp)
cmpl %edx, %edi
cmovel %r12d, %r13d
cmpl %ebx, %r13d
je 0x1c61
cmpl %ecx, %r13d
jge 0x1c61
movq %r14, -0xc8(%rbp)
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 0x1ff4
movq -0x40(%rbp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rax
movq %rax, %rcx
subq %rsi, %rcx
shrq $0x4, %rcx
leal 0x1(%r13), %r12d
cmpl %r13d, -0x2c(%rbp)
je 0x1c58
movslq %ecx, %rdx
addq $0x10, %r15
leaq 0x1(%r14), %rdi
movl %r12d, %r13d
cmpq %rdx, %r14
movq %rdi, %r14
jl 0x1c14
movq -0xc8(%rbp), %r14
jmp 0x1c64
movl %r13d, %r12d
cmpl %ecx, %r12d
movq -0x40(%rbp), %r13
jne 0x1cbe
xorl %r12d, %r12d
testl %ebx, %ebx
je 0x1cbe
subq %rsi, %rax
shrq $0x4, %rax
testl %eax, %eax
jle 0x1cbe
movl %ebx, %ebx
xorl %r12d, %r12d
leaq -0x90(%rbp), %r15
movq %r12, %rax
shlq $0x4, %rax
addq %rsi, %rax
movq %r15, %rdi
movq %rax, %rsi
callq 0x1ff4
incq %r12
cmpq %rbx, %r12
je 0x1cbe
movq (%r13), %rsi
movq 0x8(%r13), %rax
subq %rsi, %rax
shrq $0x4, %rax
cltq
cmpq %rax, %r12
jl 0x1c8b
movq %r14, %r15
leaq -0x90(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x1ff4
leaq -0x90(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x1ff4
movq (%r13), %rbx
movq 0x8(%r13), %r14
leaq -0x60(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x1ff4
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
movq %rax, %rcx
subq %rsi, %rcx
shrq $0x4, %rcx
movq -0x38(%rbp), %r14
cmpl %r14d, %ebx
je 0x1d83
cmpl %ecx, %ebx
jge 0x1d83
movslq %ebx, %r14
movq %r14, %r12
shlq $0x4, %r12
incq %r14
decl %r15d
addq %r12, %rsi
leaq -0x60(%rbp), %rdi
callq 0x1ff4
movq (%r13), %rsi
movq 0x8(%r13), %rax
movq %rax, %rcx
subq %rsi, %rcx
shrq $0x4, %rcx
leal 0x1(%rbx), %edx
cmpl %ebx, %r15d
je 0x1d7d
movslq %ecx, %rdi
addq $0x10, %r12
leaq 0x1(%r14), %r8
movl %edx, %ebx
cmpq %rdi, %r14
movq %r8, %r14
jl 0x1d42
movq -0x38(%rbp), %r14
jmp 0x1d85
movl %ebx, %edx
cmpl %ecx, %edx
jne 0x1dd2
testq %r14, %r14
je 0x1dd2
subq %rsi, %rax
shrq $0x4, %rax
testl %eax, %eax
jle 0x1dd2
xorl %ebx, %ebx
leaq -0x60(%rbp), %r15
movq %rbx, %rax
shlq $0x4, %rax
addq %rsi, %rax
movq %r15, %rdi
movq %rax, %rsi
callq 0x1ff4
incq %rbx
cmpq %r14, %rbx
je 0x1dd2
movq (%r13), %rsi
movq 0x8(%r13), %rax
subq %rsi, %rax
shrq $0x4, %rax
cltq
cmpq %rax, %rbx
jl 0x1d9f
leaq -0x60(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x1ff4
movq -0x70(%rbp), %rax
movq -0x68(%rbp), %rcx
leaq -0xec(%rbp), %rsi
movq %rcx, (%rsi)
movq %rax, 0x8(%rsi)
leaq -0x60(%rbp), %rdi
callq 0x1ff4
movq -0xd0(%rbp), %rbx
leaq -0x90(%rbp), %rsi
leaq -0x60(%rbp), %rdx
movq %rbx, %rdi
callq 0x1fb2
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x1e30
movq -0x50(%rbp), %rsi
subq %rdi, %rsi
callq 0x1100
movq -0x90(%rbp), %rdi
testq %rdi, %rdi
je 0x1e48
movq -0x80(%rbp), %rsi
subq %rdi, %rsi
callq 0x1100
movq %rbx, %rax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1e69
jmp 0x1e69
jmp 0x1e69
jmp 0x1e69
jmp 0x1e69
jmp 0x1e69
movq %rax, %rbx
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x1e81
movq -0x50(%rbp), %rsi
subq %rdi, %rsi
callq 0x1100
movq -0x90(%rbp), %rdi
testq %rdi, %rdi
je 0x1e99
movq -0x80(%rbp), %rsi
subq %rdi, %rsi
callq 0x1100
movq %rbx, %rdi
callq 0x1170