Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//#include "tsystem.h"
Toshihiro Shimizu 890ddd
#include "tmachine.h"
Toshihiro Shimizu 890ddd
#include "tcurves.h"
Toshihiro Shimizu 890ddd
#include "tcommon.h"
Toshihiro Shimizu 890ddd
#include "tregion.h"
Toshihiro Shimizu 890ddd
//#include "tregionutil.h"
Toshihiro Shimizu 890ddd
#include "tstopwatch.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tstroke.h"
Toshihiro Shimizu 890ddd
#include "tstrokeutil.h"
Toshihiro Shimizu 890ddd
#include "tvectorimageP.h"
Toshihiro Shimizu 890ddd
#include "tdebugmessage.h"
Toshihiro Shimizu 890ddd
#include <vector></vector>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tcurveutil.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <algorithm></algorithm>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#if !defined(TNZ_LITTLE_ENDIAN)
Toshihiro Shimizu 890ddd
TNZ_LITTLE_ENDIAN undefined !!
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef IS_DOTNET
Toshihiro Shimizu 890ddd
#define NULL_ITER list<intersectedstroke>::iterator()</intersectedstroke>
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#define NULL_ITER 0
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	using namespace std;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
typedef TVectorImage::IntersectionBranch IntersectionBranch;
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
inline double myRound(double x)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return (1.0 / REGION_COMPUTING_PRECISION) * ((long)(x * REGION_COMPUTING_PRECISION));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
inline TThickPoint myRound(const TThickPoint &p)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return TThickPoint(myRound(p.x), myRound(p.y), p.thick);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void print(list<intersection> &intersectionList, char *str)</intersection>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	ofstream of(str);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	of << "***************************" << endl;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	list<intersection>::const_iterator it;</intersection>
Toshihiro Shimizu 890ddd
	list<intersectedstroke>::const_iterator it1;</intersectedstroke>
Toshihiro Shimizu 890ddd
	int i, j;
