pointXY *getLinePoints(pointXY p1, pointXY p2, int *numElems, pointXY *(*draw)(pointXY, pointXY, int *)) {
    int i = 0;
    pointXY *line;
    
    // Calculate the number of elements and the slope
    float m = slope(p1, p2);
    
    // Check if there are special cases or not
    if ( (m == 0.0) || (m == 1.0) || (m == -1.0) || (m == INFINITY) || (m == -INFINITY) ) {
        pointXY newP2 = p2;
        newP2.x -= p1.x;
        newP2.y -= p1.y;
        
        int incX = 0, incY = 0;
        
        // Define the increments (due to the type of line)
        // If both conditionals meet, the line is diagonal
        if (p1.x != p2.x) incX = 1; // For vertical line
        if (p1.y != p2.y) incY = 1; // For horizontal line
        if (p2.x < p1.x) incX = -incX;
        if (p2.y < p1.y) incY = -incY;
        
        if ( (incX == 0) && (incY == 0) ) *numElems = 0;
        else if ( incX == 0 ) *numElems = abs(p2.y - p1.y);
        else *numElems = abs(p2.x - p1.x);
        (*numElems)++;
        
        line = calloc(*numElems, sizeof *line);
        
        for (i = 0; i < *numElems; i++) {
            line[i].x = p1.x + incX * i;
            line[i].y = p1.y + incY * i;
        }
    } else {
        // 1. Check which octant is the line, and pass it to the first one
        int steps = stepsToFirstOctant(p1, p2);
        int mX = (steps & 4) >> 2;
        int mY = (steps & 2) >> 1;
        int sw = steps & 1;
        
        if (mX == 1) { p1 = mirrorX(p1); p2 = mirrorX(p2); }
        if (mY == 1) { p1 = mirrorY(p1); p2 = mirrorY(p2); }
        if (sw == 1) { p1 = swap(p1); p2 = swap(p2); }
        
        // 2. Compute the line with the desired algorithm
        line = draw(p1, p2, numElems);
        
        // 3. Return the generated line to its corresponding octant
        for (i = 0; i < *numElems; i++) {
            if (sw == 1) line[i] = swap(line[i]);
            if (mY == 1) line[i] = mirrorY(line[i]);
            if (mX == 1) line[i] = mirrorX(line[i]);
        }
    }
    
    // Finally, return the computed line
    return line;
}
Example #2
0
void WireBoxCornerShrinkGrow::createWireBoxCorner(const quint8 rotate, const quint8 flip)
{
    quint8 xyz = 0;
    for (quint16 j = 0; j < m_iterations; j++)
    {
        for (quint8 i = 0; i < CUBE_SIZE * 2; i++)
        {
            xyz = CUBE_SIZE - 1 - i;
            if (i > CUBE_SIZE - 1)
                xyz = i - CUBE_SIZE;
            fillCubeArray(0x00);
            boxWireframe(0, 0, 0, xyz, xyz, xyz);

            if (flip > 0)
                mirrorZ();
            if (rotate == 1 || rotate == 3)
                mirrorY();
            if (rotate == 2 || rotate == 3)
                mirrorX();
            if(m_abort)
                return;
            waitMs(speed());
        }
    }
}
Example #3
0
void
TBIndex::setSquare(int pieceNo, int square) {
    if (pieceNo == 0) { // White king
        idx &= ~(0xf << (6*p-5));
        idx |= kingMap[square] << (6*p-5);

        int sym = symType[square];
        if (sym & 1)
            mirrorX();
        if (sym & 2)
            mirrorY();
        if (sym & 4)
            mirrorD();
    } else if (pieceNo == nWhite) { // Black king
        int oldSq = getSquare(pieceNo);
        for (int i = 1; i < p; i++) {
            if (getSquare(i) == oldSq) {
                idx &= ~(0x3f << pieceShift(i));
                idx |= square << pieceShift(i);
            }
        }
    } else {
        idx &= ~(0x3f << pieceShift(pieceNo));
        idx |= square << pieceShift(pieceNo);
    }
}
Example #4
0
AViz::AViz() 
    : QMainWindow()
{
    // Make menus in menubar
    QMenu *file = menuBar()->addMenu("&File");
    QMenu *elements = menuBar()->addMenu( "&Elements");
    QMenu *view = menuBar()->addMenu( "&View");
    QMenu *settings = menuBar()->addMenu( "&Settings");
    QMenu *data = menuBar()->addMenu("&Data");
    menuBar()->addSeparator();
    QMenu *help = menuBar()->addMenu("&Help");

    // Make a cascade menu to read files
    QMenu *openfile = file->addMenu("&Open");
    openfile->addAction("Open XYZ File...", this, SLOT(openXYZ()));
    openfile->addAction("Open File List...", this, SLOT(openList()));
    openfile->addAction("Open ViewParam File...", this, SLOT(openViewParam()));



    file->addAction( "Save ViewParam File...", this, SLOT(saveViewParam()) );
    file->addSeparator();
    file->addAction( "File List...", this, SLOT(launchFileList()) );
    file->addAction( "Animation...", this, SLOT(launchAnimation()) );
    file->addSeparator();
    m_inOutWatchModelAction = file->addAction( "Watch XYZ File", this, SLOT(watchFile()) );
    file->addSeparator();
    file->addAction( "Snap PNG File...", this, SLOT(savePNGFile()) );
    file->addSeparator();
    file->addAction( "Set Default View Param", this, SLOT(setDefaultView()));
    file->addSeparator();
    file->addAction( "E&xit", qApp, SLOT(quit()), Qt::CTRL+Qt::Key_Q );

    // Make a general view menu
    QMenu *viewpoint = view->addMenu("Set &Viewpoint");
    view->addAction( "Clipping...", this, SLOT(launchClip()) );
    view->addAction( "Slicing...", this, SLOT(launchSlice()) );

    // Make a cascade menu to set standard view points
    viewpoint->addAction( "Explicit...", this, SLOT(launchExplicit()) );
    viewpoint->addSeparator();
    viewpoint->addAction( "Default View", this, SLOT(setDefaults()) );
    viewpoint->addSeparator();
    viewpoint->addAction( "View XY +", this, SLOT(viewXYPlus()) );
    viewpoint->addAction( "View XY -", this, SLOT(viewXYMinus()) );
    viewpoint->addSeparator();
    viewpoint->addAction( "View XZ +", this, SLOT(viewXZPlus()) );
    viewpoint->addAction( "View XZ -", this, SLOT(viewXZMinus()) );
    viewpoint->addSeparator();
    viewpoint->addAction( "View YZ +", this, SLOT(viewYZPlus()) );
    viewpoint->addAction( "View YZ -", this, SLOT(viewYZMinus()) );


    // Fill a general elements menu
    m_atomsMenu = elements->addMenu("Atoms...");

    // Make a submenu for atom specifications
    m_atomsMenu->addAction( "Atoms/Molecules...", this, SLOT(launchAtoms()) );
    m_atomsMenu->addAction( "Bonds...", this, SLOT(launchBonds()) );

    m_spinsAction = elements->addAction( "Spins...", this, SLOT(launchSpins()) );
    m_liquidCrystalsAction = elements->addAction( "Liquid Crystals...", this, SLOT(launchLiquidCrystals()) );
    m_polymersMenu = elements->addMenu( "Polymers...");
    m_poresAction = elements->addAction( "Pores ...", this, SLOT(launchPores()) );
    elements->addAction( "Lights...", this, SLOT(launchLights()) );
    elements->addAction( "Annotation...", this, SLOT(launchAnnotation()) );

    // fill submenu for polymer specifications
    m_polymersMenu->addAction( "Polymers...", this, SLOT(launchPolymers()) );
    m_polymersMenu->addAction( "Bonds...", this, SLOT(launchBonds()) );


    // fill a general settings menu
    m_showHideAxesAction = settings->addAction( "Hide Axes", this, SLOT(showHideAxesCB()) );
    m_showHideContourAction = settings->addAction( "Hide Contour", this, SLOT(showHideContourCB()) );
    m_onlyContourAction = settings->addAction( "Only Contour", this, SLOT(onlyContourCB()) );

    // fill a general data menu
    data->addAction( "&Translate...", this, SLOT(launchTranslation()) );
    data->addSeparator();
    data->addAction( "Swap XY", this, SLOT(swapXY()) );
    data->addAction( "Swap XZ", this, SLOT(swapXZ()) );
    data->addAction( "Swap YZ", this, SLOT(swapYZ()) );
    data->addSeparator();
    data->addAction( "Mirror X", this, SLOT(mirrorX()) );
    data->addAction( "Mirror Y", this, SLOT(mirrorY()) );
    data->addAction( "Mirror Z", this, SLOT(mirrorZ()) );
    data->addSeparator();
    data->addAction( "Stretch XYZ...", this, SLOT(launchStretch()) );

    // fill a general help menu
    help->addAction( "&About", this, SLOT(about()), Qt::CTRL+Qt::Key_H );
    help->addAction( "License", this, SLOT(license()) );
    help->addAction( "Distribution", this, SLOT(distribute()) );

    // Now construct the main form
    // (Note having aviz as paramter for MainForm ctor
    // is "This is an ugly hack, intended to propagate the
    // address of the calling class")
    m_mainForm = new MainForm(this/*parent*/, this /*aviz*/);
    setCentralWidget(m_mainForm);

    // Construct a timer
    m_watchTimer = new QTimer(this);

    // Set initial settings
    setAtomMenus();
}