Skip to content

Commit

Permalink
fix double_array_converter
Browse files Browse the repository at this point in the history
  • Loading branch information
timotejroiko committed Jul 19, 2021
1 parent d17ccca commit 9ac36f0
Show file tree
Hide file tree
Showing 20 changed files with 27 additions and 31 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,3 @@ deps/swisseph.vcxproj
deps/swisseph.vcxproj.filters
src/functions.cpp
package-lock.json
test.ts
thread.js
2 changes: 0 additions & 2 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,3 @@ src/functions.cpp
.gitattributes
.gitignore
package-lock.json
test.ts
thread.js
4 changes: 2 additions & 2 deletions src/functions/azalt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ Napi::Value sweph_azalt(const Napi::CallbackInfo& info) {
return env.Null();
}
double geopos [3];
if(!sweph_double_array_converter(geopos, info[2])) {
if(!sweph_double_array_converter(geopos, 3, info[2])) {
Napi::TypeError::New(env, args[3].second).ThrowAsJavaScriptException();
return env.Null();
}
double xin [3];
if(!sweph_double_array_converter(xin, info[5])) {
if(!sweph_double_array_converter(xin, 3, info[5])) {
Napi::TypeError::New(env, args[6].second).ThrowAsJavaScriptException();
return env.Null();
}
Expand Down
4 changes: 2 additions & 2 deletions src/functions/azalt_rev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ Napi::Value sweph_azalt_rev(const Napi::CallbackInfo& info) {
return env.Null();
}
double geopos [3];
if(!sweph_double_array_converter(geopos, info[2])) {
if(!sweph_double_array_converter(geopos, 3, info[2])) {
Napi::TypeError::New(env, args[3].second).ThrowAsJavaScriptException();
return env.Null();
}
double xin [2];
if(!sweph_double_array_converter(xin, info[3])) {
if(!sweph_double_array_converter(xin, 2, info[3])) {
Napi::TypeError::New(env, args[4].second).ThrowAsJavaScriptException();
return env.Null();
}
Expand Down
2 changes: 1 addition & 1 deletion src/functions/cotrans.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Napi::Value sweph_cotrans(const Napi::CallbackInfo& info) {
return env.Null();
}
double in [3];
if(!sweph_double_array_converter(in, info[0])) {
if(!sweph_double_array_converter(in, 3, info[0])) {
Napi::TypeError::New(env, args[1].second).ThrowAsJavaScriptException();
return env.Null();
}
Expand Down
2 changes: 1 addition & 1 deletion src/functions/cotrans_sp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Napi::Value sweph_cotrans_sp(const Napi::CallbackInfo& info) {
return env.Null();
}
double in [6];
if(!sweph_double_array_converter(in, info[0])) {
if(!sweph_double_array_converter(in, 6, info[0])) {
Napi::TypeError::New(env, args[1].second).ThrowAsJavaScriptException();
return env.Null();
}
Expand Down
2 changes: 1 addition & 1 deletion src/functions/gauquelin_sector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Napi::Value sweph_gauquelin_sector(const Napi::CallbackInfo& info) {
return env.Null();
}
double geopos [3];
if(!sweph_double_array_converter(geopos, info[5])) {
if(!sweph_double_array_converter(geopos, 3, info[5])) {
Napi::TypeError::New(env, args[6].second).ThrowAsJavaScriptException();
return env.Null();
}
Expand Down
6 changes: 3 additions & 3 deletions src/functions/heliacal_pheno_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ Napi::Value sweph_heliacal_pheno_ut(const Napi::CallbackInfo& info) {
return env.Null();
}
double dgeo [3];
if(!sweph_double_array_converter(dgeo, info[1])) {
if(!sweph_double_array_converter(dgeo, 3, info[1])) {
Napi::TypeError::New(env, args[2].second).ThrowAsJavaScriptException();
return env.Null();
}
double datm [4];
if(!sweph_double_array_converter(datm, info[2])) {
if(!sweph_double_array_converter(datm, 4, info[2])) {
Napi::TypeError::New(env, args[3].second).ThrowAsJavaScriptException();
return env.Null();
}
double dobs [6];
if(!sweph_double_array_converter(dobs, info[3])) {
if(!sweph_double_array_converter(dobs, 6, info[3])) {
Napi::TypeError::New(env, args[4].second).ThrowAsJavaScriptException();
return env.Null();
}
Expand Down
6 changes: 3 additions & 3 deletions src/functions/heliacal_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ Napi::Value sweph_heliacal_ut(const Napi::CallbackInfo& info) {
return env.Null();
}
double dgeo [3];
if(!sweph_double_array_converter(dgeo, info[1])) {
if(!sweph_double_array_converter(dgeo, 3, info[1])) {
Napi::TypeError::New(env, args[2].second).ThrowAsJavaScriptException();
return env.Null();
}
double datm [4];
if(!sweph_double_array_converter(datm, info[2])) {
if(!sweph_double_array_converter(datm, 4, info[2])) {
Napi::TypeError::New(env, args[3].second).ThrowAsJavaScriptException();
return env.Null();
}
double dobs [6];
if(!sweph_double_array_converter(dobs, info[3])) {
if(!sweph_double_array_converter(dobs, 6, info[3])) {
Napi::TypeError::New(env, args[4].second).ThrowAsJavaScriptException();
return env.Null();
}
Expand Down
2 changes: 1 addition & 1 deletion src/functions/house_pos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Napi::Value sweph_house_pos(const Napi::CallbackInfo& info) {
return env.Null();
}
double planet [2];
if(!sweph_double_array_converter(planet, info[4])) {
if(!sweph_double_array_converter(planet, 2, info[4])) {
Napi::TypeError::New(env, args[5].second).ThrowAsJavaScriptException();
return env.Null();
}
Expand Down
2 changes: 1 addition & 1 deletion src/functions/lun_eclipse_how.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Napi::Value sweph_lun_eclipse_how(const Napi::CallbackInfo& info) {
return env.Null();
}
double geopos [3];
if(!sweph_double_array_converter(geopos, info[2])) {
if(!sweph_double_array_converter(geopos, 3, info[2])) {
Napi::TypeError::New(env, args[3].second).ThrowAsJavaScriptException();
return env.Null();
}
Expand Down
2 changes: 1 addition & 1 deletion src/functions/lun_eclipse_when_loc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Napi::Value sweph_lun_eclipse_when_loc(const Napi::CallbackInfo& info) {
return env.Null();
}
double geopos [3];
if(!sweph_double_array_converter(geopos, info[2])) {
if(!sweph_double_array_converter(geopos, 3, info[2])) {
Napi::TypeError::New(env, args[3].second).ThrowAsJavaScriptException();
return env.Null();
}
Expand Down
2 changes: 1 addition & 1 deletion src/functions/lun_occult_when_loc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Napi::Value sweph_lun_occult_when_loc(const Napi::CallbackInfo& info) {
return env.Null();
}
double geopos [3];
if(!sweph_double_array_converter(geopos, info[0])) {
if(!sweph_double_array_converter(geopos, 3, info[0])) {
Napi::TypeError::New(env, args[1].second).ThrowAsJavaScriptException();
return env.Null();
}
Expand Down
2 changes: 1 addition & 1 deletion src/functions/rise_trans.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Napi::Value sweph_rise_trans(const Napi::CallbackInfo& info) {
return env.Null();
}
double geopos [3];
if(!sweph_double_array_converter(geopos, info[5])) {
if(!sweph_double_array_converter(geopos, 3, info[5])) {
Napi::TypeError::New(env, args[6].second).ThrowAsJavaScriptException();
return env.Null();
}
Expand Down
2 changes: 1 addition & 1 deletion src/functions/rise_trans_true_hor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Napi::Value sweph_rise_trans_true_hor(const Napi::CallbackInfo& info) {
return env.Null();
}
double geopos [3];
if(!sweph_double_array_converter(geopos, info[5])) {
if(!sweph_double_array_converter(geopos, 3, info[5])) {
Napi::TypeError::New(env, args[6].second).ThrowAsJavaScriptException();
return env.Null();
}
Expand Down
2 changes: 1 addition & 1 deletion src/functions/sol_eclipse_how.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Napi::Value sweph_sol_eclipse_how(const Napi::CallbackInfo& info) {
return env.Null();
}
double geopos [3];
if(!sweph_double_array_converter(geopos, info[2])) {
if(!sweph_double_array_converter(geopos, 3, info[2])) {
Napi::TypeError::New(env, args[3].second).ThrowAsJavaScriptException();
return env.Null();
}
Expand Down
2 changes: 1 addition & 1 deletion src/functions/sol_eclipse_when_loc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Napi::Value sweph_sol_eclipse_when_loc(const Napi::CallbackInfo& info) {
return env.Null();
}
double geopos [3];
if(!sweph_double_array_converter(geopos, info[2])) {
if(!sweph_double_array_converter(geopos, 3, info[2])) {
Napi::TypeError::New(env, args[3].second).ThrowAsJavaScriptException();
return env.Null();
}
Expand Down
6 changes: 3 additions & 3 deletions src/functions/vis_limit_mag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ Napi::Value sweph_vis_limit_mag(const Napi::CallbackInfo& info) {
return env.Null();
}
double dgeo [3];
if(!sweph_double_array_converter(dgeo, info[1])) {
if(!sweph_double_array_converter(dgeo, 3, info[1])) {
Napi::TypeError::New(env, args[2].second).ThrowAsJavaScriptException();
return env.Null();
}
double datm [4];
if(!sweph_double_array_converter(datm, info[2])) {
if(!sweph_double_array_converter(datm, 4, info[2])) {
Napi::TypeError::New(env, args[3].second).ThrowAsJavaScriptException();
return env.Null();
}
double dobs [6];
if(!sweph_double_array_converter(dobs, info[3])) {
if(!sweph_double_array_converter(dobs, 6, info[3])) {
Napi::TypeError::New(env, args[4].second).ThrowAsJavaScriptException();
return env.Null();
}
Expand Down
4 changes: 2 additions & 2 deletions src/sweph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ bool sweph_type_check(const std::pair<int, const char*> types[], const Napi::Cal
return true;
}

bool sweph_double_array_converter(double *target, Napi::Value data) {
bool sweph_double_array_converter(double *target, int size, Napi::Value data) {
Napi::Array x = data.As<Napi::Array>();
for(int i = 0; i < sizeof(target) / sizeof(target[0]); i++) {
for(int i = 0; i < size; i++) {
Napi::Value v = x[i];
if(!v.IsNumber()) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/sweph.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Napi::Value sweph_cs2degstr(const Napi::CallbackInfo& info);

bool sweph_is_type(int type, Napi::Value data);
bool sweph_type_check(const std::pair<int, const char*> types[], const Napi::CallbackInfo& info);
bool sweph_double_array_converter(double *target, Napi::Value data);
bool sweph_double_array_converter(double *target, int size, Napi::Value data);
Napi::Array sweph_js_array_converter(double *src, int size, Napi::Env env);

enum TYPES {
Expand Down

0 comments on commit 9ac36f0

Please sign in to comment.