Toshihiro Shimizu 890ddd
	for (i = 0, it = intersectionList.begin(); it != intersectionList.end(); it++, i++) {
Toshihiro Shimizu 890ddd
		of << "***************************" << endl;
Toshihiro Shimizu 890ddd
		of << "Intersection#" << i << ": " << it->m_intersection << "numBranches: " << it->m_numInter << endl;
Toshihiro Shimizu 890ddd
		of << endl;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		for (j = 0, it1 = it->m_strokeList.begin(); it1 != it->m_strokeList.end(); it1++, j++) {
Toshihiro Shimizu 890ddd
			of << "----Branch #" << j;
Toshihiro Shimizu 890ddd
			if (it1->m_edge.m_index < 0)
Toshihiro Shimizu 890ddd
				of << "(AUTOCLOSE)";
Toshihiro Shimizu 890ddd
			of << "Intersection at " << it1->m_edge.m_w0 << ": "
Toshihiro Shimizu 890ddd
			   << ": " << endl;
Toshihiro Shimizu 890ddd
			of << "ColorId: " << it1->m_edge.m_styleId << endl;
Toshihiro Shimizu 890ddd
			/*
Toshihiro Shimizu 890ddd
    TColorStyle* fs = it1->m_edge.m_fillStyle;
Toshihiro Shimizu 890ddd
    if (fs==0)
Toshihiro Shimizu 890ddd
      of<<"NO color: "<< endl;
Toshihiro Shimizu 890ddd
    else 
Toshihiro Shimizu 890ddd
      {
Toshihiro Shimizu 890ddd
      TFillStyleP fp = fs->getFillStyle();
Toshihiro Shimizu 890ddd
      if (fp)
Toshihiro Shimizu 890ddd
        {
Toshihiro Shimizu 890ddd
        fp->
Toshihiro Shimizu 890ddd
      assert(false) ;
Toshihiro Shimizu 890ddd
    else
Toshihiro Shimizu 890ddd
      of<<"Color: ("<< colorStyle->getColor().r<<", "<< colorStyle->getColor().g<<", "<< colorStyle->getColor().b<<")"<
Toshihiro Shimizu 890ddd
   */
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			of << "----Stroke " << (it1->m_gettingOut ? "OUT" : "IN") << " #" << it1->m_edge.m_index << ": " << endl;
Toshihiro Shimizu 890ddd
			//if (it1->m_dead)
Toshihiro Shimizu 890ddd
			//of<<"---- DEAD Intersection.";
Toshihiro Shimizu 890ddd
			//else
Toshihiro Shimizu 890ddd
			{
Toshihiro Shimizu 890ddd
				of << "---- NEXT Intersection:";
Toshihiro Shimizu 890ddd
				if (it1->m_nextIntersection != intersectionList.end()) {
Toshihiro Shimizu 890ddd
					int dist = std::distance(intersectionList.begin(), it1->m_nextIntersection);
Toshihiro Shimizu 890ddd
					of << dist;
Toshihiro Shimizu 890ddd
					list<intersection>::iterator iit = intersectionList.begin();</intersection>
Toshihiro Shimizu 890ddd
					std::advance(iit, dist);
Toshihiro Shimizu 890ddd
					of << " " << std::distance(iit->m_strokeList.begin(), it1->m_nextStroke);
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				else
Toshihiro Shimizu 890ddd
					of << "NULL!!";
Toshihiro Shimizu 890ddd
				of << "---- NEXT Stroke:";
Toshihiro Shimizu 890ddd
				if (it1->m_nextIntersection != intersectionList.end())
Toshihiro Shimizu 890ddd
					of << it1->m_nextStroke->m_edge.m_index;
Toshihiro Shimizu 890ddd
				else
Toshihiro Shimizu 890ddd
					of << "NULL!!";
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			of << endl
Toshihiro Shimizu 890ddd
			   << endl;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void findNearestIntersection(list<intersection> &interList,</intersection>
Toshihiro Shimizu 890ddd
							 const list<intersection>::iterator &i1,</intersection>
Toshihiro Shimizu 890ddd
							 const list<intersectedstroke>::iterator &i2);</intersectedstroke>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef _TOLGO
Toshihiro Shimizu 890ddd
void checkInterList(list<intersection> &intersectionList)</intersection>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	list<intersection>::iterator it;</intersection>
Toshihiro Shimizu 890ddd
	list<intersectedstroke>::iterator it1;</intersectedstroke>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (it = intersectionList.begin(); it != intersectionList.end(); it++) {
Toshihiro Shimizu 890ddd
		int count = 0;
Toshihiro Shimizu 890ddd
		for (it1 = it->m_strokeList.begin(); it1 != it->m_strokeList.end(); it1++) {
Toshihiro Shimizu 890ddd
			int val;
Toshihiro Shimizu 890ddd
			if (it1->m_nextIntersection != intersectionList.end()) {
Toshihiro Shimizu 890ddd
				count++;
Toshihiro Shimizu 890ddd
				//assert (it1->m_nextIntersection!=intersectionList.end());
Toshihiro Shimizu 890ddd
				assert(it1->m_nextStroke->m_nextIntersection == it);
Toshihiro Shimizu 890ddd
				assert(it1->m_nextStroke->m_nextStroke == it1);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				//int k = it1->m_edge.m_index;
Toshihiro Shimizu 890ddd
				val = std::distance(intersectionList.begin(), it1->m_nextIntersection);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			//else
Toshihiro Shimizu 890ddd
			// assert(it1->m_nextIntersection==intersectionList.end());
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		assert(count == it->m_numInter);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#define checkInterList
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//void addFakeIntersection(list<intersection>& intersectionList,TStroke* s, UINT ii, double w);</intersection>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void addIntersections(IntersectionData &intersectionData,
Toshihiro Shimizu 890ddd
					  const vector<vistroke *=""> &s, int ii, int jj, const vector<doublepair> &intersections, int numStrokes);</doublepair></vistroke>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void addIntersection(IntersectionData &intData,
Toshihiro Shimizu 890ddd
					 const vector<vistroke *=""> &s, int ii, int jj,</vistroke>
Toshihiro Shimizu 890ddd
					 DoublePair intersections, int strokeSize);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool sortBBox(const TStroke *s1, const TStroke *s2)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return s1->getBBox().x0 < s2->getBBox().x0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void cleanIntersectionMarks(list<intersection> &interList)</intersection>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	for (list<intersection>::iterator it1 = interList.begin(); it1 != interList.end(); it1++)</intersection>
Toshihiro Shimizu 890ddd
		for (list<intersectedstroke>::iterator it2 = (*it1).m_strokeList.begin(); it2 != (*it1).m_strokeList.end(); it2++) {</intersectedstroke>
Toshihiro Shimizu 890ddd
			it2->m_visited = false; // Ogni ramo della lista viene messo nella condizione
Toshihiro Shimizu 890ddd
									// di poter essere visitato
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			if (it2->m_nextIntersection != interList.end()) {
Toshihiro Shimizu 890ddd
				it2->m_nextIntersection = interList.end(); //pezza tremenda, da togliere!!!
Toshihiro Shimizu 890ddd
				it1->m_numInter--;
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void cleanNextIntersection(list<intersection> &interList, TStroke *s)</intersection>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	for (list<intersection>::iterator it1 = interList.begin(); it1 != interList.end(); it1++)</intersection>
Toshihiro Shimizu 890ddd
		for (list<intersectedstroke>::iterator it2 = (*it1).m_strokeList.begin(); it2 != (*it1).m_strokeList.end(); it2++)</intersectedstroke>
Toshihiro Shimizu 890ddd
			if (it2->m_edge.m_s == s) {
Toshihiro Shimizu 890ddd
				//if (it2->m_nextIntersection==NULL)
Toshihiro Shimizu 890ddd
				//  return; //gia' ripulita prima
Toshihiro Shimizu 890ddd
				if (it2->m_nextIntersection != interList.end()) {
Toshihiro Shimizu 890ddd
					it2->m_nextIntersection = interList.end();
Toshihiro Shimizu 890ddd
					it1->m_numInter--;
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
				it2->m_nextStroke = (*it1).m_strokeList.end();
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TVectorImage::Imp::eraseEdgeFromStroke(list<intersectedstroke>::iterator it2)</intersectedstroke>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (it2->m_edge.m_index >= 0) //elimino il puntatore all'edge nella lista della VIStroke
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		VIStroke *s;
Toshihiro Shimizu 890ddd
		s = m_strokes[it2->m_edge.m_index];
Toshihiro Shimizu 890ddd
		assert(s->m_s == it2->m_edge.m_s);
Toshihiro Shimizu 890ddd
		list<tedge *="">::iterator iit = s->m_edgeList.begin(), it_e = s->m_edgeList.end();</tedge>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		for (; iit != it_e; ++iit)
Toshihiro Shimizu 890ddd
			if ((*iit)->m_w0 == it2->m_edge.m_w0 && (*iit)->m_w1 == it2->m_edge.m_w1) {
Toshihiro Shimizu 890ddd
				assert((*iit)->m_toBeDeleted == false);
Toshihiro Shimizu 890ddd
				s->m_edgeList.erase(iit);
Toshihiro Shimizu 890ddd
				return;
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
list<intersectedstroke>::iterator TVectorImage::Imp::eraseBranch(list<intersection>::iterator it1,</intersection></intersectedstroke>
Toshihiro Shimizu 890ddd
																 list<intersectedstroke>::iterator it2)</intersectedstroke>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	//list<intersection>::iterator iit1;</intersection>
Toshihiro Shimizu 890ddd
	//list<intersectedstroke>::iterator iit2;</intersectedstroke>
Toshihiro Shimizu 890ddd
	list<intersection> &intList = m_intersectionData.m_intList;</intersection>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (it2->m_nextIntersection != intList.end()) {
Toshihiro Shimizu 890ddd
		list<intersection>::iterator nextInt = it2->m_nextIntersection;</intersection>
Toshihiro Shimizu 890ddd
		list<intersectedstroke>::iterator nextStroke = it2->m_nextStroke;</intersectedstroke>
Toshihiro Shimizu 890ddd
		assert(nextStroke->m_nextIntersection == it1);
Toshihiro Shimizu 890ddd
		assert(nextStroke->m_nextStroke == it2);
Toshihiro Shimizu 890ddd
		assert(nextStroke != it2);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		//nextStroke->m_nextIntersection = intList.end();
Toshihiro Shimizu 890ddd
		//nextStroke->m_nextStroke = nextInt->m_strokeList.end();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (nextStroke->m_nextIntersection != intList.end()) {
Toshihiro Shimizu 890ddd
			nextStroke->m_nextIntersection = intList.end();
Toshihiro Shimizu 890ddd
			nextInt->m_numInter--;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		//nextInt->m_strokeList.erase(nextStroke);//non posso cancellarla, puo' servire in futuro!
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if (it2->m_nextIntersection != intList.end())
Toshihiro Shimizu 890ddd
		it1->m_numInter--;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	eraseEdgeFromStroke(it2);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	it2->m_edge.m_w0 = it2->m_edge.m_w1 = -3;
Toshihiro Shimizu 890ddd
	it2->m_edge.m_index = -3;
Toshihiro Shimizu 890ddd
	it2->m_edge.m_s = 0;
Toshihiro Shimizu 890ddd
	it2->m_edge.m_styleId = -3;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	list<intersectedstroke>::iterator ret = (*it1).m_strokeList.erase(it2);</intersectedstroke>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return ret;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TVectorImage::Imp::eraseDeadIntersections()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	list<intersection>::iterator it;</intersection>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (it = m_intersectionData.m_intList.begin(); it != m_intersectionData.m_intList.end();) //la faccio qui, e non nella eraseIntersection. vedi commento li'.
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		list<intersection> &intList = m_intersectionData.m_intList;</intersection>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (it->m_strokeList.size() == 1) {
Toshihiro Shimizu 890ddd
			eraseBranch(it, (*it).m_strokeList.begin());
Toshihiro Shimizu 890ddd
			assert(it->m_strokeList.empty());
Toshihiro Shimizu 890ddd
			it = intList.erase(it);
Toshihiro Shimizu 890ddd
		} else if (it->m_strokeList.size() == 2 &&
Toshihiro Shimizu 890ddd
				   ((*it).m_strokeList.front().m_edge.m_s == (*it).m_strokeList.back().m_edge.m_s &&
Toshihiro Shimizu 890ddd
					(*it).m_strokeList.front().m_edge.m_w0 == (*it).m_strokeList.back().m_edge.m_w0)) //intersezione finta
Toshihiro Shimizu 890ddd
		{
Toshihiro Shimizu 890ddd
			list<intersectedstroke>::iterator it1 = it->m_strokeList.begin(), iit1, iit2;</intersectedstroke>
Toshihiro Shimizu 890ddd
			list<intersectedstroke>::iterator it2 = it1;</intersectedstroke>
Toshihiro Shimizu 890ddd
			it2++;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			eraseEdgeFromStroke(it1);
Toshihiro Shimizu 890ddd
			eraseEdgeFromStroke(it2);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			iit1 = (it1->m_nextIntersection == intList.end()) ? NULL_ITER : it1->m_nextStroke;
Toshihiro Shimizu 890ddd
			iit2 = (it2->m_nextIntersection == intList.end()) ? NULL_ITER : it2->m_nextStroke;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			if (iit1 != NULL_ITER && iit2 != NULL_ITER) {
Toshihiro Shimizu 890ddd
				iit1->m_edge.m_w1 = iit2->m_edge.m_w0;
Toshihiro Shimizu 890ddd
				iit2->m_edge.m_w1 = iit1->m_edge.m_w0;
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			if (iit1 != NULL_ITER) {
Toshihiro Shimizu 890ddd
				iit1->m_nextStroke = iit2;
Toshihiro Shimizu 890ddd
				iit1->m_nextIntersection = it2->m_nextIntersection;
Toshihiro Shimizu 890ddd
				if (iit1->m_nextIntersection == intList.end())
Toshihiro Shimizu 890ddd
					it1->m_nextIntersection->m_numInter--;
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			if (iit2 != NULL_ITER) {
Toshihiro Shimizu 890ddd
				iit2->m_nextStroke = iit1;
Toshihiro Shimizu 890ddd
				iit2->m_nextIntersection = it1->m_nextIntersection;
Toshihiro Shimizu 890ddd
				if (iit2->m_nextIntersection == intList.end())
Toshihiro Shimizu 890ddd
					it2->m_nextIntersection->m_numInter--;
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			it->m_strokeList.clear();
Toshihiro Shimizu 890ddd
			it->m_numInter = 0;
Toshihiro Shimizu 890ddd
			it = intList.erase(it);
Toshihiro Shimizu 890ddd
		} else
Toshihiro Shimizu 890ddd
			++it;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TVectorImage::Imp::doEraseIntersection(int index, vector<int> *toBeDeleted)</int>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	list<intersection> &interList = m_intersectionData.m_intList;</intersection>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	list<intersection>::iterator it1 = interList.begin();</intersection>
Toshihiro Shimizu 890ddd
	TStroke *deleteIt = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	while (it1 != interList.end()) {
Toshihiro Shimizu 890ddd
		bool removeAutocloses = false;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		list<intersectedstroke>::iterator it2 = (*it1).m_strokeList.begin();</intersectedstroke>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		while (it2 != (*it1).m_strokeList.end()) {
Toshihiro Shimizu 890ddd
			IntersectedStroke &is = *it2;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			if (is.m_edge.m_index == index) {
Toshihiro Shimizu 890ddd
				if (is.m_edge.m_index >= 0)
Toshihiro Shimizu 890ddd
					//if (!is.m_autoclose && (is.m_edge.m_w0==1 || is.m_edge.m_w0==0))
Toshihiro Shimizu 890ddd
					removeAutocloses = true;
Toshihiro Shimizu 890ddd
				else
Toshihiro Shimizu 890ddd
					deleteIt = is.m_edge.m_s;
Toshihiro Shimizu 890ddd
				it2 = eraseBranch(it1, it2);
Toshihiro Shimizu 890ddd
			} else
Toshihiro Shimizu 890ddd
				++it2;
Toshihiro Shimizu 890ddd
			//checkInterList(interList);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		if (removeAutocloses) //se ho tolto una stroke dall'inter corrente, tolgo tutti le stroke di autclose che partono da qui
Toshihiro Shimizu 890ddd
		{
Toshihiro Shimizu 890ddd
			assert(toBeDeleted);
Toshihiro Shimizu 890ddd
			for (it2 = (*it1).m_strokeList.begin(); it2 != (*it1).m_strokeList.end(); it2++)
Toshihiro Shimizu 890ddd
				if (it2->m_edge.m_index < 0 && (it2->m_edge.m_w0 == 1 || it2->m_edge.m_w0 == 0))
Toshihiro Shimizu 890ddd
					toBeDeleted->push_back(it2->m_edge.m_index);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if ((*it1).m_strokeList.empty())
Toshihiro Shimizu 890ddd
			it1 = interList.erase(it1);
Toshihiro Shimizu 890ddd
		else
Toshihiro Shimizu 890ddd
			it1++;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (deleteIt)
Toshihiro Shimizu 890ddd
		delete deleteIt;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
UINT TVectorImage::Imp::getFillData(IntersectionBranch *&v)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	//print(m_intersectionData.m_intList, "C:\\temp\\intersectionPrimaSave.txt");
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	list<intersection> &intList = m_intersectionData.m_intList;</intersection>
Toshihiro Shimizu 890ddd
	if (intList.empty())
Toshihiro Shimizu 890ddd
		return 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	list<intersection>::iterator it1;</intersection>
Toshihiro Shimizu 890ddd
	list<intersectedstroke>::iterator it2;</intersectedstroke>
Toshihiro Shimizu 890ddd
	UINT currInt = 0;
Toshihiro Shimizu 890ddd
	vector<uint> branchesBefore(intList.size() + 1);</uint>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	branchesBefore[0] = 0;
Toshihiro Shimizu 890ddd
	UINT count = 0, size = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (it1 = intList.begin(); it1 != intList.end(); ++it1, currInt++) {
Toshihiro Shimizu 890ddd
		UINT strokeListSize = it1->m_strokeList.size();
Toshihiro Shimizu 890ddd
		size += strokeListSize;
Toshihiro Shimizu 890ddd
		branchesBefore[currInt + 1] = branchesBefore[currInt] + strokeListSize;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	v = new IntersectionBranch[size];
Toshihiro Shimizu 890ddd
	currInt = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (it1 = intList.begin(); it1 != intList.end(); ++it1, currInt++) {
Toshihiro Shimizu 890ddd
		UINT currBranch = 0;
Toshihiro Shimizu 890ddd
		for (it2 = it1->m_strokeList.begin(); it2 != it1->m_strokeList.end(); ++it2, currBranch++) {
Toshihiro Shimizu 890ddd
			IntersectionBranch &b = v[count];
Toshihiro Shimizu 890ddd
			b.m_currInter = currInt;
Toshihiro Shimizu 890ddd
			b.m_strokeIndex = it2->m_edge.m_index;
Toshihiro Shimizu 890ddd
			b.m_w = it2->m_edge.m_w0;
Toshihiro Shimizu 890ddd
			b.m_style = it2->m_edge.m_styleId;
Toshihiro Shimizu 890ddd
			//assert(b.m_style<100);
Toshihiro Shimizu 890ddd
			b.m_gettingOut = it2->m_gettingOut;
Toshihiro Shimizu 890ddd
			if (it2->m_nextIntersection == intList.end())
Toshihiro Shimizu 890ddd
				b.m_nextBranch = count;
Toshihiro Shimizu 890ddd
			else {
Toshihiro Shimizu 890ddd
				UINT distInt = std::distance(intList.begin(), it2->m_nextIntersection);
Toshihiro Shimizu 890ddd
				UINT distBranch = std::distance(it2->m_nextIntersection->m_strokeList.begin(), it2->m_nextStroke);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				if ((distInt < currInt) ||
Toshihiro Shimizu 890ddd
					(distInt == currInt && distBranch < currBranch)) {
Toshihiro Shimizu 890ddd
					UINT posNext = branchesBefore[distInt] + distBranch;
Toshihiro Shimizu 890ddd
					assert(posNext < count);
Toshihiro Shimizu 890ddd
					b.m_nextBranch = posNext;
Toshihiro Shimizu 890ddd
					assert(v[posNext].m_nextBranch == (std::numeric_limits<uint>::max)());</uint>
Toshihiro Shimizu 890ddd
					v[posNext].m_nextBranch = count;
Toshihiro Shimizu 890ddd
				} else
Toshihiro Shimizu 890ddd
					b.m_nextBranch = (std::numeric_limits<uint>::max)();</uint>
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			count++;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//for (UINT i=0; i
Toshihiro Shimizu 890ddd
//  assert(v[i].m_nextBranch != std::numeric_limits<uint>::max());</uint>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef _DEBUG
Toshihiro Shimizu 890ddd
/*ofstream of("C:\\temp\\fillDataOut.txt");
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
for (UINT ii=0; ii
Toshihiro Shimizu 890ddd
  {
Toshihiro Shimizu 890ddd
  of<
Toshihiro Shimizu 890ddd
  of<<"index:"<
Toshihiro Shimizu 890ddd
  of<<"w:"<
Toshihiro Shimizu 890ddd
  of<<"curr inter:"<
Toshihiro Shimizu 890ddd
  of<<"next inter:"<
Toshihiro Shimizu 890ddd
  of<<"gettingOut:"<<((v[ii].m_gettingOut)?"TRUE":"FALSE")<
Toshihiro Shimizu 890ddd
  of<<"colorId:"<
Toshihiro Shimizu 890ddd
  }*/
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return size;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
namespace
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
TStroke *reconstructAutocloseStroke(list<intersection> &intList,</intersection>
Toshihiro Shimizu 890ddd
									list<intersection>::iterator it1,</intersection>
Toshihiro Shimizu 890ddd
									list<intersectedstroke>::iterator it2)</intersectedstroke>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	bool found = false;
Toshihiro Shimizu 890ddd
	list<intersection>::iterator iit1 = it1;</intersection>
Toshihiro Shimizu 890ddd
	list<intersectedstroke>::iterator iit2;</intersectedstroke>
Toshihiro Shimizu 890ddd
	iit1++;
Toshihiro Shimizu 890ddd
	//vector<tedge*> vapp;</tedge*>
Toshihiro Shimizu 890ddd
	for (; !found && iit1 != intList.end(); iit1++) {
Toshihiro Shimizu 890ddd
		for (iit2 = iit1->m_strokeList.begin(); !found && iit2 != iit1->m_strokeList.end(); iit2++) {
Toshihiro Shimizu 890ddd
			if (it2->m_edge.m_index == iit2->m_edge.m_index) {
Toshihiro Shimizu 890ddd
				if ((iit2->m_edge.m_w0 == 1 && it2->m_edge.m_w0 == 0) ||
Toshihiro Shimizu 890ddd
					(iit2->m_edge.m_w0 == 0 && it2->m_edge.m_w0 == 1)) {
Toshihiro Shimizu 890ddd
					found = true;
Toshihiro Shimizu 890ddd
					vector<tpointd> v;</tpointd>
Toshihiro Shimizu 890ddd
					if (it2->m_edge.m_w0 == 0) {
Toshihiro Shimizu 890ddd
						v.push_back(it1->m_intersection);
Toshihiro Shimizu 890ddd
						v.push_back(iit1->m_intersection);
Toshihiro Shimizu 890ddd
					} else {
Toshihiro Shimizu 890ddd
						v.push_back(iit1->m_intersection);
Toshihiro Shimizu 890ddd
						v.push_back(it1->m_intersection);
Toshihiro Shimizu 890ddd
					}
Toshihiro Shimizu 890ddd
					it2->m_edge.m_s = iit2->m_edge.m_s = new TStroke(v);
Toshihiro Shimizu 890ddd
					//for (UINT ii=0; ii
Toshihiro Shimizu 890ddd
					// vapp[ii]->m_s = it2->m_edge.m_s;
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
				//else if (iit2->m_edge.m_w0!=0 && iit2->m_edge.m_w0!=1)
Toshihiro Shimizu 890ddd
				//  vapp.push_back(&(iit2->m_edge));
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	assert(found);
Toshihiro Shimizu 890ddd
	if (!found)
Toshihiro Shimizu 890ddd
		it2->m_edge.m_s = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return it2->m_edge.m_s;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
} //namespace
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TVectorImage::Imp::setFillData(IntersectionBranch *v, UINT branchCount)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
#ifdef _DEBUG
Toshihiro Shimizu 890ddd
/*ofstream of("C:\\temp\\fillDataIn.txt");
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
for (UINT ii=0; ii
Toshihiro Shimizu 890ddd
  {
Toshihiro Shimizu 890ddd
  of<
Toshihiro Shimizu 890ddd
  of<<"index:"<
Toshihiro Shimizu 890ddd
  of<<"w:"<
Toshihiro Shimizu 890ddd
  of<<"curr inter:"<
Toshihiro Shimizu 890ddd
  of<<"next inter:"<
Toshihiro Shimizu 890ddd
  of<<"gettingOut:"<<((v[ii].m_gettingOut)?"TRUE":"FALSE")<
Toshihiro Shimizu 890ddd
  of<<"colorId:"<
Toshihiro Shimizu 890ddd
  }*/
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (branchCount == 0)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	list<intersection> &intList = m_intersectionData.m_intList;</intersection>
Toshihiro Shimizu 890ddd
	clearPointerContainer(m_regions);
Toshihiro Shimizu 890ddd
	m_regions.clear();
Toshihiro Shimizu 890ddd
	intList.clear();
Toshihiro Shimizu 890ddd
	list<intersection>::iterator currInt;</intersection>
Toshihiro Shimizu 890ddd
	list<intersectedstroke>::iterator currBranch;</intersectedstroke>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	vector<uint> branchesBefore(v[branchCount - 1].m_currInter + 1);</uint>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	UINT i = 0;
Toshihiro Shimizu 890ddd
	for (; i < branchCount; i++) {
Toshihiro Shimizu 890ddd
		const IntersectionBranch &b = v[i];
Toshihiro Shimizu 890ddd
		if (i == 0 || v[i].m_currInter != v[i - 1].m_currInter) {
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			assert(i == 0 || v[i].m_currInter == v[i - 1].m_currInter + 1);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			branchesBefore[v[i].m_currInter] = i;
Toshihiro Shimizu 890ddd
			intList.push_back(Intersection());
Toshihiro Shimizu 890ddd
			currInt = intList.begin();
Toshihiro Shimizu 890ddd
			advance(currInt, intList.size() - 1);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		IntersectedStroke is;
Toshihiro Shimizu 890ddd
		currInt->m_strokeList.push_back(is);
Toshihiro Shimizu 890ddd
		currBranch = currInt->m_strokeList.begin();
Toshihiro Shimizu 890ddd
		advance(currBranch, currInt->m_strokeList.size() - 1);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		currBranch->m_edge.m_styleId = b.m_style;
Toshihiro Shimizu 890ddd
		//assert(b.m_style<100);
Toshihiro Shimizu 890ddd
		currBranch->m_edge.m_index = b.m_strokeIndex;
Toshihiro Shimizu 890ddd
		if (b.m_strokeIndex >= 0)
Toshihiro Shimizu 890ddd
			currBranch->m_edge.m_s = m_strokes[b.m_strokeIndex]->m_s;
Toshihiro Shimizu 890ddd
		else
Toshihiro Shimizu 890ddd
			currBranch->m_edge.m_s = 0;
Toshihiro Shimizu 890ddd
		currBranch->m_gettingOut = b.m_gettingOut;
Toshihiro Shimizu 890ddd
		currBranch->m_edge.m_w0 = b.m_w;
Toshihiro Shimizu 890ddd
		currBranch->m_edge.m_w1 = v[b.m_nextBranch].m_w;
Toshihiro Shimizu 890ddd
		assert(currBranch->m_edge.m_w0 >= -1e-8 && currBranch->m_edge.m_w0 <= 1 + 1e-8);
Toshihiro Shimizu 890ddd
		assert(currBranch->m_edge.m_w1 >= -1e-8 && currBranch->m_edge.m_w1 <= 1 + 1e-8);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (b.m_nextBranch < i) {
Toshihiro Shimizu 890ddd
			list<intersection>::iterator it1;</intersection>
Toshihiro Shimizu 890ddd
			list<intersectedstroke>::iterator it2;</intersectedstroke>
Toshihiro Shimizu 890ddd
			it1 = intList.begin();
Toshihiro Shimizu 890ddd
			std::advance(it1, v[b.m_nextBranch].m_currInter);
Toshihiro Shimizu 890ddd
			it2 = it1->m_strokeList.begin();
Toshihiro Shimizu 890ddd
			assert(b.m_nextBranch - branchesBefore[v[b.m_nextBranch].m_currInter] >= 0);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			std::advance(it2, b.m_nextBranch - branchesBefore[v[b.m_nextBranch].m_currInter]);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			currBranch->m_nextIntersection = it1;
Toshihiro Shimizu 890ddd
			currBranch->m_nextStroke = it2;
Toshihiro Shimizu 890ddd
			it2->m_nextIntersection = currInt;
Toshihiro Shimizu 890ddd
			it2->m_nextStroke = currBranch;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			//if (currBranch == currInt->m_strokeList.begin())
Toshihiro Shimizu 890ddd
			//  currInt->m_intersection = currBranch->m_edge.m_s->getPoint(currBranch->m_edge.m_w0);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			currInt->m_numInter++;
Toshihiro Shimizu 890ddd
			it1->m_numInter++;
Toshihiro Shimizu 890ddd
		} else if (b.m_nextBranch == i)
Toshihiro Shimizu 890ddd
			currBranch->m_nextIntersection = intList.end();
Toshihiro Shimizu 890ddd
		else if (b.m_nextBranch == (std::numeric_limits<uint>::max)()) {</uint>
Toshihiro Shimizu 890ddd
			currBranch->m_nextIntersection = intList.end();
Toshihiro Shimizu 890ddd
			currBranch->m_nextStroke = currInt->m_strokeList.end();
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		/* {
Toshihiro Shimizu 890ddd
    assert(b.m_nextBranch
Toshihiro Shimizu 890ddd
    assert(v[b.m_nextBranch].m_nextBranch==i);
Toshihiro Shimizu 890ddd
    }*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (i == branchCount - 1 || v[i].m_currInter != v[i + 1].m_currInter) {
Toshihiro Shimizu 890ddd
			int j = i;
Toshihiro Shimizu 890ddd
			while (v[j].m_strokeIndex < 0 && ((j > 0 && v[j].m_currInter == v[j - 1].m_currInter) || j == 0))
Toshihiro Shimizu 890ddd
				j--;
Toshihiro Shimizu 890ddd
			if (v[j].m_strokeIndex >= 0)
Toshihiro Shimizu 890ddd
				currInt->m_intersection = m_strokes[v[j].m_strokeIndex]->m_s->getPoint(v[j].m_w);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (i = 0; i < m_strokes.size(); i++)
Toshihiro Shimizu 890ddd
		m_strokes[i]->m_isNewForFill = false;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//computeRegions();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	list<intersection>::iterator it1;</intersection>
Toshihiro Shimizu 890ddd
	list<intersectedstroke>::iterator it2;</intersectedstroke>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	vector<uint> toBeDeleted;</uint>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (it1 = intList.begin(); it1 != intList.end(); it1++)
Toshihiro Shimizu 890ddd
		for (it2 = it1->m_strokeList.begin(); it2 != it1->m_strokeList.end(); ++it2) {
Toshihiro Shimizu 890ddd
			if (it2->m_edge.m_index < 0 && !it2->m_edge.m_s &&
Toshihiro Shimizu 890ddd
				(it2->m_edge.m_w0 == 0 || it2->m_edge.m_w0 == 1)) {
Toshihiro Shimizu 890ddd
				it2->m_edge.m_s = reconstructAutocloseStroke(intList, it1, it2);
Toshihiro Shimizu 890ddd
				if (it2->m_edge.m_s)
Toshihiro Shimizu 890ddd
					m_intersectionData.m_autocloseMap[it2->m_edge.m_index] = it2->m_edge.m_s;
Toshihiro Shimizu 890ddd
				else
Toshihiro Shimizu 890ddd
					toBeDeleted.push_back(it2->m_edge.m_index);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (it1 = intList.begin(); it1 != intList.end(); it1++)
Toshihiro Shimizu 890ddd
		for (it2 = it1->m_strokeList.begin(); it2 != it1->m_strokeList.end(); ++it2) {
Toshihiro Shimizu 890ddd
			if (!it2->m_edge.m_s && it2->m_edge.m_index < 0) {
Toshihiro Shimizu 890ddd
				it2->m_edge.m_s = m_intersectionData.m_autocloseMap[it2->m_edge.m_index];
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				//TEdge& e = it2->m_edge;
Toshihiro Shimizu 890ddd
				if (!it2->m_edge.m_s)
Toshihiro Shimizu 890ddd
					toBeDeleted.push_back(it2->m_edge.m_index);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (i = 0; i < toBeDeleted.size(); i++)
Toshihiro Shimizu 890ddd
		eraseIntersection(toBeDeleted[i]);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_areValidRegions = false;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	computeRegions();
Toshihiro Shimizu 890ddd
	//print(m_intersectionData.m_intList, "C:\\temp\\intersectionDopoLoad.txt");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TVectorImage::Imp::eraseIntersection(int index)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	vector<int> autocloseStrokes;</int>
Toshihiro Shimizu 890ddd
	doEraseIntersection(index, &autocloseStrokes);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (UINT i = 0; i < autocloseStrokes.size(); i++) {
Toshihiro Shimizu 890ddd
		doEraseIntersection(autocloseStrokes[i]);
Toshihiro Shimizu 890ddd
		assert(autocloseStrokes[i] < 0);
Toshihiro Shimizu 890ddd
		m_intersectionData.m_autocloseMap.erase(autocloseStrokes[i]);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void findNearestIntersection(list<intersection> &interList)</intersection>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	list<intersection>::iterator i1;</intersection>
Toshihiro Shimizu 890ddd
	list<intersectedstroke>::iterator i2;</intersectedstroke>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (i1 = interList.begin(); i1 != interList.end(); i1++) {
Toshihiro Shimizu 890ddd
		for (i2 = (*i1).m_strokeList.begin(); i2 != (*i1).m_strokeList.end(); i2++) {
Toshihiro Shimizu 890ddd
			if ((*i2).m_nextIntersection != interList.end()) //already set
Toshihiro Shimizu 890ddd
				continue;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			int versus = (i2->m_gettingOut) ? 1 : -1;
Toshihiro Shimizu 890ddd
			double minDelta = (std::numeric_limits<double>::max)();</double>
Toshihiro Shimizu 890ddd
			list<intersection>::iterator it1, it1Res;</intersection>
Toshihiro Shimizu 890ddd
			list<intersectedstroke>::iterator it2, it2Res;</intersectedstroke>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			for (it1 = i1; it1 != interList.end(); ++it1) {
Toshihiro Shimizu 890ddd
				if (it1 == i1)
Toshihiro Shimizu 890ddd
					it2 = i2, it2++;
Toshihiro Shimizu 890ddd
				else
Toshihiro Shimizu 890ddd
					it2 = (*it1).m_strokeList.begin();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				for (; it2 != (*it1).m_strokeList.end(); ++it2) {
Toshihiro Shimizu 890ddd
					if ((*it2).m_edge.m_index == i2->m_edge.m_index &&
Toshihiro Shimizu 890ddd
						(*it2).m_gettingOut == !i2->m_gettingOut) {
Toshihiro Shimizu 890ddd
						double delta = versus * (it2->m_edge.m_w0 - i2->m_edge.m_w0);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
						if (delta > 0 && delta < minDelta) {
Toshihiro Shimizu 890ddd
							it1Res = it1;
Toshihiro Shimizu 890ddd
							it2Res = it2;
Toshihiro Shimizu 890ddd
							minDelta = delta;
Toshihiro Shimizu 890ddd
						}
Toshihiro Shimizu 890ddd
					}
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			if (minDelta != (std::numeric_limits<double>::max)()) {</double>
Toshihiro Shimizu 890ddd
				(*it2Res).m_nextIntersection = i1;
Toshihiro Shimizu 890ddd
				(*it2Res).m_nextStroke = i2;
Toshihiro Shimizu 890ddd
				(*it2Res).m_edge.m_w1 = i2->m_edge.m_w0;
Toshihiro Shimizu 890ddd
				(*i2).m_nextIntersection = it1Res;
Toshihiro Shimizu 890ddd
				(*i2).m_nextStroke = it2Res;
Toshihiro Shimizu 890ddd
				(*i2).m_edge.m_w1 = it2Res->m_edge.m_w0;
Toshihiro Shimizu 890ddd
				i1->m_numInter++;
Toshihiro Shimizu 890ddd
				it1Res->m_numInter++;
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
void markDeadIntersections(list<intersection> &intList,</intersection>
Toshihiro Shimizu 890ddd
						   list<intersection>::iterator it);</intersection>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//questa funzione "cuscinetto" serve perche crashava il compilatore in release!!!
Toshihiro Shimizu 890ddd
void inline markDeadIntersectionsRic(list<intersection> &intList,</intersection>
Toshihiro Shimizu 890ddd
									 list<intersection>::iterator it)</intersection>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	markDeadIntersections(intList, it);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void markDeadIntersections(list<intersection> &intList,</intersection>
Toshihiro Shimizu 890ddd
						   list<intersection>::iterator it)</intersection>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	list<intersectedstroke>::iterator it1 = it->m_strokeList.begin();</intersectedstroke>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (it->m_numInter == 1) {
Toshihiro Shimizu 890ddd
		while (it1->m_nextIntersection == intList.end())
Toshihiro Shimizu 890ddd
			it1++;
Toshihiro Shimizu 890ddd
		assert(it1 != it->m_strokeList.end());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		list<intersection>::iterator nextInt = it1->m_nextIntersection;</intersection>
Toshihiro Shimizu 890ddd
		list<intersectedstroke>::iterator nextStroke = it1->m_nextStroke;</intersectedstroke>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		it->m_numInter = 0;
Toshihiro Shimizu 890ddd
		it1->m_nextIntersection = intList.end();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (nextInt != intList.end() /*&& !nextStroke->m_dead*/) {
Toshihiro Shimizu 890ddd
			nextInt->m_numInter--;
Toshihiro Shimizu 890ddd
			nextStroke->m_nextIntersection = intList.end();
Toshihiro Shimizu 890ddd
			markDeadIntersectionsRic(intList, nextInt);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	} else if (it->m_numInter == 2) //intersezione finta (forse)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		while (it1 != it->m_strokeList.end() && it1->m_nextIntersection == intList.end())
Toshihiro Shimizu 890ddd
			it1++;
Toshihiro Shimizu 890ddd
		assert(it1 != it->m_strokeList.end());
Toshihiro Shimizu 890ddd
		list<intersectedstroke>::iterator it2 = it1;</intersectedstroke>
Toshihiro Shimizu 890ddd
		it2++;
Toshihiro Shimizu 890ddd
		while (it2 != it->m_strokeList.end() && it2->m_nextIntersection == intList.end())
Toshihiro Shimizu 890ddd
			it2++;
Toshihiro Shimizu 890ddd
		assert(it2 != it->m_strokeList.end());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (it1->m_edge.m_s == it2->m_edge.m_s && it1->m_edge.m_w0 == it2->m_edge.m_w0) //intersezione finta
Toshihiro Shimizu 890ddd
		{
Toshihiro Shimizu 890ddd
			list<intersectedstroke>::iterator iit1, iit2;</intersectedstroke>
Toshihiro Shimizu 890ddd
			assert(it1->m_nextIntersection != intList.end() && it2->m_nextIntersection != intList.end());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			iit1 = it1->m_nextStroke;
Toshihiro Shimizu 890ddd
			iit2 = it2->m_nextStroke;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			iit2->m_edge.m_w1 = iit1->m_edge.m_w0;
Toshihiro Shimizu 890ddd
			iit1->m_edge.m_w1 = iit2->m_edge.m_w0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			//if (iit1!=0)
Toshihiro Shimizu 890ddd
			(*iit1).m_nextStroke = iit2;
Toshihiro Shimizu 890ddd
			//if (iit2!=0)
Toshihiro Shimizu 890ddd
			(*iit2).m_nextStroke = iit1;
Toshihiro Shimizu 890ddd
			//if (iit1!=0)
Toshihiro Shimizu 890ddd
			(*iit1).m_nextIntersection = it2->m_nextIntersection;
Toshihiro Shimizu 890ddd
			//if (iit2!=0)
Toshihiro Shimizu 890ddd
			(*iit2).m_nextIntersection = it1->m_nextIntersection;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			it->m_numInter = 0;
Toshihiro Shimizu 890ddd
			it1->m_nextIntersection = intList.end();
Toshihiro Shimizu 890ddd
			it2->m_nextIntersection = intList.end();
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//se cross val era 0, cerco di spostarmi un po' su w per vedere come sono orientate le tangenti agli stroke...
Toshihiro Shimizu 890ddd
double nearCrossVal(TStroke *s0, double w0, TStroke *s1, double w1)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	double ltot0 = s0->getLength();
Toshihiro Shimizu 890ddd
	double ltot1 = s1->getLength();
Toshihiro Shimizu 890ddd
	double dl = tmin(ltot1, ltot0) / 1000;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double crossVal, dl0 = dl, dl1 = dl;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPointD p0, p1;
Toshihiro Shimizu 890ddd
	int count = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (w0 == 1.0)
Toshihiro Shimizu 890ddd
		dl0 = -dl0;
Toshihiro Shimizu 890ddd
	if (w1 == 1.0)
Toshihiro Shimizu 890ddd
		dl1 = -dl1;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double l0 = s0->getLength(w0) + dl0;
Toshihiro Shimizu 890ddd
	double l1 = s1->getLength(w1) + dl1;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	do {
Toshihiro Shimizu 890ddd
		p0 = s0->getSpeed(s0->getParameterAtLength(l0));
Toshihiro Shimizu 890ddd
		p1 = s1->getSpeed(s1->getParameterAtLength(l1));
Toshihiro Shimizu 890ddd
		crossVal = cross(p0, p1);
Toshihiro Shimizu 890ddd
		l0 += dl0, l1 += dl1;
Toshihiro Shimizu 890ddd
		count++;
Toshihiro Shimizu 890ddd
	} while (areAlmostEqual(crossVal, 0.0) &&
Toshihiro Shimizu 890ddd
			 ((dl0 > 0 && l0 < ltot0) || (dl0 < 0 && l0 > 0)) &&
Toshihiro Shimizu 890ddd
			 ((dl1 > 0 && l1 < ltot1) || (dl1 < 0 && l1 > 0)));
Toshihiro Shimizu 890ddd
	return crossVal;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
inline void insertBranch(Intersection &interList, IntersectedStroke &item, bool gettingOut)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (item.m_edge.m_w0 != (gettingOut ? 1.0 : 0.0)) {
Toshihiro Shimizu 890ddd
		item.m_gettingOut = gettingOut;
Toshihiro Shimizu 890ddd
		interList.m_strokeList.push_back(item);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
double getAngle(const TPointD &p0, const TPointD &p1)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	double angle1 = 180 * atan2(p0.x, p0.y) / TConsts::pi;
Toshihiro Shimizu 890ddd
	double angle2 = 180 * atan2(p1.x, p1.y) / TConsts::pi;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (angle1 < 0)
Toshihiro Shimizu 890ddd
		angle1 = 360 + angle1;
Toshihiro Shimizu 890ddd
	if (angle2 < 0)
Toshihiro Shimizu 890ddd
		angle2 = 360 + angle2;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return (angle2 - angle1) < 0 ? 360 + angle2 - angle1 : angle2 - angle1;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
//nel caso l'angolo tra due stroke in un certo w sia nullo,
Toshihiro Shimizu 890ddd
// si va un po' avanti per vedere come sono orientate....
Toshihiro Shimizu 890ddd
double getNearAngle(const TStroke *s1, double w1, bool out1, const TStroke *s2, double w2, bool out2)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	bool verse1 = (out1 && w1 < 1) || (!out1 && w1 == 0);
Toshihiro Shimizu 890ddd
	bool verse2 = (out2 && w2 < 1) || (!out2 && w2 == 0);
Toshihiro Shimizu 890ddd
	double ltot1 = s1->getLength();
Toshihiro Shimizu 890ddd
	double ltot2 = s2->getLength();
Toshihiro Shimizu 890ddd
	double l1 = s1->getLength(w1);
Toshihiro Shimizu 890ddd
	double l2 = s2->getLength(w2);
Toshihiro Shimizu 890ddd
	double dl = min(ltot1, ltot2) / 1000;
Toshihiro Shimizu 890ddd
	double dl1 = verse1 ? dl : -dl;
Toshihiro Shimizu 890ddd
	double dl2 = verse2 ? dl : -dl;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	while (((verse1 && l1 < ltot1) || (!verse1 && l1 > 0)) && ((verse2 && l2 < ltot2) || (!verse2 && l2 > 0))) {
Toshihiro Shimizu 890ddd
		l1 += dl1;
Toshihiro Shimizu 890ddd
		l2 += dl2;
Toshihiro Shimizu 890ddd
		TPointD p1 = (out1 ? 1 : -1) * s1->getSpeed(s1->getParameterAtLength(l1));
Toshihiro Shimizu 890ddd
		TPointD p2 = (out2 ? 1 : -1) * s2->getSpeed(s2->getParameterAtLength(l2));
Toshihiro Shimizu 890ddd
		double angle = getAngle(p1, p2);
Toshihiro Shimizu 890ddd
		if (!areAlmostEqual(angle, 0, 1e-9))
Toshihiro Shimizu 890ddd
			return angle;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	return 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool makeEdgeIntersection(Intersection &interList, IntersectedStroke &item1, IntersectedStroke &item2,
Toshihiro Shimizu 890ddd
						  const TPointD &p1a, const TPointD &p1b, const TPointD &p2a, const TPointD &p2b)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	double angle1 = getAngle(p1a, p1b);
Toshihiro Shimizu 890ddd
	double angle2 = getAngle(p1a, p2a);
Toshihiro Shimizu 890ddd
	double angle3 = getAngle(p1a, p2b);
Toshihiro Shimizu 890ddd
	double angle;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool eraseP1b = false, eraseP2a = false, eraseP2b = false;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (areAlmostEqual(angle1, 0, 1e-9)) {
Toshihiro Shimizu 890ddd
		angle1 = getNearAngle(item1.m_edge.m_s, item1.m_edge.m_w0, true, item1.m_edge.m_s, item1.m_edge.m_w0, false);
Toshihiro Shimizu 890ddd
		if (areAlmostEqual(angle1, 1e-9))
Toshihiro Shimizu 890ddd
			eraseP1b = true;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if (areAlmostEqual(angle2, 0, 1e-9)) {
Toshihiro Shimizu 890ddd
		angle2 = getNearAngle(item1.m_edge.m_s, item1.m_edge.m_w0, true, item2.m_edge.m_s, item2.m_edge.m_w0, true);
Toshihiro Shimizu 890ddd
		if (areAlmostEqual(angle2, 1e-9))
Toshihiro Shimizu 890ddd
			eraseP2a = true;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if (areAlmostEqual(angle3, 0, 1e-9)) {
Toshihiro Shimizu 890ddd
		angle3 = getNearAngle(item1.m_edge.m_s, item1.m_edge.m_w0, true, item2.m_edge.m_s, item2.m_edge.m_w0, false);
Toshihiro Shimizu 890ddd
		if (areAlmostEqual(angle3, 1e-9))
Toshihiro Shimizu 890ddd
			eraseP2b = true;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (areAlmostEqual(angle1, angle2, 1e-9)) {
Toshihiro Shimizu 890ddd
		angle = getNearAngle(item1.m_edge.m_s, item1.m_edge.m_w0, false, item2.m_edge.m_s, item2.m_edge.m_w0, true);
Toshihiro Shimizu 890ddd
		if (angle != 0) {
Toshihiro Shimizu 890ddd
			angle2 += angle;
Toshihiro Shimizu 890ddd
			if (angle2 > 360)
Toshihiro Shimizu 890ddd
				angle2 -= 360;
Toshihiro Shimizu 890ddd
		} else
Toshihiro Shimizu 890ddd
			eraseP2a = true;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if (areAlmostEqual(angle1, angle3, 1e-9)) {
Toshihiro Shimizu 890ddd
		angle = getNearAngle(item1.m_edge.m_s, item1.m_edge.m_w0, false, item2.m_edge.m_s, item2.m_edge.m_w0, false);
Toshihiro Shimizu 890ddd
		if (angle != 0) {
Toshihiro Shimizu 890ddd
			angle3 += angle;
Toshihiro Shimizu 890ddd
			if (angle3 > 360)
Toshihiro Shimizu 890ddd
				angle3 -= 360;
Toshihiro Shimizu 890ddd
		} else
Toshihiro Shimizu 890ddd
			eraseP2b = true;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if (areAlmostEqual(angle2, angle3, 1e-9)) {
Toshihiro Shimizu 890ddd
		angle = getNearAngle(item1.m_edge.m_s, item1.m_edge.m_w0, false, item2.m_edge.m_s, item2.m_edge.m_w0, true);
Toshihiro Shimizu 890ddd
		if (angle != 0) {
Toshihiro Shimizu 890ddd
			angle3 += angle;
Toshihiro Shimizu 890ddd
			if (angle3 > 360)
Toshihiro Shimizu 890ddd
				angle3 -= 360;
Toshihiro Shimizu 890ddd
		} else
Toshihiro Shimizu 890ddd
			eraseP2b = true;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int fac = (angle1 < angle2) | ((angle1 < angle3) << 1) | ((angle2 < angle3) << 2);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	switch (fac) {
Toshihiro Shimizu 890ddd
		CASE 0 : //p1a p2b p2a p1b
Toshihiro Shimizu 890ddd
				 insertBranch(interList, item1, true);
Toshihiro Shimizu 890ddd
		if (!eraseP2b)
Toshihiro Shimizu 890ddd
			insertBranch(interList, item2, false);
Toshihiro Shimizu 890ddd
		if (!eraseP2a)
Toshihiro Shimizu 890ddd
			insertBranch(interList, item2, true);
Toshihiro Shimizu 890ddd
		if (!eraseP1b)
Toshihiro Shimizu 890ddd
			insertBranch(interList, item1, false);
Toshihiro Shimizu 890ddd
		CASE 1 : //p1a p2b p1b p2a
Toshihiro Shimizu 890ddd
				 insertBranch(interList, item1, true);
Toshihiro Shimizu 890ddd
		if (!eraseP2b)
Toshihiro Shimizu 890ddd
			insertBranch(interList, item2, false);
Toshihiro Shimizu 890ddd
		if (!eraseP1b)
Toshihiro Shimizu 890ddd
			insertBranch(interList, item1, false);
Toshihiro Shimizu 890ddd
		if (!eraseP2a)
Toshihiro Shimizu 890ddd
			insertBranch(interList, item2, true);
Toshihiro Shimizu 890ddd
		CASE 2 : assert(false);
Toshihiro Shimizu 890ddd
		CASE 3 : //p1a p1b p2b p2a
Toshihiro Shimizu 890ddd
				 insertBranch(interList, item1, true);
Toshihiro Shimizu 890ddd
		if (!eraseP1b)
Toshihiro Shimizu 890ddd
			insertBranch(interList, item1, false);
Toshihiro Shimizu 890ddd
		if (!eraseP2b)
Toshihiro Shimizu 890ddd
			insertBranch(interList, item2, false);
Toshihiro Shimizu 890ddd
		if (!eraseP2a)
Toshihiro Shimizu 890ddd
			insertBranch(interList, item2, true);
Toshihiro Shimizu 890ddd
		CASE 4 : //p1a p2a p2b p1b
Toshihiro Shimizu 890ddd
				 insertBranch(interList, item1, true);
Toshihiro Shimizu 890ddd
		if (!eraseP2a)
Toshihiro Shimizu 890ddd
			insertBranch(interList, item2, true);
Toshihiro Shimizu 890ddd
		if (!eraseP2b)
Toshihiro Shimizu 890ddd
			insertBranch(interList, item2, false);
Toshihiro Shimizu 890ddd
		if (!eraseP1b)
Toshihiro Shimizu 890ddd
			insertBranch(interList, item1, false);
Toshihiro Shimizu 890ddd
		CASE 5 : assert(false);
Toshihiro Shimizu 890ddd
		CASE 6 : //p1a p2a p1b p2b
Toshihiro Shimizu 890ddd
				 insertBranch(interList, item1, true);
Toshihiro Shimizu 890ddd
		if (!eraseP2a)
Toshihiro Shimizu 890ddd
			insertBranch(interList, item2, true);
Toshihiro Shimizu 890ddd
		if (!eraseP1b)
Toshihiro Shimizu 890ddd
			insertBranch(interList, item1, false);
Toshihiro Shimizu 890ddd
		if (!eraseP2b)
Toshihiro Shimizu 890ddd
			insertBranch(interList, item2, false);
Toshihiro Shimizu 890ddd
		CASE 7 : //p1a p1b p2a p2b
Toshihiro Shimizu 890ddd
				 insertBranch(interList, item1, true);
Toshihiro Shimizu 890ddd
		if (!eraseP1b)
Toshihiro Shimizu 890ddd
			insertBranch(interList, item1, false);
Toshihiro Shimizu 890ddd
		if (!eraseP2a)
Toshihiro Shimizu 890ddd
			insertBranch(interList, item2, true);
Toshihiro Shimizu 890ddd
		if (!eraseP2b)
Toshihiro Shimizu 890ddd
			insertBranch(interList, item2, false);
Toshihiro Shimizu 890ddd
	DEFAULT:
Toshihiro Shimizu 890ddd
		assert(false);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool makeIntersection(IntersectionData &intData, const vector<vistroke *=""> &s, int ii, int jj,</vistroke>
Toshihiro Shimizu 890ddd
					  DoublePair inter, int strokeSize, Intersection &interList)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	IntersectedStroke item1(intData.m_intList.end(), NULL_ITER),
Toshihiro Shimizu 890ddd
		item2(intData.m_intList.end(), NULL_ITER);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	interList.m_intersection = s[ii]->m_s->getPoint(inter.first);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	item1.m_edge.m_w0 = inter.first;
Toshihiro Shimizu 890ddd
	item2.m_edge.m_w0 = inter.second;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (ii >= 0 && ii < strokeSize) {
Toshihiro Shimizu 890ddd
		item1.m_edge.m_s = s[ii]->m_s;
Toshihiro Shimizu 890ddd
		item1.m_edge.m_index = ii;
Toshihiro Shimizu 890ddd
	} else {
Toshihiro Shimizu 890ddd
		if (ii < 0) {
Toshihiro Shimizu 890ddd
			item1.m_edge.m_s = intData.m_autocloseMap[ii];
Toshihiro Shimizu 890ddd
			item1.m_edge.m_index = ii;
Toshihiro Shimizu 890ddd
		} else {
Toshihiro Shimizu 890ddd
			item1.m_edge.m_s = s[ii]->m_s;
Toshihiro Shimizu 890ddd
			item1.m_edge.m_index = -(ii + intData.maxAutocloseId * 100000);
Toshihiro Shimizu 890ddd
			intData.m_autocloseMap[item1.m_edge.m_index] = item1.m_edge.m_s;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (jj >= 0 && jj < strokeSize) {
Toshihiro Shimizu 890ddd
		item2.m_edge.m_s = s[jj]->m_s;
Toshihiro Shimizu 890ddd
		item2.m_edge.m_index = jj;
Toshihiro Shimizu 890ddd
	} else {
Toshihiro Shimizu 890ddd
		if (jj < 0) {
Toshihiro Shimizu 890ddd
			item2.m_edge.m_s = intData.m_autocloseMap[jj];
Toshihiro Shimizu 890ddd
			item2.m_edge.m_index = jj;
Toshihiro Shimizu 890ddd
		} else {
Toshihiro Shimizu 890ddd
			item2.m_edge.m_s = s[jj]->m_s;
Toshihiro Shimizu 890ddd
			item2.m_edge.m_index = -(jj + intData.maxAutocloseId * 100000);
Toshihiro Shimizu 890ddd
			intData.m_autocloseMap[item2.m_edge.m_index] = item2.m_edge.m_s;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool reversed = false;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPointD p0, p0b, p1, p1b;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool ret1 = item1.m_edge.m_s->getSpeedTwoValues(item1.m_edge.m_w0, p0, p0b);
Toshihiro Shimizu 890ddd
	bool ret2 = item2.m_edge.m_s->getSpeedTwoValues(item2.m_edge.m_w0, p1, p1b);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (ret1 || ret2) //punto angoloso!!!!
Toshihiro Shimizu 890ddd
		return makeEdgeIntersection(interList, item1, item2, p0, p0b, p1, p1b);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double crossVal = cross(p0, p1);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//crossVal = cross(p0, p1);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (areAlmostEqual(crossVal, 0.0)) {
Toshihiro Shimizu 890ddd
		bool endpoint1 = (item1.m_edge.m_w0 == 0.0 || item1.m_edge.m_w0 == 1.0);
Toshihiro Shimizu 890ddd
		bool endpoint2 = (item2.m_edge.m_w0 == 0.0 || item2.m_edge.m_w0 == 1.0);
Toshihiro Shimizu 890ddd
		if (endpoint1 &&
Toshihiro Shimizu 890ddd
			endpoint2 &&
Toshihiro Shimizu 890ddd
			((p0.x * p1.x >= 0 && p0.y * p1.y >= 0 && item1.m_edge.m_w0 != item2.m_edge.m_w0) ||
Toshihiro Shimizu 890ddd
			 (p0.x * p1.x <= 0 && p0.y * p1.y <= 0 && item1.m_edge.m_w0 == item2.m_edge.m_w0)))
Toshihiro Shimizu 890ddd
		//due endpoint a 180 gradi;metto
Toshihiro Shimizu 890ddd
		{
Toshihiro Shimizu 890ddd
			item1.m_gettingOut = (item1.m_edge.m_w0 == 0.0);
Toshihiro Shimizu 890ddd
			interList.m_strokeList.push_back(item1);
Toshihiro Shimizu 890ddd
			item2.m_gettingOut = (item2.m_edge.m_w0 == 0.0);
Toshihiro Shimizu 890ddd
			interList.m_strokeList.push_back(item2);
Toshihiro Shimizu 890ddd
			return true;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		//crossVal = nearCrossVal(item1.m_edge.m_s, item1.m_edge.m_w0, item2.m_edge.m_s, item2.m_edge.m_w0);
Toshihiro Shimizu 890ddd
		//if (areAlmostEqual(crossVal, 0.0))
Toshihiro Shimizu 890ddd
		// return false;
Toshihiro Shimizu 890ddd
		return makeEdgeIntersection(interList, item1, item2, p0, p0b, p1, p1b);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (crossVal > 0)
Toshihiro Shimizu 890ddd
		reversed = true; //std::reverse(interList.m_strokeList.begin(), interList.m_strokeList.end());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (item1.m_edge.m_w0 != 1.0) {
Toshihiro Shimizu 890ddd
		item1.m_gettingOut = true;
Toshihiro Shimizu 890ddd
		interList.m_strokeList.push_back(item1);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if (item2.m_edge.m_w0 != (reversed ? 0.0 : 1.0)) {
Toshihiro Shimizu 890ddd
		item2.m_gettingOut = !reversed;
Toshihiro Shimizu 890ddd
		interList.m_strokeList.push_back(item2);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if (item1.m_edge.m_w0 != 0.0) {
Toshihiro Shimizu 890ddd
		item1.m_gettingOut = false;
Toshihiro Shimizu 890ddd
		interList.m_strokeList.push_back(item1);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if (item2.m_edge.m_w0 != (reversed ? 1.0 : 0.0)) {
Toshihiro Shimizu 890ddd
		item2.m_gettingOut = reversed;
Toshihiro Shimizu 890ddd
		interList.m_strokeList.push_back(item2);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*
Toshihiro Shimizu 890ddd
void checkAuto(const vector<vistroke*>& s)</vistroke*>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
for (int i=0; i<(int)s.size(); i++)
Toshihiro Shimizu 890ddd
for (int j=i+1; j<(int)s.size(); j++)
Toshihiro Shimizu 890ddd
  if (s[i]->m_s->getChunkCount()==1 && s[j]->m_s->getChunkCount()==1) //se ha una sola quadratica, probabilmente e' un autoclose.
Toshihiro Shimizu 890ddd
	  {
Toshihiro Shimizu 890ddd
		const TThickQuadratic*q = s[i]->m_s->getChunk(0);
Toshihiro Shimizu 890ddd
		const TThickQuadratic*p = s[j]->m_s->getChunk(0);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (areAlmostEqual(q->getP0(), p->getP0(), 1e-2) && areAlmostEqual(q->getP2(), p->getP2(), 1e-2))
Toshihiro Shimizu 890ddd
		  assert(!"eccolo!");
Toshihiro Shimizu 890ddd
		if (areAlmostEqual(q->getP0(), p->getP2(), 1e-2) && areAlmostEqual(q->getP2(), p->getP0(), 1e-2))
Toshihiro Shimizu 890ddd
		  assert(!"eccolo!");
Toshihiro Shimizu 890ddd
    }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool addAutocloseIntersection(IntersectionData &intData, vector<vistroke *=""> &s,</vistroke>
Toshihiro Shimizu 890ddd
							  int ii, int jj, double w0, double w1, int strokeSize)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	list<intersection>::reverse_iterator rit = intData.m_intList.rbegin();</intersection>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	assert(w0 >= 0.0 && w0 <= 1.0);
Toshihiro Shimizu 890ddd
	assert(w1 >= 0.0 && w1 <= 1.0);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (; rit != intData.m_intList.rend(); rit++) // evito di fare la connessione, se gia' ce
Toshihiro Shimizu 890ddd
												   // ne e' una simile tra le stesse due stroke
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (rit->m_strokeList.size() < 2)
Toshihiro Shimizu 890ddd
			continue;
Toshihiro Shimizu 890ddd
		list<intersectedstroke>::iterator is = rit->m_strokeList.begin();</intersectedstroke>
Toshihiro Shimizu 890ddd
		int s0 = is->m_edge.m_index;
Toshihiro Shimizu 890ddd
		if (s0 < 0)
Toshihiro Shimizu 890ddd
			continue;
Toshihiro Shimizu 890ddd
		double ww0 = is->m_edge.m_w0;
Toshihiro Shimizu 890ddd
		is++;
Toshihiro Shimizu 890ddd
		if (is->m_edge.m_index == s0 && is->m_edge.m_w0 == ww0) {
Toshihiro Shimizu 890ddd
			is++;
Toshihiro Shimizu 890ddd
			if (is == rit->m_strokeList.end())
Toshihiro Shimizu 890ddd
				continue;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		int s1 = is->m_edge.m_index;
Toshihiro Shimizu 890ddd
		if (s1 < 0)
Toshihiro Shimizu 890ddd
			continue;
Toshihiro Shimizu 890ddd
		double ww1 = is->m_edge.m_w0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (!((s0 == ii && s1 == jj) || (s0 == jj && s1 == ii)))
Toshihiro Shimizu 890ddd
			continue;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (s0 == ii && areAlmostEqual(w0, ww0, 0.1) && areAlmostEqual(w1, ww1, 0.1))
Toshihiro Shimizu 890ddd
			return false;
Toshihiro Shimizu 890ddd
		else if (s1 == ii && areAlmostEqual(w0, ww1, 0.1) && areAlmostEqual(w1, ww0, 0.1))
Toshihiro Shimizu 890ddd
			return false;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	vector<tpointd> v;</tpointd>
Toshihiro Shimizu 890ddd
	v.push_back(s[ii]->m_s->getPoint(w0));
Toshihiro Shimizu 890ddd
	v.push_back(s[jj]->m_s->getPoint(w1));
Toshihiro Shimizu 890ddd
	if (v[0] == v[1]) //le stroke si intersecano , ma la fottuta funzione intersect non ha trovato l'intersezione(tipicamente, questo accade agli estremi)!!!
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		addIntersection(intData, s, ii, jj, DoublePair(w0, w1), strokeSize);
Toshihiro Shimizu 890ddd
		return true;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//se gia e' stato messo questo autoclose, evito
Toshihiro Shimizu 890ddd
	for (int i = 0; i < (int)s.size(); i++)
Toshihiro Shimizu 890ddd
		if (s[i]->m_s->getChunkCount() == 1) //se ha una sola quadratica, probabilmente e' un autoclose.
Toshihiro Shimizu 890ddd
		{
Toshihiro Shimizu 890ddd
			const TThickQuadratic *q = s[i]->m_s->getChunk(0);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			if (areAlmostEqual(q->getP0(), v[0], 1e-2) && areAlmostEqual(q->getP2(), v[1], 1e-2) ||
Toshihiro Shimizu 890ddd
				areAlmostEqual(q->getP0(), v[1], 1e-2) && areAlmostEqual(q->getP2(), v[0], 1e-2)) {
Toshihiro Shimizu 890ddd
				return true;
Toshihiro Shimizu 890ddd
				addIntersection(intData, s, i, ii, DoublePair(0.0, w0), strokeSize);
Toshihiro Shimizu 890ddd
				addIntersection(intData, s, i, jj, DoublePair(1.0, w1), strokeSize);
Toshihiro Shimizu 890ddd
				return true;
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	s.push_back(new VIStroke(new TStroke(v)));
Toshihiro Shimizu 890ddd
	addIntersection(intData, s, s.size() - 1, ii, DoublePair(0.0, w0), strokeSize);
Toshihiro Shimizu 890ddd
	addIntersection(intData, s, s.size() - 1, jj, DoublePair(1.0, w1), strokeSize);
Toshihiro Shimizu 890ddd
	return true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
double g_autocloseTolerance = c_newAutocloseTolerance;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool makeEndPointConnections(vector<vistroke *=""> &s,</vistroke>
Toshihiro Shimizu 890ddd
							 int ii, bool isIStartPoint,
Toshihiro Shimizu 890ddd
							 int jj, bool isJStartPoint, IntersectionData &intData,
Toshihiro Shimizu 890ddd
							 int strokeSize)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	double x0 = (isIStartPoint ? 0.0 : 1.0);
Toshihiro Shimizu 890ddd
	double x1 = (isJStartPoint ? 0.0 : 1.0);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TThickPoint p0 = s[ii]->m_s->getThickPoint(x0);
Toshihiro Shimizu 890ddd
	TThickPoint p1 = s[jj]->m_s->getThickPoint(x1);
Toshihiro Shimizu 890ddd
	double dist2;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	dist2 = tdistance2(p0, p1);
Toshihiro Shimizu 890ddd
	if (dist2 >= 0 && dist2 <= tmax((g_autocloseTolerance == c_oldAutocloseTolerance) ? 9.09 : 2.0, g_autocloseTolerance * (p0.thick + p1.thick) * (p0.thick + p1.thick))) //0.01 tiene conto di quando thick==0
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		if (ii == jj) {
Toshihiro Shimizu 890ddd
			TRectD r = s[ii]->m_s->getBBox(); //se e' un autoclose su una stroke piccolissima, creerebbe uan area trascurabile, ignoro
Toshihiro Shimizu 890ddd
			if (fabs(r.x1 - r.x0) < 2 && fabs(r.y1 - r.y0) < 2)
Toshihiro Shimizu 890ddd
				return false;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		return addAutocloseIntersection(intData, s, ii, jj, x0, x1, strokeSize);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return false;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
/*
Toshihiro Shimizu 890ddd
if (s[ii]==s[jj])
Toshihiro Shimizu 890ddd
  return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
dist2 = c_autocloseTolerance*tdistance2(p01, p10);
Toshihiro Shimizu 890ddd
if (dist2>0 && dist2<=(p01.thick+p10.thick)*(p01.thick+p10.thick))
Toshihiro Shimizu 890ddd
  addAutocloseIntersection(intData, s, ii, jj, 1.0, 0.0, strokeSize);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
dist2 = c_autocloseTolerance*tdistance2(p00, p10);
Toshihiro Shimizu 890ddd
if ((dist2>0 && dist2<=(p00.thick+p10.thick)*(p00.thick+p10.thick)))
Toshihiro Shimizu 890ddd
  addAutocloseIntersection(intData, s, ii, jj, 0.0, 0.0, strokeSize);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
dist2 = c_autocloseTolerance*tdistance2(p01, p11);
Toshihiro Shimizu 890ddd
if ((dist2>0 && dist2<=(p01.thick+p11.thick)*(p01.thick+p11.thick)))
Toshihiro Shimizu 890ddd
  addAutocloseIntersection(intData, s, ii, jj, 1.0, 1.0, strokeSize);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
double getCurlW(TStroke *s, bool isBegin) //trova il punto di split su una stroke, in prossimita di un ricciolo;
Toshihiro Shimizu 890ddd
										  // un ricciolo c'e' se la curva ha un  min o max relativo su x seguito da uno su y, o viceversa.
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int numChunks = s->getChunkCount();
Toshihiro Shimizu 890ddd
	double dx2, dx1 = 0, dy2, dy1 = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (int i = 0; i < numChunks; i++) {
Toshihiro Shimizu 890ddd
		const TQuadratic *q = s->getChunk(isBegin ? i : numChunks - 1 - i);
Toshihiro Shimizu 890ddd
		dy2 = q->getP1().y - q->getP0().y;
Toshihiro Shimizu 890ddd
		if (dy1 * dy2 < 0)
Toshihiro Shimizu 890ddd
			break;
Toshihiro Shimizu 890ddd
		dy1 = dy2;
Toshihiro Shimizu 890ddd
		dy2 = q->getP2().y - q->getP1().y;
Toshihiro Shimizu 890ddd
		if (dy1 * dy2 < 0)
Toshihiro Shimizu 890ddd
			break;
Toshihiro Shimizu 890ddd
		dy1 = dy2;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if (i == numChunks)
Toshihiro Shimizu 890ddd
		return -1;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int maxMin0 = isBegin ? i : numChunks - 1 - i;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (int j = 0; j < numChunks; j++) {
Toshihiro Shimizu 890ddd
		const TQuadratic *q = s->getChunk(isBegin ? j : numChunks - 1 - j);
Toshihiro Shimizu 890ddd
		dx2 = q->getP1().x - q->getP0().x;
Toshihiro Shimizu 890ddd
		if (dx1 * dx2 < 0)
Toshihiro Shimizu 890ddd
			break;
Toshihiro Shimizu 890ddd
		dx1 = dx2;
Toshihiro Shimizu 890ddd
		dx2 = q->getP2().x - q->getP1().x;
Toshihiro Shimizu 890ddd
		if (dx1 * dx2 < 0)
Toshihiro Shimizu 890ddd
			break;
Toshihiro Shimizu 890ddd
		dx1 = dx2;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if (j == numChunks)
Toshihiro Shimizu 890ddd
		return -1;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int maxMin1 = isBegin ? j : numChunks - 1 - j;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return getWfromChunkAndT(s, isBegin ? tmax(maxMin0, maxMin1) : tmin(maxMin0, maxMin1), isBegin ? 1.0 : 0.0);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef Levo
Toshihiro Shimizu 890ddd
bool lastIsX = false, lastIsY = false;
Toshihiro Shimizu 890ddd
for (int i = 0; i < numChunks; i++) {
Toshihiro Shimizu 890ddd
	const TThickQuadratic *q = s->getChunk(isBegin ? i : numChunks - 1 - i);
Toshihiro Shimizu 890ddd
	if ((q->getP0().y < q->getP1().y && q->getP2().y < q->getP1().y) || //la quadratica ha un minimo o massimo relativo
Toshihiro Shimizu 890ddd
		(q->getP0().y > q->getP1().y && q->getP2().y > q->getP1().y)) {
Toshihiro Shimizu 890ddd
		double w = getWfromChunkAndT(s, isBegin ? i : numChunks - 1 - i, isBegin ? 1.0 : 0.0);
Toshihiro Shimizu 890ddd
		if (lastIsX) //e' il secondo min o max relativo
Toshihiro Shimizu 890ddd
			return w;
Toshihiro Shimizu 890ddd
		lastIsX = false;
Toshihiro Shimizu 890ddd
		lastIsY = true;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	} else if ((q->getP0().x < q->getP1().x && q->getP2().x < q->getP1().x) || //la quadratica ha un minimo o massimo relativo
Toshihiro Shimizu 890ddd
			   (q->getP0().x > q->getP1().x && q->getP2().x > q->getP1().x)) {
Toshihiro Shimizu 890ddd
		double w = getWfromChunkAndT(s, isBegin ? i : numChunks - 1 - i, isBegin ? 1.0 : 0.0);
Toshihiro Shimizu 890ddd
		if (lastIsY) //e' il secondo min o max relativo
Toshihiro Shimizu 890ddd
			return w;
Toshihiro Shimizu 890ddd
		lastIsX = true;
Toshihiro Shimizu 890ddd
		lastIsY = false;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
return -1;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void makeConnection(vector<vistroke *=""> &s, int ii, int jj, bool isBegin, IntersectionData &intData,</vistroke>
Toshihiro Shimizu 890ddd
					int strokeSize)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (s[ii]->m_s->isSelfLoop())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double w0 = isBegin ? 0.0 : 1.0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TThickPoint p0 = s[ii]->m_s->getThickPoint(w0);
Toshihiro Shimizu 890ddd
	double t, dist2;
Toshihiro Shimizu 890ddd
	int index;
Toshihiro Shimizu 890ddd
	TStroke sAux, *sComp;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (ii == jj) //per trovare le intersezioni con una stroke e se stessa, si toglie il
Toshihiro Shimizu 890ddd
				  //pezzo di stroke di cui si cercano vicinanze fino alla prima curva
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		double w = getCurlW(s[ii]->m_s, isBegin);
Toshihiro Shimizu 890ddd
		if (w == -1)
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		split<tstroke>(*(s[ii]->m_s), tmin(isBegin ? 1.0 : 0.0, w), tmax(isBegin ? 1.0 : 0.0, w), sAux);</tstroke>
Toshihiro Shimizu 890ddd
		sComp = &sAux;
Toshihiro Shimizu 890ddd
	} else
Toshihiro Shimizu 890ddd
		sComp = s[jj]->m_s;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (sComp->getNearestChunk(p0, t, index, dist2) && dist2 > 0) {
Toshihiro Shimizu 890ddd
		if (ii == jj) {
Toshihiro Shimizu 890ddd
			double dummy;
Toshihiro Shimizu 890ddd
			s[jj]->m_s->getNearestChunk(sComp->getChunk(index)->getPoint(t), t, index, dummy);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		//if (areAlmostEqual(w, 0.0, 0.05) || areAlmostEqual(w, 1.0, 0.05))
Toshihiro Shimizu 890ddd
		//  return; //se w e' vicino ad un estremo, rientra nell'autoclose point to point
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		//if (s[jj]->m_s->getLength(w)<=s[jj]->m_s->getThickPoint(0).thick ||
Toshihiro Shimizu 890ddd
		//    s[jj]->m_s->getLength(w, 1)<=s[jj]->m_s->getThickPoint(1).thick)
Toshihiro Shimizu 890ddd
		//  return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TThickPoint p1 = s[jj]->m_s->getChunk(index)->getThickPoint(t);
Toshihiro Shimizu 890ddd
		if (dist2 <= (tmax((g_autocloseTolerance == c_oldAutocloseTolerance) ? 9.09 : 2.0, (g_autocloseTolerance + 0.7) * (p0.thick + p1.thick) * (p0.thick + p1.thick)))) //0.01 tiene conto di quando thick==0
Toshihiro Shimizu 890ddd
		{
Toshihiro Shimizu 890ddd
			//if (areAlmostEqual(dist2, 0.0))
Toshihiro Shimizu 890ddd
			//  return;
Toshihiro Shimizu 890ddd
			double w = getWfromChunkAndT(s[jj]->m_s, index, t);
Toshihiro Shimizu 890ddd
			addAutocloseIntersection(intData, s, ii, jj, w0, w, strokeSize);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void autoclose(vector<vistroke *=""> &s, int ii, int jj, IntersectionData &IntData,</vistroke>
Toshihiro Shimizu 890ddd
			   int strokeSize)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	bool ret1 = false, ret2 = false, ret3 = false, ret4 = false;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (!s[ii]->m_s->isSelfLoop() && !s[jj]->m_s->isSelfLoop()) {
Toshihiro Shimizu 890ddd
		ret1 = makeEndPointConnections(s, ii, true, jj, false, IntData, strokeSize);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (ii != jj) {
Toshihiro Shimizu 890ddd
			ret2 = makeEndPointConnections(s, ii, true, jj, true, IntData, strokeSize);
Toshihiro Shimizu 890ddd
			ret3 = makeEndPointConnections(s, ii, false, jj, true, IntData, strokeSize);
Toshihiro Shimizu 890ddd
			ret4 = makeEndPointConnections(s, ii, false, jj, false, IntData, strokeSize);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (!ret1 && !ret2)
Toshihiro Shimizu 890ddd
		makeConnection(s, ii, jj, true, IntData, strokeSize);
Toshihiro Shimizu 890ddd
	if (!ret1 && !ret4)
Toshihiro Shimizu 890ddd
		makeConnection(s, jj, ii, false, IntData, strokeSize);
Toshihiro Shimizu 890ddd
	if (ii != jj) {
Toshihiro Shimizu 890ddd
		if (!ret2 && !ret3)
Toshihiro Shimizu 890ddd
			makeConnection(s, jj, ii, true, IntData, strokeSize);
Toshihiro Shimizu 890ddd
		if (!ret3 && !ret4)
Toshihiro Shimizu 890ddd
			makeConnection(s, ii, jj, false, IntData, strokeSize);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TPointD inline getTangent(const IntersectedStroke &item)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return (item.m_gettingOut ? 1 : -1) * item.m_edge.m_s->getSpeed(item.m_edge.m_w0, item.m_gettingOut);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void addBranch(IntersectionData &intData, list<intersectedstroke> &strokeList,</intersectedstroke>
Toshihiro Shimizu 890ddd
			   const vector<vistroke *=""> &s, int ii, double w, int strokeSize, bool gettingOut)</vistroke>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	list<intersectedstroke>::iterator it1, it2;</intersectedstroke>
Toshihiro Shimizu 890ddd
	TPointD tanRef, lastTan;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	IntersectedStroke item(intData.m_intList.end(), strokeList.end());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (ii < 0) {
Toshihiro Shimizu 890ddd
		item.m_edge.m_s = intData.m_autocloseMap[ii];
Toshihiro Shimizu 890ddd
		item.m_edge.m_index = ii;
Toshihiro Shimizu 890ddd
	} else {
Toshihiro Shimizu 890ddd
		item.m_edge.m_s = s[ii]->m_s;
Toshihiro Shimizu 890ddd
		if (ii < strokeSize)
Toshihiro Shimizu 890ddd
			item.m_edge.m_index = ii;
Toshihiro Shimizu 890ddd
		else {
Toshihiro Shimizu 890ddd
			item.m_edge.m_index = -(ii + intData.maxAutocloseId * 100000);
Toshihiro Shimizu 890ddd
			intData.m_autocloseMap[item.m_edge.m_index] = item.m_edge.m_s;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	item.m_edge.m_w0 = w;
Toshihiro Shimizu 890ddd
	item.m_gettingOut = gettingOut;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*
Toshihiro Shimizu 890ddd
if (strokeList.size()==2) //potrebbero essere orientati male; due branch possono stare come vogliono, ma col terzo no.
Toshihiro Shimizu 890ddd
  {
Toshihiro Shimizu 890ddd
  TPointD tan2 = getTangent(strokeList.back());
Toshihiro Shimizu 890ddd
  TPointD aux= getTangent(*(strokeList.begin()));
Toshihiro Shimizu 890ddd
  double crossVal = cross(aux, tan2);
Toshihiro Shimizu 890ddd
  if (areAlmostEqual(aux, tan2, 1e-3))
Toshihiro Shimizu 890ddd
	  return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (crossVal>0)
Toshihiro Shimizu 890ddd
    {
Toshihiro Shimizu 890ddd
		std::reverse(strokeList.begin(), strokeList.end());
Toshihiro Shimizu 890ddd
    //tan2 = getTangent(strokeList.back());
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
  }
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
	/*
Toshihiro Shimizu 890ddd
if (areAlmostEqual(lastCross, 0.0) && tan1.x*tan2.x>=0 && tan1.y*tan2.y>=0) //significa angolo tra tangenti nullo
Toshihiro Shimizu 890ddd
	  {
Toshihiro Shimizu 890ddd
		crossVal =  nearCrossVal(item.m_edge.m_s, item.m_edge.m_w0, strokeList.back().m_edge.m_s, strokeList.back().m_edge.m_w0);
Toshihiro Shimizu 890ddd
    if (areAlmostEqual(crossVal, 0.0))
Toshihiro Shimizu 890ddd
		  return;
Toshihiro Shimizu 890ddd
		if (!strokeList.back().m_gettingOut)
Toshihiro Shimizu 890ddd
		  crossVal = -crossVal;
Toshihiro Shimizu 890ddd
    }
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	tanRef = getTangent(item);
Toshihiro Shimizu 890ddd
	lastTan = getTangent(strokeList.back());
Toshihiro Shimizu 890ddd
	/*
Toshihiro Shimizu 890ddd
for (it=strokeList.begin(); it!=strokeList.end(); ++it)
Toshihiro Shimizu 890ddd
  {
Toshihiro Shimizu 890ddd
	TPointD curTan = getTangent(*it);
Toshihiro Shimizu 890ddd
  double angle0 = getAngle(lastTan, curTan);
Toshihiro Shimizu 890ddd
  double angle1 = getAngle(lastTan, tanRef);
Toshihiro Shimizu 890ddd
 
Toshihiro Shimizu 890ddd
  if (areAlmostEqual(angle0, angle1, 1e-8))
Toshihiro Shimizu 890ddd
	  {
Toshihiro Shimizu 890ddd
		double angle = getNearAngle( it->m_edge.m_s,  it->m_edge.m_w0,  it->m_gettingOut, 
Toshihiro Shimizu 890ddd
		                            item.m_edge.m_s, item.m_edge.m_w0, item.m_gettingOut);
Toshihiro Shimizu 890ddd
    angle1 += angle; if (angle1>360) angle1-=360;
Toshihiro Shimizu 890ddd
    }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
  if (angle1
Toshihiro Shimizu 890ddd
    {
Toshihiro Shimizu 890ddd
    strokeList.insert(it, item);
Toshihiro Shimizu 890ddd
    return;
Toshihiro Shimizu 890ddd
    }
Toshihiro Shimizu 890ddd
	lastTan=curTan;
Toshihiro Shimizu 890ddd
  }*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	it2 = strokeList.end();
Toshihiro Shimizu 890ddd
	it2--;
Toshihiro Shimizu 890ddd
	for (it1 = strokeList.begin(); it1 != strokeList.end(); ++it1) {
Toshihiro Shimizu 890ddd
		TPointD curTan = getTangent(*it1);
Toshihiro Shimizu 890ddd
		double angle0 = getAngle(lastTan, curTan);
Toshihiro Shimizu 890ddd
		double angle1 = getAngle(lastTan, tanRef);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (areAlmostEqual(angle1, 0, 1e-8)) {
Toshihiro Shimizu 890ddd
			double angle = getNearAngle(it2->m_edge.m_s, it2->m_edge.m_w0, it2->m_gettingOut,
Toshihiro Shimizu 890ddd
										item.m_edge.m_s, item.m_edge.m_w0, item.m_gettingOut);
Toshihiro Shimizu 890ddd
			angle1 += angle;
Toshihiro Shimizu 890ddd
			if (angle1 > 360)
Toshihiro Shimizu 890ddd
				angle1 -= 360;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (areAlmostEqual(angle0, angle1, 1e-8)) {
Toshihiro Shimizu 890ddd
			double angle = getNearAngle(it1->m_edge.m_s, it1->m_edge.m_w0, it1->m_gettingOut,
Toshihiro Shimizu 890ddd
										item.m_edge.m_s, item.m_edge.m_w0, item.m_gettingOut);
Toshihiro Shimizu 890ddd
			angle1 += angle;
Toshihiro Shimizu 890ddd
			if (angle1 > 360)
Toshihiro Shimizu 890ddd
				angle1 -= 360;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (angle1 < angle0) {
Toshihiro Shimizu 890ddd
			strokeList.insert(it1, item);
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		lastTan = curTan;
Toshihiro Shimizu 890ddd
		it2 = it1;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//assert(!"add branch: can't find where to insert!");
Toshihiro Shimizu 890ddd
	strokeList.push_back(item);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void addBranches(IntersectionData &intData, Intersection &intersection, const vector<vistroke *=""> &s, int ii, int jj,</vistroke>
Toshihiro Shimizu 890ddd
				 DoublePair intersectionPair, int strokeSize)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	bool foundS1 = false, foundS2 = false;
Toshihiro Shimizu 890ddd
	list<intersectedstroke>::iterator it;</intersectedstroke>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	assert(!intersection.m_strokeList.empty());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (it = intersection.m_strokeList.begin(); it != intersection.m_strokeList.end(); it++) {
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if ((ii >= 0 && (*it).m_edge.m_s == s[ii]->m_s && it->m_edge.m_w0 == intersectionPair.first) ||
Toshihiro Shimizu 890ddd
			(ii < 0 && (*it).m_edge.m_index == ii && it->m_edge.m_w0 == intersectionPair.first))
Toshihiro Shimizu 890ddd
			foundS1 = true;
Toshihiro Shimizu 890ddd
		if ((jj >= 0 && (*it).m_edge.m_s == s[jj]->m_s && it->m_edge.m_w0 == intersectionPair.second) ||
Toshihiro Shimizu 890ddd
			(jj < 0 && (*it).m_edge.m_index == jj && it->m_edge.m_w0 == intersectionPair.second))
Toshihiro Shimizu 890ddd
			foundS2 = true;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (foundS1 && foundS2) {
Toshihiro Shimizu 890ddd
		/*
Toshihiro Shimizu 890ddd
  //errore!(vedi commento sotto) possono essere un sacco di intersezioni coincidenti se passano per l'estremo di una quad
Toshihiro Shimizu 890ddd
	//significa che ci sono due intersezioni coincidenti. cioe' due stroke tangenti. quindi devo invertire l'ordine di due branch enlla rosa dei branch.
Toshihiro Shimizu 890ddd
  list<intersectedstroke>::iterator it1, it2;</intersectedstroke>
Toshihiro Shimizu 890ddd
	it1=intersection.m_strokeList.begin();
Toshihiro Shimizu 890ddd
	it2 = it1; it2++;
Toshihiro Shimizu 890ddd
	for (; it2!=intersection.m_strokeList.end(); ++it1, ++it2)
Toshihiro Shimizu 890ddd
    {
Toshihiro Shimizu 890ddd
    if ((*it1).m_gettingOut!=(*it2).m_gettingOut &&((*it1).m_edge.m_index==jj && (*it2).m_edge.m_index==ii) || 
Toshihiro Shimizu 890ddd
		    ((*it1).m_edge.m_index==ii && (*it2).m_edge.m_index==jj))
Toshihiro Shimizu 890ddd
      {
Toshihiro Shimizu 890ddd
			IntersectedStroke& el1 = (*it1);
Toshihiro Shimizu 890ddd
			IntersectedStroke& el2 = (*it2);
Toshihiro Shimizu 890ddd
      IntersectedStroke app;
Toshihiro Shimizu 890ddd
			app = el1;
Toshihiro Shimizu 890ddd
			el1=el2;
Toshihiro Shimizu 890ddd
			el2=app;
Toshihiro Shimizu 890ddd
			break;
Toshihiro Shimizu 890ddd
      }
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
  */
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (!foundS1) {
Toshihiro Shimizu 890ddd
		if (intersectionPair.first != 1)
Toshihiro Shimizu 890ddd
			addBranch(intData, intersection.m_strokeList, s, ii, intersectionPair.first, strokeSize, true);
Toshihiro Shimizu 890ddd
		if (intersectionPair.first != 0)
Toshihiro Shimizu 890ddd
			addBranch(intData, intersection.m_strokeList, s, ii, intersectionPair.first, strokeSize, false);
Toshihiro Shimizu 890ddd
		//assert(intersection.m_strokeList.size()-size>0);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if (!foundS2) {
Toshihiro Shimizu 890ddd
		if (intersectionPair.second != 1)
Toshihiro Shimizu 890ddd
			addBranch(intData, intersection.m_strokeList, s, jj, intersectionPair.second, strokeSize, true);
Toshihiro Shimizu 890ddd
		if (intersectionPair.second != 0)
Toshihiro Shimizu 890ddd
			addBranch(intData, intersection.m_strokeList, s, jj, intersectionPair.second, strokeSize, false);
Toshihiro Shimizu 890ddd
		//intersection.m_numInter+=intersection.m_strokeList.size()-size;
Toshihiro Shimizu 890ddd
		//assert(intersection.m_strokeList.size()-size>0);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void addIntersections(IntersectionData &intData,
Toshihiro Shimizu 890ddd
					  const vector<vistroke *=""> &s, int ii, int jj,</vistroke>
Toshihiro Shimizu 890ddd
					  vector<doublepair> &intersections, int strokeSize)</doublepair>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	for (int k = 0; k < (int)intersections.size(); k++) {
Toshihiro Shimizu 890ddd
		if (ii >= strokeSize &&
Toshihiro Shimizu 890ddd
			(areAlmostEqual(intersections[k].first, 0.0) || areAlmostEqual(intersections[k].first, 1.0)))
Toshihiro Shimizu 890ddd
			continue;
Toshihiro Shimizu 890ddd
		if (jj >= strokeSize &&
Toshihiro Shimizu 890ddd
			(areAlmostEqual(intersections[k].second, 0.0) || areAlmostEqual(intersections[k].second, 1.0)))
Toshihiro Shimizu 890ddd
			continue;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		addIntersection(intData, s, ii, jj, intersections[k], strokeSize);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
inline double truncate(double x)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	x += 1.0;
Toshihiro Shimizu 890ddd
	unsigned long *l = (unsigned long *)&x;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#if TNZ_LITTLE_ENDIAN
Toshihiro Shimizu 890ddd
	l[0] &= 0xFFE00000;
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
	l[1] &= 0xFFE00000;
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return x - 1.0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void addIntersection(IntersectionData &intData,
Toshihiro Shimizu 890ddd
					 const vector<vistroke *=""> &s, int ii, int jj,</vistroke>
Toshihiro Shimizu 890ddd
					 DoublePair intersection, int strokeSize)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	list<intersection>::iterator it;</intersection>
Toshihiro Shimizu 890ddd
	TPointD p;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//UINT iw;
Toshihiro Shimizu 890ddd
	//iw = ((UINT)(intersection.first*0x3fffffff));
Toshihiro Shimizu 890ddd
	//intersection.first = truncate(intersection.first);
Toshihiro Shimizu 890ddd
	//iw = (UINT)(intersection.second*0x3fffffff);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//intersection.second = truncate(intersection.second);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (areAlmostEqual(intersection.first, 0.0, 1e-8))
Toshihiro Shimizu 890ddd
		intersection.first = 0.0;
Toshihiro Shimizu 890ddd
	else if (areAlmostEqual(intersection.first, 1.0, 1e-8))
Toshihiro Shimizu 890ddd
		intersection.first = 1.0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (areAlmostEqual(intersection.second, 0.0, 1e-8))
Toshihiro Shimizu 890ddd
		intersection.second = 0.0;
Toshihiro Shimizu 890ddd
	else if (areAlmostEqual(intersection.second, 1.0, 1e-8))
Toshihiro Shimizu 890ddd
		intersection.second = 1.0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	p = s[ii]->m_s->getPoint(intersection.first);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (it = intData.m_intList.begin(); it != intData.m_intList.end(); it++)
Toshihiro Shimizu 890ddd
		if ((*it).m_intersection == p) //devono essere rigorosamente uguali, altrimenti
Toshihiro Shimizu 890ddd
									   // il calcolo dell'ordine dei rami con le tangenti sballa
Toshihiro Shimizu 890ddd
		{
Toshihiro Shimizu 890ddd
			addBranches(intData, *it, s, ii, jj, intersection, strokeSize);
Toshihiro Shimizu 890ddd
			return;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	intData.m_intList.push_back(Intersection());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (!makeIntersection(intData, s, ii, jj, intersection, strokeSize, intData.m_intList.back())) {
Toshihiro Shimizu 890ddd
		list<intersection>::iterator it = intData.m_intList.begin();</intersection>
Toshihiro Shimizu 890ddd
		advance(it, intData.m_intList.size() - 1);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		intData.m_intList.erase(it);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TVectorImage::Imp::findIntersections()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	vector<vistroke *=""> &strokeArray = m_strokes;</vistroke>
Toshihiro Shimizu 890ddd
	IntersectionData &intData = m_intersectionData;
Toshihiro Shimizu 890ddd
	int strokeSize = (int)strokeArray.size();
Toshihiro Shimizu 890ddd
	int i, j;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	assert(intData.m_intersectedStrokeArray.empty());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	intData.maxAutocloseId++;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	map<int, *="" tstroke="">::iterator it, it_b = intData.m_autocloseMap.begin();</int,>
Toshihiro Shimizu 890ddd
	map<int, *="" tstroke="">::iterator it_e = intData.m_autocloseMap.end();</int,>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//prima cerco le intersezioni tra nuove strokes e vecchi autoclose
Toshihiro Shimizu 890ddd
	for (i = 0; i < strokeSize; i++) {
Toshihiro Shimizu 890ddd
		TStroke *s1 = strokeArray[i]->m_s;
Toshihiro Shimizu 890ddd
		if (!strokeArray[i]->m_isNewForFill || strokeArray[i]->m_isPoint)
Toshihiro Shimizu 890ddd
			continue;
Toshihiro Shimizu 890ddd
		TRectD bBox = s1->getBBox();
Toshihiro Shimizu 890ddd
		double thick2 = s1->getThickPoint(0).thick * 2;
Toshihiro Shimizu 890ddd
		if (bBox.getLx() <= thick2 && bBox.getLy() <= thick2) {
Toshihiro Shimizu 890ddd
			strokeArray[i]->m_isPoint = true;
Toshihiro Shimizu 890ddd
			continue;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		for (int j = 0; j < (int)s1->getControlPointCount(); j++) {
Toshihiro Shimizu 890ddd
			TThickPoint p = s1->getControlPoint(j);
Toshihiro Shimizu 890ddd
			s1->setControlPoint(j, myRound(p));
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		for (it = it_b; it != it_e; ++it) {
Toshihiro Shimizu 890ddd
			TStroke *s2 = it->second;
Toshihiro Shimizu 890ddd
			vector<doublepair> parIntersections;</doublepair>
Toshihiro Shimizu 890ddd
			if (intersect(s1, s2, parIntersections, true))
Toshihiro Shimizu 890ddd
				addIntersections(intData, strokeArray, i, it->first, parIntersections, strokeSize);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//poi,  intersezioni tra stroke, in cui almeno uno dei due deve essere nuovo
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (i = 0; i < strokeSize; i++) {
Toshihiro Shimizu 890ddd
		TStroke *s1 = strokeArray[i]->m_s;
Toshihiro Shimizu 890ddd
		if (strokeArray[i]->m_isPoint)
Toshihiro Shimizu 890ddd
			continue;
Toshihiro Shimizu 890ddd
		for (j = i; j < strokeSize /*&& (strokeArray[i]->getBBox().x1>= strokeArray[j]->getBBox().x0)*/; j++) {
Toshihiro Shimizu 890ddd
			TStroke *s2 = strokeArray[j]->m_s;
Toshihiro Shimizu 890ddd
			if (strokeArray[j]->m_isPoint)
Toshihiro Shimizu 890ddd
				continue;
Toshihiro Shimizu 890ddd
			if (!(strokeArray[i]->m_isNewForFill || strokeArray[j]->m_isNewForFill))
Toshihiro Shimizu 890ddd
				continue;
Toshihiro Shimizu 890ddd
			vector<doublepair> parIntersections;</doublepair>
Toshihiro Shimizu 890ddd
			if (s1->getBBox().overlaps(s2->getBBox())) {
Toshihiro Shimizu 890ddd
				UINT size = intData.m_intList.size();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				if (intersect(s1, s2, parIntersections, false)) {
Toshihiro Shimizu 890ddd
					//if (i==0 && j==1) parIntersections.erase(parIntersections.begin());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
					addIntersections(intData, strokeArray, i, j, parIntersections, strokeSize);
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
				//autoclose(strokeArray, i, j, intData, strokeSize);
Toshihiro Shimizu 890ddd
				if (!strokeArray[i]->m_isNewForFill && size != intData.m_intList.size() && !strokeArray[i]->m_edgeList.empty()) //aggiunte nuove intersezioni
Toshihiro Shimizu 890ddd
				{
Toshihiro Shimizu 890ddd
					intData.m_intersectedStrokeArray.push_back(IntersectedStrokeEdges(i));
Toshihiro Shimizu 890ddd
					list<tedge *=""> &_list = intData.m_intersectedStrokeArray.back().m_edgeList;</tedge>
Toshihiro Shimizu 890ddd
					list<tedge *="">::const_iterator it;</tedge>
Toshihiro Shimizu 890ddd
					for (it = strokeArray[i]->m_edgeList.begin(); it != strokeArray[i]->m_edgeList.end(); ++it)
Toshihiro Shimizu 890ddd
						_list.push_back(new TEdge(**it, false));
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		//strokeArray[i]->m_isNewForFill = false;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (i = 0; i < strokeSize; i++) {
Toshihiro Shimizu 890ddd
		TStroke *s1 = strokeArray[i]->m_s;
Toshihiro Shimizu 890ddd
		if (strokeArray[i]->m_isPoint)
Toshihiro Shimizu 890ddd
			continue;
Toshihiro Shimizu 890ddd
		for (j = i; j < strokeSize; j++) {
Toshihiro Shimizu 890ddd
			TStroke *s2 = strokeArray[j]->m_s;
Toshihiro Shimizu 890ddd
			if (strokeArray[j]->m_isPoint)
Toshihiro Shimizu 890ddd
				continue;
Toshihiro Shimizu 890ddd
			if (!(strokeArray[i]->m_isNewForFill || strokeArray[j]->m_isNewForFill))
Toshihiro Shimizu 890ddd
				continue;
Toshihiro Shimizu 890ddd
			if (s1->getBBox().overlaps(s2->getBBox()))
Toshihiro Shimizu 890ddd
				autoclose(strokeArray, i, j, intData, strokeSize);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		strokeArray[i]->m_isNewForFill = false;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (i = 0; i < strokeSize; i++) {
Toshihiro Shimizu 890ddd
		list<tedge *="">::iterator it, it_b = strokeArray[i]->m_edgeList.begin(), it_e = strokeArray[i]->m_edgeList.end();</tedge>
Toshihiro Shimizu 890ddd
		for (it = it_b; it != it_e; ++it)
Toshihiro Shimizu 890ddd
			if ((*it)->m_toBeDeleted == 1)
Toshihiro Shimizu 890ddd
				delete *it;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		strokeArray[i]->m_edgeList.clear();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//si devono cercare le intersezioni con i segmenti aggiunti per l'autoclose
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (i = strokeSize; i < (int)strokeArray.size(); ++i) {
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TStroke *s1 = strokeArray[i]->m_s;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		for (j = i + 1; j < (int)strokeArray.size(); ++j) //intersezione segmento-segmento
Toshihiro Shimizu 890ddd
		{
Toshihiro Shimizu 890ddd
			TStroke *s2 = strokeArray[j]->m_s;
Toshihiro Shimizu 890ddd
			vector<doublepair> parIntersections;</doublepair>
Toshihiro Shimizu 890ddd
			if (intersect(s1, s2, parIntersections, true))
Toshihiro Shimizu 890ddd
				addIntersections(intData, strokeArray, i, j, parIntersections, strokeSize);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		for (j = 0; j < strokeSize; ++j) //intersezione segmento-curva
Toshihiro Shimizu 890ddd
		{
Toshihiro Shimizu 890ddd
			if (strokeArray[j]->m_isPoint)
Toshihiro Shimizu 890ddd
				continue;
Toshihiro Shimizu 890ddd
			TStroke *s2 = strokeArray[j]->m_s;
Toshihiro Shimizu 890ddd
			vector<doublepair> parIntersections;</doublepair>
Toshihiro Shimizu 890ddd
			if (intersect(s1, s2, parIntersections, true))
Toshihiro Shimizu 890ddd
				addIntersections(intData, strokeArray, i, j, parIntersections, strokeSize);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//la struttura delle intersezioni viene poi visitata per trovare
Toshihiro Shimizu 890ddd
// i link tra un'intersezione e la successiva
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int TVectorImage::Imp::computeIntersections()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	list<intersection>::iterator it1;</intersection>
Toshihiro Shimizu 890ddd
	list<intersectedstroke>::iterator it2;</intersectedstroke>
Toshihiro Shimizu 890ddd
	IntersectionData &intData = m_intersectionData;
Toshihiro Shimizu 890ddd
	int strokeSize = (int)m_strokes.size();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	findIntersections();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	findNearestIntersection(intData.m_intList);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//for (it1=intData.m_intList.begin(); it1!=intData.m_intList.end();) //la faccio qui, e non nella eraseIntersection. vedi commento li'.
Toshihiro Shimizu 890ddd
	eraseDeadIntersections();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (it1 = intData.m_intList.begin(); it1 != intData.m_intList.end(); it1++)
Toshihiro Shimizu 890ddd
		markDeadIntersections(intData.m_intList, it1);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//checkInterList(intData.m_intList);
Toshihiro Shimizu 890ddd
	return strokeSize;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*
Toshihiro Shimizu 890ddd
void endPointIntersect(const TStroke* s0, const TStroke* s1, vector<doublepair>& parIntersections)</doublepair>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
TPointD p00 = s0->getPoint(0);
Toshihiro Shimizu 890ddd
TPointD p11 = s1->getPoint(1);
Toshihiro Shimizu 890ddd
if (tdistance2(p00, p11)< 2*0.06*0.06)
Toshihiro Shimizu 890ddd
  parIntersections.push_back(DoublePair(0, 1));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
if (s0==s1)
Toshihiro Shimizu 890ddd
  return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TPointD p01 = s0->getPoint(1);
Toshihiro Shimizu 890ddd
TPointD p10 = s1->getPoint(0);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
if (tdistance2(p00, p10)< 2*0.06*0.06)
Toshihiro Shimizu 890ddd
  parIntersections.push_back(DoublePair(0, 0));
Toshihiro Shimizu 890ddd
if (tdistance2(p01, p10)< 2*0.06*0.06)
Toshihiro Shimizu 890ddd
  parIntersections.push_back(DoublePair(1, 0));
Toshihiro Shimizu 890ddd
if (tdistance2(p01, p11)< 2*0.06*0.06)
Toshihiro Shimizu 890ddd
  parIntersections.push_back(DoublePair(1, 1));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// Trova una possibile regione data una lista di punti di intersezione
Toshihiro Shimizu 890ddd
TRegion *findRegion(
Toshihiro Shimizu 890ddd
	list<intersection> &intList,</intersection>
Toshihiro Shimizu 890ddd
	list<intersection>::iterator it1,</intersection>
Toshihiro Shimizu 890ddd
	list<intersectedstroke>::iterator it2)</intersectedstroke>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TRegion *r = new TRegion();
Toshihiro Shimizu 890ddd
	int currStyle = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	list<intersectedstroke>::iterator itStart = it2;</intersectedstroke>
Toshihiro Shimizu 890ddd
	list<intersection>::iterator nextIt1;</intersection>
Toshihiro Shimizu 890ddd
	list<intersectedstroke>::iterator nextIt2;</intersectedstroke>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//Cicla finche' t2 non punta ad uno stroke gia' visitato
Toshihiro Shimizu 890ddd
	while (!it2->m_visited) {
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		it2->m_visited = true;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		// Ciclo finche' lo stroke puntato da it2 non ha un successivo punto di intersezione
Toshihiro Shimizu 890ddd
		do {
Toshihiro Shimizu 890ddd
			it2++;
Toshihiro Shimizu 890ddd
			if (it2 == it1->m_strokeList.end()) // uso la lista come se fosse circolare
Toshihiro Shimizu 890ddd
				it2 = it1->m_strokeList.begin();
Toshihiro Shimizu 890ddd
		} while (it2->m_nextIntersection == intList.end());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		nextIt1 = it2->m_nextIntersection;
Toshihiro Shimizu 890ddd
		nextIt2 = it2->m_nextStroke;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		// Viene controllato e sistemato lo stile degli stroke
Toshihiro Shimizu 890ddd
		if (it2->m_edge.m_styleId != 0) {
Toshihiro Shimizu 890ddd
			if (currStyle == 0)
Toshihiro Shimizu 890ddd
				currStyle = it2->m_edge.m_styleId;
Toshihiro Shimizu 890ddd
			else if (it2->m_edge.m_styleId != currStyle) {
Toshihiro Shimizu 890ddd
				currStyle = it2->m_edge.m_styleId;
Toshihiro Shimizu 890ddd
				for (UINT i = 0; i < r->getEdgeCount(); i++)
Toshihiro Shimizu 890ddd
					r->getEdge(i)->m_styleId = currStyle;
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		} else
Toshihiro Shimizu 890ddd
			it2->m_edge.m_styleId = currStyle;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		//Aggiunge lo stroke puntato da p2 alla regione
Toshihiro Shimizu 890ddd
		r->addEdge(&it2->m_edge);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (nextIt2 == itStart)
Toshihiro Shimizu 890ddd
			return r;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		it1 = nextIt1;
Toshihiro Shimizu 890ddd
		it2 = nextIt2;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	delete r;
Toshihiro Shimizu 890ddd
	return 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*
Toshihiro Shimizu 890ddd
bool areEqualRegions(const TRegion& r1, const TRegion& r2)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
if (r1.getBBox()!=r2.getBBox())
Toshihiro Shimizu 890ddd
  return false;
Toshihiro Shimizu 890ddd
if (r1.getEdgeCount()!=r2.getEdgeCount())
Toshihiro Shimizu 890ddd
  return false;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
for (UINT i=0; i
Toshihiro Shimizu 890ddd
  {
Toshihiro Shimizu 890ddd
  TEdge *e1 = r1.getEdge(i);
Toshihiro Shimizu 890ddd
  for (j=0; j
Toshihiro Shimizu 890ddd
    {
Toshihiro Shimizu 890ddd
    TEdge *e2 = r2.getEdge(j);
Toshihiro Shimizu 890ddd
    if (e1->m_s==e2->m_s &&
Toshihiro Shimizu 890ddd
        tmin(e1->m_w0, e1->m_w1)==tmin(e2->m_w0, e2->m_w1) &&
Toshihiro Shimizu 890ddd
        tmax(e1->m_w0, e1->m_w1)==tmax(e2->m_w0, e2->m_w1))
Toshihiro Shimizu 890ddd
      {
Toshihiro Shimizu 890ddd
      if (e1->m_styleId && !e2->m_styleId)
Toshihiro Shimizu 890ddd
        e2->m_styleId=e1->m_styleId;
Toshihiro Shimizu 890ddd
      else if (e2->m_styleId && !e1->m_styleId)
Toshihiro Shimizu 890ddd
        e1->m_styleId=e2->m_styleId;
Toshihiro Shimizu 890ddd
      break;
Toshihiro Shimizu 890ddd
      }
Toshihiro Shimizu 890ddd
    }
Toshihiro Shimizu 890ddd
  if (j==r2.getEdgeCount())  //e1 non e' uguale a nessun edge di r2
Toshihiro Shimizu 890ddd
    return false;
Toshihiro Shimizu 890ddd
  }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
return true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*
Toshihiro Shimizu 890ddd
bool isMetaRegion(const TRegion& r1, const TRegion& r2)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
if (areEqualRegions(r1, r2))
Toshihiro Shimizu 890ddd
    return true;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
for (UINT i=0; i
Toshihiro Shimizu 890ddd
  {
Toshihiro Shimizu 890ddd
  if (isMetaRegion(*r1.getRegion(i), r2))
Toshihiro Shimizu 890ddd
    return true;
Toshihiro Shimizu 890ddd
  }
Toshihiro Shimizu 890ddd
return false;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool isMetaRegion(const vector<tregion*>& m_regions, const TRegion& r)</tregion*>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
for (UINT i=0; i
Toshihiro Shimizu 890ddd
  if (isMetaRegion(*(m_regions[i]), r))
Toshihiro Shimizu 890ddd
    return true;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
return false;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool isValidArea(const vector<tregion *=""> ®ions, const TRegion &r)</tregion>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	double area = 0.0;
Toshihiro Shimizu 890ddd
	TPointD p, pOld /*, pAux*/;
Toshihiro Shimizu 890ddd
	int pointAdded = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int size = r.getEdgeCount();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (size == 0)
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//if (size<2)
Toshihiro Shimizu 890ddd
	//  return !isMetaRegion(regions, r);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int firstControlPoint;
Toshihiro Shimizu 890ddd
	int lastControlPoint;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TEdge *e = r.getEdge(size - 1);
Toshihiro Shimizu 890ddd
	pOld = e->m_s->getPoint(e->m_w1);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (int i = 0; i < size; i++) {
Toshihiro Shimizu 890ddd
		TEdge *e = r.getEdge(i);
Toshihiro Shimizu 890ddd
		TStroke *s = e->m_s;
Toshihiro Shimizu 890ddd
		firstControlPoint = s->getControlPointIndexAfterParameter(e->m_w0);
Toshihiro Shimizu 890ddd
		lastControlPoint = s->getControlPointIndexAfterParameter(e->m_w1);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		p = s->getPoint(e->m_w0);
Toshihiro Shimizu 890ddd
		area += (p.y + pOld.y) * (pOld.x - p.x);
Toshihiro Shimizu 890ddd
		pOld = p;
Toshihiro Shimizu 890ddd
		pointAdded++;
Toshihiro Shimizu 890ddd
		if (firstControlPoint <= lastControlPoint) {
Toshihiro Shimizu 890ddd
			if (firstControlPoint & 0x1)
Toshihiro Shimizu 890ddd
				firstControlPoint++;
Toshihiro Shimizu 890ddd
			if (lastControlPoint - firstControlPoint <= 2) ///per evitare di avere troppi pochi punti....
Toshihiro Shimizu 890ddd
			{
Toshihiro Shimizu 890ddd
				p = s->getPoint(0.333333 * e->m_w0 + 0.666666 * e->m_w1);
Toshihiro Shimizu 890ddd
				area += (p.y + pOld.y) * (pOld.x - p.x);
Toshihiro Shimizu 890ddd
				pOld = p;
Toshihiro Shimizu 890ddd
				pointAdded++;
Toshihiro Shimizu 890ddd
				p = s->getPoint(0.666666 * e->m_w0 + 0.333333 * e->m_w1);
Toshihiro Shimizu 890ddd
				area += (p.y + pOld.y) * (pOld.x - p.x);
Toshihiro Shimizu 890ddd
				pOld = p;
Toshihiro Shimizu 890ddd
				pointAdded++;
Toshihiro Shimizu 890ddd
			} else
Toshihiro Shimizu 890ddd
				for (int j = firstControlPoint; j < lastControlPoint; j += 2) {
Toshihiro Shimizu 890ddd
					p = s->getControlPoint(j);
Toshihiro Shimizu 890ddd
					area += (p.y + pOld.y) * (pOld.x - p.x);
Toshihiro Shimizu 890ddd
					pOld = p;
Toshihiro Shimizu 890ddd
					pointAdded++;
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
		} else {
Toshihiro Shimizu 890ddd
			firstControlPoint--; //this case, getControlPointIndexBEFOREParameter
Toshihiro Shimizu 890ddd
			lastControlPoint--;
Toshihiro Shimizu 890ddd
			if (firstControlPoint & 0x1)
Toshihiro Shimizu 890ddd
				firstControlPoint--;
Toshihiro Shimizu 890ddd
			if (firstControlPoint - lastControlPoint <= 2) ///per evitare di avere troppi pochi punti....
Toshihiro Shimizu 890ddd
			{
Toshihiro Shimizu 890ddd
				p = s->getPoint(0.333333 * e->m_w0 + 0.666666 * e->m_w1);
Toshihiro Shimizu 890ddd
				area += (p.y + pOld.y) * (pOld.x - p.x);
Toshihiro Shimizu 890ddd
				pOld = p;
Toshihiro Shimizu 890ddd
				pointAdded++;
Toshihiro Shimizu 890ddd
				p = s->getPoint(0.666666 * e->m_w0 + 0.333333 * e->m_w1);
Toshihiro Shimizu 890ddd
				area += (p.y + pOld.y) * (pOld.x - p.x);
Toshihiro Shimizu 890ddd
				pOld = p;
Toshihiro Shimizu 890ddd
				pointAdded++;
Toshihiro Shimizu 890ddd
			} else
Toshihiro Shimizu 890ddd
				for (int j = firstControlPoint; j > lastControlPoint; j -= 2) {
Toshihiro Shimizu 890ddd
					p = s->getControlPoint(j);
Toshihiro Shimizu 890ddd
					area += (p.y + pOld.y) * (pOld.x - p.x);
Toshihiro Shimizu 890ddd
					pOld = p;
Toshihiro Shimizu 890ddd
					pointAdded++;
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		p = s->getPoint(e->m_w1);
Toshihiro Shimizu 890ddd
		area += (p.y + pOld.y) * (pOld.x - p.x);
Toshihiro Shimizu 890ddd
		pOld = p;
Toshihiro Shimizu 890ddd
		pointAdded++;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	assert(pointAdded >= 4);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return area > 0.5;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void transferColors(const list<tedge *=""> &oldList, const list<tedge *=""> &newList, bool isStrokeChanged, bool isFlipped, bool overwriteColor);</tedge></tedge>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
void printStrokes1(vector<vistroke *=""> &v, int size)</vistroke>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	UINT i = 0;
Toshihiro Shimizu 890ddd
	ofstream of("C:\\temp\\strokes.txt");
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (i = 0; i < (UINT)size; i++) {
Toshihiro Shimizu 890ddd
		TStroke *s = v[i]->m_s;
Toshihiro Shimizu 890ddd
		of << "***stroke " << i << endl;
Toshihiro Shimizu 890ddd
		for (UINT j = 0; j < (UINT)s->getChunkCount(); j++) {
Toshihiro Shimizu 890ddd
			const TThickQuadratic *q = s->getChunk(j);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			of << "   s0 " << q->getP0() << endl;
Toshihiro Shimizu 890ddd
			of << "   s1 " << q->getP1() << endl;
Toshihiro Shimizu 890ddd
			of << "   s2 " << q->getP2() << endl;
Toshihiro Shimizu 890ddd
			of << "****** " << endl;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		of << endl;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	for (i = size; i < v.size(); i++) {
Toshihiro Shimizu 890ddd
		TStroke *s = v[i]->m_s;
Toshihiro Shimizu 890ddd
		of << "***Autostroke " << i << endl;
Toshihiro Shimizu 890ddd
		of << "s0 " << s->getPoint(0.0) << endl;
Toshihiro Shimizu 890ddd
		of << "s1 " << s->getPoint(1.0) << endl;
Toshihiro Shimizu 890ddd
		of << endl;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
#ifdef _DEBUG
Toshihiro Shimizu 890ddd
static void printTime(TStopWatch &sw, string name)
Toshihiro Shimizu 890ddd
{
kogaki 5bbc3c
	ostrstream ss;
Toshihiro Shimizu 890ddd
	ss << name << " : ";
Toshihiro Shimizu 890ddd
	sw.print(ss);
Toshihiro Shimizu 890ddd
	ss << '\n' << '\0';
Toshihiro Shimizu 890ddd
	string s = ss.str();
Toshihiro Shimizu 890ddd
	ss.freeze(false);
Toshihiro Shimizu 890ddd
	//TSystem::outputDebug(s);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
void printStrokes1(vector<vistroke *=""> &v, int size);</vistroke>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// Trova le regioni in una TVectorImage
Toshihiro Shimizu 890ddd
int TVectorImage::Imp::computeRegions()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
#if defined(_DEBUG) && !defined(MACOSX)
Toshihiro Shimizu 890ddd
	TStopWatch stopWatch;
Toshihiro Shimizu 890ddd
	stopWatch.start(true);
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (!m_computeRegions)
Toshihiro Shimizu 890ddd
		return 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*if (m_intersectionData.m_computedAlmostOnce)
Toshihiro Shimizu 890ddd
  {
Toshihiro Shimizu 890ddd
  UINT i,n=m_strokes.size();
Toshihiro Shimizu 890ddd
	vector<int> vv(n);</int>
Toshihiro Shimizu 890ddd
  for( i=0; i
Toshihiro Shimizu 890ddd
  m_intersectionData.m_computedAlmostOnce = true;
Toshihiro Shimizu 890ddd
  notifyChangedStrokes(vv,vector<tstroke*>(), false);</tstroke*>
Toshihiro Shimizu 890ddd
  
Toshihiro Shimizu 890ddd
  return true;
Toshihiro Shimizu 890ddd
  }*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	g_autocloseTolerance = m_autocloseTolerance;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//Cancella le regioni gia' esistenti per ricalcolarle
Toshihiro Shimizu 890ddd
	clearPointerContainer(m_regions);
Toshihiro Shimizu 890ddd
	m_regions.clear();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// Controlla che ci siano degli stroke
Toshihiro Shimizu 890ddd
	if (m_strokes.empty()) {
Toshihiro Shimizu 890ddd
#if defined(_DEBUG) && !defined(MACOSX)
Toshihiro Shimizu 890ddd
		stopWatch.stop();
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
		return 0;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//Inizializza la lista di intersezioni intList
Toshihiro Shimizu 890ddd
	m_intersectionData.m_computedAlmostOnce = true;
Toshihiro Shimizu 890ddd
	list<intersection> &intList = m_intersectionData.m_intList;</intersection>
Toshihiro Shimizu 890ddd
	cleanIntersectionMarks(intList);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//calcolo struttura delle intersezioni
Toshihiro Shimizu 890ddd
	int added = 0, notAdded = 0;
Toshihiro Shimizu 890ddd
	int strokeSize;
Toshihiro Shimizu 890ddd
	strokeSize = computeIntersections();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	list<intersection>::iterator it1;</intersection>
Toshihiro Shimizu 890ddd
	list<intersectedstroke>::iterator it2;</intersectedstroke>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (it1 = intList.begin(); it1 != intList.end(); it1++)
Toshihiro Shimizu 890ddd
		for (it2 = (*it1).m_strokeList.begin(); it2 != (*it1).m_strokeList.end(); it2++)
Toshihiro Shimizu 890ddd
			it2->m_edge.m_r = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (it1 = intList.begin(); it1 != intList.end(); it1++) {
Toshihiro Shimizu 890ddd
		// Controlla che il punto in questione non sia isolato
Toshihiro Shimizu 890ddd
		if (it1->m_numInter == 0)
Toshihiro Shimizu 890ddd
			continue;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		for (it2 = it1->m_strokeList.begin(); it2 != it1->m_strokeList.end(); it2++) {
Toshihiro Shimizu 890ddd
			TRegion *region;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			// se lo stroke non unisce due punti di intersezione
Toshihiro Shimizu 890ddd
			// non lo considero e vado avanti con un altro stroke
Toshihiro Shimizu 890ddd
			if (it2->m_nextIntersection == intList.end())
Toshihiro Shimizu 890ddd
				continue;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			//Se lo stroke puntato da t2 non e' stato ancora visitato, trova una regione
Toshihiro Shimizu 890ddd
			if (!it2->m_visited && (region = findRegion(intList, it1, it2))) {
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				// Se la regione e' valida la aggiunge al vettore delle regioni
Toshihiro Shimizu 890ddd
				if (isValidArea(m_regions, *region)) {
Toshihiro Shimizu 890ddd
					added++;
Toshihiro Shimizu 890ddd
					addRegion(m_regions, region);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
					//Lega ogni ramo della regione alla regione di appartenenza
Toshihiro Shimizu 890ddd
					for (UINT i = 0; i < region->getEdgeCount(); i++) {
Toshihiro Shimizu 890ddd
						TEdge *e = region->getEdge(i);
Toshihiro Shimizu 890ddd
						e->m_r = region;
Toshihiro Shimizu 890ddd
						if (e->m_index >= 0)
Toshihiro Shimizu 890ddd
							m_strokes[e->m_index]->addEdge(e);
Toshihiro Shimizu 890ddd
					}
Toshihiro Shimizu 890ddd
				} else // Se la regione non e' valida viene scartata
Toshihiro Shimizu 890ddd
				{
Toshihiro Shimizu 890ddd
					notAdded++;
Toshihiro Shimizu 890ddd
					delete region;
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (!m_notIntersectingStrokes) {
Toshihiro Shimizu 890ddd
		UINT i;
Toshihiro Shimizu 890ddd
		for (i = 0; i < m_intersectionData.m_intersectedStrokeArray.size(); i++) {
Toshihiro Shimizu 890ddd
			if (!m_strokes[m_intersectionData.m_intersectedStrokeArray[i].m_index]->m_edgeList.empty())
Toshihiro Shimizu 890ddd
				transferColors(m_intersectionData.m_intersectedStrokeArray[i].m_edgeList,
Toshihiro Shimizu 890ddd
							   m_strokes[m_intersectionData.m_intersectedStrokeArray[i].m_index]->m_edgeList, false, false, true);
Toshihiro Shimizu 890ddd
			clearPointerContainer(m_intersectionData.m_intersectedStrokeArray[i].m_edgeList);
Toshihiro Shimizu 890ddd
			m_intersectionData.m_intersectedStrokeArray[i].m_edgeList.clear();
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		m_intersectionData.m_intersectedStrokeArray.clear();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	assert(m_intersectionData.m_intersectedStrokeArray.empty());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//tolgo i segmenti aggiunti con l'autoclose
Toshihiro Shimizu 890ddd
	vector<vistroke *="">::iterator it = m_strokes.begin();</vistroke>
Toshihiro Shimizu 890ddd
	advance(it, strokeSize);
Toshihiro Shimizu 890ddd
	m_strokes.erase(it, m_strokes.end());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_areValidRegions = true;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#if defined(_DEBUG) && !defined(MACOSX)
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*
Toshihiro Shimizu 890ddd
class Branch
Toshihiro Shimizu 890ddd
  {
Toshihiro Shimizu 890ddd
	TEdge m_edge;
Toshihiro Shimizu 890ddd
  bool m_out, m_visited;
Toshihiro Shimizu 890ddd
	Branch *m_next;
Toshihiro Shimizu 890ddd
	Branch *m_nextBranch;
Toshihiro Shimizu 890ddd
	Intersection* m_intersection;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	public:
Toshihiro Shimizu 890ddd
	  Branch* next()
Toshihiro Shimizu 890ddd
		  {
Toshihiro Shimizu 890ddd
			assert(m_intersection);
Toshihiro Shimizu 890ddd
			return m_next?m_next:m_intersection->m_branchList;
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	
Toshihiro Shimizu 890ddd
	 
Toshihiro Shimizu 890ddd
class Intersection
Toshihiro Shimizu 890ddd
  {
Toshihiro Shimizu 890ddd
	private: 
Toshihiro Shimizu 890ddd
	TPointD m_intersectionPoint;
Toshihiro Shimizu 890ddd
  int m_intersectionCount;
Toshihiro Shimizu 890ddd
  Branch *m_branchList;
Toshihiro Shimizu 890ddd
	Intersection* m_next;
Toshihiro Shimizu 890ddd
  list<intersectedstroke> m_strokeList;</intersectedstroke>
Toshihiro Shimizu 890ddd
	public:
Toshihiro Shimizu 890ddd
  AddIntersection(int index0, int index1, DoublePair intersectionValues);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
*/