Skip to content

Commit

Permalink
refactor Tetra serialization to use new serdes
Browse files Browse the repository at this point in the history
  • Loading branch information
zeddie888 committed Nov 5, 2023
2 parents e592d3d + 48fcaa2 commit 2f6c369
Show file tree
Hide file tree
Showing 19 changed files with 579 additions and 500 deletions.
8 changes: 8 additions & 0 deletions documentation/database.man
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ Sets the maximum allowable angle between stars in a Tetra pattern to \fImax\fP (

.SH OTHER OPTIONS

.TP
\fB--swap-integer-endianness\fP
If true, generate databases with all integer values having opposite endianness than the generating machine. It will not be possible to use the generated databases on the system they were generated on.

.TP
\fB--swap-float-endianness\fP
If true, generate databases with all floating point values having opposite endianness than the generating machine. It will not be possible to use the generated databases on the system they were generated on.

.TP
\fB--output\fP \fIoutput-path\fP
The file to output the database to. Defaults to stdout.
Expand Down
2 changes: 1 addition & 1 deletion src/attitude-estimators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ float QuestCharPoly(float x, float a, float b, float c, float d, float s) {retur
float QuestCharPolyPrime(float x, float a, float b, float c) {return 4*pow(x,3) - 2*(a+b)*x - c;}

/**
* Approximates roots of a real function using the Newton-Raphson algorithm
* Approximates roots of a real function using the Newton-Raphson algorithm
* @see https://www.geeksforgeeks.org/program-for-newton-raphson-method/
*/
float QuestEigenvalueEstimator(float guess, float a, float b, float c, float d, float s) {
Expand Down
30 changes: 13 additions & 17 deletions src/attitude-utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <assert.h>
#include <iostream>

#include "serialize-helpers.hpp"

namespace lost {

/// Multiply two quaternions using the usual definition of quaternion multiplication (effectively composes rotations)
Expand Down Expand Up @@ -460,25 +462,19 @@ bool Attitude::IsKnown() const {
}
}

/// The length that a Vec3 will take up when serialized
long SerializeLengthVec3() {
return sizeof(float)*3;
/// Serialize a Vec3 to buffer. Takes up space according to SerializeLengthVec3
void SerializeVec3(SerializeContext *ser, const Vec3 &vec) {
SerializePrimitive<float>(ser, vec.x);
SerializePrimitive<float>(ser, vec.y);
SerializePrimitive<float>(ser, vec.z);
}

/// Serialize a Vec3 to buffer. Takes up space according to SerializeLengthVec3
void SerializeVec3(const Vec3 &vec, unsigned char *buffer) {
float *fBuffer = (float *)buffer;
*fBuffer++ = vec.x;
*fBuffer++ = vec.y;
*fBuffer = vec.z;
}

Vec3 DeserializeVec3(const unsigned char *buffer) {
Vec3 result;
const float *fBuffer = (float *)buffer;
result.x = *fBuffer++;
result.y = *fBuffer++;
result.z = *fBuffer;
Vec3 DeserializeVec3(DeserializeContext *des) {
Vec3 result = {
DeserializePrimitive<float>(des),
DeserializePrimitive<float>(des),
DeserializePrimitive<float>(des),
};
return result;
}

Expand Down
7 changes: 4 additions & 3 deletions src/attitude-utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <numeric> // iota
#include <vector>

#include "serialize-helpers.hpp"

namespace lost {

// At first, I wanted to have two separate Attitude classes, one storing Euler angles and converting
Expand Down Expand Up @@ -78,9 +80,8 @@ class Mat3 {

extern const Mat3 kIdentityMat3;

long SerializeLengthVec3();
void SerializeVec3(const Vec3 &, unsigned char *);
Vec3 DeserializeVec3(const unsigned char *);
void SerializeVec3(SerializeContext *, const Vec3 &);
Vec3 DeserializeVec3(DeserializeContext *des);

float Distance(const Vec2 &, const Vec2 &);
float Distance(const Vec3 &, const Vec3 &);
Expand Down
22 changes: 12 additions & 10 deletions src/database-options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

#include <string>

LOST_CLI_OPTION("min-mag" , float , minMag , 100 , atof(optarg) , kNoDefaultArgument)
LOST_CLI_OPTION("max-stars" , int , maxStars , 10000 , atoi(optarg) , kNoDefaultArgument)
LOST_CLI_OPTION("min-separation" , float , minSeparation , 0.05 , atof(optarg) , kNoDefaultArgument)
LOST_CLI_OPTION("kvector" , bool , kvector , false , atobool(optarg), true)
LOST_CLI_OPTION("kvector-min-distance" , float , kvectorMinDistance , 0.5 , atof(optarg) , kNoDefaultArgument)
LOST_CLI_OPTION("kvector-max-distance" , float , kvectorMaxDistance , 15 , atof(optarg) , kNoDefaultArgument)
LOST_CLI_OPTION("kvector-distance-bins", long , kvectorNumDistanceBins, 10000 , atol(optarg) , kNoDefaultArgument)
LOST_CLI_OPTION("tetra" , bool , tetra , false , atobool(optarg), true)
LOST_CLI_OPTION("tetra-max-angle" , float , tetraMaxAngle , 12 , atof(optarg) , kNoDefaultArgument)
LOST_CLI_OPTION("output" , std::string, outputPath , "-" , optarg , kNoDefaultArgument)
LOST_CLI_OPTION("min-mag" , float , minMag , 100 , atof(optarg) , kNoDefaultArgument)
LOST_CLI_OPTION("max-stars" , int , maxStars , 10000 , atoi(optarg) , kNoDefaultArgument)
LOST_CLI_OPTION("min-separation" , float , minSeparation , 0.08 , atof(optarg) , kNoDefaultArgument)
LOST_CLI_OPTION("kvector" , bool , kvector , false , atobool(optarg), true)
LOST_CLI_OPTION("kvector-min-distance" , float , kvectorMinDistance , 0.5 , atof(optarg) , kNoDefaultArgument)
LOST_CLI_OPTION("kvector-max-distance" , float , kvectorMaxDistance , 15 , atof(optarg) , kNoDefaultArgument)
LOST_CLI_OPTION("kvector-distance-bins" , long , kvectorNumDistanceBins, 10000 , atol(optarg) , kNoDefaultArgument)
LOST_CLI_OPTION("swap-integer-endianness", bool , swapIntegerEndianness , false , atobool(optarg), true)
LOST_CLI_OPTION("swap-float-endianness" , bool , swapFloatEndianness , false , atobool(optarg), true)
LOST_CLI_OPTION("tetra" , bool , tetra , false , atobool(optarg), true)
LOST_CLI_OPTION("tetra-max-angle" , float , tetraMaxAngle , 12 , atof(optarg) , kNoDefaultArgument)
LOST_CLI_OPTION("output" , std::string, outputPath , "-" , optarg , kNoDefaultArgument)
Loading

0 comments on commit 2f6c369

Please sign in to comment.