示例#1
0
void 
FromJSON( const std::string & json, Spherical * pSpherical )
{
    JSONObject jsonObj;
    FromJSON( json, &jsonObj );
    Angle longitude, latitude;
    double distance;
    FromJSON( jsonObj[ "longitude" ], &longitude );
    FromJSON( jsonObj[ "latitude" ], &latitude );
    FromJSON( jsonObj[ "distance" ], &distance );
    pSpherical->Set( longitude, latitude, distance );
}
示例#2
0
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;
   }
}
示例#3
0
void 
FromJSON( const std::string & json, AngleDMS * pAngle )
{
    JSONObject jsonObj;
    FromJSON( json, &jsonObj );
    bool pos;
    int d, m;
    double s;
    FromJSON( jsonObj[ "positive" ], &pos );
    FromJSON( jsonObj[ "degrees" ], &d );
    FromJSON( jsonObj[ "minutes" ], &m );
    FromJSON( jsonObj[ "seconds" ], &s );
    if ( ! pos )
        d = -d;
    pAngle->Set( d, m, s );
}
wxCrafterCBSettings& wxCrafterCBSettings::Load()
{
    wxFileName fnConfig(wxStandardPaths::Get().GetUserConfigDir(), wxT(".wxCrafterCB.conf"));
    JSONRoot root( fnConfig );
    FromJSON( root.toElement() );
    return *this;
}
示例#5
0
LLDBSettings& LLDBSettings::Load()
{
    wxFileName fn( clStandardPaths::Get().GetUserDataDir(), "lldb.conf");
    fn.AppendDir("config");
     wxFFile fp(fn.GetFullPath(), "rb");
    if ( fp.IsOpened() ) {
        wxString content;
        fp.ReadAll( &content, wxConvUTF8 );
        
        JSONRoot root(content);
        FromJSON( root.toElement() );
        fp.Close();
    }
    return *this;
}
示例#6
0
bool ValueTraits<ShapeValue>::FromJSON(const skjson::Value& jv,
                                       const internal::AnimationBuilder* abuilder,
                                       ShapeValue* v) {
    SkASSERT(v->fVertices.empty());

    // Some versions wrap values as single-element arrays.
    if (const skjson::ArrayValue* av = jv) {
        if (av->size() == 1) {
            return FromJSON((*av)[0], abuilder, v);
        }
    }

    if (!jv.is<skjson::ObjectValue>())
        return false;
    const auto& ov = jv.as<skjson::ObjectValue>();

    std::vector<SkPoint> verts,  // Cubic Bezier vertices.
                         inPts,  // Cubic Bezier "in" control points, relative to vertices.
                         outPts; // Cubic Bezier "out" control points, relative to vertices.

    if (!ParsePointVec(ov["v"], &verts)) {
        // Vertices are required.
        return false;
    }

    // In/out points are optional.
    ParsePointVec(ov["i"], &inPts);
    if (!inPts.empty() && inPts.size() != verts.size()) {
        return false;
    }
    inPts.resize(verts.size(), { 0, 0 });

    ParsePointVec(ov["o"], &outPts);
    if (!outPts.empty() && outPts.size() != verts.size()) {
        return false;
    }
    outPts.resize(verts.size(), { 0, 0 });

    v->fVertices.reserve(inPts.size());
    for (size_t i = 0; i < inPts.size(); ++i) {
        v->fVertices.push_back(BezierVertex({inPts[i], outPts[i], verts[i]}));
    }
    v->fClosed = ParseDefault<bool>(ov["c"], false);

    return true;
}
示例#7
0
	/* Private */
	void SpellData::ParseSpellList(std::string &response, TSpellDataList &items)
	{
		Poco::JSON::Parser parser;

		auto parsed = parser.parse(response);
		if (parsed.isArray()) {
			auto spellObjects = parsed.extract<JSONArray::Ptr>();

			for (int i = 0; i < spellObjects->size(); i++) {
				JSONObject *object = spellObjects->getObject(i);
				auto data = std::make_shared<SpellData>();
				data->FromJSON(object);

				items.push_back(data);
			}
		}
	}
