Revision: 70872 http://sourceforge.net/p/brlcad/code/70872 Author: d_rossberg Date: 2018-04-08 13:42:02 +0000 (Sun, 08 Apr 2018) Log Message: ----------- applied the angles_v4.patch from Sharan Narayan see https://sourceforge.net/p/brlcad/patches/481 "Implement a libbn function for supporting angle inputs in rads and degs"
Modified Paths: -------------- brlcad/trunk/include/bn/str.h brlcad/trunk/src/gtools/glint.c brlcad/trunk/src/libbn/str.c brlcad/trunk/src/libged/gqa.c brlcad/trunk/src/rt/opt.c Modified: brlcad/trunk/include/bn/str.h =================================================================== --- brlcad/trunk/include/bn/str.h 2018-04-05 21:05:06 UTC (rev 70871) +++ brlcad/trunk/include/bn/str.h 2018-04-08 13:42:02 UTC (rev 70872) @@ -48,6 +48,8 @@ * XXX don't spoil the conversion. */ +BN_EXPORT extern int bn_decode_angle(double *ang, + const char *str); BN_EXPORT extern int bn_decode_mat(mat_t m, const char *str); BN_EXPORT extern int bn_decode_quat(quat_t q, Modified: brlcad/trunk/src/gtools/glint.c =================================================================== --- brlcad/trunk/src/gtools/glint.c 2018-04-05 21:05:06 UTC (rev 70871) +++ brlcad/trunk/src/gtools/glint.c 2018-04-08 13:42:02 UTC (rev 70872) @@ -37,6 +37,7 @@ #include "vmath.h" #include "raytrace.h" #include "bn/plot3.h" +#include "bn/str.h" #define made_it() bu_log("Made it to %s:%d\n", __FILE__, __LINE__); @@ -802,7 +803,7 @@ while ((ch = bu_getopt(argc, argv, OPT_STRING)) != -1) switch (ch) { case 'a': - if (sscanf(bu_optarg, "%lf", &azimuth) != 1) { + if (bn_decode_angle(&azimuth,bu_optarg) == 0) { bu_log("Invalid azimuth specification: '%s'\n", bu_optarg); printusage(); bu_exit (1, NULL); @@ -812,7 +813,7 @@ cell_center = 1; break; case 'e': - if (sscanf(bu_optarg, "%lf", &elevation) != 1) { + if (bn_decode_angle(&elevation,bu_optarg) == 0) { bu_log("Invalid elevation specification: '%s'\n", bu_optarg); printusage(); bu_exit (1, NULL); Modified: brlcad/trunk/src/libbn/str.c =================================================================== --- brlcad/trunk/src/libbn/str.c 2018-04-05 21:05:06 UTC (rev 70871) +++ brlcad/trunk/src/libbn/str.c 2018-04-08 13:42:02 UTC (rev 70872) @@ -42,7 +42,31 @@ extern double rint(double x); #endif + int +bn_decode_angle(double *ang, const char *str) +{ + char unit[5]; + double val; + int ret; + + ret = sscanf(str,"%lf%4s",&val,unit); + if (ret == 1) { + *ang = val; + } else if (ret == 2) { + if (BU_STR_EQUAL(unit,"rad")) { + *ang = (val * RAD2DEG); + } else if (BU_STR_EQUAL(unit,"deg")){ + *ang = val; + } else { + ret = 0; + } + } + return ret; +} + + +int bn_decode_mat(fastf_t *mat, const char *str) { double m[16]; Modified: brlcad/trunk/src/libged/gqa.c =================================================================== --- brlcad/trunk/src/libged/gqa.c 2018-04-05 21:05:06 UTC (rev 70871) +++ brlcad/trunk/src/libged/gqa.c 2018-04-08 13:42:02 UTC (rev 70872) @@ -554,7 +554,7 @@ } case 'a': bu_vls_printf(_ged_current_gedp->ged_result_str, "azimuth not implemented\n"); - if (sscanf(bu_optarg, "%lg", &azimuth_deg) != 1) { + if (bn_decode_angle(&azimuth_deg,bu_optarg) == 0) { bu_vls_printf(_ged_current_gedp->ged_result_str, "error parsing azimuth \"%s\"\n", bu_optarg); return -1; } @@ -561,7 +561,7 @@ break; case 'e': bu_vls_printf(_ged_current_gedp->ged_result_str, "elevation not implemented\n"); - if (sscanf(bu_optarg, "%lg", &elevation_deg) != 1) { + if (bn_decode_angle(&elevation_deg,bu_optarg) == 0) { bu_vls_printf(_ged_current_gedp->ged_result_str, "error parsing elevation \"%s\"\n", bu_optarg); return -1; } Modified: brlcad/trunk/src/rt/opt.c =================================================================== --- brlcad/trunk/src/rt/opt.c 2018-04-05 21:05:06 UTC (rev 70871) +++ brlcad/trunk/src/rt/opt.c 2018-04-08 13:42:02 UTC (rev 70872) @@ -35,6 +35,7 @@ #include "bu/getopt.h" #include "bu/parallel.h" #include "bu/units.h" +#include "bn/str.h" #include "vmath.h" #include "raytrace.h" #include "fb.h" @@ -398,12 +399,16 @@ case 'a': /* Set azimuth */ - azimuth = atof(bu_optarg); + if (bn_decode_angle(&azimuth,bu_optarg) == 0) { + fprintf(stderr, "WARNING: Unexpected units for azimuth angle, using default value\n"); + } matflag = 0; break; case 'e': /* Set elevation */ - elevation = atof(bu_optarg); + if (bn_decode_angle(&elevation,bu_optarg) == 0) { + fprintf(stderr, "WARNING: Unexpected units for elevation angle, using default value\n"); + } matflag = 0; break; case 'l': This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ BRL-CAD Source Commits mailing list brlcad-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/brlcad-commits