• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

NREL / SolTrace / 19979510856

06 Dec 2025 12:06AM UTC coverage: 87.255% (-1.9%) from 89.184%
19979510856

Pull #89

github

web-flow
Merge 5cb7cfc67 into a73a760a4
Pull Request #89: simulation_data changes to support UI-side constructions

0 of 148 new or added lines in 5 files covered. (0.0%)

1 existing line in 1 file now uncovered.

5970 of 6842 relevant lines covered (87.26%)

7824776.54 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

82.47
/coretrace/simulation_data/surface.cpp
1

2
#include "surface.hpp"
3
#include "simdata_io.hpp"
4

5
#include <vector>
6

7
namespace SolTrace::Data {
8

9
surface_ptr make_surface_from_type(SurfaceType type, const std::vector<double> &args)
15,038✔
10
{
11
    surface_ptr retval = nullptr;
15,038✔
12
    unsigned nargs = args.size();
15,038✔
13

14
    switch (type)
15,038✔
15
    {
16
    case SurfaceType::CONE:
3✔
17
        retval = nargs < 1 ? nullptr : make_surface<Cone>(args[0]);
3✔
18
        break;
3✔
19
    case SurfaceType::CYLINDER:
6✔
20
        retval = nargs < 1 ? nullptr : make_surface<Cylinder>(1.0 / args[0]);
6✔
21
        break;
6✔
22
    case SurfaceType::FLAT:
7✔
23
        retval = make_surface<Flat>();
7✔
24
        break;
7✔
25
    case SurfaceType::PARABOLA:
14,939✔
26
    {
27
        if (nargs < 2)
14,939✔
28
            retval = nullptr;
2✔
29
        else
30
        {
31
            double cx = args[0];
14,937✔
32
            double cy = args[1];
14,937✔
33
            double fx = 1.0 / (2.0 * cx);
14,937✔
34
            double fy = 1.0 / (2.0 * cy);
14,937✔
35
            retval = make_surface<Parabola>(fx, fy);
14,937✔
36
        }
37
        break;
14,939✔
38
    } 
39
    case SurfaceType::SPHERE:
79✔
40
        retval = nargs < 1 ? nullptr : make_surface<Sphere>(args[0]);
79✔
41
        break;
79✔
42
    case SurfaceType::HYPER:
4✔
43
    case SurfaceType::GENERAL_SPENCER_MURTY:
44
    case SurfaceType::TORUS:
45
    default:
46
        retval = nullptr; // Not implemented yet
4✔
47
        break;
4✔
48
    }
49

50
    return retval;
15,038✔
51
}
×
52

53
surface_ptr make_surface_from_json(const nlohmann::ordered_json& jnode)
2,437✔
54
{
55
    if (!jnode.contains("surface_type"))
2,437✔
56
        throw std::invalid_argument("Missing surface_type");
1✔
57
    std::string type_str = jnode.at("surface_type");
2,436✔
58
    SurfaceType surface_type = get_enum_from_string(type_str, SurfaceTypeMap, SurfaceType::SURFACE_UNKNOWN);
2,436✔
59
    if (surface_type == SurfaceType::SURFACE_UNKNOWN)
2,436✔
60
        throw std::invalid_argument("Unknown surface");
1✔
61
    switch (surface_type)
2,435✔
62
    {
63
        case SurfaceType::CONE:                 return make_surface<Cone>(jnode);
2✔
64
        case SurfaceType::CYLINDER:             return make_surface<Cylinder>(jnode);
3✔
65
        case SurfaceType::FLAT:                 return make_surface<Flat>(jnode);
6✔
66
        case SurfaceType::PARABOLA:             return make_surface<Parabola>(jnode);
2,372✔
67
        case SurfaceType::SPHERE:               return make_surface<Sphere>(jnode);
52✔
68
        default:
×
69
            throw std::invalid_argument("Unsupported surface_type: " + type_str);
×
70
    }
71
}
2,436✔
72

73
Cone::Cone(const nlohmann::ordered_json& jnode)
2✔
74
    : Surface(SurfaceType::CONE)
2✔
75
{
76
    this->half_angle = jnode.at("half_angle");
2✔
77
}
2✔
78

79
void Cone::write_json(nlohmann::ordered_json& jnode) const
×
80
{
81
    SurfaceType type = SurfaceType::CONE;
×
82
    jnode["surface_type"] = SurfaceTypeMap.at(type);
×
83
    jnode["half_angle"] = this->half_angle;
×
84
}
×
85

86
Cylinder::Cylinder(const nlohmann::ordered_json& jnode)
3✔
87
    : Surface(SurfaceType::CYLINDER)
3✔
88
{
89
    this->radius = jnode.at("radius");
3✔
90
}
3✔
91

92
void Cylinder::write_json(nlohmann::ordered_json& jnode) const
1✔
93
{
94
    SurfaceType type = SurfaceType::CYLINDER;
1✔
95
    jnode["surface_type"] = SurfaceTypeMap.at(type);
1✔
96
    jnode["radius"] = this->radius;
1✔
97
}
1✔
98

99
void Flat::write_json(nlohmann::ordered_json& jnode) const
6✔
100
{
101
    SurfaceType type = SurfaceType::FLAT;
6✔
102
    jnode["surface_type"] = SurfaceTypeMap.at(type);
6✔
103
}
6✔
104

105
Parabola::Parabola(const nlohmann::ordered_json& jnode)
2,372✔
106
    : Surface(SurfaceType::PARABOLA)
2,372✔
107
{
108
    this->focal_length_x = jnode.at("focal_length_x");
2,372✔
109
    this->focal_length_y = jnode.at("focal_length_y");
2,372✔
110
}
2,372✔
111

112
void Parabola::write_json(nlohmann::ordered_json& jnode) const
2,370✔
113
{
114
    SurfaceType type = SurfaceType::PARABOLA;
2,370✔
115
    jnode["surface_type"] = SurfaceTypeMap.at(type);
2,370✔
116
    jnode["focal_length_x"] = this->focal_length_x;
2,370✔
117
    jnode["focal_length_y"] = this->focal_length_y;
2,370✔
118
}
2,370✔
119

120
Sphere::Sphere(const nlohmann::ordered_json& jnode)
52✔
121
    : Surface(SurfaceType::SPHERE)
52✔
122
{
123
    this->vertex_curv = jnode.at("vertex_curv");
52✔
124
}
52✔
125

126
void Sphere::write_json(nlohmann::ordered_json& jnode) const
75✔
127
{
128
    SurfaceType type = SurfaceType::SPHERE;
75✔
129
    jnode["surface_type"] = SurfaceTypeMap.at(type);
75✔
130
    jnode["vertex_curv"] = this->vertex_curv;
75✔
131
}
75✔
132

NEW
133
double Cone::z(double x, double y) const {
×
NEW
134
    return sqrt(x * x + y * y) / tan(half_angle);
×
135
}
NEW
136
double Cylinder::z(double x, double) const {
×
137
    // TODO: Fix ? This is really only the top half of the cylinder
138
    //       Clyinder breaks the model since it is a mulit-valued fuction: each
139
    //       x values produces two z values Returning only the positive root
NEW
140
    return radius + sqrt(x * x + radius * radius);
×
141
}
NEW
142
double Parabola::z(double x, double y) const {
×
143
    // z(x,y) = (cx * x^2 + cy * y^2) / 2
NEW
144
    return x * x / focal_length_x + y * y / focal_length_y;
×
145
}
NEW
146
double Sphere::z(double x, double y) const {
×
147
    // TODO: Double-check: This provides only the bottom-half of the sphere,
148
    // aligning with the image in the documentation
149
    // TODO: Verify how vertex_curv relates to radius, i.e., vertex_curve = 1/r?
NEW
150
    return vertex_curv * (x * x + y * y) /
×
NEW
151
           (1 + sqrt(1 - vertex_curv * vertex_curv * (x * x + y * y)));
×
152
}
153

154
} // namespace SolTrace::Data
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc