/// Tests the Operators
/// @return True if all tests were executed, false if not
bool DirectionTestSuite::TestCaseOperator()
{
    //------Last Checked------//
    // - Jan 11, 2005
                
    // TEST CASE: Operator=
    {
        Direction direction(12, Direction::toCoda, Direction::activeDaCapo, 4);
        Direction direction2 = direction;        
        TEST(wxT("Operator="), 
            (direction2 == direction)
        );
        
        direction = direction;
        TEST(wxT("Operator= (self-assignment)"), 
            (direction == direction)
        );
    }
    
    // TEST CASE: Operator==
    {
        Direction direction(12, Direction::toCoda, Direction::activeDaCapo, 4);
        Direction direction2(12, Direction::toCoda, Direction::activeDaCapo, 4);
        Direction direction3(13, Direction::toDoubleCoda, Direction::activeDaCapo, 4);
        Direction direction4(12, Direction::toCoda, Direction::activeNone, 4);
        Direction direction5(12, Direction::toCoda, Direction::activeDaCapo, 5);
        Direction direction6(12, Direction::toCoda, Direction::activeDaCapo, 4);
        direction6.AddSymbol(Direction::toDoubleCoda, Direction::activeDaCapo, 4);
                       
        TEST(wxT("Operator== - direction == direction"), (direction == direction2));
        TEST(wxT("Operator== - direction != direction"), !(direction == direction3));
        TEST(wxT("Operator== - direction != direction 2"), !(direction == direction4));
        TEST(wxT("Operator== - direction != direction 3"), !(direction == direction5));
        TEST(wxT("Operator== - direction != direction 4"), !(direction == direction6));
    }
        
    // TEST CASE: Operator!=
    {
        Direction direction(12, Direction::toCoda, Direction::activeDaCapo, 4);
        Direction direction2(12, Direction::toCoda, Direction::activeDaCapo, 4);
        Direction direction3(13, Direction::toDoubleCoda, Direction::activeDaCapo, 4);
        Direction direction4(12, Direction::toCoda, Direction::activeNone, 4);
        Direction direction5(12, Direction::toCoda, Direction::activeDaCapo, 5);
        Direction direction6(12, Direction::toCoda, Direction::activeDaCapo, 4);
        direction6.AddSymbol(Direction::toDoubleCoda, Direction::activeDaCapo, 4);
                       
        TEST(wxT("Operator!= - direction == direction"), !(direction != direction2));
        TEST(wxT("Operator!= - direction != direction"), (direction != direction3));
        TEST(wxT("Operator!= - direction != direction 2"), (direction != direction4));
        TEST(wxT("Operator!= - direction != direction 3"), (direction != direction5));
        TEST(wxT("Operator!= - direction != direction 4"), (direction != direction6));
    }

    return (true);
}
/// Tests the Constructors
/// @return True if all tests were executed, false if not
bool DirectionTestSuite::TestCaseConstructor()
{
    //------Last Checked------//
    // - Jan 11, 2005
    
    // TEST CASE: Default constructor
    {
        Direction direction;
        TEST(wxT("Default Constructor"), 
            (direction.GetPosition() == Direction::DEFAULT_POSITION) &&
            (direction.GetSymbolCount() == 0)
        );        
    }
    
    // TEST CASE: Primary constructor
    {
        Direction direction(12, Direction::toCoda, Direction::activeDaCapo, 4);
        wxByte symbolType = 0;
        wxByte activeSymbol = 0;
        wxByte repeatNumber = 0;
        bool ok = direction.GetSymbol(0, symbolType, activeSymbol, repeatNumber);
        TEST(wxT("Primary Constructor"), 
            (ok) &&
            (direction.GetPosition() ==  12) &&
            (symbolType == Direction::toCoda) &&
            (activeSymbol == Direction::activeDaCapo) &&
            (repeatNumber == 4)
        );
    }
    
    // TEST CASE: Copy constructor
    {
        Direction direction(12, Direction::toCoda, Direction::activeDaCapo, 4);
        Direction direction2(direction);
        TEST(wxT("Copy Constructor"), 
            (direction2 == direction)
        );
    }
    
    return (true);
}
예제 #3
0
/**
 * We could properly speed this up by calling the draw function of this snapper within the paint event
 * this will avoid creating/deletion of the lines
 */
