Пример #1
0
void MyButton::paintEvent(QPaintEvent *e){
	/*绘制按钮的形状*/
	QPainter  g(this);
	int w=width();
	int h=height();
	QPoint pTop(w/2,2);
	QPoint pBottom(w/2,h-2);
	QPoint pLeft(2,h/2);
	QPoint pRight(w-2,h/2);
	QColor cWhite(255,255,255);
	QColor cBlack(  0,  0,  0);
	QBrush bWhite(cWhite);
	QBrush bBlack(cBlack);
	QPen	 penWhite(bWhite,2);
	QPen	 penBlack(bBlack,2);
	
	
	/*白色*/
	g.setPen(penWhite);
	g.drawLine(pTop,pLeft);
	g.drawLine(pTop,pRight);
	/*黑色*/
	g.setPen(penBlack);
	g.drawLine(pBottom,pLeft);
	g.drawLine(pBottom,pRight);
}
Пример #2
0
int main() {
	pid_t pid;

	fprintf(stdout, "%s%d%s", "P1 (pid=", getpid(), ")\n");
	
	pid = fork();

	if (pid==0) {
		pRight();
		exit(0);
	} else {
		pLeft();
		wait((int*) 0);
		fprintf(stdout, "%s%d%s", "P9 (pid=", getpid(), ")\n");
		return 0;
	}
}
Пример #3
0
    int DocumentSourceSort::compare(
        const intrusive_ptr<Document> &pL, const intrusive_ptr<Document> &pR) {

        /*
          populate() already checked that there is a non-empty sort key,
          so we shouldn't have to worry about that here.

          However, the tricky part is what to do is none of the sort keys are
          present.  In this case, consider the document less.
        */
        const size_t n = vSortKey.size();
        for(size_t i = 0; i < n; ++i) {
            /* evaluate the sort keys */
            ExpressionFieldPath *pE = vSortKey[i].get();
            intrusive_ptr<const Value> pLeft(pE->evaluate(pL));
            intrusive_ptr<const Value> pRight(pE->evaluate(pR));

            /*
              Compare the two values; if they differ, return.  If they are
              the same, move on to the next key.
            */
            int cmp = Value::compare(pLeft, pRight);
            if (cmp) {
                /* if necessary, adjust the return value by the key ordering */
                if (!vAscending[i])
                    cmp = -cmp;

                return cmp;
            }
        }

        /*
          If we got here, everything matched (or didn't exist), so we'll
          consider the documents equal for purposes of this sort.
        */
        return 0;
    }
