Various header cleanups. NFC.

* Don't use a reserved identifier in include guards.
  * Use fabs() from <cmath> instead of our own ffabs().
    This shouldn't make any difference with modern toolchains.
  * Convert a few preprocessor macros to constexprs.
pull/598/head^2
whitequark 2020-05-10 09:24:12 +00:00
parent e00d4867e1
commit d857e3e9cd
5 changed files with 28 additions and 35 deletions

View File

@ -7,6 +7,8 @@
#ifndef SOLVESPACE_GUI_H
#define SOLVESPACE_GUI_H
class RgbaColor;
namespace Platform {
//-----------------------------------------------------------------------------

View File

@ -4,13 +4,14 @@
// Copyright 2016 whitequark
//-----------------------------------------------------------------------------
#ifndef __RESOURCE_H
#define __RESOURCE_H
#ifndef SOLVESPACE_RESOURCE_H
#define SOLVESPACE_RESOURCE_H
class Camera;
class Point2d;
class Pixmap;
class Vector;
class RgbaColor;
std::string LoadString(const std::string &name);
std::string LoadStringFromGzip(const std::string &name);

View File

@ -151,7 +151,7 @@ void SolveSpaceUI::Init() {
}
bool SolveSpaceUI::LoadAutosaveFor(const Platform::Path &filename) {
Platform::Path autosaveFile = filename.WithExtension(AUTOSAVE_EXT);
Platform::Path autosaveFile = filename.WithExtension(BACKUP_EXT);
FILE *f = OpenFile(autosaveFile, "rb");
if(!f)
@ -474,7 +474,7 @@ bool SolveSpaceUI::GetFilenameAndSave(bool saveAs) {
if(saveAs || saveFile.IsEmpty()) {
Platform::FileDialogRef dialog = Platform::CreateSaveFileDialog(GW.window);
dialog->AddFilter(C_("file-type", "SolveSpace models"), { "slvs" });
dialog->AddFilter(C_("file-type", "SolveSpace models"), { SKETCH_EXT });
dialog->ThawChoices(settings, "Sketch");
if(!newSaveFile.IsEmpty()) {
dialog->SetFilename(newSaveFile);
@ -503,13 +503,13 @@ void SolveSpaceUI::Autosave()
ScheduleAutosave();
if(!saveFile.IsEmpty() && unsaved) {
SaveToFile(saveFile.WithExtension(AUTOSAVE_EXT));
SaveToFile(saveFile.WithExtension(BACKUP_EXT));
}
}
void SolveSpaceUI::RemoveAutosave()
{
Platform::Path autosaveFile = saveFile.WithExtension(AUTOSAVE_EXT);
Platform::Path autosaveFile = saveFile.WithExtension(BACKUP_EXT);
RemoveFile(autosaveFile);
}

View File

@ -85,6 +85,7 @@ namespace SolveSpace {
using std::min;
using std::max;
using std::swap;
using std::fabs;
#if defined(__GNUC__)
__attribute__((noreturn))
@ -116,44 +117,31 @@ inline double WRAP_SYMMETRIC(double v, double n) {
return v;
}
// Why is this faster than the library function?
inline double ffabs(double v) { return (v > 0) ? v : (-v); }
#define CO(v) (v).x, (v).y, (v).z
#define ANGLE_COS_EPS (1e-6)
#define LENGTH_EPS (1e-6)
#define VERY_POSITIVE (1e10)
#define VERY_NEGATIVE (-1e10)
static constexpr double ANGLE_COS_EPS = 1e-6;
static constexpr double LENGTH_EPS = 1e-6;
static constexpr double VERY_POSITIVE = 1e10;
static constexpr double VERY_NEGATIVE = -1e10;
inline double Random(double vmax) {
return (vmax*rand()) / RAND_MAX;
}
#include "platform/platform.h"
#include "platform/gui.h"
#include "resource.h"
class Expr;
class ExprVector;
class ExprQuaternion;
class RgbaColor;
enum class Command : uint32_t;
//================
// From the platform-specific code.
#include "platform/platform.h"
#include "platform/gui.h"
const size_t MAX_RECENT = 8;
#define AUTOSAVE_EXT "slvs~"
// Temporary heap, defined in the platform-specific code.
void *AllocTemporary(size_t n);
void FreeAllTemporary();
// End of platform-specific functions
//================
#include "resource.h"
enum class Unit : uint32_t {
MM = 0,
INCHES,
@ -670,7 +658,9 @@ public:
static void MenuFile(Command id);
void Autosave();
void RemoveAutosave();
static const size_t MAX_RECENT = 8;
static constexpr size_t MAX_RECENT = 8;
static constexpr const char *SKETCH_EXT = "slvs";
static constexpr const char *BACKUP_EXT = "slvs~";
std::vector<Platform::Path> recentFiles;
bool Load(const Platform::Path &filename);
bool GetFilenameAndSave(bool saveAs);

View File

@ -187,15 +187,15 @@ bool System::SolveLinearSystem(double X[], double A[][MAX_UNKNOWNS],
// greater. First, find a pivot (between rows i and N-1).
max = 0;
for(ip = i; ip < n; ip++) {
if(ffabs(A[ip][i]) > max) {
if(fabs(A[ip][i]) > max) {
imax = ip;
max = ffabs(A[ip][i]);
max = fabs(A[ip][i]);
}
}
// Don't give up on a singular matrix unless it's really bad; the
// assumption code is responsible for identifying that condition,
// so we're not responsible for reporting that error.
if(ffabs(max) < 1e-20) continue;
if(fabs(max) < 1e-20) continue;
// Swap row imax with row i
for(jp = 0; jp < n; jp++) {
@ -217,7 +217,7 @@ bool System::SolveLinearSystem(double X[], double A[][MAX_UNKNOWNS],
// We've put the matrix in upper triangular form, so at this point we
// can solve by back-substitution.
for(i = n - 1; i >= 0; i--) {
if(ffabs(A[i][i]) < 1e-20) continue;
if(fabs(A[i][i]) < 1e-20) continue;
temp = B[i];
for(j = n - 1; j > i; j--) {
@ -309,7 +309,7 @@ bool System::NewtonSolve(int tag) {
if(isnan(mat.B.num[i])) {
return false;
}
if(ffabs(mat.B.num[i]) > CONVERGE_TOLERANCE) {
if(fabs(mat.B.num[i]) > CONVERGE_TOLERANCE) {
converged = false;
break;
}
@ -493,7 +493,7 @@ didnt_converge:
SK.constraint.ClearTags();
// Not using range-for here because index is used in additional ways
for(i = 0; i < eq.n; i++) {
if(ffabs(mat.B.num[i]) > CONVERGE_TOLERANCE || isnan(mat.B.num[i])) {
if(fabs(mat.B.num[i]) > CONVERGE_TOLERANCE || isnan(mat.B.num[i])) {
// This constraint is unsatisfied.
if(!mat.eq[i].isFromConstraint()) continue;