示例#8
0
	void SpellData::GetSpellById(const UUID &id, std::function<void(SpellDataPtr)> success, APIFailureCallback failure)
	{
		APIRequestManager *manager = APIRequestManager::GetDefaultManager();
		std::stringstream url;
		url << "/spell/" << id.toString();

		manager->Send(url.str(), "GET", "", [success](std::istream &stream) {
			Poco::JSON::Parser parser;

			auto object = parser.parse(stream).extract<JSONObject::Ptr>();
			auto data = std::make_shared<SpellData>();
			data->FromJSON(object);

			success(data);

		}, [failure](const std::string &error)  {
			failure(error);
		});
	}
示例#9
0
	void SpellData::Save(SpellDataSingleCallback success, APIFailureCallback failure)
	{
		APIRequestManager *manager = APIRequestManager::GetDefaultManager();
		std::stringstream url;
		url << "/spell/" << this->GetId().toString();

		std::string body = this->ToJSONString();

		manager->Send(url.str(), "POST", body, [success](std::istream &stream) {
			Poco::JSON::Parser parser;

			auto object = parser.parse(stream).extract<JSONObject::Ptr>();
			auto data = std::make_shared<SpellData>();
			data->FromJSON(object);

			success(data);
		}, [failure](const std::string &error)  {
			failure(error);
		});
	}
void 
FromJSON( const std::string & json, RotationMatrix2<T> * pMat )
{
    FromJSON( json, &(pMat->m_matrix) );
}
示例#11
0
// todo(@m) Factor out to geojson.hpp? Add geojson to myjansson?
bool Hierarchy::Entry::DeserializeFromJSONImpl(json_t * const root, string const & jsonStr,
                                               ParsingStats & stats)
{
  if (!json_is_object(root))
  {
    ++stats.m_badJsons;
    MYTHROW(base::Json::Exception, ("Not a json object."));
  }

  json_t * properties = nullptr;
  FromJSONObject(root, "properties", properties);
  json_t * address = nullptr;
  FromJSONObject(properties, "address", address);

  bool hasDuplicateAddress = false;

  for (size_t i = 0; i < static_cast<size_t>(Type::Count); ++i)
  {
    Type const type = static_cast<Type>(i);
    string const & levelKey = ToString(type);
    json_t * levelJson = nullptr;
    FromJSONObjectOptionalField(address, levelKey, levelJson);
    if (!levelJson)
      continue;

    if (base::JSONIsNull(levelJson))
      return false;

    string levelValue;
    FromJSON(levelJson, levelValue);
    if (levelValue.empty())
      continue;

    if (!m_address[i].empty())
    {
      LOG(LDEBUG, ("Duplicate address field", type, "when parsing", jsonStr));
      hasDuplicateAddress = true;
    }

    search::NormalizeAndTokenizeAsUtf8(levelValue, m_address[i]);

    if (!m_address[i].empty())
      m_type = static_cast<Type>(i);
  }

  auto const & subregion = m_address[static_cast<size_t>(Type::Subregion)];
  auto const & locality = m_address[static_cast<size_t>(Type::Locality)];
  if (m_type == Type::Street && locality.empty() && subregion.empty() /* if locality detection fail */)
  {
    ++stats.m_noLocalityStreets;
    return false;
  }
  if (m_type == Type::Building && locality.empty() && subregion.empty() /* if locality detection fail */)
  {
    ++stats.m_noLocalityBuildings;
    return false;
  }

  m_nameTokens.clear();
  FromJSONObjectOptionalField(properties, "name", m_name);
  search::NormalizeAndTokenizeAsUtf8(m_name, m_nameTokens);

  if (m_name.empty())
    ++stats.m_emptyNames;

  if (hasDuplicateAddress)
    ++stats.m_duplicateAddresses;

  if (m_type == Type::Count)
  {
    LOG(LDEBUG, ("No address in an hierarchy entry:", jsonStr));
    ++stats.m_emptyAddresses;
  }
  else if (m_nameTokens != m_address[static_cast<size_t>(m_type)])
  {
    ++stats.m_mismatchedNames;
  }

  return true;
}
示例#12
0
void 
FromJSON( const std::string & json, Matrix3<T> * pMat )
{
    FromJSON( json, &(pMat->m_elements) );
}
示例#13
0
LLDBReply::LLDBReply(const wxString& str)
{
    JSONRoot root(str);
    FromJSON(root.toElement());
}
示例#14
0
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;
}
示例#15
0
void PHPProject::Load(const wxFileName& filename)
{
    m_filename = filename;
    JSONRoot root(m_filename);
    FromJSON(root.toElement());
}
示例#16
0
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;
}
示例#17
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;
}
示例#18
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;
}
示例#19
0
bool PHPWorkspace::Open(const wxString& filename, wxEvtHandler* view, bool createIfMissing)
{
    // Close the currently opened workspace
    if(IsOpen()) {
        Close(true, true);
    }

    m_workspaceFile = filename;
    wxFileName fnNewWspFile = m_workspaceFile;
    fnNewWspFile.SetExt("workspace");

    if(!fnNewWspFile.Exists()) {
        wxLogNull nolog;
        if(::wxCopyFile(m_workspaceFile.GetFullPath(), fnNewWspFile.GetFullPath())) {
            m_workspaceFile = fnNewWspFile;
        }
    }

    // Ensure that the workspace file is renamed to .workspace
    {
        // Create the private folder if needed
        wxFileName fn(m_workspaceFile);
        fn.AppendDir(".codelite");
        wxLogNull nolog;
        ::wxMkdir(fn.GetPath());
    }

    if(!m_workspaceFile.FileExists()) {
        if(createIfMissing) {
            if(!Create(filename)) {
                return false;
            }
        } else {
            m_workspaceFile.Clear();
            return false;
        }
    }

    // point the tags storage to the correct db file
    wxFileName tagsfile(filename);
    tagsfile.SetExt(wxT("phptags"));

    // set the working directory to the workspace path
    ::wxSetWorkingDirectory(m_workspaceFile.GetPath());

    JSONRoot root(m_workspaceFile);
    FromJSON(root.toElement());

    // We open the symbols database manually here and _not_ via an event
    // since the parser thread might open it first and leave us with a lock
    PHPCodeCompletion::Instance()->Open(m_workspaceFile);

    // Notify internally that the workspace is loaded
    PHPEvent phpEvent(wxEVT_PHP_WORKSPACE_LOADED);
    phpEvent.SetFileName(m_workspaceFile.GetFullPath());
    EventNotifier::Get()->AddPendingEvent(phpEvent);

    // Notify that the a new workspace is loaded
    // This time send the standard codelite event
    // this is important so other plugins such as Svn, Git
    // want to adjust their paths according to the new workspace
    {
        wxCommandEvent event(wxEVT_WORKSPACE_LOADED);
        event.SetString(GetFilename().GetFullPath());
        EventNotifier::Get()->AddPendingEvent(event);
    }

    // wxBusyInfo busy(_("Scanning for workspace files..."), EventNotifier::Get()->TopFrame());
    // wxYieldIfNeeded();
    wxBusyCursor bc;
    SyncWithFileSystemAsync(view);

    // Perform a quick re-parse of the workspace
    ParseWorkspace(false);

    // set this workspace as the active one
    clWorkspaceManager::Get().SetWorkspace(this);

    // and finally, request codelite to keep this workspace in the recently opened workspace list
    clGetManager()->AddWorkspaceToRecentlyUsedList(GetFilename());

    CallAfter(&PHPWorkspace::RestoreWorkspaceSession);
    // Change the workspace extension
    return true;
}