void RWInterface()
{
   std::string sJSON = "{"
      "\"type\":\"Add\","
         "\"operand1\":{\"type\":\"Multiply\","
            "\"operand1\":{\"type\":\"Value\",\"value\":10},"
            "\"operand2\":{\"type\":\"Value\",\"value\":15}}"
         ",\"operand2\":{\"type\":\"Value\",\"value\":26}}";

   std::shared_ptr<IOperation> test;
   FromJSON(test, sJSON);
   
   std::string sOut = ToJSON(test);
   std::cout << sOut << std::endl;
   
   auto result =  test->Execute();
   std::cout << "test->Execute() = " << result << std::endl;
   if((sOut == sJSON) && (result == 176))
   {
      std::cout << "test pass" << std::endl;
   }
   else
   {
      std::cout << "test fail" << std::endl;
   }
}
Beispiel #2
0
void PHPProject::Save()
{
    JSONRoot root(cJSON_Object);
    JSONElement pro = root.toElement();
    ToJSON(pro);
    root.save(m_filename);
}
string
HinduSolarOptions::Get( CalendarService::Format format )
{
    string versionName = s_versionNames[ HinduSolarCalendar::GetVersion() ];
    switch ( format )
    {
    case CalendarService::JSON:
    {
        JSONObject jsonObj;
        jsonObj[ "version" ] = ToJSON( versionName );
        return ToJSON( jsonObj );
    }
    default:
        throw Exception( "Unexpected format" );
    }
}
std::string
DMYWCalendarService< C, W, O >::JDToDate( std::string calendarName,
                                          CalendarService::Format format )
{
    CGIInput & cgiInput = CGIInput::Instance();
    long julianDay = std::atol( cgiInput[ "julianDay" ].c_str() );
    int day, month;
    long year;
    C::JulianDayToDMY( julianDay, &day, &month, &year );
    int dayOfWeek = (int)ModP( (julianDay + W::DayOfWeekOfJD0()),
                               (long)W::DaysInWeek() );
    std::string options = O::Get( format );
    switch ( format )
    {
    case CalendarService::JSON:
    {
        JSONObject jsonObj;
        jsonObj[ "calendar" ] = ToJSON( calendarName );
        jsonObj[ "options" ] = options;
        jsonObj[ "julianDay" ] = ToJSON( julianDay );
        jsonObj[ "day" ] = ToJSON( day );
        jsonObj[ "month" ] = ToJSON( month );
        jsonObj[ "year" ] = ToJSON( year );
        jsonObj[ "dayOfWeek" ] = ToJSON( dayOfWeek );
        return ToJSON( jsonObj );
    }
    default:
        throw Exception( "Unexpected format" );
    }
}
wxCrafterCBSettings& wxCrafterCBSettings::Save()
{
    wxFileName fnConfig(wxStandardPaths::Get().GetUserConfigDir(), wxT(".wxCrafterCB.conf"));
    JSONRoot root(cJSON_Object);
    JSONElement json = root.toElement();
    ToJSON( json );
    root.save( fnConfig );
    return *this;
}
std::string
DMYWCalendarService< C, W, O >::AvailableOptions( std::string calendarName,
                                                CalendarService::Format format )
{
    std::vector< std::string > monthNames;
    CGIInput & cgiInput = CGIInput::Instance();
    std::string availableOptions = O::GetAvailable( format );
    switch ( format )
    {
    case CalendarService::JSON:
    {
        JSONObject jsonObj;
        jsonObj[ "calendar" ] = ToJSON( calendarName );
        jsonObj[ "availableOptions" ] = availableOptions;
        return ToJSON( jsonObj );
    }
    default:
        throw Exception( "Unexpected format" );
    }
}
Beispiel #7
0
void PHPWorkspace::Save()
{
    if(!IsOpen()) {
        return;
    }
    // serialize the workspace and store it to disk
    JSONRoot root(cJSON_Object);
    JSONElement ele = root.toElement();
    ToJSON(ele);
    root.save(m_workspaceFile);
}
Beispiel #8
0
void Player::Save(EntityManager* manager)
{
	JsonBox::Value v(ToJSON());
	v.writeToFile(GetName() + ".json");

	JsonBox::Object obj;
	for (auto area : visitedAreas)
		obj[area] = manager->GetEntity<Area>(area)->GetJSON();

	JsonBox::Value v2(obj);
	v2.writeToFile(GetName() + "_areas.json");
}
string
HinduLunisolarCalendarService::AvailableOptions( string calendarName,
                                                CalendarService::Format format )
{
    vector< string > monthNames;
    CGIInput & cgiInput = CGIInput::Instance();
    switch ( format )
    {
    case CalendarService::JSON:
    {
        JSONObject jsonObj;
        jsonObj[ "calendar" ] = ToJSON( calendarName );
        JSONObject availableOptions;
        availableOptions[ "versions" ] = ToJSON( s_versionNames );
        jsonObj[ "availableOptions" ] = ToJSON( availableOptions );
        return ToJSON( jsonObj );
    }
    default:
        throw Exception( "Unexpected format" );
    }
}
Beispiel #10
0
LLDBSettings& LLDBSettings::Save()
{
    wxFileName fn( clStandardPaths::Get().GetUserDataDir(), "lldb.conf");
    fn.AppendDir("config");
    
    wxFFile fp(fn.GetFullPath(), "w+b");
    if ( fp.IsOpened() ) {
        fp.Write( ToJSON().format() );
        fp.Close();
    }
    return *this;
}
std::string
DMYWCalendarService< C, W, O >::Names( std::string calendarName,
                                       CalendarService::Format format )
{
    CGIInput & cgiInput = CGIInput::Instance();
    std::string options = O::Get( format );
    int month = std::atoi( cgiInput[ "month" ].c_str() );
    long year = std::atol( cgiInput[ "year" ].c_str() );
    std::vector< std::string > weekdayNames;
    for ( int i = 0; i < W::DaysInWeek(); ++i )
        weekdayNames.push_back( W::WeekDayName( i ) );
    std::vector< std::string > monthNames;
    for ( int m = 1; m <= C::MonthsInYear( year ); ++m )
        monthNames.push_back( C::MonthName( m, year ) );
    switch ( format )
    {
    case CalendarService::JSON:
    {
        JSONObject jsonObj;
        jsonObj[ "calendar" ] = ToJSON( calendarName );
        jsonObj[ "options" ] = options;
        jsonObj[ "month" ] = ToJSON( month );
        jsonObj[ "year" ] = ToJSON( year );
        jsonObj[ "weekdayNames" ] = ToJSON( weekdayNames );
        jsonObj[ "monthNames" ] = ToJSON( monthNames );
        return ToJSON( jsonObj );
    }
    default:
        throw Exception( "Unexpected format" );
    }
}
inline
std::string
NoOptions::GetAvailable( CalendarService::Format format )
{
    switch ( format )
    {
    case CalendarService::JSON:
    {
        return ToJSON( "" );
    }
    default:
        throw Exception( "Unexpected format" );
    }
}
string
HinduLunisolarCalendarService::Names( string calendarName,
                                      CalendarService::Format format )
{
    vector< string > monthNames;
    for ( int m = 0; m < 12; ++m )
        monthNames.push_back( HinduLunisolarCalendar::MonthName( m ) );
    vector< string > weekdayNames;
    for ( int i = 0; i < HinduWeek::DaysInWeek(); ++i )
        weekdayNames.push_back( HinduWeek::WeekDayName( i ) );
    switch ( format )
    {
    case CalendarService::JSON:
    {
        JSONObject jsonObj;
        jsonObj[ "calendar" ] = ToJSON( calendarName );
        jsonObj[ "monthNames" ] = ToJSON( monthNames );
        jsonObj[ "weekdayNames" ] = ToJSON( weekdayNames );
        return ToJSON( jsonObj );
    }
    default:
        throw Exception( "Unexpected format" );
    }
}
string
HinduLunisolarCalendarService::DateToJD( string calendarName,
                                         CalendarService::Format format )
{
    CGIInput & cgiInput = CGIInput::Instance();
    int day = atoi( cgiInput[ "day" ].c_str() );
    bool dayLeap = (cgiInput[ "dayLeap" ] == "leap");
    int month = atoi( cgiInput[ "month" ].c_str() );
    bool monthLeap = (cgiInput[ "monthLeap" ] == "leap");
    long year = atol( cgiInput[ "year" ].c_str() );
    HinduLunisolarDate date( day, dayLeap, month, monthLeap, year );
    date.MakeValid( );
    long julianDay = date.JulianDay();
    HinduLunisolarCalendar::JulianDayToDLMLY( julianDay, &day, &dayLeap,
                                              &month, &monthLeap, &year );
    int dayOfWeek = (int)ModP( (julianDay + HinduWeek::DayOfWeekOfJD0()),
                               (long)HinduWeek::DaysInWeek() );
    switch ( format )
    {
    case CalendarService::JSON:
    {
        JSONObject jsonObj;
        jsonObj[ "calendar" ] = ToJSON( calendarName );
        jsonObj[ "julianDay" ] = ToJSON( julianDay );
        jsonObj[ "day" ] = ToJSON( day );
        jsonObj[ "dayLeap" ] = ToJSON( dayLeap );
        jsonObj[ "month" ] = ToJSON( month );
        jsonObj[ "monthLeap" ] = ToJSON( monthLeap );
        jsonObj[ "year" ] = ToJSON( year );
        jsonObj[ "dayOfWeek" ] = ToJSON( dayOfWeek );
        return ToJSON( jsonObj );
    }
    default:
        throw Exception( "Unexpected format" );
    }
}
Beispiel #15
0
bool PHPWorkspace::Create(const wxString& filename)
{
    {
        wxFileName fn(filename);
        fn.AppendDir(".codelite");
        wxLogNull nolog;
        ::wxMkdir(fn.GetPath());
    }

    wxFileName fn(filename);

    if(fn.FileExists()) {
        return true;
    }

    // create it
    JSONRoot root(cJSON_Object);
    JSONElement ele = root.toElement();
    ToJSON(ele);
    root.save(fn);
    return true;
}
std::string 
ToJSON( const RotationMatrix2<T> & mat )
{
    return ToJSON( mat.m_matrix );
}
Beispiel #17
0
std::string 
ToJSON( const Matrix3<T> & mat )
{
    return ToJSON( mat.m_elements );
}
Beispiel #18
0
bool 
AngleDMS::Test( )
{
    bool ok = true;
    cout << "Testing AngleDMS" << endl;

    cout << "AngleDMS( ) [default constructor]" << endl;
    AngleDMS angleDMS0;
    cout << "Set( )" << endl;
    angleDMS0.Set( );
    TESTCHECK( angleDMS0.Positive(), true, &ok );
    TESTCHECK( angleDMS0.Degrees(), 0, &ok );
    TESTCHECK( angleDMS0.Minutes(), 0, &ok );
    TESTCHECK( angleDMS0.Seconds(), 0., &ok );
    TESTCHECK( angleDMS0.TotalDegrees(), 0., &ok );
    int d = -60;
    int m = 49;
    double s = 48.;
    cout << "AngleDMS( " << d << ", " << m << ", " << s << " ) [d,m,s constructor]" << endl;
    AngleDMS angleDMS1( d, m, s );
    TESTCHECK( angleDMS1.Positive(), false, &ok );
    TESTCHECK( angleDMS1.Degrees(), -d, &ok );
    TESTCHECK( angleDMS1.Minutes(), m, &ok );
    TESTCHECK( angleDMS1.Seconds(), s, &ok );
    TESTCHECKF( angleDMS1.TotalDegrees(), -60.83, &ok );
    double dd = -29.30;
    cout << "AngleDMS( " << dd << " ) [degrees constructor]" << endl;
    AngleDMS angleDMS2( dd );
    TESTCHECK( angleDMS2.Positive(), false, &ok );
    TESTCHECK( angleDMS2.Degrees(), 29, &ok );
    TESTCHECK( angleDMS2.Minutes(), 18, &ok );
    TESTCHECKF( angleDMS2.Seconds(), 0., &ok );
    TESTCHECKF( angleDMS2.TotalDegrees(), dd, &ok );
    double r = 4.;
    Angle angle4( r );
    cout << "AngleDMS( Angle( " << r << " ) ) [Angle constructor]" << endl;
    AngleDMS angleDMS3( angle4 );
    TESTCHECK( angleDMS3.Positive(), true, &ok );
    TESTCHECK( angleDMS3.Degrees(), 229, &ok );
    TESTCHECK( angleDMS3.Minutes(), 10, &ok );
    TESTCHECKF( angleDMS3.Seconds(), 59.2249884, &ok );
    cout << "Angle( angleDMS3 )" << endl;
    Angle angle( angleDMS3 );
    TESTCHECKF( angle.Radians(), r, &ok );
    TESTCHECKF( angleDMS3.TotalDegrees(), angle.Degrees(), &ok );

    ostringstream ost;
    ost.precision( 2 );
    cout << "operator<<" << endl;
    ost << angleDMS2;
    TESTCHECK( ost.str(), string( "-29°18\'00.000\"" ), &ok );

    TESTCHECK( ToJSON( angleDMS1 ),
               string( "{\n"
                       "\"degrees\": 60,\n"
                       "\"minutes\": 49,\n"
                       "\"positive\": false,\n"
                       "\"seconds\": +4.80000000000000e+001\n"
                       "}" ),
               &ok );
    cout << "FromJSON( ToJSON( angleDMS1 ), &angleDMS3 )" << endl;
    FromJSON( ToJSON( angleDMS1 ), &angleDMS3 );
    TESTCHECK( angleDMS3.Positive(), false, &ok );
    TESTCHECK( angleDMS3.Degrees(), 60, &ok );
    TESTCHECK( angleDMS3.Minutes(), 49, &ok );
    TESTCHECK( angleDMS3.Seconds(), 48., &ok );

    if ( ok )
        cout << "AngleDMS PASSED." << endl << endl;
    else
        cout << "AngleDMS FAILED." << endl << endl;
    return ok;
}
bool 
Spherical::Test( )
{
    bool ok = true;
    cout << "Testing Spherical" << endl;

    cout << "Spherical( ) [default constructor]" << endl;
    Spherical spherical0;
    cout << "Set( )" << endl;
    spherical0.Set( );
    TESTCHECK( spherical0.Longitude().Radians(), 0., &ok );
    TESTCHECK( spherical0.Latitude().Radians(), 0., &ok );
    TESTCHECK( spherical0.Distance(), 0., &ok );
    Point3D rect0 = spherical0.Rectangular();
    TESTCHECK( rect0.X(), 0., &ok );
    TESTCHECK( rect0.Y(), 0., &ok );
    TESTCHECK( rect0.Z(), 0., &ok );
    double lng = - M_PI / 2;
    Angle longitude( lng );
    double lat = M_PI / 4;
    Angle latitude( lat );
    double dist = sqrt( 2. );
    cout << "Spherical( Angle(" << lng << "), Angle(" << lng << "), " << dist << " ) [longitude, latitude, distance constructor]" << endl;
    Spherical spherical1( longitude, latitude, dist );
    TESTCHECK( spherical1.Longitude().Radians(), lng, &ok );
    TESTCHECK( spherical1.Latitude().Radians(), lat, &ok );
    TESTCHECK( spherical1.Distance(), dist, &ok );
    Point3D rect = spherical1.Rectangular();
    TESTCHECKF( rect.X(), 0., &ok );
    TESTCHECKF( rect.Y(), -1., &ok );
    TESTCHECKF( rect.Z(), 1., &ok );
    lng = 3 * M_PI / 4;
    lat = 0.;
    dist = 4.;
    longitude.Set( lng );
    latitude.Set( lat );
    cout << "Set( Angle(" << lng << "), Angle(" << lng << "),  " << dist << " )" << endl;
    spherical1.Set( longitude, latitude, dist );
    TESTCHECK( spherical1.Longitude().Radians(), lng, &ok );
    TESTCHECK( spherical1.Latitude().Radians(), lat, &ok );
    TESTCHECK( spherical1.Distance(), dist, &ok );
    rect = spherical1.Rectangular();
    TESTCHECKF( rect.X(), - sqrt( 8. ), &ok );
    TESTCHECKF( rect.Y(), sqrt( 8. ), &ok );
    TESTCHECKF( rect.Z(), 0., &ok );
    ostringstream ost;
    cout << "operator<<" << endl;
    ost << spherical1;
    TESTCHECK( ost.str(), string( "( 135°, 0°, 4 )" ), &ok );
    double x = 3.;
    double y = 4.;
    double z = 0.;
    rect.Set( x, y, z );
    cout << "Spherical( Point3D(" << x << ", " << y <<  ", " << z << ") ) [rectangular constructor]" << endl;
    Spherical spherical2( rect );
    TESTCHECKF( spherical2.Longitude().Radians(), 0.927295218, &ok );
    TESTCHECKF( spherical2.Latitude().Radians(), 0., &ok );
    TESTCHECKF( spherical2.Distance(), 5., &ok );
    rect = spherical2.Rectangular();
    TESTCHECKF( rect.X(), x, &ok );
    TESTCHECKF( rect.Y(), y, &ok );
    TESTCHECKF( rect.Z(), z, &ok );
    x = 12.;
    y = 0.;
    z = -5.;
    rect.Set( x, y, z );
    cout << "Set( Point3D(" << x << ", " << y <<  ", " << z << ") )" << endl;
    spherical2.Set( rect );
    TESTCHECKF( spherical2.Longitude().Radians(), 0., &ok );
    TESTCHECKF( spherical2.Latitude().Radians(), -0.39479112, &ok );
    TESTCHECKF( spherical2.Distance(), 13., &ok );
    rect = spherical2.Rectangular();
    TESTCHECKF( rect.X(), x, &ok );
    TESTCHECKF( rect.Y(), y, &ok );
    TESTCHECKF( rect.Z(), z, &ok );
    int h = 14;
    int m = 15;
    double s = 39.7;
    cout << "ra = AngleHMS( " << h << ", " << m << ", " << s << " )" << endl;
    const Angle raArcturus( AngleHMS( h, m, s ) );
    int d = 19;
    m = 10;
    s = 57.;
    cout << "dec = AngleDMS( " << d << ", " << m << ", " << s << " )" << endl;
    const Angle decArcturus( AngleDMS( d, m, s ) );
    cout << "Arcturus: ( ra, dec, 1. )" << endl;
    const Spherical Arcturus( raArcturus, decArcturus );
    h = 13;
    m = 25;
    s = 11.6;
    cout << "ra = AngleHMS( " << h << ", " << m << ", " << s << " )" << endl;
    const Angle raSpica( AngleHMS( h, m, s ) );
    d = -11;
    m = 9;
    s = 41.;
    cout << "dec = AngleDMS( " << d << ", " << m << ", " << s << " )" << endl;
    const Angle decSpica( AngleDMS( d, m, s ) );
    cout << "Spica: ( ra, dec, 1. )" << endl;
    const Spherical Spica( raSpica, decSpica );
    cout << "Separation( Arcturus, Spica )" << endl;
    Angle sep = Separation( Arcturus, Spica );
    TESTCHECKF( sep.Degrees(), 32.7930103, &ok );
    lng = -1.5;
    lat = 0.75;
    dist = 40.;
    longitude.Set( lng );
    latitude.Set( lat );
    cout << "Set( Angle(" << lng << "), Angle(" << lat << "), "
         << dist << " )" << endl;
    spherical1.Set( longitude, latitude, dist );
    TESTCHECK( ToJSON( spherical1 ),
               string( "{\n"
                       "\"distance\": +4.00000000000000e+001,\n"
                       "\"latitude\": +7.50000000000000e-001,\n"
                       "\"longitude\": -1.50000000000000e+000\n"
                       "}"),
               &ok );
    cout << "FromJSON( ToJSON( spherical1 ), &spherical2 )" << endl;
    FromJSON(  ToJSON( spherical1 ), &spherical2 );
    TESTCHECK( spherical2.Longitude().Radians(), lng, &ok );
    TESTCHECK( spherical2.Latitude().Radians(), lat, &ok );
    TESTCHECK( spherical2.Distance(), dist, &ok );

    if ( ok )
        cout << "Spherical PASSED." << endl << endl;
    else
        cout << "Spherical FAILED." << endl << endl;
    return ok;
}
bool 
TestQuaternion( )
{
    bool ok = true;
    cout << "Testing Quaternion" << endl;

    cout << "Quaternion( ) [default constructor]" << endl;
    QuaternionF quat0;
    float w = 3.f;
    float x = 0.f;
    float y = 4.f;
    float z = 0.f;
    cout << "Set( " << w << ", " << x << ", " << y << ", " << z << " )" << endl;
    quat0.Set( w, x, y, z );
    TESTCHECK( quat0.W(), w, &ok );
    TESTCHECK( quat0.X(), x, &ok );
    TESTCHECK( quat0.Y(), y, &ok );
    TESTCHECK( quat0.Z(), z, &ok );
    TESTCHECK( quat0[0], w, &ok );
    TESTCHECK( quat0[1], x, &ok );
    TESTCHECK( quat0[2], y, &ok );
    TESTCHECK( quat0[3], z, &ok );
    TESTCHECK( quat0.At( 0 ), w, &ok );
    TESTCHECK( quat0.At( 1 ), x, &ok );
    TESTCHECK( quat0.At( 2 ), y, &ok );
    TESTCHECK( quat0.At( 3 ), z, &ok );
    try
    {
        TESTCHECK( quat0.At(4), 0.f, &ok );
        cout << "At(4) should have thrown an exception." << endl;
        ok = false;
    }
    catch( out_of_range & exceptn )
    {
        cout << "Exception here is OK" << endl;
        cout << exceptn.what() << endl;
    }
    cout << "quat0.Array()" << endl;
    const float * pF = quat0.Array();
    TESTCHECK( pF[0], w, &ok );
    TESTCHECK( pF[1], x, &ok );
    TESTCHECK( pF[2], y, &ok );
    TESTCHECK( pF[3], z, &ok );
    TESTCHECK( quat0.Real(), w, &ok );
    TESTCHECK( quat0.Imaginary().X(), x, &ok );
    TESTCHECK( quat0.Imaginary().Y(), y, &ok );
    TESTCHECK( quat0.Imaginary().Z(), z, &ok );
    cout << "Conjugate( )" << endl;
    QuaternionF quat1 = quat0.Conjugate( );
    TESTCHECK( quat1.W(), w, &ok );
    TESTCHECK( quat1.X(), -x, &ok );
    TESTCHECK( quat1.Y(), -y, &ok );
    TESTCHECK( quat1.Z(), -z, &ok );
    TESTCHECK( quat0.Length(), 5.f, &ok );
    TESTCHECK( quat0.Norm(), 25.f, &ok );
    TESTCHECK( quat1.Length(), 5.f, &ok );
    TESTCHECK( quat1.Norm(), 25.f, &ok );
    TESTCHECK( (quat0 + quat1).W(), 6.f, &ok );
    TESTCHECK( (quat0 + quat1).X(), 0.f, &ok );
    TESTCHECK( (quat0 + quat1).Y(), 0.f, &ok );
    TESTCHECK( (quat0 + quat1).Z(), 0.f, &ok );
    ostringstream ost;
    cout << "operator<<" << endl;
    ost << quat0;
    TESTCHECK( ost.str(), string( "( 3, 0, 4, 0 )" ), &ok );
    TESTCHECK( ToJSON( quat0 ),
               string( "[ +3.00000e+00, +0.00000e+00, +4.00000e+00,"
                       " +0.00000e+00 ]" ),
               &ok );
    FromJSON( "[ 3, 0, -4.0, 0. ]", &quat1 );
    TESTCHECK( quat1.W(), w, &ok );
    TESTCHECK( quat1.X(), -x, &ok );
    TESTCHECK( quat1.Y(), -y, &ok );
    TESTCHECK( quat1.Z(), -z, &ok );
    cout << "Normalize( )" << endl;
    quat1.Normalize( );
    TESTCHECKF( quat1.W(), 0.6f, &ok );
    TESTCHECKF( quat1.X(), 0.f, &ok );
    TESTCHECKF( quat1.Y(), -0.8f, &ok );
    TESTCHECKF( quat1.Z(), 0.f, &ok );
    TESTCHECKF( quat1.Norm(), 1.f, &ok );
    cout << "Inverse( )" << endl;
    quat1 = quat0.Inverse( );
    TESTCHECKF( quat1.W(), 0.12f, &ok );
    TESTCHECKF( quat1.X(), 0.f, &ok );
    TESTCHECKF( quat1.Y(), -0.16f, &ok );
    TESTCHECKF( quat1.Z(), 0.f, &ok );
    TESTCHECKF( (quat0 * quat1).W(), 1.f, &ok );
    TESTCHECKF( (quat0 * quat1).X(), 0.f, &ok );
    TESTCHECKF( (quat0 * quat1).Y(), 0.f, &ok );
    TESTCHECKF( (quat0 * quat1).Z(), 0.f, &ok );
    float coords[4] = { 0.5f, 0.5f, 0.5f, 0.5f };
    cout << "QuaternionF( coords ) [array constructor]" << endl;
    QuaternionF quat2( coords );
    TESTCHECKF( quat2.W(), 0.5f, &ok );
    TESTCHECKF( quat2.X(), 0.5f, &ok );
    TESTCHECKF( quat2.Y(), 0.5f, &ok );
    TESTCHECKF( quat2.Z(), 0.5f, &ok );
    TESTCHECKF( quat2.Norm(), 1.f, &ok );
    cout << "Normalize( )" << endl;
    quat2.Normalize( );
    TESTCHECKF( quat2.W(), 0.5f, &ok );
    TESTCHECKF( quat2.X(), 0.5f, &ok );
    TESTCHECKF( quat2.Y(), 0.5f, &ok );
    TESTCHECKF( quat2.Z(), 0.5f, &ok );
    TESTCHECKF( quat2.Norm(), 1.f, &ok );
    cout << "Conjugate( )" << endl;
    quat1 = quat2.Conjugate( );
    TESTCHECKF( quat1.W(), 0.5f, &ok );
    TESTCHECKF( quat1.X(), -0.5f, &ok );
    TESTCHECKF( quat1.Y(), -0.5f, &ok );
    TESTCHECKF( quat1.Z(), -0.5f, &ok );
    TESTCHECKF( quat1.Norm(), 1.f, &ok );
    TESTCHECKF( (quat1 + quat2).W(), 1.f, &ok );
    TESTCHECKF( (quat1 + quat2).X(), 0.f, &ok );
    TESTCHECKF( (quat1 + quat2).Y(), 0.f, &ok );
    TESTCHECKF( (quat1 + quat2).Z(), 0.f, &ok );
    TESTCHECKF( (quat1 - quat2).W(), 0.f, &ok );
    TESTCHECKF( (quat1 - quat2).X(), -1.f, &ok );
    TESTCHECKF( (quat1 - quat2).Y(), -1.f, &ok );
    TESTCHECKF( (quat1 - quat2).Z(), -1.f, &ok );
    TESTCHECKF( (quat1 * quat2).W(), 1.f, &ok );
    TESTCHECKF( (quat1 * quat2).X(), 0.f, &ok );
    TESTCHECKF( (quat1 * quat2).Y(), 0.f, &ok );
    TESTCHECKF( (quat1 * quat2).Z(), 0.f, &ok );
    cout << "Inverse( )" << endl;
    quat1 = quat2.Inverse( );
    TESTCHECKF( quat1.W(), 0.5f, &ok );
    TESTCHECKF( quat1.X(), -0.5f, &ok );
    TESTCHECKF( quat1.Y(), -0.5f, &ok );
    TESTCHECKF( quat1.Z(), -0.5f, &ok );
    TESTCHECKF( quat1.Norm(), 1.f, &ok );
    double a = M_PI / 2.;
    cout << "QuaternionF( AxisAngle( Vector3F::UnitZ, Angle( " << a
         << " ) ) ) [axis-angle constructor]" << endl;
    QuaternionF quat3( AxisAngleF( Vector3F::UnitZ, Angle( a ) ) );
    TESTCHECKF( quat3.W(), sqrt( 0.5f ), &ok );
    TESTCHECKF( quat3.X(), 0.f, &ok );
    TESTCHECKF( quat3.Y(), 0.f, &ok );
    TESTCHECKF( quat3.Z(), sqrt( 0.5f ), &ok );
    TESTCHECKF( quat3.Norm(), 1.f, &ok );
    cout << "GetAxisAngle( )" << endl;
    AxisAngleF axisAngle = quat3.GetAxisAngle( );
    TESTCHECKF( axisAngle.Axis().X(), 0.f, &ok );
    TESTCHECKF( axisAngle.Axis().Y(), 0.f, &ok );
    TESTCHECKF( axisAngle.Axis().Z(), 1.f, &ok );
    TESTCHECKF( axisAngle.GetAngle().Radians(), M_PI / 2., &ok );
    cout << "Set( 2, a )" << endl;
    quat1.Set( 2, a );
    TESTCHECKF( quat1.W(), sqrt( 0.5f ), &ok );
    TESTCHECKF( quat1.X(), 0.f, &ok );
    TESTCHECKF( quat1.Y(), 0.f, &ok );
    TESTCHECKF( quat1.Z(), sqrt( 0.5f ), &ok );
    TESTCHECKF( quat1.Norm(), 1.f, &ok );
    cout << "Log()" << endl;
    quat1 = quat3.Log( );
    TESTCHECKF( quat1.W(), 0.f, &ok );
    TESTCHECKF( quat1.X(), 0.f, &ok );
    TESTCHECKF( quat1.Y(), 0.f, &ok );
    TESTCHECKF( quat1.Z(), M_PI / 4.f, &ok );
    cout << "SetW( 1. )" << endl;
    quat1.SetW( 1.f );
    cout << "Exp()" << endl;
    quat1 = quat1.Exp( );
    TESTCHECKF( quat1.W(), exp( 1.f ) * sqrt( 0.5f ), &ok );
    TESTCHECKF( quat1.X(), 0.f, &ok );
    TESTCHECKF( quat1.Y(), 0.f, &ok );
    TESTCHECKF( quat1.Z(), exp( 1.f ) * sqrt( 0.5f ), &ok );
    TESTCHECK( (quat1 == quat3), false, &ok );
    cout << "Log()" << endl;
    quat1 = quat1.Log( );
    TESTCHECKF( quat1.W(), 1.f, &ok );
    TESTCHECKF( quat1.X(), 0.f, &ok );
    TESTCHECKF( quat1.Y(), 0.f, &ok );
    TESTCHECKF( quat1.Z(), M_PI / 4.f, &ok );
    a = 2. * M_PI / 3.;
    float f = static_cast<float>( sqrt( 1./3. ) );
    cout << "RotationMatrix3F( AxisAngleF( Vector3F( " << f << ", " << f
         << ", " << f << "), Angle( " << a << " ) ) )" << endl;
    axisAngle.Set( Vector3F( f, f, f ), Angle( a ) );
    RotationMatrix3F mat0( axisAngle );
    cout << "QuaternionF( mat0 ) [rotation matrix constructor]" << endl;
    QuaternionF quat4( mat0 );
    TESTCHECKF( quat4.W(), quat2.W(), &ok );
    TESTCHECKF( quat4.X(), quat2.X(), &ok );
    TESTCHECKF( quat4.Y(), quat2.Y(), &ok );
    TESTCHECKF( quat4.Z(), quat2.Z(), &ok );
    TESTCHECKF( quat4.Norm(), 1.f, &ok );
    cout << "GetAxisAngle( )" << endl;
    axisAngle = quat4.GetAxisAngle( );
    TESTCHECKF( axisAngle.Axis().X(), f, &ok );
    TESTCHECKF( axisAngle.Axis().Y(), f, &ok );
    TESTCHECKF( axisAngle.Axis().Z(), f, &ok );
    TESTCHECKF( axisAngle.GetAngle().Radians(), a, &ok );
    cout << "Matrix( )" << endl;
    RotationMatrix3F mat1 = quat4.Matrix( );
    TESTCHECKF( mat1(0,0), mat0(0,0), &ok );
    TESTCHECKF( mat1(0,1), mat0(0,1), &ok );
    TESTCHECKF( mat1(0,2), mat0(0,2), &ok );
    TESTCHECKF( mat1(1,0), mat0(1,0), &ok );
    TESTCHECKF( mat1(1,1), mat0(1,1), &ok );
    TESTCHECKF( mat1(1,2), mat0(1,2), &ok );
    TESTCHECKF( mat1(2,0), mat0(2,0), &ok );
    TESTCHECKF( mat1(2,1), mat0(2,1), &ok );
    TESTCHECKF( mat1(2,2), mat0(2,2), &ok );
    cout << "(quat4 * Quaternion( Vector3F::UnitX )"
         << "* quat4.Conjugate()).Imaginary() [rotation]" << endl;
    Vector3F vec1 = (quat4 * QuaternionF( Vector3F::UnitX )
                     * quat4.Conjugate()).Imaginary();
    TESTCHECKF( vec1.X(), 0.f, &ok );
    TESTCHECKF( vec1.Y(), 1.f, &ok );
    TESTCHECKF( vec1.Z(), 0.f, &ok );
    cout << "Rotate( Vector3F::UnitX )" << endl;
    vec1 = quat4.Rotate( Vector3F::UnitX );
    TESTCHECKF( vec1.X(), 0.f, &ok );
    TESTCHECKF( vec1.Y(), 1.f, &ok );
    TESTCHECKF( vec1.Z(), 0.f, &ok );
    float a0 = -2.9f;
    float a1 = 1.8f;
    float a2 = -0.7f;
    cout << "Quaternion qrot0( 0, " << a0 << " )" << endl;
    QuaternionF qrot0( 0, Angle( a0 ) );
    cout << "Quaternion qrot1( 1, " << a1 << " )" << endl;
    QuaternionF qrot1( 1, Angle( a1 ) );
    cout << "Quaternion qrot2( 2, " << a2 << " )" << endl;
    QuaternionF qrot2( 2, Angle( a2 ) );
    cout << "quat1 = qrot1 * qrot2 * qrot0" << endl;
    quat1 = qrot1 * qrot2 * qrot0;
    cout << "GetEulerAngles( EulerAngles::YZX )" << endl;
    EulerAngles euler = quat1.GetEulerAngles( EulerAngles::YZX );
    TESTCHECKF( euler[0].Radians(), a1, &ok );
    TESTCHECKF( euler[1].Radians(), a2, &ok );
    TESTCHECKF( euler[2].Radians(), a0, &ok );
    cout << "Quaternion( EulerAngles( " << a1 << ", " << a2 << ", " << a0
         << " ), EulerAngles::YZX ) [Euler angles constructor]" << endl;
    QuaternionF quat5( EulerAngles( a1, a2, a0 ), EulerAngles::YZX );
    TESTCHECKF( quat5.W(), quat1.W(), &ok );
    TESTCHECKF( quat5.X(), quat1.X(), &ok );
    TESTCHECKF( quat5.Y(), quat1.Y(), &ok );
    TESTCHECKF( quat5.Z(), quat1.Z(), &ok );
    cout << "GetEulerAngles( EulerAngles::YZX )" << endl;
    euler = quat5.GetEulerAngles( EulerAngles::YZX );
    TESTCHECKF( euler[0].Radians(), a1, &ok );
    TESTCHECKF( euler[1].Radians(), a2, &ok );
    TESTCHECKF( euler[2].Radians(), a0, &ok );
    a2 = static_cast<float>( - M_PI / 2. );
    cout << "qrot2.Set( 2, " << a2 << " )" << endl;
    qrot2.Set( 2, Angle( a2 ) );
    cout << "quat1 = qrot1 * qrot2 * qrot0" << endl;
    quat1 = qrot1 * qrot2 * qrot0;
    cout << "GetEulerAngles( EulerAngles::YZX )" << endl;
    euler = quat1.GetEulerAngles( EulerAngles::YZX );
    Angle a10( a1 - a0 );
    a10.Normalize();
    float a1_a0 = static_cast<float>( a10.Radians() );
    TESTCHECKF( euler[0].Radians(), a1_a0, &ok );
    TESTCHECKF( euler[1].Radians(), a2, &ok );
    TESTCHECKF( euler[2].Radians(), 0.f, &ok );
    cout << "Matrix().GetEulerAngles( EulerAngles::YZX )" << endl;
    euler = quat1.Matrix().GetEulerAngles( EulerAngles::YZX );
    TESTCHECKF( euler[0].Radians(), a1_a0, &ok );
    TESTCHECKF( euler[1].Radians(), a2, &ok );
    TESTCHECKF( euler[2].Radians(), 0.f, &ok );
    cout << "Set( EulerAngles( " << a1 << ", " << a2 << ", " << a0
         << " ), EulerAngles::YZX )" << endl;
    quat5.Set( EulerAngles( a1, a2, a0 ), EulerAngles::YZX );
    TESTCHECKF( quat5.W(), quat1.W(), &ok );
    TESTCHECKF( quat5.X(), quat1.X(), &ok );
    TESTCHECKF( quat5.Y(), quat1.Y(), &ok );
    TESTCHECKF( quat5.Z(), quat1.Z(), &ok );
    cout << "GetEulerAngles( EulerAngles::YZX )" << endl;
    euler = quat5.GetEulerAngles( EulerAngles::YZX );
    TESTCHECKF( euler[0].Radians(), a1_a0, &ok );
    TESTCHECKF( euler[1].Radians(), a2, &ok );
    TESTCHECKF( euler[2].Radians(), 0.f, &ok );
    a0 = 1.1f;
    a1 = -1.0f;
    a2 = 0.5f;
    cout << "qrot0.Set( 0, " << a0 << " )" << endl;
    qrot0.Set( 0, Angle( a0 ) );
    cout << "qrot1.Set( 1, " << a1 << " )" << endl;
    qrot1.Set( 1, Angle( a1 ) );
    cout << "qrot2.Set( 2, " << a2 << " )" << endl;
    qrot2.Set( 2, Angle( a2 ) );
    cout << "quat1 = qrot2 * qrot1 * qrot0" << endl;
    quat1 = qrot2 * qrot1 * qrot0;
    cout << "GetEulerAngles( EulerAngles::ZYX )" << endl;
    euler = quat1.GetEulerAngles( EulerAngles::ZYX );
    TESTCHECKF( euler[0].Radians(), a2, &ok );
    TESTCHECKF( euler[1].Radians(), a1, &ok );
    TESTCHECKF( euler[2].Radians(), a0, &ok );
    cout << "Matrix().GetEulerAngles( EulerAngles::ZYX )" << endl;
    euler = quat1.Matrix().GetEulerAngles( EulerAngles::ZYX );
    TESTCHECKF( euler[0].Radians(), a2, &ok );
    TESTCHECKF( euler[1].Radians(), a1, &ok );
    TESTCHECKF( euler[2].Radians(), a0, &ok );
    cout << "Set( EulerAngles( " << a2 << ", " << a1 << ", " << a0
         << " ), EulerAngles::ZYX )" << endl;
    quat5.Set( EulerAngles( a2, a1, a0 ), EulerAngles::ZYX );
    TESTCHECKF( quat5.W(), quat1.W(), &ok );
    TESTCHECKF( quat5.X(), quat1.X(), &ok );
    TESTCHECKF( quat5.Y(), quat1.Y(), &ok );
    TESTCHECKF( quat5.Z(), quat1.Z(), &ok );
    cout << "GetEulerAngles( EulerAngles::ZYX )" << endl;
    euler = quat5.GetEulerAngles( EulerAngles::ZYX );
    TESTCHECKF( euler[0].Radians(), a2, &ok );
    TESTCHECKF( euler[1].Radians(), a1, &ok );
    TESTCHECKF( euler[2].Radians(), a0, &ok );
    a1 = static_cast<float>( M_PI / 2. );
    cout << "qrot1.Set( 1, " << a1 << " )" << endl;
    qrot1.Set( 1, Angle( a1 ) );
    cout << "quat1 = qrot2 * qrot1 * qrot0" << endl;
    quat1 = qrot2 * qrot1 * qrot0;
    cout << "GetEulerAngles( EulerAngles::ZYX )" << endl;
    euler = quat1.GetEulerAngles( EulerAngles::ZYX );
    Angle a20 = Angle( a2 - a0 );
    a20.Normalize();
    float a2_a0 = static_cast<float>( a20.Radians() );
    TESTCHECKF( euler[0].Radians(), a2_a0, &ok );
    TESTCHECKF( euler[1].Radians(), a1, &ok );
    TESTCHECKF( euler[2].Radians(), 0.f, &ok );
    cout << "Set( EulerAngles( " << a2 << ", " << a1 << ", " << a0
         << " ), EulerAngles::ZYX )" << endl;
    quat5.Set( EulerAngles( a2, a1, a0 ), EulerAngles::ZYX );
    TESTCHECKF( quat5.W(), quat1.W(), &ok );
    TESTCHECKF( quat5.X(), quat1.X(), &ok );
    TESTCHECKF( quat5.Y(), quat1.Y(), &ok );
    TESTCHECKF( quat5.Z(), quat1.Z(), &ok );
    cout << "GetEulerAngles( EulerAngles::ZYX )" << endl;
    euler = quat5.GetEulerAngles( EulerAngles::ZYX );
    TESTCHECKF( euler[0].Radians(), a2_a0, &ok );
    TESTCHECKF( euler[1].Radians(), a1, &ok );
    TESTCHECKF( euler[2].Radians(), 0.f, &ok );
    
    if ( ok )
        cout << "Quaternion PASSED." << endl << endl;
    else
        cout << "Quaternion FAILED." << endl << endl;
    return ok;
}
Beispiel #21
0
bool 
TestVector4( )
{
    bool ok = true;
    cout << "Testing Vector4" << endl;

    cout << "Vector4<float>() [default constructor]" << endl;
    Vector4<float> vf0;
    cout << "Set( )" << endl;
    vf0.Set( );
    TESTCHECK( vf0.X(), 0.f, &ok );
    TESTCHECK( vf0.Y(), 0.f, &ok );
    TESTCHECK( vf0.Z(), 0.f, &ok );
    TESTCHECK( vf0.W(), 0.f, &ok );
    TESTCHECK( vf0[0], 0.f, &ok );
    TESTCHECK( vf0[1], 0.f, &ok );
    TESTCHECK( vf0[2], 0.f, &ok );
    TESTCHECK( vf0[3], 0.f, &ok );
    TESTCHECK( vf0.At(0), 0.f, &ok );
    TESTCHECK( vf0.At(1), 0.f, &ok );
    TESTCHECK( vf0.At(2), 0.f, &ok );
    TESTCHECK( vf0.At(3), 0.f, &ok );
    try
    {
        TESTCHECK( vf0.At(4), 0.f, &ok );
        cout << "At(4) should have thrown an exception." << endl;
        ok = false;
    }
    catch( out_of_range & exceptn )
    {
        cout << "Assert here is OK" << endl;
        cout << exceptn.what() << endl;
    }
    TESTCHECK( (vf0 == vf0), true, &ok );
    TESTCHECK( (vf0 == Vector4F::Zero), true, &ok );
    float xf = 37.f;
    float yf = -17.f;
    float zf = -3.f;
    float wf = 13.f;
    cout << "Set( " << xf << ", " << yf << ", " << zf << ", " << wf << " ) :"
         << endl;
    vf0.Set( xf, yf, zf, wf );
    TESTCHECK( vf0.X(), xf, &ok );
    TESTCHECK( vf0.Y(), yf, &ok );
    TESTCHECK( vf0.Z(), zf, &ok );
    TESTCHECK( vf0.W(), wf, &ok );
    TESTCHECK( vf0[0], xf, &ok );
    TESTCHECK( vf0[1], yf, &ok );
    TESTCHECK( vf0[2], zf, &ok );
    TESTCHECK( vf0[3], wf, &ok );
    TESTCHECK( vf0.At(0), xf, &ok );
    TESTCHECK( vf0.At(1), yf, &ok );
    TESTCHECK( vf0.At(2), zf, &ok );
    TESTCHECK( vf0.At(3), wf, &ok );
    TESTCHECK( (vf0 == vf0), true, &ok );
    xf = 11.f;
    cout << "vf0[0] = " << xf << " [index assignment]" << endl;
    vf0[0] = xf;
    TESTCHECK( vf0.X(), xf, &ok );
    TESTCHECK( vf0.Y(), yf, &ok );
    TESTCHECK( vf0.Z(), zf, &ok );
    TESTCHECK( vf0.W(), wf, &ok );
    TESTCHECK( vf0[0], xf, &ok );
    TESTCHECK( vf0[1], yf, &ok );
    TESTCHECK( vf0[2], zf, &ok );
    TESTCHECK( vf0[3], wf, &ok );
    TESTCHECK( vf0.At(0), xf, &ok );
    TESTCHECK( vf0.At(1), yf, &ok );
    TESTCHECK( vf0.At(2), zf, &ok );
    TESTCHECK( vf0.At(3), wf, &ok );
    yf = -11.f;
    cout << "vf0[1] = " << yf << " [index assignment]" << endl;
    vf0[1] = yf;
    TESTCHECK( vf0.X(), xf, &ok );
    TESTCHECK( vf0.Y(), yf, &ok );
    TESTCHECK( vf0.Z(), zf, &ok );
    TESTCHECK( vf0.W(), wf, &ok );
    TESTCHECK( vf0[0], xf, &ok );
    TESTCHECK( vf0[1], yf, &ok );
    TESTCHECK( vf0[2], zf, &ok );
    TESTCHECK( vf0[3], wf, &ok );
    TESTCHECK( vf0.At(0), xf, &ok );
    TESTCHECK( vf0.At(1), yf, &ok );
    TESTCHECK( vf0.At(2), zf, &ok );
    TESTCHECK( vf0.At(3), wf, &ok );
    zf = 14.f;
    cout << "vf0[2] = " << zf << " [index assignment]" << endl;
    vf0[2] = zf;
    TESTCHECK( vf0.X(), xf, &ok );
    TESTCHECK( vf0.Y(), yf, &ok );
    TESTCHECK( vf0.Z(), zf, &ok );
    TESTCHECK( vf0.W(), wf, &ok );
    TESTCHECK( vf0[0], xf, &ok );
    TESTCHECK( vf0[1], yf, &ok );
    TESTCHECK( vf0[2], zf, &ok );
    TESTCHECK( vf0[3], wf, &ok );
    TESTCHECK( vf0.At(0), xf, &ok );
    TESTCHECK( vf0.At(1), yf, &ok );
    TESTCHECK( vf0.At(2), zf, &ok );
    TESTCHECK( vf0.At(3), wf, &ok );
    wf = 100.f;
    cout << "vf0[3] = " << wf << " [index assignment]" << endl;
    vf0[3] = wf;
    TESTCHECK( vf0.X(), xf, &ok );
    TESTCHECK( vf0.Y(), yf, &ok );
    TESTCHECK( vf0.Z(), zf, &ok );
    TESTCHECK( vf0.W(), wf, &ok );
    TESTCHECK( vf0[0], xf, &ok );
    TESTCHECK( vf0[1], yf, &ok );
    TESTCHECK( vf0[2], zf, &ok );
    TESTCHECK( vf0[3], wf, &ok );
    TESTCHECK( vf0.At(0), xf, &ok );
    TESTCHECK( vf0.At(1), yf, &ok );
    TESTCHECK( vf0.At(2), zf, &ok );
    TESTCHECK( vf0.At(3), wf, &ok );
    xf = 111.f;
    cout << "vf0.At(0) = " << xf << " [index assignment]" << endl;
    vf0.At(0) = xf;
    TESTCHECK( vf0.X(), xf, &ok );
    TESTCHECK( vf0.Y(), yf, &ok );
    TESTCHECK( vf0.Z(), zf, &ok );
    TESTCHECK( vf0.W(), wf, &ok );
    TESTCHECK( vf0[0], xf, &ok );
    TESTCHECK( vf0[1], yf, &ok );
    TESTCHECK( vf0[2], zf, &ok );
    TESTCHECK( vf0[3], wf, &ok );
    TESTCHECK( vf0.At(0), xf, &ok );
    TESTCHECK( vf0.At(1), yf, &ok );
    TESTCHECK( vf0.At(2), zf, &ok );
    TESTCHECK( vf0.At(3), wf, &ok );
    yf = -111.f;
    cout << "vf0.At(1) = " << yf << " [index assignment]" << endl;
    vf0.At(1) = yf;
    TESTCHECK( vf0.X(), xf, &ok );
    TESTCHECK( vf0.Y(), yf, &ok );
    TESTCHECK( vf0.Z(), zf, &ok );
    TESTCHECK( vf0.W(), wf, &ok );
    TESTCHECK( vf0[0], xf, &ok );
    TESTCHECK( vf0[1], yf, &ok );
    TESTCHECK( vf0[2], zf, &ok );
    TESTCHECK( vf0[3], wf, &ok );
    TESTCHECK( vf0.At(0), xf, &ok );
    TESTCHECK( vf0.At(1), yf, &ok );
    TESTCHECK( vf0.At(2), zf, &ok );
    TESTCHECK( vf0.At(3), wf, &ok );
    zf = 114.f;
    cout << "vf0.At(2) = " << zf << " [index assignment]" << endl;
    vf0.At(2) = zf;
    TESTCHECK( vf0.X(), xf, &ok );
    TESTCHECK( vf0.Y(), yf, &ok );
    TESTCHECK( vf0.Z(), zf, &ok );
    TESTCHECK( vf0.W(), wf, &ok );
    TESTCHECK( vf0[0], xf, &ok );
    TESTCHECK( vf0[1], yf, &ok );
    TESTCHECK( vf0[2], zf, &ok );
    TESTCHECK( vf0[3], wf, &ok );
    TESTCHECK( vf0.At(0), xf, &ok );
    TESTCHECK( vf0.At(1), yf, &ok );
    TESTCHECK( vf0.At(2), zf, &ok );
    TESTCHECK( vf0.At(3), wf, &ok );
    wf = -3000.f;
    cout << "vf0.At(3) = " << wf << " [index assignment]" << endl;
    vf0.At(3) = wf;
    TESTCHECK( vf0.X(), xf, &ok );
    TESTCHECK( vf0.Y(), yf, &ok );
    TESTCHECK( vf0.Z(), zf, &ok );
    TESTCHECK( vf0.W(), wf, &ok );
    TESTCHECK( vf0[0], xf, &ok );
    TESTCHECK( vf0[1], yf, &ok );
    TESTCHECK( vf0[2], zf, &ok );
    TESTCHECK( vf0[3], wf, &ok );
    TESTCHECK( vf0.At(0), xf, &ok );
    TESTCHECK( vf0.At(1), yf, &ok );
    TESTCHECK( vf0.At(2), zf, &ok );
    TESTCHECK( vf0.At(3), wf, &ok );
    try
    {
        vf0.At(4) = 33.f;
        cout << "At(4) should have thrown an exception." << endl;
        ok = false;
    }
    catch( out_of_range & exceptn )
    {
        cout << "Exception here is OK" << endl;
        cout << exceptn.what() << endl;
    }
    cout << "pf = vf0.Array()" << endl;
    float * pf = vf0.Array();
    TESTCHECK( pf[0], xf, &ok );
    TESTCHECK( pf[1], yf, &ok );
    TESTCHECK( pf[2], zf, &ok );
    TESTCHECK( pf[3], wf, &ok );
    xf = 32.f;
    cout << "pf[0] = " << xf << endl;
    pf[0] = xf;
    yf = 23.f;
    cout << "pf[1] = " << yf << endl;
    pf[1] = yf;
    zf = -10.f;
    cout << "pf[2] = " << zf << endl;
    pf[2] = zf;
    wf = -29.f;
    cout << "pf[3] = " << wf << endl;
    pf[3] = wf;
    TESTCHECK( vf0[0], xf, &ok );
    TESTCHECK( vf0[1], yf, &ok );
    TESTCHECK( vf0[2], zf, &ok );
    TESTCHECK( vf0[3], wf, &ok );
    TESTCHECKF( vf0.Length( ), 49.93996396f, &ok );
    TESTCHECK( ToJSON( vf0 ),
               string( "[ +3.20000e+01, +2.30000e+01,"
                       " -1.00000e+01, -2.90000e+01 ]" ),
               &ok );
    cout << "FromJSON( \"[ 32, 23, -10, -29 ]\", &vf0 )" << endl;
    FromJSON( "[ 32, 23, -10, -29 ]", &vf0 );
    TESTCHECK( vf0.X(), xf, &ok );
    TESTCHECK( vf0.Y(), yf, &ok );
    TESTCHECK( vf0.Z(), zf, &ok );
    TESTCHECK( vf0.W(), wf, &ok );
    cout << "Normalize()" << endl;
    vf0.Normalize( );
    TESTCHECKF( vf0.X(), 0.64076939f, &ok );
    TESTCHECKF( vf0.Y(), 0.46055299f, &ok );
    TESTCHECKF( vf0.Z(), -0.20024043f, &ok );
    TESTCHECKF( vf0.W(), -0.58069725f, &ok );
    TESTCHECKF( vf0.Length(), 1.f, &ok );
    cout << "Set( ) : " << endl;
    vf0.Set( );
    TESTCHECK( vf0.X(), 0.f, &ok );
    TESTCHECK( vf0.Y(), 0.f, &ok );
    TESTCHECK( vf0.Z(), 0.f, &ok );
    TESTCHECK( vf0.W(), 0.f, &ok );
    TESTCHECK( vf0[0], 0.f, &ok );
    TESTCHECK( vf0[1], 0.f, &ok );
    TESTCHECK( vf0[2], 0.f, &ok );
    TESTCHECK( vf0[3], 0.f, &ok );
    TESTCHECK( vf0.At(0), 0.f, &ok );
    TESTCHECK( vf0.At(1), 0.f, &ok );
    TESTCHECK( vf0.At(2), 0.f, &ok );
    TESTCHECK( vf0.At(3), 0.f, &ok );
    TESTCHECK( vf0.Length(), 0.f, &ok );
    try
    {
        cout << "Normalize()" << endl;
        vf0.Normalize( );
        cout << "Normalize() should have thrown an exception." << endl;
        ok = false;
    }
    catch( NullVectorException & exceptn )
    {
        cout << "Exception here is OK" << endl;
        cout << exceptn.Description() << endl;
    }
    xf = -11.f;
    yf = 4.f;
    zf = 7.f;
    wf = 100.f;
    cout << "Vector4<float>( " << xf << ", " << yf << ", " << zf << ", " << wf
         << " ) [x,y,z,w constructor]" << endl;
    Vector4<float> vf1( xf, yf, zf, wf );
    TESTCHECK( vf1.X(), xf, &ok );
    TESTCHECK( vf1.Y(), yf, &ok );
    TESTCHECK( vf1.Z(), zf, &ok );
    TESTCHECK( vf1.W(), wf, &ok );
    TESTCHECK( vf1[0], xf, &ok );
    TESTCHECK( vf1[1], yf, &ok );
    TESTCHECK( vf1[2], zf, &ok );
    TESTCHECK( vf1[3], wf, &ok );
    TESTCHECK( vf1.At(0), xf, &ok );
    TESTCHECK( vf1.At(1), yf, &ok );
    TESTCHECK( vf1.At(2), zf, &ok );
    TESTCHECK( vf1.At(3), wf, &ok );
    TESTCHECK( (vf1 == vf1), true, &ok );
    TESTCHECK( (vf0 == vf1), false, &ok );
    const float fArr0[] = { 21.f, -55.f, -1000.f, -123.f };
    cout << "Vector4<float>( { " << fArr0[0] << ", " << fArr0[1] << ", "
         << fArr0[2] << ", " << fArr0[3] << " } ) [array constructor]" << endl;
    Vector4<float> vf2( fArr0 );
    TESTCHECK( vf2.X(), fArr0[0], &ok );
    TESTCHECK( vf2.Y(), fArr0[1], &ok );
    TESTCHECK( vf2.Z(), fArr0[2], &ok );
    TESTCHECK( vf2.W(), fArr0[3], &ok );
    TESTCHECK( vf2[0], fArr0[0], &ok );
    TESTCHECK( vf2[1], fArr0[1], &ok );
    TESTCHECK( vf2[2], fArr0[2], &ok );
    TESTCHECK( vf2[3], fArr0[3], &ok );
    TESTCHECK( vf2.At(0), fArr0[0], &ok );
    TESTCHECK( vf2.At(1), fArr0[1], &ok );
    TESTCHECK( vf2.At(2), fArr0[2], &ok );
    TESTCHECK( vf2.At(3), fArr0[3], &ok );
    try
    {
        TESTCHECK( vf2.At(4), 0.f, &ok );
        cout << "At(4) should have thrown an exception." << endl;
        ok = false;
    }
    catch( out_of_range & exceptn )
    {
        cout << "Exception here is OK" << endl;
        cout << exceptn.what() << endl;
    }
    const float fArr1[] = { -12.f, 1955.f, 1729.f, -.125f };
    cout << "Set( { " << fArr1[0] << ", " << fArr1[1] << ", " << fArr1[2]
         << " } )" << endl;
    vf2.Set( fArr1 );
    TESTCHECK( vf2.X(), fArr1[0], &ok );
    TESTCHECK( vf2.Y(), fArr1[1], &ok );
    TESTCHECK( vf2.Z(), fArr1[2], &ok );
    TESTCHECK( vf2.W(), fArr1[3], &ok );
    TESTCHECK( vf2[0], fArr1[0], &ok );
    TESTCHECK( vf2[1], fArr1[1], &ok );
    TESTCHECK( vf2[2], fArr1[2], &ok );
    TESTCHECK( vf2[3], fArr1[3], &ok );
    TESTCHECK( vf2.At(0), fArr1[0], &ok );
    TESTCHECK( vf2.At(1), fArr1[1], &ok );
    TESTCHECK( vf2.At(2), fArr1[2], &ok );
    TESTCHECK( vf2.At(3), fArr1[3], &ok );
    cout << "Vector4<float>( vf2 ) [copy constructor]" << endl;
    Vector4<float> vf3( vf2 );
    TESTCHECK( (vf3 == vf2), true, &ok );
    TESTCHECK( vf3.X(), fArr1[0], &ok );
    TESTCHECK( vf3.Y(), fArr1[1], &ok );
    TESTCHECK( vf3.Z(), fArr1[2], &ok );
    TESTCHECK( vf3.W(), fArr1[3], &ok );
    cout << "= vf1 [assignment]" << endl;
    vf3 = vf1;
    TESTCHECK( (vf3 == vf2), false, &ok );
    TESTCHECK( (vf3 == vf1), true, &ok );
    TESTCHECK( vf3.X(), xf, &ok );
    TESTCHECK( vf3.Y(), yf, &ok );
    TESTCHECK( vf3.Z(), zf, &ok );
    TESTCHECK( vf3.W(), wf, &ok );
    cout << "= - vf1 [negation]" << endl;
    vf3 = - vf1;
    TESTCHECK( (vf3 == vf1), false, &ok );
    TESTCHECK( vf3.X(), -xf, &ok );
    TESTCHECK( vf3.Y(), -yf, &ok );
    TESTCHECK( vf3.Z(), -zf, &ok );
    TESTCHECK( vf3.W(), -wf, &ok );
    cout << "+= vf1" << endl;
    vf3 += vf1;
    TESTCHECK( (vf3 == vf0), true, &ok );
    TESTCHECK( vf3.X(), 0.f, &ok );
    TESTCHECK( vf3.Y(), 0.f, &ok );
    TESTCHECK( vf3.Z(), 0.f, &ok );
    TESTCHECK( vf3.W(), 0.f, &ok );
    cout << "-= vf1" << endl;
    vf3 -= vf1;
    TESTCHECK( (vf3 == -vf1), true, &ok );
    TESTCHECK( vf3.X(), -xf, &ok );
    TESTCHECK( vf3.Y(), -yf, &ok );
    TESTCHECK( vf3.Z(), -zf, &ok );
    TESTCHECK( vf3.W(), -wf, &ok );
    cout << "vf1 + vf3" << endl;
    vf2 = vf1 + vf3;
    TESTCHECK( (vf2 == vf0), true, &ok );
    TESTCHECK( vf2.X(), 0.f, &ok );
    TESTCHECK( vf2.Y(), 0.f, &ok );
    TESTCHECK( vf2.Z(), 0.f, &ok );
    TESTCHECK( vf2.W(), 0.f, &ok );
    cout << "vf2 - vf1" << endl;
    vf2 = vf2 - vf1;
    TESTCHECK( (vf2 == vf3), true, &ok );
    TESTCHECK( vf2.X(), -xf, &ok );
    TESTCHECK( vf2.Y(), -yf, &ok );
    TESTCHECK( vf2.Z(), -zf, &ok );
    TESTCHECK( vf2.W(), -wf, &ok );
    float af = -1;
    cout << "*= " << af << endl;
    vf2 *= af;
    TESTCHECK( (vf2 == vf1), true, &ok );
    TESTCHECK( vf2.X(), xf, &ok );
    TESTCHECK( vf2.Y(), yf, &ok );
    TESTCHECK( vf2.Z(), zf, &ok );
    TESTCHECK( vf2.W(), wf, &ok );
    af = 8.f;
    cout << "*= " << af << endl;
    vf2 *= af;
    TESTCHECK( (vf2 == vf1), false, &ok );
    TESTCHECK( vf2.X(), -88.f, &ok );
    TESTCHECK( vf2.Y(), 32.f, &ok );
    TESTCHECK( vf2.Z(), 56.f, &ok );
    TESTCHECK( vf2.W(), 800.f, &ok );
    af = -2.f;
    cout << "vf2 * " << af << endl;
    vf2 = vf2 * af;
    TESTCHECK( vf2.X(), 176.f, &ok );
    TESTCHECK( vf2.Y(), -64.f, &ok );
    TESTCHECK( vf2.Z(), -112.f, &ok );
    TESTCHECK( vf2.W(), -1600.f, &ok );
    af = - 1.f/16.f;
    cout << af << "* vf2" << endl;
    vf2 = af * vf2;
    TESTCHECK( vf2.X(), xf, &ok );
    TESTCHECK( vf2.Y(), yf, &ok );
    TESTCHECK( vf2.Z(), zf, &ok );
    TESTCHECK( vf2.W(), wf, &ok );
    TESTCHECK( vf0 * vf1, 0.f, &ok );
    TESTCHECK( vf1 * vf1, 10186.f, &ok );
    TESTCHECK( vf2 * vf3, -10186.f, &ok );
    xf = 23.f;
    yf = -47.f;
    zf = 2.f;
    cout << "Vector3F( " << xf << ", " << yf << ", " << zf << " )" << endl;
    Vector3F v3f1( xf, yf, zf );
    cout << "Vector4F( v3f1 ) [Vector3 constructor]" << endl;
    Vector4F vf4( v3f1 );
    TESTCHECK( vf4.X(), xf, &ok );
    TESTCHECK( vf4.Y(), yf, &ok );
    TESTCHECK( vf4.Z(), zf, &ok );
    TESTCHECK( vf4.W(), 0.f, &ok );
    xf = -11.f;
    yf = 22.f;
    zf = -3.f;
    cout << "Point3F( " << xf << ", " << yf << ", " << zf << " )" << endl;
    Point3F p3f( xf, yf, zf );
    cout << "Set( p3f )" << endl;
    vf4.Set( p3f );
    TESTCHECK( vf4.X(), xf, &ok );
    TESTCHECK( vf4.Y(), yf, &ok );
    TESTCHECK( vf4.Z(), zf, &ok );
    TESTCHECK( vf4.W(), 1.f, &ok );
    xf = 37.f;
    yf = -17.f;
    zf = -3.f;
    wf = 13.f;
    cout << "Set( " << xf << ", " << yf << ", " << zf << ", " << wf << " ) :"
         << endl;
    vf4.Set( xf, yf, zf, wf );
    TESTCHECK( vf4.X(), xf, &ok );
    TESTCHECK( vf4.Y(), yf, &ok );
    TESTCHECK( vf4.Z(), zf, &ok );
    TESTCHECK( vf4.W(), wf, &ok );
    ostringstream ost;
    cout << "operator<<" << endl;
    ost << vf4;
    TESTCHECK( ost.str(), string( "[ 37, -17, -3, 13 ]" ), &ok );
    cout << "Set( p3f )" << endl;
    vf4.Set( p3f );
    TESTCHECK( vf4.X(), p3f[0], &ok );
    TESTCHECK( vf4.Y(), p3f[1], &ok );
    TESTCHECK( vf4.Z(), p3f[2], &ok );
    TESTCHECK( vf4.W(), 1.f, &ok );
    cout << "Homogenize( )" << endl;
    vf1.Homogenize( );
    TESTCHECKF( vf1.X(), -0.11f, &ok );
    TESTCHECKF( vf1.Y(), 0.04f, &ok );
    TESTCHECKF( vf1.Z(), 0.07f, &ok );
    TESTCHECK( vf1.W(), 1.f, &ok );
    cout << "Project3( )" << endl;
    v3f1 = vf1.Project3( );
    TESTCHECKF( v3f1.X(), -0.11f, &ok );
    TESTCHECKF( v3f1.Y(), 0.04f, &ok );
    TESTCHECKF( v3f1.Z(), 0.07f, &ok );

    cout << "Vector4<long> vl1( -352, 128, 224, 1000000 )" << endl;
    Vector4<long> vl1( -352, 128, 224, 1000000 );
    cout << "Vector4F( vl1 )" << endl;
    Vector4F vf5( vl1 );
    TESTCHECK( vf5.X(), -352.f, &ok );
    TESTCHECK( vf5.Y(), 128.f, &ok );
    TESTCHECK( vf5.Z(), 224.f, &ok );
    TESTCHECK( vf5.W(), 1000000.f, &ok );

    xf = 7.7f;
    yf = -5.2;
    zf = -3.6f;
    wf = 10.0f;
    cout << "Vector4F( " << xf << ", " << yf << ", " << zf << ", " << wf
         << " )" << endl;
    Vector4F vf6( xf, yf, zf, wf );
    TESTCHECK( vf6.X(), xf, &ok );
    TESTCHECK( vf6.Y(), yf, &ok );
    TESTCHECK( vf6.Z(), zf, &ok );
    TESTCHECK( vf6.W(), wf, &ok );
    cout << "Vector3<long>( vf6 )" << endl;
    Vector4<long> vl2( vf6 );
    TESTCHECK( vl2.X(), 7L, &ok );
    TESTCHECK( vl2.Y(), -5L, &ok );
    TESTCHECK( vl2.Z(), -3L, &ok );
    TESTCHECK( vl2.W(), 10L, &ok );
    cout << "Round()" << endl;
    Vector4F vf7 = Round( vf6 );
    TESTCHECK( vf7.X(), 8.f, &ok );
    TESTCHECK( vf7.Y(), -5.f, &ok );
    TESTCHECK( vf7.Z(), -4.f, &ok );
    TESTCHECK( vf7.W(), 10.f, &ok );
    cout << "Vector4<short>( vf7 )" << endl;
    Vector4<long> vl3( vf7 );
    TESTCHECK( vl3.X(), 8L, &ok );
    TESTCHECK( vl3.Y(), -5L, &ok );
    TESTCHECK( vl3.Z(), -4L, &ok );
    TESTCHECK( vl3.W(), 10L, &ok );

    TESTCHECK( Vector4F::UnitX.X(), 1.f, &ok );
    TESTCHECK( Vector4F::UnitX.Y(), 0.f, &ok );
    TESTCHECK( Vector4F::UnitX.Z(), 0.f, &ok );
    TESTCHECK( Vector4F::UnitX.W(), 0.f, &ok );
    TESTCHECK( Vector4F::UnitY.X(), 0.f, &ok );
    TESTCHECK( Vector4F::UnitY.Y(), 1.f, &ok );
    TESTCHECK( Vector4F::UnitY.Z(), 0.f, &ok );
    TESTCHECK( Vector4F::UnitY.W(), 0.f, &ok );
    TESTCHECK( Vector4F::UnitZ.X(), 0.f, &ok );
    TESTCHECK( Vector4F::UnitZ.Y(), 0.f, &ok );
    TESTCHECK( Vector4F::UnitZ.Z(), 1.f, &ok );
    TESTCHECK( Vector4F::UnitZ.W(), 0.f, &ok );
    TESTCHECK( Vector4F::UnitW.X(), 0.f, &ok );
    TESTCHECK( Vector4F::UnitW.Y(), 0.f, &ok );
    TESTCHECK( Vector4F::UnitW.Z(), 0.f, &ok );
    TESTCHECK( Vector4F::UnitW.W(), 1.f, &ok );

    if ( ok )
        cout << "Vector4 PASSED." << endl << endl;
    else
        cout << "Vector4 FAILED." << endl << endl;
    return ok;
}