8000 general: rework the way files are included for better maintainability by iscgar · Pull Request #1607 · solvespace/solvespace · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions bench/harness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@
//
// Copyright 2016 whitequark
//-----------------------------------------------------------------------------
#include <chrono>
#include <functional>
#include <string>
#include <vector>

#include "solvespace.h"

using namespace SolveSpace;

static bool RunBenchmark(std::function<void()> setupFn,
std::function<bool()> benchFn,
std::function<void()> teardownFn,
Expand Down
6 changes: 4 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ endif()
# Solver
add_library(slvs-solver INTERFACE)
target_sources(slvs-solver INTERFACE
dsc.h
expr.h
handle.h
param.h
platform/platform.h
solvespace.h

Expand Down Expand Up @@ -100,8 +104,6 @@ if(ENABLE_GUI OR ENABLE_CLI)
solvespace.cpp)

add_library(solvespace-core STATIC
dsc.h
expr.h
polygon.h
sketch.h
ui.h
Expand Down
22 changes: 13 additions & 9 deletions src/bsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
//-----------------------------------------------------------------------------
#include "solvespace.h"

SBsp2 *SBsp2::Alloc() { return (SBsp2 *)AllocTemporary(sizeof(SBsp2)); }
SBsp3 *SBsp3::Alloc() { return (SBsp3 *)AllocTemporary(sizeof(SBsp3)); }
namespace SolveSpace {

SBsp2 *SBsp2::Alloc() { return (SBsp2 *)Platform::AllocTemporary(sizeof(SBsp2)); }
SBsp3 *SBsp3::Alloc() { return (SBsp3 *)Platform::AllocTemporary(sizeof(SBsp3)); }

SBsp3 *SBsp3::FromMesh(const SMesh *m) {
SMesh mc = {};
Expand Down Expand Up @@ -150,35 +152,35 @@ class BspUtil {
Vector *vneg;

static BspUtil *Alloc() {
return (BspUtil *)AllocTemporary(sizeof(BspUtil));
return (BspUtil *)Platform::AllocTemporary(sizeof(BspUtil));
}

void AllocOn() {
on = (Vector *)AllocTemporary(sizeof(Vector) * 2);
on = (Vector *)Platform::AllocTemporary(sizeof(Vector) * 2);
}

void AllocTriangle() {
btri = (STriangle *)AllocTemporary(sizeof(STriangle));
btri = (STriangle *)Platform::AllocTemporary(sizeof(STriangle));
}

void AllocTriangles() {
btri = (STriangle *)AllocTemporary(sizeof(STriangle) * 2);
btri = (STriangle *)Platform::AllocTemporary(sizeof(STriangle) * 2);
ctri = &btri[1];
}

void AllocQuad() {
vpos = (Vector *)AllocTemporary(sizeof(Vector) * 4);
vpos = (Vector *)Platform::AllocTemporary(sizeof(Vector) * 4);
}

void AllocClassify(size_t size) {
// Allocate a one big piece is faster than a small ones.
isPos = (bool *)AllocTemporary(sizeof(bool) * size * 3);
isPos = (bool *)Platform::AllocTemporary(sizeof(bool) * size * 3);
isNeg = &isPos[size];
isOn = &isNeg[size];
}

void AllocVertices(size_t size) {
vpos = (Vector *)AllocTemporary(sizeof(Vector) * size * 2);
vpos = (Vector *)Platform::AllocTemporary(sizeof(Vector) * size * 2);
vneg = &vpos[size];
}

Expand Down Expand Up @@ -727,3 +729,5 @@ void SBsp2::InsertTriangle(STriangle *tr, SMesh *m, SBsp3 *bsp3) {

return;
}

} // namespace SolveSpace
3 changes: 3 additions & 0 deletions src/clipboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
//-----------------------------------------------------------------------------
#include "solvespace.h"

namespace SolveSpace {

void SolveSpaceUI::Clipboard::Clear() {
c.Clear();
r.Clear();
Expand Down Expand Up @@ -522,3 +524,4 @@ void TextWindow::ShowPasteTransformed() {
Printf(true, "(or %Fl%Ll%fcancel operation%E)", &ScreenHome);
}

} // namespace SolveSpace
3 changes: 3 additions & 0 deletions src/confscreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <omp.h>
#endif

namespace SolveSpace {

void TextWindow::ScreenChangeColor(int link, uint32_t v) {
SS.TW.ShowEditControlWithColorPicker(13, SS.modelColor[v]);

Expand Down Expand Up @@ -587,3 +589,4 @@ bool TextWindow::EditControlDoneForConfiguration(const std::string &s) {
return true;
}

} // namespace SolveSpace
4 changes: 4 additions & 0 deletions src/constraint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
//-----------------------------------------------------------------------------
#include "solvespace.h"

namespace SolveSpace {

std::string Constraint::DescriptionString() const {
std::string s;
switch(type) {
Expand Down Expand Up @@ -988,3 +990,5 @@ void Constraint::MenuConstrain(Command id) {
}

#endif /* ! LIBRARY */

} // namespace SolveSpace
3 changes: 3 additions & 0 deletions src/constrainteq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
//-----------------------------------------------------------------------------
#include "solvespace.h"

namespace SolveSpace {

const hConstraint ConstraintBase::NO_CONSTRAINT = { 0 };

bool ConstraintBase::HasLabel() const {
Expand Down Expand Up @@ -1057,3 +1059,4 @@ void ConstraintBase::GenerateEquations(IdList<Equation,hEquation> *l,
ssassert(false, "Unexpected constraint ID");
}

} // namespace SolveSpace
15 changes: 15 additions & 0 deletions 3255 src/defs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef SOLVESPACE_DEFS_H
#define SOLVESPACE_DEFS_H

namespace SolveSpace {

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;

static constexpr double PI = 3.1415926535897931;

} // namespace SolveSpace

#endif // !SOLVESPACE_DEFS_H
3 changes: 3 additions & 0 deletions src/describescreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
//-----------------------------------------------------------------------------
#include "solvespace.h"

namespace SolveSpace {

void TextWindow::ScreenUnselectAll(int link, uint32_t v) {
GraphicsWindow::MenuEdit(Command::UNSELECT_ALL);
}
Expand Down Expand Up @@ -584,3 +586,4 @@ void TextWindow::GoToScreen(Screen screen) {
shown.screen = screen;
}

} // namespace SolveSpace
4 changes: 4 additions & 0 deletions src/draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
//-----------------------------------------------------------------------------
#include "solvespace.h"

namespace SolveSpace {

bool GraphicsWindow::Selection::Equals(Selection *b) {
if(entity != b->entity) return false;
if(constraint != b->constraint) return false;
Expand Down Expand Up @@ -952,3 +954,5 @@ void GraphicsWindow::Invalidate(bool clearPersistent) {
window->Invalidate();
}
}

} // namespace SolveSpace
4 changes: 4 additions & 0 deletions src/drawconstraint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
//-----------------------------------------------------------------------------
#include "solvespace.h"

namespace SolveSpace {

std::string Constraint::Label() const {
std::string result;
if(type == Type::ANGLE) {
Expand Down Expand Up @@ -1378,3 +1380,5 @@ bool Constraint::HasLabel() const {
bool Constraint::ShouldDrawExploded() const {
return SK.GetGroup(group)->ShouldDrawExploded();
}

} // namespace SolveSpace
4 changes: 4 additions & 0 deletions src/drawentity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
//-----------------------------------------------------------------------------
#include "solvespace.h"

namespace SolveSpace {

std::string Entity::DescriptionString() const {
if(h.isFromRequest()) {
Request *r = SK.GetRequest(h.request());
Expand Down Expand Up @@ -861,3 +863,5 @@ void Entity::Draw(DrawAs how, Canvas *canvas) {
}
ssassert(false, "Unexpected entity type");
}

} // namespace SolveSpace
62 changes: 18 additions & 44 deletions src/dsc.h
3255 D96B
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,16 @@
#ifndef SOLVESPACE_DSC_H
#define SOLVESPACE_DSC_H

#include <type_traits>
#include <algorithm>
#include <cmath>
#include <cstddef>
#include <cstdint>
#include <vector>

/// Trait indicating which types are handle types and should get the associated operators.
/// Specialize for each handle type and inherit from std::true_type.
template<typename T>
struct IsHandleOracle : std::false_type {};
#include "defs.h"
#include "util.h"

// Equality-compare any two instances of a handle type.
template<typename T>
static inline typename std::enable_if<IsHandleOracle<T>::value, bool>::type
operator==(T const &lhs, T const &rhs) {
return lhs.v == rhs.v;
}

// Inequality-compare any two instances of a handle type.
template<typename T>
static inline typename std::enable_if<IsHandleOracle<T>::value, bool>::type
operator!=(T const &lhs, T const &rhs) {
return !(lhs == rhs);
}

// Less-than-compare any two instances of a handle type.
template<typename T>
static inline typename std::enable_if<IsHandleOracle<T>::value, bool>::type
operator<(T const &lhs, T const &rhs) {
return lhs.v < rhs.v;
}

template<class T>
struct HandleHasher {
static_assert(IsHandleOracle<T>::value, "Not a valid handle type");

inline size_t operator()(const T &h) const {
using Hasher = std::hash<decltype(T::v)>;
return Hasher{}(h.v);
}
};
namespace SolveSpace {

class Vector;
class Vector4;
Expand Down Expand Up @@ -157,9 +129,9 @@ inline double Vector::Element(int i) const {
inline bool Vector::Equals(Vector v, double tol) const {
// Quick axis-aligned tests before going further
const Vector dv = this->Minus(v);
if (fabs(dv.x) > tol) return false;
if (fabs(dv.y) > tol) return false;
if (fabs(dv.z) > tol) return false;
if (std::abs(dv.x) > tol) return false;
if (std::abs(dv.y) > tol) return false;
if (std::abs(dv.z) > tol) return false;

return dv.MagSquared() < tol*tol;
}
Expand Down Expand Up @@ -201,13 +173,13 @@ inline Vector Vector::ScaledBy(const double v) const {
}

inline void Vector::MakeMaxMin(Vector *maxv, Vector *minv) const {
maxv->x = max(maxv->x, x);
maxv->y = max(maxv->y, y);
maxv->z = max(maxv->z, z);
maxv->x = std::max(maxv->x, x);
maxv->y = std::max(maxv->y, y);
maxv->z = std::max(maxv->z, z);

minv->x = min(minv->x, x);
minv->y = min(minv->y, y);
minv->z = min(minv->z, z);
minv->x = std::min(minv->x, x);
minv->y = std::min(minv->y, y);
minv->z = std::min(minv->z, z);
}

struct VectorHash {
Expand Down Expand Up @@ -753,4 +725,6 @@ class BBox {
bool Contains(const Point2d &p, double r = 0.0) const;
};

} // namespace SolveSpace

#endif
4 changes: 4 additions & 0 deletions src/entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
//-----------------------------------------------------------------------------
#include "solvespace.h"

namespace SolveSpace {

const hEntity EntityBase::FREE_IN_3D = { 0 };
const hEntity EntityBase::NO_ENTITY = { 0 };

Expand Down Expand Up @@ -991,3 +993,5 @@ void EntityBase::GenerateEquations(IdList<Equation,hEquation> *l) const {
break;
}
}

} // namespace SolveSpace
4 changes: 4 additions & 0 deletions src/export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "solvespace.h"
#include "config.h"

namespace SolveSpace {

void SolveSpaceUI::ExportSectionTo(const Platform::Path &filename) {
Vector gn = (SS.GW.projRight).Cross(SS.GW.projUp);
gn = gn.WithMagnitude(1);
Expand Down Expand Up @@ -1266,3 +1268,5 @@ void SolveSpaceUI::ExportAsPngTo(const Platform::Path &filename) {
// The rest of the work is done in the next redraw.
GW.Invalidate();
}

} // namespace SolveSpace
3 changes: 3 additions & 0 deletions src/exportstep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
//-----------------------------------------------------------------------------
#include "solvespace.h"

namespace SolveSpace {

#define FP "%.5f" // Floating Point coordinate precision. Since LENGTH_EPS = 1e-6 output 5 decimal places thus rounding out errors e.g. 0.999999mm
#define CARTESIAN_POINT_FORMAT "#%d=CARTESIAN_POINT('',(" FP "," FP "," FP "));\n"
const double PRECISION = 2*LENGTH_EPS;
Expand Down Expand Up @@ -716,3 +718,4 @@ void StepFileWriter::WriteWireframe() {
curves.Clear();
}

} // namespace SolveSpace
3 changes: 3 additions & 0 deletions 8020 src/exportvector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <libdxfrw.h>
#include "solvespace.h"

namespace SolveSpace {

//-----------------------------------------------------------------------------
// Routines for DXF export
//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -1355,3 +1357,4 @@ void Step2dFileWriter::FinishAndCloseFile() {
fclose(f);
}

} // namespace SolveSpace
Loading
Loading
0