// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %rax
movq %rdi, %rbx
addq $0x48, %rdi
movq 0x48(%rbx), %rsi
callq 0xe4f0
movl 0x60(%rbx), %esi
leaq 0xad18(%rip), %rdi      # 0x1081f
xorl %eax, %eax
callq 0x2030
cmpl $0x0, 0x60(%rbx)
je 0x5b34
movq 0x20(%rbx), %rax
subq 0x18(%rbx), %rax
shrq $0x4, %rax
imull $0x38e38e39, %eax, %esi # imm = 0x38E38E39
leaq 0xacfe(%rip), %rdi      # 0x1082b
xorl %eax, %eax
callq 0x2030
movq %rbx, %rdi
callq 0x2aa0
cmpl $0x0, 0x60(%rbx)
je 0x5b62
movq 0x38(%rbx), %rax
subq 0x30(%rbx), %rax
shrq $0x4, %rax
imull $0x38e38e39, %eax, %esi # imm = 0x38E38E39
leaq 0xacdf(%rip), %rdi      # 0x1083a
xorl %eax, %eax
callq 0x2030
leaq 0xad16(%rip), %r15      # 0x1087f
leaq 0xacec(%rip), %r12      # 0x1085c
leaq 0xaccd(%rip), %r13      # 0x10844
cmpl $0x0, 0x60(%rbx)
je 0x5b8d
movl 0x148(%rbx), %esi
movq %r13, %rdi
xorl %eax, %eax
callq 0x2030
movq %rbx, %rdi
callq 0x5538
movq %rbx, %rdi
callq 0x5c1e
cmpl $0x0, 0x60(%rbx)
je 0x5bbf
movq 0x50(%rbx), %rax
subq 0x48(%rbx), %rax
shrq $0x4, %rax
imull $0xb6db6db7, %eax, %esi # imm = 0xB6DB6DB7
movq %r12, %rdi
xorl %eax, %eax
callq 0x2030
xorps %xmm0, %xmm0
movq %rbx, %rdi
callq 0x6b46
movl 0x148(%rbx), %ebp
cmpl $0x0, 0x60(%rbx)
je 0x5be2
movq %r15, %rdi
movl %ebp, %esi
xorl %eax, %eax
callq 0x2030
movq %rbx, %rdi
callq 0x6bd0
movl %eax, %r14d
cmpl $0x0, 0x60(%rbx)
je 0x5c03
leaq 0xac9e(%rip), %rdi      # 0x10898
movl %ebp, %esi
xorl %eax, %eax
callq 0x2030
testb %r14b, %r14b
jne 0x5b77
movb $0x1, %al
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop