stage changes

This commit is contained in:
L-Nafaryus 2024-03-14 15:57:16 +05:00
parent 38d628d4ef
commit 39b2063889
Signed by: L-Nafaryus
GPG Key ID: 582F8B0866B294A1
27 changed files with 3393 additions and 2917 deletions

66
.clang-format Normal file
View File

@ -0,0 +1,66 @@
# Generated from CLion C/C++ Code Style settings
BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: None
AlignOperands: Align
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Always
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Always
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterReturnType: None
AlwaysBreakTemplateDeclarations: Yes
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: true
BreakBeforeBinaryOperators: None
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakInheritanceList: BeforeColon
ColumnLimit: 0
CompactNamespaces: false
ContinuationIndentWidth: 8
IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 4
KeepEmptyLinesAtTheStartOfBlocks: true
MaxEmptyLinesToKeep: 2
NamespaceIndentation: All
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PointerAlignment: Right
ReflowComments: false
SpaceAfterCStyleCast: true
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 0
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
TabWidth: 4
UseTab: Never

15
.vscode/c_cpp_properties.json vendored Normal file
View File

@ -0,0 +1,15 @@
{
"configurations": [
{
"name": "windows-gcc",
"compileCommands": ".vscode/compile_commands.json",
"intelliSenseMode": "windows-gcc-x64",
"compilerPath": "C:/Users/Administrator/scoop/apps/msys2/current/mingw64/bin/gcc.exe",
"includePath": [
"${workspaceFolder}/source"
],
"cppStandard": "gnu++20"
}
],
"version": 4
}

26
.vscode/compile_commands.json vendored Normal file
View File