Пример #4
0
	void FunnelPlanner::computeCrossing( float radius, const Vector2 & startPos, PortalPath * path, size_t startPortal ) {
		assert( path->getPortalCount() > 0 && "Funnel planner should only be applied to PortalPaths with at least one portal" );
		FunnelApex apex( startPortal - 1, startPos );	// if startPortal is zero, this should go to all 1s...i.e. -1 > all other size_t values
		
		const WayPortal * portal = path->getPortal( startPortal );
		Vector2 pLeft( portal->getLeft( radius ) );
		Vector2 pRight( portal->getRight( radius ) );
		Vector2 dirLeft( pLeft - apex._pos );
		Vector2 dirRight( pRight - apex._pos );
	#ifdef SIMPLE_FUNNEL
		FunnelEdge funnelLeft( startPortal, dirLeft );
		FunnelEdge funnelRight( startPortal, dirRight );
		size_t currPortal = startPortal + 1;
		const size_t PORTAL_COUNT = path->getPortalCount();
		while ( currPortal < PORTAL_COUNT ) {
			portal = path->getPortal( currPortal );
			pLeft.set( portal->getLeft( radius ) );
			pRight.set( portal->getRight( radius ) );
			dirLeft.set( pLeft - apex._pos );
			dirRight.set( pRight - apex._pos );

			// test left side of the funnel
			if ( funnelRight.isOnRight( dirLeft ) ) {
				// the portal's funnel is on the right of the current funnel
				Vector2 oldApex = apex._pos;
				Vector2 newApex = funnelRight._dir + apex._pos;
				//if ( apex._id != -1 && apex._id < currPortal ) {
					path->setWaypoints( apex._id + 1, funnelRight._id + 1, newApex, norm( funnelRight._dir ) );
				//}
				apex.set( funnelRight._id, newApex );
				currPortal = funnelRight._id + 1;

				portal = path->getPortal( currPortal );
				pLeft.set( portal->getLeft( radius ) );
				pRight.set( portal->getRight( radius ) );
				dirLeft.set( pLeft - apex._pos );
				dirRight.set( pRight - apex._pos );
				funnelLeft.set( currPortal, dirLeft );
				funnelRight.set( currPortal, dirRight );
				++currPortal;
				
				continue;
			} else if ( funnelLeft.isOnRight( dirLeft ) ) {
				funnelLeft.set( currPortal, dirLeft );
			}

			// test right side of the funnel
			if ( funnelLeft.isOnLeft( dirRight ) ) {
				// the portal's funnel is on the left of the current funnel
				Vector2 oldApex = apex._pos;
				Vector2 newApex = funnelLeft._dir + apex._pos;
				//if ( apex._id != -1 && apex._id < currPortal ) {
					path->setWaypoints( apex._id + 1, funnelLeft._id + 1, newApex, norm( funnelLeft._dir ) );
				//}
				apex.set( funnelLeft._id, newApex );
				currPortal = funnelLeft._id + 1;

				portal = path->getPortal( currPortal );
				pLeft.set( portal->getLeft( radius ) );
				pRight.set( portal->getRight( radius ) );
				dirLeft.set( pLeft - apex._pos );
				dirRight.set( pRight - apex._pos );
				funnelLeft.set( currPortal, dirLeft );
				funnelRight.set( currPortal, dirRight );
				++currPortal;
				
				continue;
			} else if ( funnelRight.isOnLeft( dirRight ) ) {
				funnelRight.set( currPortal, dirRight );
			}
			++currPortal;
		}

		// Now handle goal
		const Vector2 goalPt = path->getGoalCentroid();
		Vector2 goalDir( goalPt - apex._pos );

		if ( funnelLeft.isOnLeft( goalDir ) ) {
			// The goal point is on the left side of the funnel
			if ( apex._id != -1 && apex._id < PORTAL_COUNT ) {
				path->setWaypoints( apex._id + 1, PORTAL_COUNT, apex._pos + funnelLeft._dir, norm( funnelLeft._dir ) );
			}
		} else if ( funnelRight.isOnRight( goalDir ) ) {
			// The goal point is on the right side of the funnel
			if ( apex._id != -1 && apex._id < PORTAL_COUNT ) {
				path->setWaypoints( apex._id + 1, PORTAL_COUNT, apex._pos + funnelRight._dir, norm( funnelRight._dir ) );
			}
		} 

		if ( apex._id + 1 < PORTAL_COUNT ) {
			path->setWaypoints( (size_t)apex._id + 1, (size_t)PORTAL_COUNT, goalPt, norm( goalPt - apex._pos ) );
		}

	#else
		_left.push_back( FunnelEdge( startPortal - 1, startPortal, dirLeft, startPos ) );
		_right.push_back( FunnelEdge( startPortal - 1, startPortal, dirRight, startPos ) );
		const size_t PORTAL_COUNT = path->getPortalCount();
		for ( size_t i = startPortal + 1; i < PORTAL_COUNT; ++i ) {
			portal = path->getPortal( i );

			// investigate the left point
			pLeft.set( portal->getLeft( radius ) );			
			bool apexMoved = false;
			while ( !_right.empty() ) {
				std::list< FunnelEdge >::iterator itr = _right.begin();
				Vector2 dir = pLeft - itr->_origin;
				if ( itr->isOnRight( dir ) ) {
					apexMoved = true;
					Vector2 newApex = itr->_origin + itr->_dir;
					path->setWaypoints( itr->_id + 1, itr->_endID + 1, newApex, norm( itr->_dir ) );
					apex.set( itr->_endID, newApex );
					_right.pop_front();
				} else {
					break;
				}
			}
			if ( apexMoved ) {
				_left.clear();
				_left.push_back( FunnelEdge( apex._id, i, pLeft - apex._pos, apex._pos ) );
			} else {
				std::list< FunnelEdge >::reverse_iterator itr = _left.rbegin();
				while ( ! _left.empty() ) {
					Vector2 dir = pLeft - itr->_origin;
					if ( itr->isOnRight( dir ) ) {
						_left.pop_back();
						itr = _left.rbegin();
					} else {
						break;
					}
				}
				if ( _left.empty() ) {
					_left.push_back( FunnelEdge( apex._id, i, pLeft - apex._pos, apex._pos ) );
				} else {
					Vector2 origin( itr->_origin + itr->_dir );
					_left.push_back( FunnelEdge( itr->_endID, i, pLeft - origin, origin ) );
				}
			}

			// investigate the right point
			pRight.set( portal->getRight( radius ) );
			apexMoved = false;
			while ( !_left.empty() ) {
				std::list< FunnelEdge >::iterator itr = _left.begin();
				Vector2 dir = pRight - itr->_origin;
				if ( itr->isOnLeft( dir ) ) {
					apexMoved = true;
					Vector2 newApex = itr->_origin + itr->_dir;
					path->setWaypoints( itr->_id + 1, itr->_endID + 1, newApex, norm( itr->_dir ) );
					apex.set( itr->_endID, newApex );
					_left.pop_front();
				} else {
					break;
				}
			}
			if ( apexMoved ) {
				_right.clear();
				_right.push_back( FunnelEdge( apex._id, i, pRight - apex._pos, apex._pos ) );
			} else {
				std::list< FunnelEdge >::reverse_iterator itr = _right.rbegin();
				while ( ! _right.empty() ) {
					Vector2 dir = pRight - itr->_origin;
					if ( itr->isOnLeft( dir ) ) {
						_right.pop_back();
						itr = _right.rbegin();
					} else {
						break;
					}
				}
				if ( _right.empty() ) {
					_right.push_back( FunnelEdge( apex._id, i, pRight - apex._pos, apex._pos ) );
				} else {
					Vector2 origin( itr->_origin + itr->_dir );
					_right.push_back( FunnelEdge( itr->_endID, i, pRight - origin, origin ) );
				}
			}
		}
		// handle the goal
		const Vector2 goalPt = path->getGoalCentroid();
		Vector2 goalDir;

		bool apexMoved = false;
		while ( !_left.empty() ) {
			std::list< FunnelEdge >::iterator itr = _left.begin();
			goalDir.set( goalPt - itr->_origin );
			if ( itr->isOnLeft( goalDir ) ) {
				apexMoved = true;
				Vector2 newApex = itr->_origin + itr->_dir;
				apex.set( itr->_endID, newApex );
				path->setWaypoints( itr->_id + 1, itr->_endID + 1, newApex, norm( itr->_dir ) );
				_left.pop_front();
			} else {
				break;
			}
		}
		if ( apexMoved ) {
			goalDir.set( goalPt - apex._pos );
			path->setWaypoints( apex._id + 1, PORTAL_COUNT, goalPt, norm( goalDir ) );
		} else {
			// apexMoved is already false -- it is the only way to reach this branch
			while ( !_right.empty() ) {
				std::list< FunnelEdge >::iterator itr = _right.begin();
				goalDir.set( goalPt - itr->_origin );
				if ( itr->isOnRight( goalDir ) ) {
					apexMoved = true;
					Vector2 newApex = itr->_origin + itr->_dir;
					apex.set( itr->_endID, newApex );
					path->setWaypoints( itr->_id + 1, itr->_endID + 1, newApex, norm( itr->_dir ) );
					_right.pop_front();
				} else {
					break;
				}
			}

			goalDir.set( goalPt - apex._pos );
			path->setWaypoints( apex._id + 1, PORTAL_COUNT, goalPt, norm( goalDir ) );

		}
	#endif	// SIMPLE_FUNNEL
	}
