From b5fd8cd1d9f364217d8b5cfa8e97f05e4d6990c4 Mon Sep 17 00:00:00 2001 From: John Halley Gotway Date: Thu, 11 Jan 2024 13:59:51 -0700 Subject: [PATCH] Per #2486, update vx_math affine.h/.cc and vx_vector.h/.cc based on Randy's versions in jethro:/d1/bullock/codetree/randy/basic/vx_math. Also replace cerr with calls to mlog << Error and add fix std::ostream. --- src/basic/vx_math/affine.cc | 78 +++++++++++++++++++++++++--------- src/basic/vx_math/affine.h | 22 +++------- src/basic/vx_math/vx_vector.cc | 32 +++++++------- src/basic/vx_math/vx_vector.h | 5 --- 4 files changed, 81 insertions(+), 56 deletions(-) diff --git a/src/basic/vx_math/affine.cc b/src/basic/vx_math/affine.cc index 69a17c98ee..e53b16f7b9 100644 --- a/src/basic/vx_math/affine.cc +++ b/src/basic/vx_math/affine.cc @@ -236,7 +236,8 @@ calc_det(); if ( fabs(Det) < 1.0e-7 ) { - cerr << "\n\n Affine::set_mb() -> determinant nearly zero!\n\n"; + mlog << Error << "\nAffine::set_mb() -> " + << "determinant nearly zero!\n\n"; exit ( 1 ); @@ -264,6 +265,21 @@ return; //////////////////////////////////////////////////////////////////////// +void Affine::set_b(double _b1, double _b2) + +{ + +TX = _b1; +TY = _b2; + +return; + +} + + +//////////////////////////////////////////////////////////////////////// + + bool Affine::is_conformal() const { @@ -545,7 +561,8 @@ D = x1_from*(y2_from - y3_from) if ( D == 0.0 ) { - cerr << "\n\n Affine::set_three_points_v1() -> collinear (u, v) points!\n\n"; + mlog << Error << "\nAffine::set_three_points_v1() -> " + << "collinear (u, v) points!\n\n"; exit ( 1 ); @@ -580,7 +597,8 @@ calc_det(); if ( fabs(Det) < 1.0e-7 ) { - cerr << "\n\n Affine::set_three_points_v1() -> (x, y) points nearly collinear!\n\n"; + mlog << Error << "\nAffine::set_three_points_v1() -> " + << "(x, y) points nearly collinear!\n\n"; exit ( 1 ); @@ -814,7 +832,8 @@ calc_det(); if ( fabs(Det) < 1.0e-7 ) { - cerr << "\n\n DiagonalAffine::set_mb() -> determinant nearly zero!\n\n"; + mlog << Error << "\nDiagonalAffine::set_mb() -> " + << "determinant nearly zero!\n\n"; exit ( 1 ); @@ -1152,7 +1171,8 @@ calc_det(); if ( fabs(Det) < 1.0e-7 ) { - cerr << "\n\n DiagonalAffine::set_two_points() -> (x, y) points nearly collinear!\n\n"; + mlog << Error << "\nDiagonalAffine::set_two_points() -> " + << "(x, y) points nearly collinear!\n\n"; exit ( 1 ); @@ -1422,7 +1442,8 @@ void ConformalAffine::set_scale(double s) if ( s <= 0.0 ) { - cerr << "\n\n ConformalAffine::set_scale(double) -> scale must be strictly positive!\n\n"; + mlog << Error << "\nConformalAffine::set_scale(double) -> " + << "scale must be strictly positive!\n\n"; exit ( 1 ); @@ -1903,7 +1924,8 @@ Top = T; if ( width() < 0.0 ) { - cerr << "\n\n Box::set_lrbt() -> negative width!\n\n"; + mlog << Error << "\nBox::set_lrbt() -> " + << "negative width!\n\n"; exit ( 1 ); @@ -1911,7 +1933,8 @@ if ( width() < 0.0 ) { if ( height() < 0.0 ) { - cerr << "\n\n Box::set_lrbt() -> negative height!\n\n"; + mlog << Error << "\nBox::set_lrbt() -> " + << "negative height!\n\n"; exit ( 1 ); @@ -2023,7 +2046,8 @@ void Box::scale_from_ll(double s) if ( s <= 0.0 ) { - cerr << "\n\n Box::scale_from_ll(double) -> scale factor must be strictly positive\n\n"; + mlog << Error << "\nBox::scale_from_ll(double) -> " + << "scale factor must be strictly positive\n\n"; exit ( 1 ); @@ -2072,7 +2096,8 @@ Bottom -= py; if ( (width() <= 0.0) || (height() <= 0.0) ) { - cerr << "\n\n Box::pad(double, double) -> width and/or height is negative!\n\n"; + mlog << Error << "\nBox::pad(double, double) -> " + << "width and/or height is negative!\n\n"; exit ( 1 ); @@ -2092,7 +2117,8 @@ void Box::scale_from_center(double s) if ( s <= 0.0 ) { - cerr << "\n\n Box::scale_from_center(double) -> scale factor must be strictly positive\n\n"; + mlog << Error << "\nBox::scale_from_center(double) -> " + << "scale factor must be strictly positive\n\n"; exit ( 1 ); @@ -2132,7 +2158,8 @@ void Box::scale_from_origin(double s) if ( s <= 0.0 ) { - cerr << "\n\n Box::scale_from_origin(double) -> scale factor must be strictly positive\n\n"; + mlog << Error << "\nBox::scale_from_origin(double) -> " + << "scale factor must be strictly positive\n\n"; exit ( 1 ); @@ -2163,7 +2190,8 @@ void Box::scale_from_origin(double sx, double sy) if ( (sx <= 0.0) || (sy <= 0.0) ) { - cerr << "\n\n Box::scale_from_origin(double, double) -> scale factor(s) must be strictly positive\n\n"; + mlog << Error << "\nBox::scale_from_origin(double, double) -> " + << "scale factor(s) must be strictly positive\n\n"; exit ( 1 ); @@ -2431,7 +2459,8 @@ void Box::set_center(const Box & b) if ( b.is_empty() ) { - cerr << "\n\n Box::set_center(const Box &) -> given box is empty!\n\n"; + mlog << Error << "\nBox::set_center(const Box &) -> " + << "given box is empty!\n\n"; exit ( 1 ); @@ -2479,7 +2508,8 @@ double calc_aspect(double width, double height) if ( (width < 0.0) || (height < 0.0) ) { - cerr << "\n\n calc_aspect() const -> negative box dimensions!\n\n"; + mlog << Error << "\ncalc_aspect() const -> " + << "negative box dimensions!\n\n"; exit ( 1 ); @@ -2487,7 +2517,8 @@ if ( (width < 0.0) || (height < 0.0) ) { if ( height == 0.0 ) { - cerr << "\n\n calc_aspect() const -> zero height!\n\n"; + mlog << Error << "\ncalc_aspect() const -> " + << "zero height!\n\n"; exit ( 1 ); @@ -2677,7 +2708,8 @@ Box surround(const Box * a, int n_boxes) if ( n_boxes <= 0 ) { - cerr << "\n\n surround(const Box * a, int n_boxes) -> bad number of boxes ... " << n_boxes << "\n\n"; + mlog << Error << "\nsurround(const Box * a, int n_boxes) -> " + << "bad number of boxes ... " << n_boxes << "\n\n"; exit ( 1 ); @@ -2737,7 +2769,8 @@ Box surround(const double * x_points, const double * y_points, const int n) if ( n < 2 ) { - cerr << "\n\n surround(const double * x, const double * y, const int n) -> need at least 2 points!\n\n"; + mlog << Error << "\nsurround(const double * x, const double * y, const int n) -> " + << "need at least 2 points!\n\n"; exit ( 1 ); @@ -2767,7 +2800,8 @@ for (j=1; j bad box width!\n\n"; + mlog << Error << "\nsurround(const double * x, const double * y, const int n) -> " + << "bad box width!\n\n"; exit ( 1 ); @@ -2775,7 +2809,8 @@ if ( (R - L) <= 0.0 ) { if ( (T - B) <= 0.0 ) { - cerr << "\n\n surround(const double * x, const double * y, const int n) -> bad box height!\n\n"; + mlog << Error << "\nsurround(const double * x, const double * y, const int n) -> " + << "bad box height!\n\n"; exit ( 1 ); @@ -2815,7 +2850,8 @@ switch ( g ) { default: - cerr << "\n\n viewgravity_to_uv() -> bad gravity ... " + mlog << Error << "\nviewgravity_to_uv() -> " + << "bad gravity ... " << viewgravity_to_string(g) << "\n\n"; exit ( 1 ); break; diff --git a/src/basic/vx_math/affine.h b/src/basic/vx_math/affine.h index 9982518504..c9b346abea 100644 --- a/src/basic/vx_math/affine.h +++ b/src/basic/vx_math/affine.h @@ -13,16 +13,6 @@ #define __VX_MATH_AFFINE_H__ -//////////////////////////////////////////////////////////////////////// - - - // - // This header file is part of the Verification Group's - // - // Math Library code - // - - //////////////////////////////////////////////////////////////////////// @@ -77,7 +67,7 @@ class AffineInterface { virtual void clear() = 0; - virtual void dump(ostream &, int depth = 0) const = 0; + virtual void dump(std::ostream &, int depth = 0) const = 0; // // set stuff @@ -165,7 +155,7 @@ class Affine : public AffineInterface { void clear(); // set to identity - virtual void dump(ostream &, int depth = 0) const; + virtual void dump(std::ostream &, int depth = 0) const; // // set stuff @@ -181,6 +171,8 @@ class Affine : public AffineInterface { void set_m (double _m11, double _m12, double _m21, double _m22); // sets TX = TY = 0.0 + void set_b (double _b1, double _b2); + // // version 1 // @@ -311,7 +303,7 @@ class DiagonalAffine : public AffineInterface { void clear(); // set to identity - virtual void dump(ostream &, int depth = 0) const; + virtual void dump(std::ostream &, int depth = 0) const; // // set stuff @@ -475,7 +467,7 @@ class ConformalAffine : public AffineInterface { void clear(); - void dump (ostream &, int depth = 0) const; + void dump (std::ostream &, int depth = 0) const; // // set stuff @@ -624,7 +616,7 @@ class Box { virtual void clear(); - virtual void dump(ostream &, int = 0) const; + virtual void dump(std::ostream &, int = 0) const; // // set stuff diff --git a/src/basic/vx_math/vx_vector.cc b/src/basic/vx_math/vx_vector.cc index fd6c7f0645..bfc266b91a 100644 --- a/src/basic/vx_math/vx_vector.cc +++ b/src/basic/vx_math/vx_vector.cc @@ -1,8 +1,3 @@ - - -//////////////////////////////////////////////////////////////////////// - - // *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* // ** Copyright UCAR (c) 1992 - 2023 // ** University Corporation for Atmospheric Research (UCAR) @@ -26,6 +21,7 @@ using namespace std; #include "indent.h" #include "trig.h" #include "vx_vector.h" +#include "vx_log.h" //////////////////////////////////////////////////////////////////////// @@ -101,9 +97,8 @@ double t = XX*XX + YY*YY + ZZ*ZZ; if ( t == 0.0 ) { - // cerr might not have been constructed yet - - fprintf(stderr, "Vector::Vector(double XX, double YY, double ZZ, char) -> can't make unit vector from zero vector!\n\n"); + mlog << Error << "\nVector::Vector(double XX, double YY, double ZZ, char) -> " + << "can't make unit vector from zero vector!\n\n"; exit ( 1 ); @@ -261,7 +256,8 @@ double t = abs(); if ( t == 0.0 ) { - cerr << "\n\n Vector::normalize() -> can't normalize zero vector!\n\n"; + mlog << Error << "\nVector::normalize() -> " + << "can't normalize zero vector!\n\n"; exit ( 1 ); @@ -381,7 +377,8 @@ r = abs(); if ( r == 0.0 ) { - cerr << "\n\n Vector::get_altaz() -> zero vector!\n\n"; + mlog << Error << "\nVector::get_altaz() -> " + << "zero vector!\n\n"; exit ( 1 ); @@ -421,7 +418,8 @@ t = axis.abs(); if ( t == 0.0 ) { - cerr << "\n\n Vector::rotate() -> axis is the zero vector!\n\n"; + mlog << Error << "\nVector::rotate() -> " + << "axis is the zero vector!\n\n"; exit ( 1 ); @@ -542,7 +540,8 @@ void Vector::operator/=(double t) if ( t == 0.0 ) { - cerr << "\n\n Vector::operator/=(double) -> can't divide by zero!\n\n"; + mlog << Error << "\nVector::operator/=(double) -> " + << "can't divide by zero!\n\n"; exit ( 1 ); @@ -566,7 +565,8 @@ void Vector::operator/=(int i) if ( i == 0 ) { - cerr << "\n\n Vector::operator/=(int) -> can't divide by zero!\n\n"; + mlog << Error << "\nVector::operator/=(int) -> " + << "can't divide by zero!\n\n"; exit ( 1 ); @@ -895,7 +895,8 @@ Vector operator/(const Vector & a, double t) if ( t == 0.0 ) { - cerr << "\n\n Vector operator/(const Vector &a, double t) -> division by zero!\n\n"; + mlog << Error << "\nVector operator/(const Vector &a, double t) -> " + << "division by zero!\n\n"; exit ( 1 ); @@ -925,7 +926,8 @@ Vector operator/(const Vector & a, int i) if ( i == 0 ) { - cerr << "\n\n Vector operator/(const Vector &a, double t) -> division by zero!\n\n"; + mlog << Error << "\nVector operator/(const Vector &a, double t) -> " + << "division by zero!\n\n"; exit ( 1 ); diff --git a/src/basic/vx_math/vx_vector.h b/src/basic/vx_math/vx_vector.h index e272f1bd8d..e30b19f863 100644 --- a/src/basic/vx_math/vx_vector.h +++ b/src/basic/vx_math/vx_vector.h @@ -1,8 +1,3 @@ - - -//////////////////////////////////////////////////////////////////////// - - // *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* // ** Copyright UCAR (c) 1992 - 2023 // ** University Corporation for Atmospheric Research (UCAR)