@ -0,0 +1,26 @@
[
{
"directory": "c:\\Users\\Administrator\\Projects\\hpr",
"arguments": ["C:\\Users\\Administrator\\scoop\\apps\\msys2\\current\\mingw64\\bin\\x86_64-w64-mingw32-g++.exe", "-c", "-m64", "-O3", "-std=c++20", "-Isource", "-IC:\\Users\\Administrator\\AppData\\Local\\.xmake\\packages\\i\\imgui\\v1.90-docking\\600835732f214b96b5dbfaccf42f7a60\\include", "-IC:\\Users\\Administrator\\AppData\\Local\\.xmake\\packages\\i\\imgui\\v1.90-docking\\600835732f214b96b5dbfaccf42f7a60\\include\\imgui", "-IC:\\Users\\Administrator\\AppData\\Local\\.xmake\\packages\\i\\imgui\\v1.90-docking\\600835732f214b96b5dbfaccf42f7a60\\include\\backends", "-IC:\\Users\\Administrator\\AppData\\Local\\.xmake\\packages\\i\\imgui\\v1.90-docking\\600835732f214b96b5dbfaccf42f7a60\\include\\misc\\cpp", "-IC:\\Users\\Administrator\\AppData\\Local\\.xmake\\packages\\i\\implot\\v0.15\\6861f774eb2844d6a543372e119845e3\\include", "-IC:\\Users\\Administrator\\AppData\\Local\\.xmake\\packages\\i\\imgui\\v1.90\\853d785fcf03454094beebf60559d12f\\include", "-IC:\\Users\\Administrator\\AppData\\Local\\.xmake\\packages\\i\\imgui\\v1.90\\853d785fcf03454094beebf60559d12f\\include\\imgui", "-IC:\\Users\\Administrator\\AppData\\Local\\.xmake\\packages\\i\\imgui\\v1.90\\853d785fcf03454094beebf60559d12f\\include\\backends", "-IC:\\Users\\Administrator\\AppData\\Local\\.xmake\\packages\\i\\imgui\\v1.90\\853d785fcf03454094beebf60559d12f\\include\\misc\\cpp", "-IC:\\Users\\Administrator\\AppData\\Local\\.xmake\\packages\\g\\glfw\\3.3.8\\d31abc5641874d8fbdc13f33b5569420\\include", "-IC:\\Users\\Administrator\\scoop\\apps\\msys2\\2023-10-26\\mingw64\\include", "-IC:\\Users\\Administrator\\scoop\\apps\\msys2\\2023-10-26\\mingw64\\include\\opencascade", "-DHPR_SCALAR=float", "-DGLFW_INCLUDE_NONE", "-DNDEBUG", "-o", "build\\.objs\\hpr\\mingw\\x86_64\\release\\source\\hpr\\hpr.cpp.obj", "source\\hpr\\hpr.cpp"],
"file": "source\\hpr\\hpr.cpp"
},
{
"directory": "c:\\Users\\Administrator\\Projects\\hpr",
"arguments": ["C:\\Users\\Administrator\\scoop\\apps\\msys2\\current\\mingw64\\bin\\x86_64-w64-mingw32-g++.exe", "-c", "-m64", "-fvisibility=hidden", "-fvisibility-inlines-hidden", "-O3", "-std=c++20", "-Isource", "-IC:\\Users\\Administrator\\AppData\\Local\\.xmake\\packages\\g\\gtest\\1.12.1\\40112995bdf04048acde0ee5a34578c3\\include", "-DHPR_SCALAR=float", "-DNDEBUG", "-o", "build\\.objs\\tests\\mingw\\x86_64\\release\\source\\hpr\\tests\\main.cpp.obj", "source\\hpr\\tests\\main.cpp"],
"file": "source\\hpr\\tests\\main.cpp"
},
{
"directory": "c:\\Users\\Administrator\\Projects\\hpr",
"arguments": ["C:\\Users\\Administrator\\scoop\\apps\\msys2\\current\\mingw64\\bin\\x86_64-w64-mingw32-g++.exe", "-c", "-m64", "-fvisibility=hidden", "-fvisibility-inlines-hidden", "-O3", "-std=c++20", "-Isource", "-IC:\\Users\\Administrator\\AppData\\Local\\.xmake\\packages\\g\\gtest\\1.12.1\\40112995bdf04048acde0ee5a34578c3\\include", "-DHPR_SCALAR=float", "-DNDEBUG", "-o", "build\\.objs\\tests\\mingw\\x86_64\\release\\source\\hpr\\tests\\test_container.cpp.obj", "source\\hpr\\tests\\test_container.cpp"],
"file": "source\\hpr\\tests\\test_container.cpp"
},
{
"directory": "c:\\Users\\Administrator\\Projects\\hpr",
"arguments": ["C:\\Users\\Administrator\\scoop\\apps\\msys2\\current\\mingw64\\bin\\x86_64-w64-mingw32-g++.exe", "-c", "-m64", "-fvisibility=hidden", "-fvisibility-inlines-hidden", "-O3", "-std=c++20", "-Isource", "-IC:\\Users\\Administrator\\AppData\\Local\\.xmake\\packages\\g\\gtest\\1.12.1\\40112995bdf04048acde0ee5a34578c3\\include", "-DHPR_SCALAR=float", "-DNDEBUG", "-o", "build\\.objs\\tests\\mingw\\x86_64\\release\\source\\hpr\\tests\\test_math.cpp.obj", "source\\hpr\\tests\\test_math.cpp"],
"file": "source\\hpr\\tests\\test_math.cpp"
},
{
"directory": "c:\\Users\\Administrator\\Projects\\hpr",
"arguments": ["C:\\Users\\Administrator\\scoop\\apps\\msys2\\current\\mingw64\\bin\\x86_64-w64-mingw32-g++.exe", "-c", "-m64", "-fvisibility=hidden", "-fvisibility-inlines-hidden", "-O3", "-std=c++20", "-Isource", "-IC:\\Users\\Administrator\\AppData\\Local\\.xmake\\packages\\g\\gtest\\1.12.1\\40112995bdf04048acde0ee5a34578c3\\include", "-DHPR_SCALAR=float", "-DNDEBUG", "-o", "build\\.objs\\tests\\mingw\\x86_64\\release\\source\\hpr\\tests\\test_numeric.cpp.obj", "source\\hpr\\tests\\test_numeric.cpp"],
"file": "source\\hpr\\tests\\test_numeric.cpp"
}]

View File

@ -3,3 +3,4 @@
#include <hpr/numeric.hpp> #include <hpr/numeric.hpp>
#include <hpr/container.hpp> #include <hpr/container.hpp>
#include <hpr/math.hpp> #include <hpr/math.hpp>
#include <hpr/shape.hpp>

