Changeset 14709


Ignore:
Timestamp:
12/01/12 18:59:31 (12 years ago)
Author:
tbretz
Message:
added dist function to Sky class
Location:
trunk/FACT++/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/InterpreterV8.cc

    r14695 r14709  
    12501250}
    12511251
    1252 Handle<Value> InterpreterV8::LocalDist(const Arguments &args)
     1252Handle<Value> InterpreterV8::CalcDist(const Arguments &args, const bool local)
    12531253{
    12541254    if (args.Length()!=2)
     
    12661266    };
    12671267
    1268     const Handle<String> s_zd = String::New("zd");
    1269     const Handle<String> s_az = String::New("az");
    1270 
    1271     const double zd0 = obj[0]->Get(s_zd)->NumberValue() * M_PI/180;
    1272     const double az0 = obj[0]->Get(s_az)->NumberValue() * M_PI/180;
    1273     const double zd1 = obj[1]->Get(s_zd)->NumberValue() * M_PI/180;
    1274     const double az1 = obj[1]->Get(s_az)->NumberValue() * M_PI/180;
    1275 
    1276     if (!finite(zd0) || !finite(zd1) || !finite(az0) || !finite(az1))
     1268    const Handle<String> s_theta = String::New(local?"zd":"dec"); // was: zd
     1269    const Handle<String> s_phi   = String::New(local?"az":"ra");  // was: az
     1270
     1271    const double conv_t = M_PI/180;
     1272    const double conv_p = local ? -M_PI/180 : M_PI/12;
     1273    const double offset = local ? 0 : M_PI;
     1274
     1275    const double theta0 = offset - obj[0]->Get(s_theta)->NumberValue() * conv_t;
     1276    const double phi0   =          obj[0]->Get(s_phi  )->NumberValue() * conv_p;
     1277    const double theta1 = offset - obj[1]->Get(s_theta)->NumberValue() * conv_t;
     1278    const double phi1   =          obj[1]->Get(s_phi  )->NumberValue() * conv_p;
     1279
     1280    if (!finite(theta0) || !finite(theta1) || !finite(phi0) || !finite(phi1))
    12771281        return ThrowException(String::New("some values not valid or not finite."));
    12781282
     
    12911295    // cos(az1-az0) = cos(az1)*cos(az0) + sin(az1)*sin(az0)
    12921296
    1293     const double x = sin(zd0) * sin(zd1) * cos(az1-az0);
    1294     const double y = cos(zd0) * cos(zd1);
     1297    const double x = sin(theta0) * sin(theta1) * cos(phi1-phi0);
     1298    const double y = cos(theta0) * cos(theta1);
    12951299
    12961300    const double res = acos(x + y) * 180/M_PI;
    12971301
    12981302    return handle_scope.Close(Number::New(res));
     1303}
     1304
     1305Handle<Value> InterpreterV8::LocalDist(const Arguments &args)
     1306{
     1307    return CalcDist(args, true);
     1308}
     1309
     1310Handle<Value> InterpreterV8::SkyDist(const Arguments &args)
     1311{
     1312    return CalcDist(args, false);
    12991313}
    13001314
     
    19701984    Handle<FunctionTemplate> sky = FunctionTemplate::New(ConstructorSky);
    19711985    sky->SetClassName(String::New("Sky"));
     1986    sky->Set(String::New("dist"),  FunctionTemplate::New(SkyDist), ReadOnly);
    19721987    global->Set(String::New("Sky"), sky, ReadOnly);
    19731988
  • trunk/FACT++/src/InterpreterV8.h

    r14690 r14709  
    9292    static double GetDataMember(const v8::Arguments &args, const char *name);
    9393
     94    static v8::Handle<v8::Value> CalcDist(const v8::Arguments &args, const bool);
     95
    9496    static v8::Handle<v8::Value> LocalToString(const v8::Arguments &args);
    9597    static v8::Handle<v8::Value> SkyToString(const v8::Arguments &args);
    9698    static v8::Handle<v8::Value> MoonToString(const v8::Arguments &args);
    9799    static v8::Handle<v8::Value> LocalDist(const v8::Arguments &args);
     100    static v8::Handle<v8::Value> SkyDist(const v8::Arguments &args);
    98101    static v8::Handle<v8::Value> MoonDisk(const v8::Arguments &args);
    99102    static v8::Handle<v8::Value> LocalToSky(const v8::Arguments &args);
Note: See TracChangeset for help on using the changeset viewer.