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

NREL / SolTrace / 19578767093

21 Nov 2025 05:42PM UTC coverage: 89.226% (+0.4%) from 88.811%
19578767093

Pull #85

github

web-flow
Merge 7bb36476f into 1bb98f803
Pull Request #85: Add json import/export to SimulationData

416 of 443 new or added lines in 17 files covered. (93.91%)

6 existing lines in 2 files now uncovered.

5963 of 6683 relevant lines covered (89.23%)

8010941.34 hits per line

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

90.91
/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 ✔
NEW
68
        default:
×
NEW
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

NEW
79
void Cone::write_json(nlohmann::ordered_json& jnode) const
×
80
{
NEW
81
    SurfaceType type = SurfaceType::CONE;
×
NEW
82
    jnode["surface_type"] = SurfaceTypeMap.at(type);
×
NEW
83
    jnode["half_angle"] = this->half_angle;
×
NEW
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

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

© 2026 Coveralls, Inc