int intersection(Segment a, Segment b) { if(onLine(a, b.s) || onLine(a, b.t) || onLine(b, a.s) || onLine(b, a.t)) return 1; if(cross(a.s, a.t, b.s)*cross(a.s, a.t, b.t) < 0 && cross(a.t, a.s, b.s)*cross(a.t, a.s, b.t) < 0 && cross(b.s, b.t, a.s)*cross(b.s, b.t, a.t) < 0 && cross(b.t, b.s, a.s)*cross(b.t, b.s, a.t) < 0 ) return 1; return 0; }
bool LineSegment::onSegment(Coord C, double tolerance) const { // C must be on the line if( !onLine(C, tolerance) ) return false; // additionally, C must be between A and B if( (A < C) && (C < B) ) return true; else return false; }
Line planePlaneIntersection(const Plane& p1,const Plane& p2) { //Process: http://stackoverflow.com/a/17628505 Vector normal1=Vector(p1.getA(),p1.getB(),p1.getC()); //vector normal to p1 Vector normal2=Vector(p2.getA(),p2.getB(),p2.getC()); //vector normal to p2 Vector cross=Vector::cross(normal1, normal2); //vector parallel to line of intersection if (fabs(cross.norm())<EPS) { //planes are parallel Point zero=Point(0,0,0); return Line(zero,zero); } double a1=p1.getA(); double b1=p1.getB(); double c1=p1.getC(); double d1=-1*p1.getD(); double a2=p2.getA(); double b2=p2.getB(); double c2=p2.getC(); double d2=-1*p2.getD(); double a3=cross.getX(); double b3=cross.getY(); double c3=cross.getZ(); double d3=0; //solve with cramers rule Matrix3x3 denom(a1,b1,c1, a2,b2,c2, a3,b3,c3); Matrix3x3 xNum(d1,b1,c1, d2,b2,c2, d3,b3,c3); Matrix3x3 yNum(a1,d1,c1, a2,d2,c2, a3,d3,c3); Matrix3x3 zNum(a1,b1,d1, a2,b2,d2, a3,b3,d3); double denomDeterminant=denom.determinant(); double xsolution=xNum.determinant()/denomDeterminant; double ysolution=yNum.determinant()/denomDeterminant; double zsolution=zNum.determinant()/denomDeterminant; Point onLine(xsolution,ysolution,zsolution); Point onLine2=onLine+cross; return Line(onLine,onLine2); }
/** * Checks to see if there is a away message that we should put up right now. * Once done starts a new clock. */ void AwaySchedule::checkToSeeIfWeShouldGoAway() { QDate d = QDate::currentDate(); int day = d.dayOfWeek()-1; QTime t = QTime::currentTime(); appointment *a = appointments.first(); while( a ) { if( a->day == day ) { if( a->startHour <= t.hour() && a->endHour >= t.hour() ) { bool found = true; if( a->startHour == t.hour() ) { if( a->startMinute <= t.minute() ) found = true; else found = false; } if( found == true ) { if( a->endHour == t.hour() ) { if( a->endMinute >= t.minute() ) found = true; else found = false; } if( found == true ) { if(!onLine()) { // We are not online break; } else { qDebug("We found it within the hour time."); if( enabled ) setAwayNow(a->message); break; } } } } } a = appointments.next(); } QTimer::singleShot( TIME_TO_CHECK_IN_SECONDS*1000, this, SLOT(checkToSeeIfWeShouldGoAway())); }
int Engine::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QObject::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: onEnginePanic((*reinterpret_cast< Atom(*)>(_a[1])),(*reinterpret_cast< Word(*)>(_a[2])),(*reinterpret_cast< const QString(*)>(_a[3])),(*reinterpret_cast< const QString(*)>(_a[4]))); break; case 1: onLine((*reinterpret_cast< Atom(*)>(_a[1])),(*reinterpret_cast< Word(*)>(_a[2]))); break; case 2: onExecutionFinished(); break; case 3: onEngineStarted(); break; case 4: onEngineStopped(); break; case 5: eval((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])),(*reinterpret_cast< bool(*)>(_a[3]))); break; case 6: evalFn((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< Atom(*)>(_a[2]))); break; case 7: fullstop(); break; default: ; } _id -= 8; } return _id; }
/* * DoTimeouts() * * This is the function responsible for actual checking of timeouts. It * returns TRUE if you want modIn to break out, too. It should only be called * from modIn(). */ char DoTimeouts() { int yr, dy, hr, mn, temp, mon, secs, milli; static char warned = FALSE; #ifdef SYSTEM_CLOCK static int LastMinute = -1; #endif static int LastDay = 0; extern int PriorityMail; TwoNumbers *tmp; EvDoorRec *evtmp; extern SListBase UntilNetSessions; void Activate(); char Oldpage; getRawDate(&yr, &mon, &dy, &hr, &mn, &secs, &milli); #ifdef SYSTEM_CLOCK if (LastMinute != mn) { ScrTimeUpdate(hr, mn); LastMinute = mn; } #endif if (LastDay != dy) { LastDay = dy; RunListA(&DayBased, Activate, (void *) &LastDay); } ThisMinute = (WhatDay() * 1440) + (hr * 60) + mn; ThisAbsolute = (long) ThisMinute; ThisSecond = ThisAbsolute * 60 + secs; ThisAbsolute = CurAbsolute(); /* First we deal with events which are deactivating */ if ((tmp = GetFirst(&EventEnds)) != NULL) { if (ThisAbsolute >= tmp->second) { /* event is ending! */ ClassActive[tmp->first] = FALSE; KillData(&EventEnds, tmp); /* take it off the list */ if (tmp->first == CL_DL_TIME) ResolveDLStuff(); } } if ((evtmp = GetFirst(&AutoDoors)) != NULL) { if (ThisAbsolute >= evtmp->finish) { /* autodoor finish */ KillData(&AutoDoors, evtmp); } } if ((evtmp = GetFirst(&Redirected)) != NULL) { if (ThisAbsolute >= evtmp->finish) { /* redirection finish */ KillData(&Redirected, evtmp); } } /* Next we deal with preemptive events, which are Type 0 */ /* give a warning at T-5 */ if ((Cur = GetFirst(&Types[0].List)) != NULL && !warned && Types[0].NextAbs - ThisAbsolute < 300l && onLine()) { temp = Cur->EvMinutes % 1440; warned = TRUE; outFlag = IMPERVIOUS; Oldpage = Pageable; Pageable = FALSE; mPrintf("\n %cWARNING: System going down at %d:%02d for %s.\n ", BELL, temp/60, temp%60, Cur->EvWarn + cfg.codeBuf); outFlag = OUTOK; Pageable = Oldpage; return FALSE; } else if (Cur != NULL && Types[0].NextAbs < ThisAbsolute) { if (onLine()) { /* first boot off user, next time do event */ outFlag = IMPERVIOUS; PagingOff(); mPrintf("\n %cGoing to %s, bye!\n ", BELL, Cur->EvWarn + cfg.codeBuf); if (onConsole) { /* Ugly cheat */ onConsole = FALSE; whichIO = MODEM; justLostCarrier = TRUE; EnableModem(FALSE); } else HangUp(FALSE); outFlag = OUTOK; return TRUE; } warned = FALSE; return FigureEvent(0); } if (!onLine() && (Cur = GetFirst(&Types[1].List)) != NULL && Types[1].NextAbs < ThisAbsolute) return FigureEvent(1); if ((Cur = GetFirst(&Types[2].List)) != NULL && Types[2].NextAbs < ThisAbsolute) return FigureEvent(2); /* check priority mail -- odd place for the check, but wotthehell */ if (PriorityMail) { if (!onLine()) { netController((hr*60) + mn, 0, PRIORITY_MAIL, ANYTIME_NET, 0); PriorityMail = 0; } } /* handle anytime netting here - is special type of thing */ if (chkTimeSince(NEXT_ANYNET) > DeadTime || ForceNet) { if (ClassActive[CL_ANYTIME_NET]) { if (!onLine()) { netController((hr * 60) + mn, AnyNetLen, AnyTimeNets, ANYTIME_NET, 0); ScrNewUser(); ForceNet = FALSE; } } else ForceNet = FALSE; startTimer(NEXT_ANYNET); } /* * now see if we have any other net sessions due to be run. These are * sessions scheduled by the user from the Net menu. If so, run each of * them by killing the list (the kill function should run each). */ if (!onLine() && GetFirst(&UntilNetSessions) != NULL) { KillList(&UntilNetSessions); } return ExitToMsdos; }
bool overlap (const Line2D& l) const { return onLine(l.p0) && parallel(l); }