void RS_Snapper::drawSnapper() {
        graphicView->getOverlayContainer(RS2::Snapper)->clear();
    if (!finished && snapSpot.valid) {
                RS_EntityContainer *container=graphicView->getOverlayContainer(RS2::Snapper);
                RS_Pen crossHairPen(RS_Color(255,194,0), RS2::Width00, RS2::DashLine2);

        if (snapCoord.valid) {
                        RS_DEBUG->print("RS_Snapper::Snapped draw start");
                        // Pen for snapper
                        RS_Pen pen(RS_Color(255,194,0), RS2::Width00, RS2::SolidLine);
                        pen.setScreenWidth(1);

                        // Circle to show snap area
                        RS_Circle *circle=new RS_Circle(NULL, RS_CircleData(snapCoord, 4/graphicView->getFactor().x));
                        circle->setPen(pen);

                        container->addEntity(circle);

                        // crosshairs:
                        if (showCrosshairs==true) {
                            if(graphicView->isGridIsometric()) {//isometric crosshair
                                RS2::CrosshairType chType=graphicView->getCrosshairType();
                                RS_Vector direction1;
                                RS_Vector direction2(0.,1.);
                                double l=graphicView->getWidth()+graphicView->getHeight();
                                switch(chType){
                                case RS2::RightCrosshair:
                                    direction1=RS_Vector(M_PI*5./6.)*l;
                                    direction2*=l;
                                    break;
                                case RS2::LeftCrosshair:
                                    direction1=RS_Vector(M_PI*1./6.)*l;
                                    direction2*=l;
                                    break;
                                default:
                                    direction1=RS_Vector(M_PI*1./6.)*l;
                                    direction2=RS_Vector(M_PI*5./6.)*l;
                                }
                                RS_Vector center(graphicView->toGui(snapCoord));
                                RS_OverlayLine *line=new RS_OverlayLine(NULL,RS_LineData(center-direction1,center+direction1));
                                line->setPen(crossHairPen);
                                container->addEntity(line);
                                line=new RS_OverlayLine(NULL,RS_LineData(center-direction2,center+direction2));
                                line->setPen(crossHairPen);
                                container->addEntity(line);
                            }else{//orthogonal crosshair


                                RS_OverlayLine *line=new RS_OverlayLine(NULL, RS_LineData(RS_Vector(0, graphicView->toGuiY(snapCoord.y)),
                                                                                          RS_Vector(graphicView->getWidth(), graphicView->toGuiY(snapCoord.y))));
                                line->setPen(crossHairPen);
                                container->addEntity(line);

                                line=new RS_OverlayLine(NULL, RS_LineData(RS_Vector(graphicView->toGuiX(snapCoord.x),0),
                                                                          RS_Vector(graphicView->toGuiX(snapCoord.x), graphicView->getHeight())));
                                line->setPen(crossHairPen);
                                container->addEntity(line);
                            }

                        }
                        graphicView->redraw(RS2::RedrawOverlay); // redraw will happen in the mouse movement event
                        RS_DEBUG->print("RS_Snapper::Snapped draw end");
        }
        if (snapCoord.valid && snapCoord!=snapSpot) {

                        RS_OverlayLine *line=new RS_OverlayLine(NULL, RS_LineData(graphicView->toGui(snapSpot)+RS_Vector(-5,0),
                                                                                                                                          graphicView->toGui(snapSpot)+RS_Vector(-1,4)));
                        line->setPen(crossHairPen);
                        container->addEntity(line);
                        line=new RS_OverlayLine(NULL, RS_LineData(graphicView->toGui(snapSpot)+RS_Vector(0,5),
                                                                                                                                          graphicView->toGui(snapSpot)+RS_Vector(4,1)));
                        line->setPen(crossHairPen);
                        container->addEntity(line);
                        line=new RS_OverlayLine(NULL, RS_LineData(graphicView->toGui(snapSpot)+RS_Vector(5,0),
                                                                                                                                          graphicView->toGui(snapSpot)+RS_Vector(1,-4)));
                        line->setPen(crossHairPen);
                        container->addEntity(line);
                        line=new RS_OverlayLine(NULL, RS_LineData(graphicView->toGui(snapSpot)+RS_Vector(0,-5),
                                                                                                                                          graphicView->toGui(snapSpot)+RS_Vector(-4,-1)));
                        line->setPen(crossHairPen);
                        container->addEntity(line);

                        graphicView->redraw(RS2::RedrawOverlay); // redraw will happen in the mouse movement event
        }
    }

}
예제 #4
0
		const direction2 operator/(const direction2& lhs, const real rhs)
		{
			return direction2(lhs.vec / rhs);
		}
