File indexing completed on 2025-12-21 09:19:52
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include <map>
0012 #include <optional>
0013 #include <string>
0014 #include <utility>
0015 #include <vector>
0016
0017 #include "actsvg/core/style.hpp"
0018 #include "actsvg/proto/material.hpp"
0019 #include "actsvg/styles/defaults.hpp"
0020 #include "grid.hpp"
0021
0022 namespace actsvg {
0023
0024 namespace proto {
0025
0026
0027
0028
0029
0030
0031
0032 template <typename point3_container>
0033 struct surface {
0034
0035 using point3 = typename point3_container::value_type;
0036
0037
0038 struct transform3 {
0039
0040 point3 _translation = {0., 0., 0.};
0041
0042 std::array<point3, 3u> _rotation = {
0043 point3{1., 0., 0.}, point3{0., 1., 0.}, point3{0., 0., 1.}};
0044
0045 point3 rotate(const point3& p_) const {
0046
0047 point3 ret{0.f, 0.f, 0.f};
0048
0049 ret[0] += _rotation[0][0] * p_[0];
0050 ret[1] += _rotation[1][0] * p_[0];
0051 ret[2] += _rotation[2][0] * p_[0];
0052
0053 ret[0] += _rotation[0][1] * p_[1];
0054 ret[1] += _rotation[1][1] * p_[1];
0055 ret[2] += _rotation[2][1] * p_[1];
0056
0057 ret[0] += _rotation[0][2] * p_[2];
0058 ret[1] += _rotation[1][2] * p_[2];
0059 ret[2] += _rotation[2][2] * p_[2];
0060
0061 return ret;
0062 }
0063
0064
0065 point3 point_to_global(const point3& p_) const {
0066
0067 point3 ret = rotate(p_);
0068 ret[0] += _translation[0];
0069 ret[1] += _translation[1];
0070 ret[2] += _translation[2];
0071 return ret;
0072 }
0073
0074
0075 static transform3 identity() { return transform3{}; }
0076 };
0077
0078 enum class type {
0079 e_annulus,
0080 e_cylinder,
0081 e_diamond,
0082 e_disc,
0083 e_polygon,
0084 e_rectangle,
0085 e_straw,
0086 e_trapez
0087 };
0088
0089 enum class sf_type { e_portal, e_sensitive, e_passive };
0090
0091 enum class boolean { e_clipping, e_union, e_subtraction, e_none };
0092
0093
0094 std::string _name = "unnamed_surface";
0095
0096
0097 std::map<std::string, std::vector<std::string>> _aux_info = {};
0098
0099
0100 point3_container _vertices = {};
0101
0102
0103
0104 std::optional<transform3> _surface_transform = std::nullopt;
0105
0106
0107
0108 std::array<scalar, 2> _radii = {0., 0.};
0109 std::array<scalar, 2> _opening = {-pi, pi};
0110 std::array<scalar, 2> _zparameters = {0., 0.};
0111
0112
0113 std::vector<surface<point3_container>> _boolean_surface = {};
0114 boolean _boolean_operation = boolean::e_none;
0115
0116
0117 style::fill _fill = defaults::__s_fill;
0118 style::stroke _stroke = defaults::__s_stroke;
0119 style::transform _transform = defaults::__t_identity;
0120
0121
0122 type _type = type::e_trapez;
0123 sf_type _sf_type = sf_type::e_sensitive;
0124
0125
0126 std::vector<scalar> _measures = {};
0127
0128
0129 std::map<std::string, svg::object> _decorations;
0130
0131
0132 surface_material _material = {};
0133
0134
0135 svg::object _template_object;
0136
0137 using point3_type = typename point3_container::value_type;
0138
0139
0140
0141
0142
0143
0144 static surface<point3_container> from_template(
0145 const surface<point3_container>& t_, const svg::object& o_,
0146 const std::string& name_) {
0147 surface<point3_container> s;
0148 s._name = name_;
0149 s._type = t_._type;
0150 s._sf_type = t_._sf_type;
0151 s._aux_info = t_._aux_info;
0152 s._vertices = t_._vertices;
0153 s._measures = t_._measures;
0154 s._radii = t_._radii;
0155 s._opening = t_._opening;
0156 s._fill = t_._fill;
0157 s._stroke = t_._stroke;
0158 s._transform = t_._transform;
0159 s._template_object = o_;
0160 s._decorations = t_._decorations;
0161 return s;
0162 }
0163 };
0164
0165 }
0166
0167 }