Skip to content

Commit

Permalink
fix: use DECIMAL macro instead of typecast
Browse files Browse the repository at this point in the history
  • Loading branch information
mookums committed Nov 29, 2023
1 parent f9c1d80 commit 321a4ab
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/attitude-estimators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace lost {

#define EPSILON (decimal) 0.0001 // threshold for 0 for Newton-Raphson method
#define EPSILON DECIMAL(0.0001) // threshold for 0 for Newton-Raphson method

Attitude DavenportQAlgorithm::Go(const Camera &camera,
const Stars &stars,
Expand Down
2 changes: 1 addition & 1 deletion src/camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Camera {

Camera(decimal focalLength, int xResolution, int yResolution)
: Camera(focalLength,
xResolution / (decimal) 2.0, yResolution / (decimal) 2.0,
xResolution / DECIMAL(2.0), yResolution / DECIMAL(2.0),
xResolution, yResolution) {};

Vec2 SpatialToCamera(const Vec3 &) const;
Expand Down
20 changes: 10 additions & 10 deletions src/centroiders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

#include <cmath>
#include <vector>
#include <iostream>
#include <unordered_map>
Expand All @@ -21,7 +21,7 @@ std::vector<Star> DummyCentroidAlgorithm::Go(unsigned char *, int imageWidth, in

unsigned int randomSeed = 123456;
for (int i = 0; i < numStars; i++) {
result.push_back(Star(rand_r(&randomSeed) % imageWidth, rand_r(&randomSeed) % imageHeight, 10.0));
result.push_back(Star(rand_r(&randomSeed) % imageWidth, rand_r(&randomSeed) % imageHeight, DECIMAL(10.0)));
}

return result;
Expand Down Expand Up @@ -197,7 +197,7 @@ std::vector<Star> CenterOfGravityAlgorithm::Go(unsigned char *image, int imageWi

//Determines how accurate and how much iteration is done by the IWCoG algorithm,
//smaller means more accurate and more iterations.
decimal iWCoGMinChange = 0.0002;
decimal iWCoGMinChange = DECIMAL(0.0002);

struct IWCoGParams {
int xMin;
Expand Down Expand Up @@ -286,8 +286,8 @@ Stars IterativeWeightedCenterOfGravityAlgorithm::Go(unsigned char *image, int im
standardDeviation = fwhm / (DECIMAL(2.0) * DECIMAL_SQRT(DECIMAL(2.0) * DECIMAL_LOG(2.0)));
decimal modifiedStdDev = DECIMAL(2.0) * DECIMAL_POW(standardDeviation, 2);
// TODO: Why are these decimals? --Mark
decimal guessXCoord = (decimal) (p.guess % imageWidth);
decimal guessYCoord = (decimal) (p.guess / imageWidth);
decimal guessXCoord = (p.guess % imageWidth);
decimal guessYCoord = (p.guess / imageWidth);
//how much our new centroid estimate changes w each iteration
decimal change = INFINITY;
int stop = 0;
Expand All @@ -300,13 +300,13 @@ Stars IterativeWeightedCenterOfGravityAlgorithm::Go(unsigned char *image, int im
stop++;
for (long j = 0; j < (long)starIndices.size(); j++) {
//calculate w
decimal currXCoord = (decimal) (starIndices.at(j) % imageWidth);
decimal currYCoord = (decimal) (starIndices.at(j) / imageWidth);
decimal currXCoord = starIndices.at(j) % imageWidth;
decimal currYCoord = starIndices.at(j) / imageWidth;
w = p.maxIntensity * DECIMAL_EXP(DECIMAL(-1.0) * ((DECIMAL_POW(currXCoord - guessXCoord, 2) / modifiedStdDev) + (DECIMAL_POW(currYCoord - guessYCoord, 2) / modifiedStdDev)));

xWeightedCoordMagSum += w * currXCoord * ((decimal) image[starIndices.at(j)]);
yWeightedCoordMagSum += w * currYCoord * ((decimal) image[starIndices.at(j)]);
weightedMagSum += w * ((decimal) image[starIndices.at(j)]);
xWeightedCoordMagSum += w * currXCoord * DECIMAL(image[starIndices.at(j)]);
yWeightedCoordMagSum += w * currYCoord * DECIMAL(image[starIndices.at(j)]);
weightedMagSum += w * DECIMAL(image[starIndices.at(j)]);
}
decimal xTemp = xWeightedCoordMagSum / weightedMagSum;
decimal yTemp = yWeightedCoordMagSum / weightedMagSum;
Expand Down
10 changes: 5 additions & 5 deletions src/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ void SurfacePlot(std::string description,
cairo_set_font_options(cairoCtx, cairoFontOptions);
cairo_text_extents_t cairoTextExtents;
cairo_text_extents(cairoCtx, "1234567890", &cairoTextExtents);
decimal textHeight = (decimal) cairoTextExtents.height;
decimal textHeight = cairoTextExtents.height;

for (const Star &centroid : stars) {
// plot the box around the star
Expand Down Expand Up @@ -691,7 +691,7 @@ GeneratedPipelineInput::GeneratedPipelineInput(const Catalog &catalog,
// might have to sample many many times (and furthermore, the results won't be useful
// anyway)
decimal photons = photonsBuffer[i];
if (photons > (decimal)LONG_MAX - DECIMAL(3.0) * DECIMAL_SQRT(LONG_MAX)) {
if (photons > DECIMAL(LONG_MAX) - DECIMAL(3.0) * DECIMAL_SQRT(LONG_MAX)) {
std::cout << "ERROR: One of the pixels had too many photons. Generated image would not be physically accurate, exiting." << std::endl;
exit(1);
}
Expand Down Expand Up @@ -1558,9 +1558,9 @@ static void PipelineComparatorAttitude(std::ostream &os,
}
}

decimal attitudeErrorMean = attitudeErrorSum / numCorrect;
decimal fractionCorrect = (decimal)numCorrect / expected.size();
decimal fractionIncorrect = (decimal)numIncorrect / expected.size();
decimal attitudeErrorMean = DECIMAL(attitudeErrorSum) / numCorrect;
decimal fractionCorrect = DECIMAL(numCorrect) / expected.size();
decimal fractionIncorrect = DECIMAL(numIncorrect) / expected.size();

os << "attitude_error_mean " << attitudeErrorMean << std::endl;
os << "attitude_availability " << fractionCorrect << std::endl;
Expand Down

0 comments on commit 321a4ab

Please sign in to comment.