예제 #5
0
		const direction2 operator*(const real lhs, const direction2& rhs)
		{
			return direction2(lhs * rhs.vec);
		}
예제 #6
0
		const direction2 operator-(const direction2& lhs, const direction2& rhs)
		{
			return direction2(lhs.vec - rhs.vec);
		}
예제 #7
0
		const direction2 FromTo(const point2& from, const point2& to)
		{
			return direction2(to.vec - from.vec);
		}
예제 #8
0
		const direction2 ToUnit(const direction2& dir)
		{
			return direction2(GetNormalized(dir.vec));
		}
예제 #9
0
/**
 * We could properly speed this up by calling the draw function of this snapper within the paint event
 * this will avoid creating/deletion of the lines
 */
void RS_Snapper::drawSnapper()
{
    graphicView->getOverlayContainer(RS2::Snapper)->clear();
	if (!finished && pImpData->snapSpot.valid)
    {
        RS_EntityContainer *container=graphicView->getOverlayContainer(RS2::Snapper);

        RS_DEBUG->print("RS_Snapper::Snapped draw start");

        if (snap_indicator->lines_state)
        {
            QString type = snap_indicator->lines_type;

            if (type == "Crosshair")
            {
                RS_OverlayLine *line = new RS_OverlayLine(nullptr,
                    {{0., graphicView->toGuiY(pImpData->snapCoord.y)},
                    {double(graphicView->getWidth()),
                    graphicView->toGuiY(pImpData->snapCoord.y)}});

                line->setPen(snap_indicator->lines_pen);
                container->addEntity(line);

                line = new RS_OverlayLine(nullptr,
                    {{graphicView->toGuiX(pImpData->snapCoord.x),0.},
                    {graphicView->toGuiX(pImpData->snapCoord.x),
                    double(graphicView->getHeight())}});

                line->setPen(snap_indicator->lines_pen);
                container->addEntity(line);
            }
            else if (type == "Crosshair2")
            {
                double xenoRadius=16;

                double snapX=graphicView->toGuiX(pImpData->snapCoord.x);
                double snapY=graphicView->toGuiY(pImpData->snapCoord.y);

                double viewWidth=double(graphicView->getWidth());
                double viewHeight=double(graphicView->getHeight());

                RS_OverlayLine *line;

                // ----O     (Left)
                line=new RS_OverlayLine(nullptr, {
                    {0., snapY},
                    {snapX-xenoRadius, snapY}
                });
                {
                    line->setPen(snap_indicator->lines_pen);
                    container->addEntity(line);
                }

                //     O---- (Right)
                line=new RS_OverlayLine(nullptr, {
                    {snapX+xenoRadius, snapY},
                    {viewWidth, snapY}
                });
                {
                    line->setPen(snap_indicator->lines_pen);
                    container->addEntity(line);
                }

                // (Top)
                line=new RS_OverlayLine(nullptr, {
                    {snapX, 0.},
                    {snapX, snapY-xenoRadius}
                });
                {
                    line->setPen(snap_indicator->lines_pen);
                    container->addEntity(line);
                }

                // (Bottom)
                line=new RS_OverlayLine(nullptr, {
                    {snapX, snapY+xenoRadius},
                    {snapX, viewHeight}
                });
                {
                    line->setPen(snap_indicator->lines_pen);
                    container->addEntity(line);
                }
            }
            else if (type == "Isometric")
            {
                //isometric crosshair
                RS2::CrosshairType chType=graphicView->getCrosshairType();
                RS_Vector direction1;
                RS_Vector direction2(0.,1.);
                double l=graphicView->getWidth()+graphicView->getHeight();
                switch(chType){
                case RS2::RightCrosshair:
                    direction1=RS_Vector(M_PI*5./6.)*l;
                    direction2*=l;
                    break;
                case RS2::LeftCrosshair:
                    direction1=RS_Vector(M_PI*1./6.)*l;
                    direction2*=l;
                    break;
                default:
                    direction1=RS_Vector(M_PI*1./6.)*l;
                    direction2=RS_Vector(M_PI*5./6.)*l;
                }
                RS_Vector center(graphicView->toGui(pImpData->snapCoord));
                RS_OverlayLine *line=new RS_OverlayLine(container,
                {center-direction1,center+direction1});
                line->setPen(snap_indicator->lines_pen);
                container->addEntity(line);
                line=new RS_OverlayLine(nullptr,
                {center-direction2,center+direction2});
                line->setPen(snap_indicator->lines_pen);
                container->addEntity(line);
            }
            else if (type == "Spiderweb")
            {
                RS_OverlayLine* line;
                RS_Vector point1;
                RS_Vector point2;

                point1 = RS_Vector{0, 0};
                point2 = RS_Vector{graphicView->toGuiX(pImpData->snapCoord.x),
                                   graphicView->toGuiY(pImpData->snapCoord.y)};
                line=new RS_OverlayLine{nullptr, {point1, point2}};
                line->setPen(snap_indicator->lines_pen);
                container->addEntity(line);

                point1 = RS_Vector(0, graphicView->getHeight());
                line = new RS_OverlayLine{nullptr, {point1, point2}};
                line->setPen(snap_indicator->lines_pen);
                container->addEntity(line);

                point1 = RS_Vector(graphicView->getWidth(), 0);
                line = new RS_OverlayLine(nullptr, {point1, point2});
                line->setPen(snap_indicator->lines_pen);
                container->addEntity(line);

                point1 = RS_Vector(graphicView->getWidth(), graphicView->getHeight());
                line = new RS_OverlayLine(nullptr, {point1, point2});
                line->setPen(snap_indicator->lines_pen);
                container->addEntity(line);
            }
        }
        if (snap_indicator->shape_state)
        {
            QString type = snap_indicator->shape_type;

            if (type == "Circle")
            {
                RS_Circle *circle=new RS_Circle(container,
                    {pImpData->snapCoord, 4./graphicView->getFactor().x});
                circle->setPen(snap_indicator->shape_pen);
                container->addEntity(circle);
            }
            else if (type == "Point")
            {
                RS_Point *point=new RS_Point(container, pImpData->snapCoord);
                point->setPen(snap_indicator->shape_pen);
                container->addEntity(point);
            }
            else if (type == "Square")
            {
                RS_Vector snap_point{graphicView->toGuiX(pImpData->snapCoord.x),
                                     graphicView->toGuiY(pImpData->snapCoord.y)};

                double a = 6.0;
                RS_Vector p1 = snap_point + RS_Vector(-a, a);
                RS_Vector p2 = snap_point + RS_Vector(a, a);
                RS_Vector p3 = snap_point + RS_Vector(a, -a);
                RS_Vector p4 = snap_point + RS_Vector(-a, -a);

                RS_OverlayLine* line;
                line=new RS_OverlayLine{nullptr, {p1, p2}};
                line->setPen(snap_indicator->shape_pen);
                container->addEntity(line);

                line = new RS_OverlayLine{nullptr, {p2, p3}};
                line->setPen(snap_indicator->shape_pen);
                container->addEntity(line);

                line = new RS_OverlayLine(nullptr, {p3, p4});
                line->setPen(snap_indicator->shape_pen);
                container->addEntity(line);

                line = new RS_OverlayLine(nullptr, {p4, p1});
                line->setPen(snap_indicator->shape_pen);
                container->addEntity(line);
            }
        }
        graphicView->redraw(RS2::RedrawOverlay); // redraw will happen in the mouse movement event
        RS_DEBUG->print("RS_Snapper::Snapped draw end");
    }
}
/// Tests the Symbol Array Functions
bool DirectionTestSuite::TestCaseSymbolArray()
{
    //------Last Checked------//
    // - Jan 11, 2005
    
    Direction direction(12, Direction::toCoda, Direction::activeDaCapo, 4);
    direction.AddSymbol(Direction::toDoubleCoda, Direction::activeDalSegno, 5);
    direction.AddSymbol(Direction::coda);
    
    // TEST CASE: IsValidSymbolIndex
    {
        wxUint32 i = 0;
        for (; i <= Direction::MAX_SYMBOLS; i++)
            TEST(wxString::Format(wxT("IsValidSymbolIndex - %d"), i), 
                (direction.IsValidSymbolIndex(i) == (i < Direction::MAX_SYMBOLS))
            );
    }
    
    // TEST CASE: AddSymbol
    {
        Direction direction2;
        TEST(wxT("AddSymbol"), 
            (direction2.AddSymbol(Direction::toCoda, Direction::activeDaCapo, 5)) &&
            (direction2.GetSymbolCount() == 1)
        );
        
        TEST(wxT("AddSymbol - full"), (!direction.AddSymbol(Direction::doubleCoda)));
    }

    // TEST CASE: GetSymbolCount
    {    
        TEST(wxT("GetSymbolCount"), (direction.GetSymbolCount() == 3));
    }
    
    // TEST CASE: SetSymbol
    {
        Direction direction2(12, Direction::toCoda, Direction::activeDaCapo, 5);
        TEST(wxT("SetSymbol - invalid index"),
            (!direction2.SetSymbol(Direction::MAX_SYMBOLS, Direction::coda, Direction::activeNone, 0))
        );
        
        TEST(wxT("SetSymbol - invalid symbol type"),
            (!direction2.SetSymbol(0, 255, Direction::activeNone, 0))
        );
        
        TEST(wxT("SetSymbol - invalid active symbol"),
            (!direction2.SetSymbol(0, Direction::coda, 255, 0))
        );
        
        TEST(wxT("SetSymbol - invalid repeat number"),
            (!direction2.SetSymbol(0, Direction::coda, Direction::activeNone, Direction::MAX_REPEAT_NUMBER + 1))
        );
        
        direction2.SetSymbol(0, Direction::coda, Direction::activeNone, 0);
        
        wxByte symbolType = 0;
        wxByte activeSymbol = 0;
        wxByte repeatNumber = 0;
        direction2.GetSymbol(0, symbolType, activeSymbol, repeatNumber);
        
        TEST(wxT("SetSymbol"),
            (symbolType == Direction::coda) &&
            (activeSymbol == Direction::activeNone) &&
            (repeatNumber == 0)
        );
    }
    
    // TEST CASE: IsSymbolType
    {
        TEST(wxT("IsSymbolType - invalid index"),
            (!direction.IsSymbolType(Direction::MAX_SYMBOLS, Direction::toCoda))
        );
        
        TEST(wxT("IsSymbolType - invalid symbol type"),
            (!direction.IsSymbolType(0, 255))
        );
        
        TEST(wxT("IsSymbolType"),
            (direction.IsSymbolType(0, Direction::toCoda)) &&
            (direction.IsSymbolType(1, Direction::toDoubleCoda)) &&
            (direction.IsSymbolType(2, Direction::coda))
        );
    }
    
    // TEST CASE: RemoveSymbolAtIndex
    {
        TEST(wxT("RemoveSymbolAtIndex - invalid index"),
            (!direction.RemoveSymbolAtIndex(Direction::MAX_SYMBOLS))
        );
        TEST(wxT("RemoveSymbolAtIndex"),
            (direction.RemoveSymbolAtIndex(0)) &&
            (direction.GetSymbolCount() == 2)
        );
    }
    
    // TEST CASE: DeleteSymbolArrayContents
    {
        direction.DeleteSymbolArrayContents();
        TEST(wxT("DeleteSymbolArrayContents"),
            (direction.GetSymbolCount() == 0)
        );
    }
    return (true);
}