当前位置: 首页>>代码示例>>C++>>正文


C++ math::abs方法代码示例

本文整理汇总了C++中math::abs方法的典型用法代码示例。如果您正苦于以下问题:C++ math::abs方法的具体用法?C++ math::abs怎么用?C++ math::abs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在math的用法示例。


在下文中一共展示了math::abs方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: drawLine

/**
* @brief Draw a line
*
* Draws a straight line between the two points.
*
* @param x1 the x coordinate of the first point
* @param y2 the y coordinate of the first point
* @param x1 the x coordinate of the second point
* @param y2 the y coordinate of the second point
* @param color the Color to of the line
*/
void CatPictureApp::drawLine(int x1, int y1, int x2, int y2, Color8u* color)
// changed the names of the parametets, thought x1 would make more sense
// to the user than xF, fairly arbitrary though.. might just be personal preference
{
    //Implementation of Bresenham's line algorithm, derived from pseudocode
    //from Wikipedia.


    int dx = intMath->abs(x2 - x1);
    int dy = intMath->abs(y2 - y1);

    int sx = intMath->signum(x2 - x1);
    int sy = intMath->signum(y2 - y1);
    int err = dx - dy;
    int x = x1;
    int y = y1;

    while(true)
    {
        modify(color,x,y);
        if(x == x2 && y == y2)
            break;
        int e2 = 2 * err;
        if(e2 > -dy)
        {
            err -= dy;
            x += sx;
        }
        if(e2 < dx)
        {
            err += dx;
            y += sy;
        }
    }
}
开发者ID:dadoskbm,项目名称:CatPicture,代码行数:46,代码来源:CatPictureApp.cpp

示例2: drawLine

/**
* Draws a straight line between the two points.
* Params:
	xI = Initial X
	yI = Initial Y
	xF = Final X
	yF = Final Y
	color = Color to draw.
*/
void CatPictureApp::drawLine(int xI, int yI, int xF, int yF, Color8u* color)
{
	//Implementation of Bresenham's line algorithm, derived from pseudocode
	//from Wikipedia.

	
	int dx = intMath->abs(xF - xI);
	int dy = intMath->abs(yF - yI);

	int sx = intMath->signum(xF - xI);
	int sy = intMath->signum(yF - yI);
	int err = dx - dy;
	int x = xI;
	int y = yI;

	while(true)
	{
		modify(color,x,y);
		if(x == xF && y == yF)
			break;
		int e2 = 2 * err;
		if(e2 > -dy)
		{
			err -= dy;
			x += sx;
		}
		if(e2 < dx)
		{
			err += dx;
			y += sy;
		}
	}
}
开发者ID:CBMiami019,项目名称:CatPicture,代码行数:42,代码来源:CatPictureApp.cpp


注:本文中的math::abs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。