Пример #5
0
bool plug::LinkGameEraser::CheckTwoPoint(POINT first, POINT secode)
{
    plug::ChessPoint pLeft(first);
    plug::ChessPoint pRight(secode);
    POINT tempLeft = {};
    POINT tempRight = {};
    int left = 0;
    int right = 0;
    if ((first.x == secode.x) && (first.y == secode.y))
    {
        return false;
    }
    else if (buffer_[first.y][first.x] == 0 || buffer_[secode.y][secode.x] == 0)
    {
        return false;
    }
    else if (buffer_[first.y][first.x] != buffer_[secode.y][secode.x])
    {
        return false;
    }

    tempLeft = first;
    tempRight = secode;
    if (first.y == secode.y)
    {
        if ((pLeft.right_.x == pRight.p_.x) || (pLeft.left_.x == pRight.p_.x))
        {
            return true;
        }

        if (CheckLine(pLeft.right_, pRight.left_))
            return true;

        tempLeft = first;
        tempRight = secode;
        if ((pLeft.up_.y >= 0) && (pLeft.up_.y <= 10))
        {
            for (right = 0; right < pLeft.up_.y; ++right)
            {
                tempLeft.y = right;
                tempRight.y = right;
                if (CheckLine(tempLeft, pLeft.up_) &&
                    CheckLine(tempRight, pRight.up_) &&
                    CheckLine(tempLeft, tempRight))
                    return true;
            }
        }
        tempLeft = first;
        tempRight = secode;
        if (pLeft.down_.y >= 0 && (pLeft.down_.y <= 10))
        {
            for (right = pLeft.down_.y; right <= 10; ++right)
            {
                tempLeft.y = right;
                tempRight.y = right;
                if (CheckLine(tempLeft, pLeft.down_) &&
                    CheckLine(tempRight, pRight.down_) &&
                    CheckLine(tempLeft, tempRight))
                {
                    return true;
                }
            }
        }
    }
    else if (first.x == secode.x)
    {
        if ((pLeft.down_.y == pRight.p_.y) || (pLeft.up_.y == pRight.p_.y))
        {
            return true;
        }

        if (CheckLine(pLeft.down_, pRight.up_))
        {
            return true;
        }

        tempLeft = first;
        tempRight = secode;
        for (left = 0; left <= pLeft.left_.x; ++left)
        {
            tempLeft.x = left;
            tempRight.x = left;
            if (CheckLine(tempLeft, pLeft.left_) &&
                CheckLine(tempRight, pRight.left_) &&
                CheckLine(tempLeft, tempRight))
            {
                return true;
            }

            tempLeft = first;
            tempRight = secode;
            for (left = pLeft.right_.x; left <= 18; ++left)
            {
                tempLeft.x = left;
                tempRight.x = left;

                if (CheckLine(tempLeft, pLeft.right_) &&
                    CheckLine(tempRight, pRight.right_) &&
                    CheckLine(tempLeft, tempRight))
                {
                    return true;
                }
            }
        }
        if (CheckLine(pLeft.down_, pRight.up_))
            return true;
    }
    else
    {
        tempLeft = first;
        tempRight = secode;
        if (first.x > secode.x)
        {
            for (left = 0; left <= pRight.left_.x; ++left)
            {
                tempLeft.x = left;
                tempRight.x = left;
                if (CheckLine(tempLeft, pLeft.left_) &&
                    CheckLine(tempLeft, tempRight) &&
                    CheckLine(tempRight, pRight.left_))
                {
                    return true;
                }
            }

            for (left = pRight.right_.x; left <= pLeft.left_.x; ++left)
            {
                tempLeft.x = left;
                tempRight.x = left;
                if (CheckLine(pRight.right_, tempRight) &&
                    CheckLine(tempLeft, tempRight) &&
                    CheckLine(tempLeft, pLeft.left_))
                {
                    return true;
                }
            }

            for (left = pRight.right_.x; left <= 18; ++left)
            {
                tempLeft.x = left;
                tempRight.x = left;
                if (CheckLine(pLeft.right_, tempLeft) &&
                    CheckLine(pRight.right_, tempRight) &&
                    CheckLine(tempLeft, tempRight))
                {
                    return true;
                }
            }

            tempLeft.x = first.x;
            tempRight.x = secode.x;
            for (right = 0; right <= pLeft.up_.y; ++right)
            {
                tempLeft.y = right;
                tempRight.y = right;
                if (CheckLine(tempRight, tempLeft) &&
                    CheckLine(tempLeft, pLeft.up_) &&
                    CheckLine(tempRight, pRight.up_))
                {
                    return true;
                }
            }

            for (right = pLeft.down_.y; right <= pRight.up_.y; ++right)
            {
                tempRight.y = right;
                tempLeft.y = right;
                if (CheckLine(tempRight, tempLeft) &&
                    CheckLine(pLeft.down_, tempLeft) &&
                    CheckLine(tempRight, pRight.up_))
                {
                    return true;
                }
            }

            for (right = pRight.down_.y; right <= 10; ++right)
            {
                tempLeft.y = right;
                tempRight.y = right;
                if (CheckLine(tempRight, tempLeft) &&
                    CheckLine(pLeft.down_, tempLeft) &&
                    CheckLine(pRight.down_, tempRight))
                {

                    return true;
                }
            }
        }
        else
        {
            tempLeft.y = first.y;
            tempRight.y = secode.y;
            for (left = 0; left <= pLeft.left_.x; ++left)
            {
                tempLeft.x = left;
                tempRight.x = left;
                if (CheckLine(tempLeft, tempRight) &&
                    CheckLine(tempLeft, pLeft.left_) &&
                    CheckLine(tempRight, pRight.left_))
                {
                    return true;
                }
            }

            for (left = pLeft.right_.x; left < pRight.left_.x; ++left)
            {
                tempLeft.x = left;
                tempRight.x = left;
                if (CheckLine(tempLeft, tempRight) &&
                    CheckLine(pLeft.right_, tempLeft) &&
                    CheckLine(tempRight, pRight.left_))
                {
                    return true;
                }
            }

            for (left = pRight.right_.x; left <= 18; ++left)
            {
                tempLeft.x = 0;
                tempRight.x = left;
                if (CheckLine(tempLeft, tempRight) &&
                    CheckLine(pLeft.right_, tempLeft) &&
                    CheckLine(pRight.right_, tempRight))
                {
                    return true;
                }
            }

            tempLeft.x = first.x;
            tempRight.x = secode.x;
            if ((pLeft.up_.y >= 0) && (pLeft.up_.y <= 10))
            {
                for (right = 0; right <= pLeft.up_.y; ++right)
                {
                    tempLeft.y = right;
                    tempRight.y = right;
                    if (CheckLine(tempLeft, tempRight) &&
                        CheckLine(tempLeft, pLeft.up_) &&
                        CheckLine(tempRight, pRight.up_))
                    {
                        return true;
                    }
                }
            }

            tempLeft.x = first.x;
            tempRight.x = secode.x;
            if ((pLeft.down_.y <= 10) && (pRight.up_.y >= 0))
            {
                for (right = pLeft.down_.y; right <= pRight.up_.y; ++right)
                {
                    tempLeft.y = right;
                    tempRight.y = right;
                    if (CheckLine(tempLeft, tempRight) &&
                        CheckLine(pLeft.down_, tempLeft) &&
                        CheckLine(tempRight, pRight.up_))
                    {
                        return true;
                    }
                }
            }

            tempLeft.x = first.x;
            tempRight.x = secode.x;
            if (pRight.down_.y <= 10)
            {
                for (right = pRight.down_.y; right <= 10; ++right)
                {
                    tempLeft.y = right;
                    tempRight.y = right;
                    if (CheckLine(tempLeft, tempRight) &&
                        CheckLine(pLeft.down_, tempLeft) &&
                        CheckLine(pRight.down_, tempRight))
                    {
                        return true;
                    }
                }
            }
        }
    }

    return false;
}