int CCalendar::getNbSecond(const CDate & date) const { // Retourne le nombre de secondes écoulées depuis le début de l'année. CDate _d0(date); int nbday = 0; for(_d0.setMonth(1); _d0.getMonth() < date.getMonth(); _d0.setMonth(_d0.getMonth()+1)) nbday += getMonthLength(_d0); return ((((nbday + date.getDay()) * getDayLength() + date.getHour()) * getHourLength() + date.getMinute()) * getMinuteLength() + date.getSecond()); }
ToolPath* toolPathGen_GeomShape( GeomShape *shape ) { // @TODO Add Speed control. // Evetually ToolPath will not only be a container to hold instruction // but will also know things about the material so that this generator // can be smart about speeds and bits, etc. ToolPath* tempPath = new ToolPath(); //start computing tool path double toolRadius = 1.0 / 16; double moveHeight = .1; double passes = 1; double totalDepth = -(1.0 / 16.0); double plunge = (totalDepth / passes); for( int nPoly = 0; nPoly < shape->polyCount(); nPoly = nPoly + 1 ) { trace("nPoly %d \n", nPoly); for(double depth = plunge; depth >= totalDepth; depth += plunge ) { trace("depth %d \n", depth); GeomPoly* outline = shape->polys[nPoly]; int d; double sum = 0.0; for( d=0; d<outline->vertCount(); d++ ) { //SOLVE for d0 DVec3 d0 = outline->verts[(d + 1) % outline->vertCount()]; d0.sub(outline->verts[d]); //SOLVE for d1 DVec3 d1 = outline->verts[(d + 2) % outline->vertCount()]; d1.sub(outline->verts[(d + 1) % outline->vertCount()]); DVec3 _d0( d0 ); DVec3 _d1( d1 ); _d0.cross( _d1 ); sum+=_d0.z; } double sign = sum > 0.0 ? -1.0 : 1.0; /* //Use this if winding breaks. if(manwind) { if(wind) sign = 1.0; else sign = -1.0; } */ for( d=0; d<outline->vertCount(); d++ ) { //SOLVE for d0 DVec3 d0 = outline->verts[(d + 1) % outline->vertCount()]; d0.sub(outline->verts[d]); //SOLVE for d1 DVec3 d1 = outline->verts[(d + 2) % outline->vertCount()]; d1.sub(outline->verts[(d + 1) % outline->vertCount()]); //SOLVE for v0 DVec2 v0 = d0; v0.perp(); v0.normalize(); v0.mul( sign * toolRadius ); //SOLVE for v1 DVec2 v1 = d1; v1.perp(); v1.normalize(); v1.mul( sign * toolRadius ); //SOLVE for p0 DVec2 p0 = outline->verts[d]; p0.add( v0 ); //SOLVE for p1 DVec2 p1 = outline->verts[(d+1)%outline->vertCount()]; p1.add( v1 ); //COMPUTE where the two lines meet to find the next vert for the toolPath DMat2 m; m.m[0][0] = d0.x; m.m[0][1] = d0.y; m.m[1][0] = -d1.x; m.m[1][1] = -d1.y; DVec2 b = DVec2( -p0.x + p1.x, -p0.y + p1.y ); if( m.inverse() ) { DVec2 x = m.mul( b ); DVec2 point( p0.x + (x.x * d0.x), p0.y + (x.x * d0.y) ); bool notToClose = true; for( int nPoly2 = 0; nPoly2 < shape->polyCount(); nPoly2++ ) { trace("nPoly2 %d \n", nPoly2); for( int d2=0; d2 < shape->polys[nPoly2]->vertCount(); d2++ ) { DVec2 dist = shape->polys[nPoly2]->verts[d2]; dist.sub(point); double dista = dist.mag(); if(dista < toolRadius - .001) { notToClose = false; } } } if(d == 0) { tempPath->add( DVec3( point.x, point.y, moveHeight ) ); } if( notToClose ) { tempPath->add( DVec3( point.x, point.y, depth ) ); } } } } tempPath->add( DVec3( tempPath->instructions[tempPath->instructions.count - 1]->pos.x, tempPath->instructions[tempPath->instructions.count - 1]->pos.y, moveHeight) ); } return tempPath; }