bool TrackedTouch::updateMatching() { bool reportStatus = false; if (hasMatching()) lifeCounter++; else lifeCounter--; bool changing = false; if (status == kTouchTypeStarted) { if (lifeCounter == Constants::OBJECT_FRAMES_TO_ACCEPT + 1) changing = true; else if (lifeCounter == 0) status = kTouchTypeReleased; } if (status == kTouchTypeHolding || changing) { reportStatus = true; if (hasMatching()) { lifeCounter = Constants::TOUCH_FRAMES_TO_DISCARD; if (point == matchingTouch->point) { reportStatus = false; } else { point = matchingTouch->point; } polygon = matchingTouch->polygon; removeMatching(); } else { if (lifeCounter == 0) { status = kTouchTypeReleased; } } } return reportStatus; }
/** * An exception will be thrown if there is an error. */ void RuleSet::generateRule(Command *command) { Rule *rule; Shard *it; GemTest *terms; // Create the rule object. if(command->isName("format")) { rule = new FormatRule(((Block*)command->last()->first())->collect()); } else { rule = new LengthRule; } terms = &rule->terms(); // Compile the terms (command -> shards -> blocks -> tokens). for(it = command->first(); it && it != command->last(); it = it->next()) { if(!it->first()) continue; terms->addBefore(new GemTest((Token*)it->first()->first())); } if(command->isName("format")) { // There must not be format rules with matching terms. removeMatching(*terms, Rule::FORMAT); add(rule); } else { add(rule); Length *len = &((LengthRule*)rule)->length(); // Set the lengths that were given. // Get last argument -> block -> first token. len->init((Token*)command->last()->first()->first()); // Was this all for naught? if(len->isClear()) delete remove(rule); } }
void edgeColoring(int N, int d) { int i; printf("N=%i, d=%i\n\n", N, d); srandom(time(NULL)); int *right_sides, *matching, unmatched; struct Graph *graph, *graphCopy; right_sides = createRightSides(N,d); graph = createRandomRegBipartite(N,d,false,right_sides); graphCopy = createRandomRegBipartite(N,d,false,right_sides); START_TIMER int **matchings; matchings = colorGraphQuickmatch(graph); STOP_TIMER printf("\nFinished in %f seconds\n\n", seconds); // WARNING: BAD TIME COMPLEXITY O(d*E) for (i=d-1; i>=0; i--) { validateMatching(matchings[i], graphCopy); printf("Matching %i valid. \n", i); removeMatching(graphCopy, matchings[i]); } }
TrackedTouch::TrackedTouch(const IPolygonPtr& polygon, const ofVec3f& point) : id(gId++), status(kTouchTypeStarted), polygon(polygon), point(point), lifeCounter(2) { removeMatching(); }