Example #1
0
void rotate(vector<vector<float> >& rotOp, vector<float>& pt) {
    vector<float> newpt(pt);
    newpt[0] = rotOp[0][0]*pt[0] + rotOp[0][1]*pt[1] + rotOp[0][2]*pt[2];
    newpt[1] = rotOp[1][0]*pt[0] + rotOp[1][1]*pt[1] + rotOp[1][2]*pt[2];
    newpt[2] = rotOp[2][0]*pt[0] + rotOp[2][1]*pt[1] + rotOp[2][2]*pt[2];
    pt = newpt;
}
Example #2
0
int MgGrid::snap(Point2d& pnt, float& distx, float& disty) const
{
    int ret = 0;
    Point2d newpt(pnt);
    Point2d org(getPoint(3));
    Vector2d cell(m_cell == Vector2d() ? Vector2d(getWidth()/4, getHeight()/4) : m_cell / 2);
    
    if (cell.x < _MGZERO || cell.y < _MGZERO)
        return ret;
    
    distx *= 3;
    disty *= 3;
    
    for (float x = cell.x; x < getWidth() - _MGZERO; x += cell.x) {        
        if (distx > fabs(pnt.x - (org.x + x))) {
            newpt.x = org.x + x;
            distx = (float)fabs(pnt.x - newpt.x);
            ret |= 1;
        }
    }
    for (float y = cell.y; y < getHeight() - _MGZERO; y += cell.y) {
        if (disty > fabs(pnt.y - (org.y + y))) {
            newpt.y = org.y + y;
            disty = (float)fabs(pnt.y - newpt.y);
            ret |= 2;
        }
    }
    
    pnt = newpt;
    if ((ret & 1) == 0)
        distx /= 3;
    if ((ret & 2) == 0)
        disty /= 3;
    
    return ret;
}