// File: /workspace/github_cpp_makefile_star2_O2/realuptime[P]PolyDetector/PolyDetector.cpp
// Function: PolyDetector::DetectPolygons()
bool PolyDetector::DetectPolygons()
{
    polys.clear();
    
    logoutf("verbose:%u", verbose);
    
    if (verbose)
        logoutf("origLines: %u", uint32_t(origLines.size()));

    if (!CreateLines())
    {
        logoutf1("Error: Could not successfully create lines!");
        return false;
    }
    if (verbose)
        logoutf("lines %u", uint32_t(lines.size()));
    
    while (true)
    {
        bool stop = false;
        
        if (verbose)
            logoutf("----------- BEGIN %u {", dissolveCount);
        
        SortLines();
        
        if (!FindPolys())
        {
            logoutf1("Error constructing the polygon set.");
            return false;
        }

        if (verbose)
            logoutf("Polygon set contains %d polygons.", GetPolyCount());
        
        SimplifyPolys(0.0);
        //logoutf("Polygon set contains %d polygons after simplification!.", GetPolyCount());
        
        auto beforeCount = dissolveCount;
        
        if (verbose)
            logoutf("----------- DISSOLVE %u", dissolveCount);
        
        if (!dissolve())
            stop = true;
        
        if (verbose)
            logoutf("} ----------- END %u\n", beforeCount);
        
        if (stop)
            break;
    }
    
#if 1
    //std::sort(polys.begin(), polys.end(), [](const PolyPol &a, const PolyPol &b) {
    //    return a.dissolveStep < b.dissolveStep;
    //});
    
    std::string str;
    
    for (auto &p : polys)
    {
        //if (verbose)
        //    p.cycle.print(("[FINI_ALL STEP:" + std::to_string(p.dissolveStep) + "] ").c_str());
        
        /*
        str = "[";
        for (auto &lid : p.cycle.idx)
        {
            auto l = findLine(lid);
            if (!l) continue;
            
            str += "{";
            for (auto &pid : {l->aIdx, l->bIdx})
                str += std::to_string(pid) + " ";
            str.pop_back();
            str += "} ";
        }
        if (!str.empty())
            str.pop_back();
        str += "]";
        
        logoutf("[%u]: pts:%s", p.dissolveStep, str.c_str());
        */
    }
#endif

    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
addq $0x48, %rdi
callq 0x88f8
movl 0x60(%rbx), %esi
leaq 0x8e77(%rip), %rdi      # 0xd7f3
xorl %eax, %eax
callq 0x2040
cmpl $0x0, 0x60(%rbx)
je 0x49ab
movq 0x20(%rbx), %rax
subq 0x18(%rbx), %rax
movl $0x90, %ecx
cqto
idivq %rcx
leaq 0x8e5d(%rip), %rdi      # 0xd7ff
movl %eax, %esi
xorl %eax, %eax
callq 0x2040
movq %rbx, %rdi
callq 0x288a
cmpl $0x0, 0x60(%rbx)
je 0x49db
movq 0x38(%rbx), %rax
subq 0x30(%rbx), %rax
movl $0x90, %ecx
cqto
idivq %rcx
leaq 0x8e3c(%rip), %rdi      # 0xd80e
movl %eax, %esi
xorl %eax, %eax
callq 0x2040
leaq 0x8e71(%rip), %r15      # 0xd853
leaq 0x8e47(%rip), %r12      # 0xd830
leaq 0x8e28(%rip), %r13      # 0xd818
cmpl $0x0, 0x60(%rbx)
je 0x4a06
movl 0x148(%rbx), %esi
movq %r13, %rdi
xorl %eax, %eax
callq 0x2040
movq %rbx, %rdi
callq 0x456e
movq %rbx, %rdi
callq 0x4ab2
cmpl $0x0, 0x60(%rbx)
je 0x4a38
movq 0x50(%rbx), %rax
subq 0x48(%rbx), %rax
cqto
pushq $0x70
popq %rcx
idivq %rcx
movq %r12, %rdi
movl %eax, %esi
xorl %eax, %eax
callq 0x2040
xorps %xmm0, %xmm0
movq %rbx, %rdi
callq 0x5596
movl 0x148(%rbx), %ebp
cmpl $0x0, 0x60(%rbx)
je 0x4a5b
movq %r15, %rdi
movl %ebp, %esi
xorl %eax, %eax
callq 0x2040
movq %rbx, %rdi
callq 0x5616
movl %eax, %r14d
cmpl $0x0, 0x60(%rbx)
je 0x4a7c
leaq 0x8df9(%rip), %rdi      # 0xd86c
movl %ebp, %esi
xorl %eax, %eax
callq 0x2040
testb %r14b, %r14b
jne 0x49f0
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x8(%rsp), %rdi
callq 0x20b0
movb $0x1, %al
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop