// File: /workspace/github_cpp_makefile_star2_O1/Hybryd[P]HyRoadGenerator/main.cpp
// Function: main
int main()
{
  srand(time(NULL));
  double Amin=0.05;
  double Amax=0.7;
  int iterMax=20;
  
  
  std::stack<Polygon> mustBeEmpty;
  std::vector<Polygon> mustBeFull;
  
  
  Polygon pInit;

  // DO NOT PUT NEGATIVE VALUES (for the algorithm for areas)  
  std::pair < Point,Point > e1 (Point(0,0), Point(10,0));
  std::pair < Point,Point > e2 (Point(10,0), Point(10,10));
  std::pair < Point,Point > e3 (Point(10,10), Point(0,10));
  std::pair < Point,Point > e4 (Point(0,10),Point(0,0));

  
  pInit.push_back(e1);
  pInit.push_back(e2);
  pInit.push_back(e3);
  pInit.push_back(e4);

//  std::pair < Point,Point > e1 (Point(0,0), Point(10,0));
//  std::pair < Point,Point > e2 (Point(10,0), Point(0,10));
//  std::pair < Point,Point > e3 (Point(0,10), Point(0,0));

//  
//  pInit.push_back(e1);
//  pInit.push_back(e2);
//  pInit.push_back(e3);


  mustBeEmpty.push(pInit);


  Polygon p;
  std::pair< Polygon,Polygon> pair;
  bool ok=true;
  int j=0;
  double xbar1=0;
  double ybar1=0;
  double xbar2=0;
  double ybar2=0;


  while(mustBeEmpty.size()!=0)
  {
    p=mustBeEmpty.top();
    mustBeEmpty.pop();
    if(p.area() > (1-density(p.getBary().x(),p.getBary().y()))*Amax)
    {
      ok=true;
      j=0;
      xbar1=0;
      ybar1=0;
      xbar2=0;
      ybar2=0;
      while(ok && j<iterMax)
      {
        pair = p.split();
        xbar1=pair.first.getBary().x();
        ybar1=pair.first.getBary().y();
        xbar2=pair.second.getBary().x();
        ybar2=pair.second.getBary().y();
        
        // constraints on the resulting polygons
        ok = !(pair.first.area() > (1-density(xbar1,ybar1))*Amin && pair.second.area() > (1-density(xbar2,ybar2))*Amin && pair.first.isClosed() && pair.second.isClosed() && (pair.first.isAcceptable(10)  && pair.second.isAcceptable(10)  ));
        ++j;
      }
      mustBeEmpty.push(pair.first);
      mustBeEmpty.push(pair.second);
    }
    else
    {
      mustBeFull.push_back(p);
    }
//    std::cerr << mustBeFull.size() << std::endl;
  }



  // display all the polygons
  for(int i=0;i<mustBeFull.size();++i)
    std::cout << mustBeFull[i] << std::endl << std::endl;

  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
xorl %edi, %edi
callq 0x10d0
movl %eax, %edi
callq 0x10e0
xorpd %xmm0, %xmm0
leaq -0x160(%rbp), %rdi
movapd %xmm0, 0x40(%rdi)
movapd %xmm0, 0x30(%rdi)
movapd %xmm0, 0x20(%rdi)
movapd %xmm0, 0x10(%rdi)
movapd %xmm0, (%rdi)
xorl %esi, %esi
callq 0x3058
xorpd %xmm0, %xmm0
movapd %xmm0, -0x70(%rbp)
movq $0x0, -0x60(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x142c
movaps 0x1ac4(%rip), %xmm0     # 0x40d0
leaq -0x1a0(%rbp), %rsi
movups %xmm0, (%rsi)
movaps 0x1ac3(%rip), %xmm0     # 0x40e0
movups %xmm0, -0x190(%rbp)
movaps 0x1ac5(%rip), %xmm0     # 0x40f0
movups %xmm0, -0x180(%rbp)
movsd 0x1ac6(%rip), %xmm0     # 0x4100
movupd %xmm0, -0x170(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x217c
leaq -0x50(%rbp), %rdi
leaq -0x190(%rbp), %rsi
callq 0x217c
leaq -0x50(%rbp), %rdi
leaq -0x180(%rbp), %rsi
callq 0x217c
leaq -0x50(%rbp), %rdi
leaq -0x170(%rbp), %rsi
callq 0x217c
leaq -0x160(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x323c
leaq -0xd0(%rbp), %rdi
callq 0x142c
leaq -0x108(%rbp), %rdi
callq 0x2bdc
leaq -0xf0(%rbp), %r14
leaq -0xd0(%rbp), %r15
leaq -0xb8(%rbp), %r13
leaq -0x108(%rbp), %r12
movq -0x118(%rbp), %rax
movq %rax, %rcx
subq -0x138(%rbp), %rcx
sarq $0x3, %rcx
cmpq $0x1, %rax
adcq $-0x1, %rcx
leaq (%rcx,%rcx,4), %rdx
leaq (%rcx,%rdx,4), %rdx
movq -0x140(%rbp), %rdi
movq -0x130(%rbp), %rsi
movq -0x128(%rbp), %rcx
movq %rsi, %r8
subq %rcx, %r8
sarq $0x3, %r8
movabsq $-0x5555555555555555, %r9 # imm = 0xAAAAAAAAAAAAAAAB
imulq %r9, %r8
subq -0x150(%rbp), %rdi
addq %rdx, %r8
sarq $0x3, %rdi
movabsq $0x5555555555555555, %rdx # imm = 0x5555555555555555
imulq %rdx, %rdi
cmpq %rdi, %r8
je 0x2a15
cmpq %rcx, %rsi
jne 0x2747
movq -0x8(%rax), %rsi
movl $0x1f8, %eax            # imm = 0x1F8
addq %rax, %rsi
addq $-0x18, %rsi
movq %r15, %rdi
callq 0x2cfe
leaq -0x160(%rbp), %rdi
callq 0x34d8
movq %r15, %rdi
callq 0x15d4
movsd %xmm0, -0x30(%rbp)
movq %r13, %rdi
movq %r15, %rsi
callq 0x1920
movss -0xb8(%rbp), %xmm0
movss %xmm0, -0x38(%rbp)
leaq -0xd8(%rbp), %rdi
movq %r15, %rsi
callq 0x1920
xorps %xmm0, %xmm0
cvtss2sd -0x38(%rbp), %xmm0
xorps %xmm1, %xmm1
cvtss2sd -0xd4(%rbp), %xmm1
movsd 0x18e2(%rip), %xmm2     # 0x4090
addsd %xmm2, %xmm0
addsd %xmm2, %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
divsd 0x18ce(%rip), %xmm0     # 0x4098
callq 0x1190
mulsd 0x18d1(%rip), %xmm0     # 0x40a8
addsd 0x18d1(%rip), %xmm0     # 0x40b0
mulsd 0x18d1(%rip), %xmm0     # 0x40b8
movsd -0x30(%rbp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x2a04
xorl %ebx, %ebx
movq %r13, %rdi
movq %r15, %rsi
callq 0x1a36
movq %r12, %rdi
movq %r13, %rsi
callq 0x2cfe
movq %r14, %rdi
leaq -0xa0(%rbp), %rsi
callq 0x2cfe
movq -0xa0(%rbp), %rdi
testq %rdi, %rdi
je 0x2838
movq -0x90(%rbp), %rsi
subq %rdi, %rsi
callq 0x1110
movq -0xb8(%rbp), %rdi
testq %rdi, %rdi
je 0x2853
movq -0xa8(%rbp), %rsi
subq %rdi, %rsi
callq 0x1110
movq %r13, %rdi
movq %r12, %rsi
callq 0x1920
xorps %xmm0, %xmm0
cvtss2sd -0xb8(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movq %r13, %rdi
movq %r12, %rsi
callq 0x1920
xorps %xmm0, %xmm0
cvtss2sd -0xb4(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movq %r13, %rdi
movq %r14, %rsi
callq 0x1920
xorps %xmm0, %xmm0
cvtss2sd -0xb8(%rbp), %xmm0
movsd %xmm0, -0x80(%rbp)
movq %r13, %rdi
movq %r14, %rsi
callq 0x1920
xorps %xmm0, %xmm0
cvtss2sd -0xb4(%rbp), %xmm0
movsd %xmm0, -0x78(%rbp)
movq %r12, %rdi
callq 0x15d4
movsd %xmm0, -0x88(%rbp)
movsd 0x17b9(%rip), %xmm1     # 0x4090
movsd -0x30(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd -0x38(%rbp), %xmm2
addsd %xmm1, %xmm2
mulsd %xmm2, %xmm2
mulsd %xmm0, %xmm0
addsd %xmm2, %xmm0
divsd 0x179b(%rip), %xmm0     # 0x4098
callq 0x1190
mulsd 0x179e(%rip), %xmm0     # 0x40a8
addsd 0x179e(%rip), %xmm0     # 0x40b0
mulsd 0x17a6(%rip), %xmm0     # 0x40c0
movsd -0x88(%rbp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x29cd
movq %r14, %rdi
callq 0x15d4
movsd %xmm0, -0x30(%rbp)
movsd 0x174f(%rip), %xmm1     # 0x4090
movsd -0x80(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd -0x78(%rbp), %xmm2
addsd %xmm1, %xmm2
mulsd %xmm2, %xmm2
mulsd %xmm0, %xmm0
addsd %xmm2, %xmm0
divsd 0x1731(%rip), %xmm0     # 0x4098
callq 0x1190
mulsd 0x1734(%rip), %xmm0     # 0x40a8
addsd 0x1734(%rip), %xmm0     # 0x40b0
mulsd 0x173c(%rip), %xmm0     # 0x40c0
movsd -0x30(%rbp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x29cd
movq %r12, %rdi
callq 0x1852
testb %al, %al
je 0x29cd
movq %r14, %rdi
callq 0x1852
testb %al, %al
je 0x29cd
movq %r12, %rdi
movsd 0x1716(%rip), %xmm0     # 0x40c8
callq 0x18d4
testb %al, %al
je 0x29cd
movq %r14, %rdi
movsd 0x1702(%rip), %xmm0     # 0x40c8
callq 0x18d4
jmp 0x29cf
xorl %eax, %eax
testb %al, %al
jne 0x29e1
leal 0x1(%rbx), %eax
cmpl $0x12, %ebx
movl %eax, %ebx
jbe 0x27f8
leaq -0x160(%rbp), %rdi
movq %r12, %rsi
callq 0x323c
leaq -0x160(%rbp), %rdi
movq %r14, %rsi
callq 0x323c
jmp 0x26bf
leaq -0x70(%rbp), %rdi
movq %r15, %rsi
callq 0x2c58
jmp 0x26bf
movq -0x70(%rbp), %rsi
cmpq %rsi, -0x68(%rbp)
je 0x2abc
xorl %r15d, %r15d
movq 0x45a3(%rip), %rbx      # 0x6fd0
xorl %r12d, %r12d
addq %r15, %rsi
movq %rbx, %rdi
callq 0x2029
movq %rax, %r14
movq (%rax), %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
movq %rax, %r14
movq (%rax), %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
incq %r12
movq -0x70(%rbp), %rsi
movq -0x68(%rbp), %rax
subq %rsi, %rax
sarq $0x3, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rax
addq $0x18, %r15
cmpq %r12, %rax
ja 0x2a30
movq -0xf0(%rbp), %rdi
testq %rdi, %rdi
je 0x2ad7
movq -0xe0(%rbp), %rsi
subq %rdi, %rsi
callq 0x1110
movq -0x108(%rbp), %rdi
testq %rdi, %rdi
je 0x2af2
movq -0xf8(%rbp), %rsi
subq %rdi, %rsi
callq 0x1110
movq -0xd0(%rbp), %rdi
testq %rdi, %rdi
je 0x2b0d
movq -0xc0(%rbp), %rsi
subq %rdi, %rsi
callq 0x1110
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x2b22
movq -0x40(%rbp), %rsi
subq %rdi, %rsi
callq 0x1110
leaq -0x70(%rbp), %rdi
callq 0x2c94
leaq -0x160(%rbp), %rdi
callq 0x2ea0
xorl %eax, %eax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x2b8e
jmp 0x2b57
movq %rax, %rbx
jmp 0x2bbe
movq %rax, %rbx
jmp 0x2ba9
jmp 0x2b6e
jmp 0x2b6e
jmp 0x2b6e
jmp 0x2b6e
jmp 0x2b6e
jmp 0x2b6e
jmp 0x2b6e
jmp 0x2b6e
jmp 0x2b6e
movq %rax, %rbx
jmp 0x2b82
movq %rax, %rbx
leaq -0xb8(%rbp), %rdi
callq 0x2c18
leaq -0x108(%rbp), %rdi
callq 0x2c18
movq -0xd0(%rbp), %rdi
testq %rdi, %rdi
je 0x2ba9
movq -0xc0(%rbp), %rsi
subq %rdi, %rsi
callq 0x1110
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x2bbe
movq -0x40(%rbp), %rsi
subq %rdi, %rsi
callq 0x1110
leaq -0x70(%rbp), %rdi
callq 0x2c94
leaq -0x160(%rbp), %rdi
callq 0x2ea0
movq %rbx, %rdi
callq 0x1180
nop