void CellularAutomata::step() { for (auto& head : m_playhead) { head.position += vecFromDir(head.direction); } for (int i = 0; i < m_playhead.size() - 1; ++i) { for (int j = i+1; j < m_playhead.size(); ++j) { if (m_playhead[i].position == m_playhead[j].position) { Direction& d0 = m_playhead[i].direction; Direction& d1 = m_playhead[j].direction; d0 = rightOf(d0); d1 = rightOf(d1); m_headCollisions.append(HeadHeadCollision(i,j,m_playhead[i].position)); } } } for (auto& head : m_playhead) { Direction d = head.direction; if ( (Direction::LEFT == d) && (head.position.x == 0) ) { head.direction = Direction::RIGHT; m_wallCollisions.append(HeadWallCollision(d, head.position)); } else if ( (Direction::RIGHT == d) && (head.position.x == m_width - 1) ) { head.direction = Direction::LEFT; m_wallCollisions.append(HeadWallCollision(d, head.position)); } else if ( (Direction::UP == d) && (head.position.y == m_height - 1) ) { head.direction = Direction::DOWN; m_wallCollisions.append(HeadWallCollision(d, head.position)); } else if ( (Direction::DOWN == d) && (head.position.y == 0) ) { head.direction = Direction::UP; m_wallCollisions.append(HeadWallCollision(d, head.position)); } } }
void insert(rbtree **root, rbtree *z) { current+=1; if (*root == NULL) { *root = z; } rbtree *n = *root; while (1) { int comparisonResult = n->T-z->T; if (comparisonResult == 0) { return; } else if (comparisonResult < 0) { if (leftOf(n) == NULL) { n->left=z; adjustAfterInsertion(*root, z); break; } n = leftOf(n); } else { // comparisonResult > 0 if (rightOf(n) == NULL) { n->right=z; adjustAfterInsertion(*root,z); break; } n = rightOf(n); } } }
// This method calculates the exitPoint from the startingRect and the entryPoint into the candidate rect. // The line between those 2 points is the closest distance between the 2 rects. void entryAndExitPointsForDirection(FocusDirection direction, const IntRect& startingRect, const IntRect& potentialRect, IntPoint& exitPoint, IntPoint& entryPoint) { switch (direction) { case FocusDirectionLeft: exitPoint.setX(startingRect.x()); entryPoint.setX(potentialRect.maxX()); break; case FocusDirectionUp: exitPoint.setY(startingRect.y()); entryPoint.setY(potentialRect.maxY()); break; case FocusDirectionRight: exitPoint.setX(startingRect.maxX()); entryPoint.setX(potentialRect.x()); break; case FocusDirectionDown: exitPoint.setY(startingRect.maxY()); entryPoint.setY(potentialRect.y()); break; default: ASSERT_NOT_REACHED(); } switch (direction) { case FocusDirectionLeft: case FocusDirectionRight: if (below(startingRect, potentialRect)) { exitPoint.setY(startingRect.y()); entryPoint.setY(potentialRect.maxY()); } else if (below(potentialRect, startingRect)) { exitPoint.setY(startingRect.maxY()); entryPoint.setY(potentialRect.y()); } else { exitPoint.setY(max(startingRect.y(), potentialRect.y())); entryPoint.setY(exitPoint.y()); } break; case FocusDirectionUp: case FocusDirectionDown: if (rightOf(startingRect, potentialRect)) { exitPoint.setX(startingRect.x()); entryPoint.setX(potentialRect.maxX()); } else if (rightOf(potentialRect, startingRect)) { exitPoint.setX(startingRect.maxX()); entryPoint.setX(potentialRect.x()); } else { exitPoint.setX(max(startingRect.x(), potentialRect.x())); entryPoint.setX(exitPoint.x()); } break; default: ASSERT_NOT_REACHED(); } }
sf::IntRect& fitRectByShrinking(sf::IntRect& innerRect, const sf::IntRect& outerRect) { int iLeft = leftOf(innerRect); int iRight = rightOf(innerRect); int iTop = topOf(innerRect); int iBottom = bottomOf(innerRect); int oLeft = leftOf(outerRect); int oRight = rightOf(outerRect); int oTop = topOf(outerRect); int oBottom = bottomOf(outerRect); iLeft = iLeft < oLeft ? oLeft : iLeft; iRight = iRight > oRight ? oRight : iRight; iTop = iTop < oTop ? oTop : iTop; iBottom = iBottom > oBottom ? oBottom : iBottom; return setRectByCorners(innerRect, iLeft, iTop, iRight, iBottom); }
// * a = Current focused node's rect. // * b = Focus candidate node's rect. static long long spatialDistance(FocusDirection direction, const IntRect& a, const IntRect& b) { int x1 = 0, y1 = 0, x2 = 0, y2 = 0; if (direction == FocusDirectionLeft) { // #1 |--| // // #2 |--| |--| // // #3 |--| x1 = a.x(); x2 = b.right(); if (below(a, b)) { // #1 The a rect is below b. y1 = a.y(); y2 = b.bottom(); } else if (below(b, a)) { // #3 The b rect is below a. y1 = a.bottom(); y2 = b.y(); } else { // #2 Both b and a share some common y's. y1 = 0; y2 = 0; } } else if (direction == FocusDirectionRight) { // |--| #1 // // |--| |--| #2 // // |--| #3 x1 = a.right(); x2 = b.x(); if (below(a, b)) { // #1 The b rect is above a. y1 = a.y(); y2 = b.bottom(); } else if (below(b, a)) { // #3 The b rect is below a. y1 = a.bottom(); y2 = b.y(); } else { // #2 Both b and a share some common y's. y1 = 0; y2 = 0; } } else if (direction == FocusDirectionUp) { // // #1 #2 #3 // // |--| |--| |--| // // |--| y1 = a.y(); y2 = b.bottom(); if (rightOf(a, b)) { // #1 The b rect is to the left of a. x1 = a.x(); x2 = b.right(); } else if (rightOf(b, a)) { // #3 The b rect is to the right of a. x1 = a.right(); x2 = b.x(); } else { // #2 Both b and a share some common x's. x1 = 0; x2 = 0; } } else if (direction == FocusDirectionDown) { // |--| // // |--| |--| |--| // // #1 #2 #3 y1 = a.bottom(); y2 = b.y(); if (rightOf(a, b)) { // #1 The b rect is to the left of a. x1 = a.x(); x2 = b.right(); } else if (rightOf(b, a)) { // #3 The b rect is to the right of a x1 = a.right(); x2 = b.x(); } else { // #2 Both b and a share some common x's. x1 = 0; x2 = 0; } } long long dx = x1 - x2; long long dy = y1 - y2; long long distance = (dx * dx) + (dy * dy); if (distance < 0) distance *= -1; return distance; }
QModelIndex QtTreeCursorNavigation::nextCellOnThisRow(QModelIndex const &index) const { return rightOf(index); }
bool Subdivision::ccwBoundary(const Edge *e) { return !rightOf(e->Oprev()->Dest(), e); }