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

BlueBrain / MorphIO / 6533524408

16 Oct 2023 12:24PM UTC coverage: 76.051% (-0.02%) from 76.073%
6533524408

push

github

mgeplf
fix test_root_node_split

1972 of 2593 relevant lines covered (76.05%)

903.23 hits per line

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

21.25
/src/vasc/section.cpp
1
/* Copyright (c) 2013-2023, EPFL/Blue Brain Project
2
 *
3
 * SPDX-License-Identifier: Apache-2.0
4
 */
5
#include <iostream>
6

7
#include <morphio/vasc/section.h>
8

9
#include "../point_utils.h"
10

11
namespace morphio {
12
namespace vasculature {
13

14
using graph_iterator = graph_iterator_t<Section, Vasculature>;
15

16
Section::Section(uint32_t id, const std::shared_ptr<property::Properties>& properties)
6,160✔
17
    : id_(id)
18
    , properties_(properties) {
6,160✔
19
    const auto& sections = properties->get<property::VascSection>();
6,160✔
20
    if (id_ >= sections.size()) {
6,160✔
21
        throw RawDataError(
22
            "Requested section ID (" + std::to_string(id_) +
×
23
            ") is out of array bounds (array size = " + std::to_string(sections.size()) + ")");
×
24
    }
25
    const size_t start = sections[id_];
6,160✔
26
    const size_t end = id_ == sections.size() - 1 ? properties->get<property::Point>().size()
12,318✔
27
                                                  : sections[id_ + 1];
6,158✔
28
    range_ = std::make_pair(start, end);
6,160✔
29

30
    if (range_.second <= range_.first) {
6,160✔
31
        // TODO: shouldn't print to std::cerr
32
        std::cerr << "Dereferencing broken properties section " << id_
×
33
                  << "\nSection range: " << range_.first << " -> " << range_.second << '\n';
×
34
    }
35
}
6,160✔
36

37
Section& Section::operator=(const Section& section) {
×
38
    if (&section == this) {
×
39
        return *this;
×
40
    }
41
    id_ = section.id_;
×
42
    range_ = section.range_;
×
43
    properties_ = section.properties_;
×
44
    return *this;
×
45
}
46

47
bool Section::operator==(const Section& other) const {
×
48
    return other.id_ == id_ && other.properties_ == properties_;
×
49
}
50

51
bool Section::operator!=(const Section& other) const {
×
52
    return !(*this == other);
×
53
}
54

55
uint32_t Section::id() const noexcept {
×
56
    return id_;
×
57
}
58

59
template <typename TProperty>
60
range<const typename TProperty::Type> Section::get() const {
6,160✔
61
    const auto& data = properties_->get<TProperty>();
6,160✔
62
    if (data.empty()) {
6,160✔
63
        return range<const typename TProperty::Type>();
×
64
    }
65
    auto ptr_start = data.data() + range_.first;
6,160✔
66
    return range<const typename TProperty::Type>(ptr_start, range_.second - range_.first);
6,160✔
67
}
68

69
std::vector<Section> Section::predecessors() const {
×
70
    std::vector<Section> result;
×
71
    const auto it = properties_->predecessors().find(id_);
×
72
    if (it != properties_->predecessors().end()) {
×
73
        result.reserve(it->second.size());
×
74
        for (uint32_t id : it->second) {
×
75
            result.emplace_back(id, properties_);
×
76
        }
77
    }
78
    return result;
×
79
}
80

81
std::vector<Section> Section::successors() const {
×
82
    std::vector<Section> result;
×
83
    const auto it = properties_->successors().find(id_);
×
84
    if (it != properties_->successors().end()) {
×
85
        result.reserve(it->second.size());
×
86
        for (uint32_t id : it->second) {
×
87
            result.emplace_back(id, properties_);
×
88
        }
89
    }
90
    return result;
×
91
}
92

93
std::vector<Section> Section::neighbors() const {
×
94
    auto pre = this->predecessors();
×
95
    const auto& suc = this->successors();
×
96
    pre.reserve(pre.size() + suc.size());
×
97
    std::copy(suc.begin(), suc.end(), std::back_inserter(pre));
×
98
    return pre;
×
99
}
100

101
VascularSectionType Section::type() const {
×
102
    return properties_->get<property::SectionType>()[id_];
×
103
}
104

105
floatType Section::length() const {
×
106
    const auto& points_ = this->points();
×
107
    if (points_.size() < 2) {
×
108
        return 0;
×
109
    }
110

111
    size_t last = points_.size() - 1;
×
112
    return euclidean_distance(points_[0], points_[last]);
×
113
}
114

115
range<const Point> Section::points() const {
6,160✔
116
    return get<property::Point>();
6,160✔
117
}
118

119
range<const floatType> Section::diameters() const {
×
120
    return get<property::Diameter>();
×
121
}
122

123
bool Section::operator<(const Section& other) const {
×
124
    return this->id_ > other.id();
×
125
}
126

127
graph_iterator Section::begin() const {
×
128
    return graph_iterator(*this);
×
129
}
130

131
graph_iterator Section::end() const {
×
132
    return graph_iterator();
×
133
}
134
}  // namespace vasculature
135
}  // namespace morphio
136

137
std::ostream& operator<<(std::ostream& os, const morphio::vasculature::Section& section) {
×
138
    const auto& points = section.points();
×
139
    if (points.empty()) {
×
140
        os << "Section(id=" << section.id() << ", points=[])";
×
141
    } else {
142
        os << "Section(id=" << section.id() << ", points=[(" << points[0] << "),..., ("
×
143
           << points[points.size() - 1] << ")])";
×
144
    }
145
    return os;
×
146
}
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