3
source/hpr/shape.hpp Normal file
View File

@ -0,0 +1,3 @@
#pragma once
#include <hpr/shape/shape.hpp>

360
source/hpr/shape/shape.hpp Normal file
View File

@ -0,0 +1,360 @@
#pragma once
#include <hpr/numeric.hpp>
#include <hpr/container/dynamic_array.hpp>
#include <map>
#include <string>
#include <Geom_Surface.hxx>
#include <GeomLProp_SLProps.hxx>
#include <Poly_Triangle.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Vertex.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Wire.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Compound.hxx>
#include <TopoDS_CompSolid.hxx>
#include <TopoDS_Shell.hxx>
#include <TopoDS_Solid.hxx>
#include <TopExp_Explorer.hxx>
#include <BRepBuilderAPI_MakeVertex.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <BRepBuilderAPI_MakeShell.hxx>
#include <BRepBuilderAPI_MakeSolid.hxx>
#include <BRepBuilderAPI_Sewing.hxx>
#include <BRep_Builder.hxx>
#include <BRepBndLib.hxx>
#include <BRep_Tool.hxx>
#include <BRepTools.hxx>
#include <BRepGProp.hxx>
#include <GProp_GProps.hxx>
#include <ShapeUpgrade_UnifySameDomain.hxx>
#include <BRepExtrema_DistShapeShape.hxx>
#include <BRepBuilderAPI_Transform.hxx>
#include <BRepBuilderAPI_GTransform.hxx>
#include <BRepFilletAPI_MakeFillet.hxx>
#include <BRepAlgoAPI_Fuse.hxx>
#include <BRepAlgoAPI_Common.hxx>
#include <BRepAlgoAPI_Cut.hxx>
#include <BRepPrimAPI_MakeSphere.hxx>
#include <BRepPrimAPI_MakeBox.hxx>
#include <BRepPrimAPI_MakePrism.hxx>
#include <STEPControl_Writer.hxx>
#include <Interface_Static.hxx>
#include <BRepMesh_IncrementalMesh.hxx>
#include <Poly_PolygonOnTriangulation.hxx>
#include <Poly_Triangulation.hxx>
#include <TopAbs_ShapeEnum.hxx>
#include <TopLoc_Location.hxx>
#include <NCollection_List.hxx>
#include <ShapeFix_Solid.hxx>
#include <ShapeFix_Shell.hxx>
#include <ShapeFix_Face.hxx>
namespace hpr::csg
{
class Shape;
}
namespace std
{
template<>
struct less<hpr::csg::Shape>
{
bool operator() (const hpr::csg::Shape& s1, const hpr::csg::Shape& s2) const;
};
}
namespace hpr::csg
{
// Class declaration
class Shape
{
public:
enum class Type
{
Compound,
Compsolid,
Solid,
Shell,
Face,
Wire,
Edge,
Vertex,
Shape,
Unknown
};
enum class Format
{
Unknown,
STEP
};
class Metadata
{
public:
std::string label;
public:
Metadata() :
label {"default"}
{}
void merge(const Metadata& data)
{
if (label == "default" && data.label != "default")
label = data.label;
}
};
public:
// TODO: clean up map
static
std::map<Shape, Shape::Metadata> metadata;
protected:
TopoDS_Shape p_shape;
public:
[[nodiscard]]
TopoDS_Shape tshape() const { return p_shape; }
Shape(const TopoDS_Shape& s) :
p_shape {s}
{}
Shape(TopoDS_Shape&& s) noexcept:
p_shape {std::forward<TopoDS_Shape>(s)}
{}
public:
Shape() :
p_shape {}
{}
virtual
~Shape() = default;
//{
//if (metadata.contains(*this))
// metadata.erase(*this);
//}
[[nodiscard]]
Type type() const
{
switch (p_shape.ShapeType())
{
case TopAbs_VERTEX:
return Type::Vertex;
case TopAbs_EDGE:
return Type::Edge;
case TopAbs_FACE:
return Type::Face;
case TopAbs_WIRE:
return Type::Wire;
case TopAbs_SHELL:
return Type::Shell;
case TopAbs_SOLID:
return Type::Solid;
case TopAbs_COMPOUND:
return Type::Compound;
case TopAbs_COMPSOLID:
return Type::Compsolid;
case TopAbs_SHAPE:
return Type::Shape;
default:
return Type::Unknown;
}
}
[[nodiscard]]
vec3 center() const
{
GProp_GProps props;
switch (type())
{
case Type::Solid:
case Type::Compsolid:
case Type::Compound:
BRepGProp::VolumeProperties(p_shape, props);
case Type::Shell:
case Type::Face:
BRepGProp::SurfaceProperties(p_shape, props);
default:
BRepGProp::LinearProperties(p_shape, props);
}
gp_Pnt center {props.CentreOfMass()};
return vec3 {static_cast<scalar>(center.X()), static_cast<scalar>(center.Y()), static_cast<scalar>(center.Z())};
}
[[nodiscard]]
double length() const
{
GProp_GProps props;
switch (type())
{
case Type::Vertex:
return 0;
default:
BRepGProp::LinearProperties(p_shape, props);
return props.Mass();
}
}
[[nodiscard]]
double area() const
{
GProp_GProps props;
switch (type())
{
case Type::Vertex:
case Type::Edge:
case Type::Wire:
return 0;
default:
BRepGProp::SurfaceProperties(p_shape, props);
return props.Mass();
}
}
[[nodiscard]]
double volume() const
{
GProp_GProps props;
switch (type())
{
case Type::Compsolid:
case Type::Solid:
BRepGProp::VolumeProperties(p_shape, props);
return props.Mass();
default:
return 0;
}
}
void label(const std::string& label) const
{
metadata[*this].label = label;
}
[[nodiscard]]
std::string label() const
{
return metadata[*this].label;
}
void dump(const std::string& filename, Format format) const
{
if (p_shape.IsNull())
throw std::runtime_error("Trying to export null shape");
switch (format)
{
case Format::STEP:
{
STEPControl_Writer writer;
Interface_Static::SetCVal("xstep.cascade.unit", "MM");
Interface_Static::SetCVal("write.step.unit", "MM");
Interface_Static::SetIVal("write.step.nonmanifold", 1);
writer.Transfer(p_shape, STEPControl_AsIs);
writer.Write(filename.c_str());
break;
}
case Format::Unknown:
default:
throw std::invalid_argument("Unknown export format");
}
}
//
[[nodiscard]]
sarray<vec3, 2> boundingBox() const
{
Bnd_Box bbox;
BRepBndLib::Add(p_shape, bbox, true);
gp_Pnt p1 {bbox.CornerMin()};
gp_Pnt p2 {bbox.CornerMax()};
return sarray<vec3, 2> {
{static_cast<scalar>(p1.X()), static_cast<scalar>(p1.Y()), static_cast<scalar>(p1.Z())},
{static_cast<scalar>(p2.X()), static_cast<scalar>(p2.Y()), static_cast<scalar>(p2.Z())}
};
}
void incrementalMesh(double deflection)
{
BRepTools::Clean(p_shape);
BRepMesh_IncrementalMesh(p_shape, deflection, true);
}
darray<Shape> subShapes(Type type) const
{
darray<Shape> shapes;
for (TopExp_Explorer exp(p_shape, static_cast<TopAbs_ShapeEnum>(type)); exp.More(); exp.Next())
shapes.push(Shape(exp.Current()));
return shapes;
}
darray<Shape> edges() const
{
return subShapes(Type::Edge);
}
darray<Shape> faces() const
{
return subShapes(Type::Face);
}
darray<Shape> shells() const
{
return subShapes(Type::Shell);
}
};
double distance(const Shape& lhs, const Shape& rhs)
{
return BRepExtrema_DistShapeShape(lhs.tshape(), rhs.tshape()).Value();
}
}

View File

@ -0,0 +1,5 @@

View File

@ -31,7 +31,7 @@ add_requires("implot v0.15")
add_requires("glfw 3.3.8") add_requires("glfw 3.3.8")
if has_config("csg") then if has_config("csg") then
add_requires("conan::opencascade/7.6.2") add_requires("pacman::opencascade 7.7.2", {alias = "opencascade"})
end end
if has_config("tests") then if has_config("tests") then