C++ (Cpp) abs Examples

C++ (Cpp) abs - 30 examples found. These are the top rated real world C++ (Cpp) examples of abs extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
void CUITracker::AdjustRect(int nHandle, LPRECT)
{
    if (nHandle == hitMiddle)
        return;

    // convert the handle into locations within m_rect
    int *px, *py;
    GetModifyPointers(nHandle, &px, &py, NULL, NULL);

    // enforce minimum width
    int nNewWidth = m_rect.Width();
    int nAbsWidth = m_bAllowInvert ? abs(nNewWidth) : nNewWidth;
    if (px != NULL && nAbsWidth < m_sizeMin.cx)
    {
        nNewWidth = nAbsWidth != 0 ? nNewWidth / nAbsWidth : 1;
        ptrdiff_t iRectInfo = (int*)px - (int*)&m_rect;
        ENSURE(0 <= iRectInfo && iRectInfo < _countof(g_RectInfo));
        const RectInfo* pRectInfo = &g_RectInfo[iRectInfo];
        *px = *(int*)((BYTE*)&m_rect + pRectInfo->nOffsetAcross) +
              nNewWidth * m_sizeMin.cx * -pRectInfo->nSignAcross;
    }

    // enforce minimum height
    int nNewHeight = m_rect.Height();
    int nAbsHeight = m_bAllowInvert ? abs(nNewHeight) : nNewHeight;
    if (py != NULL && nAbsHeight < m_sizeMin.cy)
    {
        nNewHeight = nAbsHeight != 0 ? nNewHeight / nAbsHeight : 1;
        ptrdiff_t iRectInfo = (int*)py - (int*)&m_rect;
        ENSURE(0 <= iRectInfo && iRectInfo < _countof(g_RectInfo));
        const RectInfo* pRectInfo = &g_RectInfo[iRectInfo];
        *py = *(int*)((BYTE*)&m_rect + pRectInfo->nOffsetAcross) +
              nNewHeight * m_sizeMin.cy * -pRectInfo->nSignAcross;
    }
}
Example #2
0
static int wm8731_set_deemph(struct snd_soc_codec *codec)
{
    struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec);
    int val, i, best;

    /* If we're using deemphasis select the nearest available sample
     * rate.
     */
    if (wm8731->deemph) {
        best = 1;
        for (i = 2; i < ARRAY_SIZE(wm8731_deemph); i++) {
            if (abs(wm8731_deemph[i] - wm8731->playback_fs) <
                    abs(wm8731_deemph[best] - wm8731->playback_fs))
                best = i;
        }

        val = best << 1;
    } else {
        best = 0;
        val = 0;
    }

    dev_dbg(codec->dev, "Set deemphasis %d (%dHz)\n",
            best, wm8731_deemph[best]);

    return snd_soc_update_bits(codec, WM8731_APDIGI, 0x6, val);
}
Example #3
0
void C_DECL A_PotteryCheck(mobj_t* actor)
{
    mobj_t* pmo;

    if(!IS_NETGAME)
    {
        pmo = players[CONSOLEPLAYER].plr->mo;
        if(P_CheckSight(actor, pmo) &&
                (abs((int32_t)(M_PointToAngle2(pmo->origin, actor->origin) - pmo->angle)) <= ANGLE_45))
        {
            // Previous state (pottery bit waiting state).
            P_MobjChangeState(actor, actor->state - &STATES[0] - 1);
        }

        return;
    }
    else
    {
        int i;
        for(i = 0; i < MAXPLAYERS; ++i)
        {
            if(!players[i].plr->inGame) continue;

            pmo = players[i].plr->mo;
            if(P_CheckSight(actor, pmo) &&
                    (abs((int32_t)(M_PointToAngle2(pmo->origin, actor->origin) - pmo->angle)) <= ANGLE_45))
            {
                // Previous state (pottery bit waiting state).
                P_MobjChangeState(actor, actor->state - &STATES[0] - 1);
                return;
            }
        }
    }
}
Example #4
0
void Craby::update(Uint32 ticks) {
    advanceFrame(ticks);
    float x=(target->X()-X());
    float y=(target->Y()-Y());
    float length = sqrt(x*x+y*y);

    velocityX(target->getSpeed()*0.01*Gamedata::getInstance().getRandInRange(1, 10)*(x/length));

    velocityY(target->getSpeed()*0.01*Gamedata::getInstance().getRandInRange(1, 4)*(y/length));

    Vector2f incr = getVelocity() * static_cast<float>(ticks) * 0.001;
    setPosition(getPosition() + incr);

    if ( Y() < 0) {
        velocityY( abs( velocityY() ) );
    }
    if ( Y() > worldHeight-frameHeight) {
        velocityY( -abs( velocityY() ) );
    }

    if ( X() < 0) {
        velocityX( abs( velocityX() ) );
    }
    if ( X() > worldWidth-frameWidth) {
        velocityX( -abs( velocityX() ) );
    }
}
Example #5
0
Direction* Character::dirTo(Coordinate* c) {
    int dx = c->get(X) - loc->get(X);
    int dz = c->get(Y) - loc->get(Y);
    int absdx = abs(dx);
    int absdz = abs(dz);

    int finalX, finalZ;
    if(absdx < absdz) {
        if(absdx < absdz*0.42f)
            finalX = 0;
        else if(dx < 0)
            finalX = -1;
        else
            finalX = 1;
        if(dz < 0)
            finalZ = -1;
        else
            finalZ = 1;
    }
    else {
        if(absdz < absdx*0.42f)
            finalZ = 0;
        else if(dz < 0)
            finalZ = -1;
        else
            finalZ = 1;
        if(dx < 0)
            finalX = -1;
        else
            finalX = 1;
    }
    return World::getDir(finalX, finalZ);
}
Example #6
0
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
void drawPath(int* path, int length, int numOfNodes) {
    int radius = 150;
    int x0 = 210;
    int y0 = 210;
    int nodeRadius = 20;
    int i = 0;
    Form1->Image1->Canvas->Pen->Color = clRed;
    while (i < length) {
        double degreesFrom = 6.28 / (numOfNodes) * path[i];
        int xFrom = radius * cos(degreesFrom);
        int yFrom = radius * sin(degreesFrom);
        if (i + 1 < length) {
            double degreesTo = 6.28 / (numOfNodes) * path[i + 1];
            int xTo = radius * cos(degreesTo);
            int yTo = radius * sin(degreesTo);
            double angle = atan2(abs(xTo - xFrom + 0.0),
                                 abs(yTo - yFrom + 0.0));
            int coefX = xTo - xFrom < 0 ? -1 : 1;
            int coefY = yTo - yFrom < 0 ? -1 : 1;
            int x1 = xTo - coefX * nodeRadius * sin(angle);
            int y1 = yTo - coefY * nodeRadius * cos(angle);
            Form1->Image1->Canvas->MoveTo(xFrom + x0, y0 + yFrom);
            Form1->Image1->Canvas->LineTo(x1 + x0, y1 + y0);
        }
        i++;
    }
    Form1->Image1->Canvas->Pen->Color = clBlack;
}