/*
 *  sweepLineDg.cpp
 *  VSweep
 *
 *  Created by Chema on 10/13/10.
 *  Copyright 2010 __MyCompanyName__. All rights reserved.
 *
 */

#include "GLInclude.h"
#include <utility>
#include <iostream>
#include <sstream>
#include "segment.h"
#include "triangle.h"
#include "sweepLineDg.h"

using namespace std;
namespace DBUG {

    void printInterx(const SL::Interx& ix) {
        cout << "ix" << ":"<< ix.p_<< (*ix.a_).index_ << " "<< (*ix.b_).index_ ;
        cout<< endl;
    }

    void printInterxs(const SL::Interx::set& interxs, int limit) {
        SL::Interx::set::iterator itr = interxs.begin();
        while(limit--!=0 && itr!=interxs.end()) {
            printInterx(*itr);
            ++itr;
        }
    }

    void printEvent(const Event& e) {
        cout << e.type_ << ":"<< e.p_;
//        cout<< e.sa_->index_<<" ";
//        cout<< e.sb_->index_<<endl;
        cout<< endl;
    }
    
    void printEvents(const Event::queue& events, int limit) {
        Event::queue::const_iterator itr = events.begin();
        while(limit--!=0 && itr!=events.end()) {
            printEvent(*itr);
            ++itr;
        }
    }

    void printSLS(const Segment& sls) {
        cout <<"l:"<<sls.aeg_[0]->p_<<"r:"<<sls.aeg_[1]<<sls.index_<<" "<<&sls<<endl;
    }
    
    void printTree(const Segment::tree& tree, int limit) {
        unsigned cc=0;
        Segment::tree::iterator itr = tree.begin();
        while(limit--!=0 && itr!=tree.end()) {
            printf("%d",cc++);
            printSLS(**itr);
            ++itr;
        }
    }

    void printSegments(const Segment::vector& segs, int limit) {
        Segment::vector::const_iterator itr = segs.begin();
        while(limit--!=0 && itr!=segs.end()) {
            printSLS(*itr);
            ++itr;
        }
    }

    void DUMP_ACTIVE(const Segment::tree& tree) {
        Segment::tree::iterator itr = tree.begin();
        while(itr!=tree.end()) {
            cout<<(*itr)->index_<<",";
            ++itr;
        }
    }    
    void DEBUG_DRAW( const Event::queue& events, const SL::Interx::set& interxs, const Segment::tree& tree,  Font& font) {

        Event::queue::const_iterator itr;


//        glColor3ub(255,0,0);
//        glPointSize(2);
//        glBegin(GL_POINTS);
//        SL::Interx::set::iterator ixr = interxs.begin();
//        while(ixr!=interxs.end()) {
//            glVertex2f((*ixr).p_[0],(*ixr).p_[1]);
//            ++ixr;
//        }
//        glEnd();

        glColor3ub(255,255,255);
        glBegin(GL_LINES);
        itr = events.begin();    
        while(itr!=events.end()) {
            if ((*itr).type_!=Event::eInterx) {
                Segment* seg = (*itr).sa_;
                const DReal2& p  = seg->aeg_[0]->p_;
                const DReal2& q  = seg->aeg_[1]->p_;                    
                glVertex3d(p[0],seg->aeg_[0]->y_,p[1]);
                glVertex3d(q[0],seg->aeg_[1]->y_,q[1]);
            }
            ++itr;
        }
        glEnd();


//        glColor3ub(127,255,0);
//        itr = events.begin();
//        glBegin(GL_LINES);    
//        if(itr!=events.end()) {
//            glVertex2f((*itr).p_.x(),(*itr).p_.y());
//            glVertex2f((*itr).p_.x(),600);
//        }
//        glEnd();
        
    }
    
}
