Skip to content

Commit b447071

Browse files
committed
Add .clang-format
1 parent 828ee6c commit b447071

File tree

2 files changed

+85
-56
lines changed

2 files changed

+85
-56
lines changed

.clang-format

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
BasedOnStyle: Google
2+
3+
# Make it slightly more similar to Rust.
4+
# Based loosely on https://gist.github.com/YodaEmbedding/c2c77dc693d11f3734d78489f9a6eea4
5+
AccessModifierOffset: -2
6+
AlignAfterOpenBracket: BlockIndent
7+
AllowAllArgumentsOnNextLine: false
8+
AllowShortBlocksOnASingleLine: false
9+
AllowShortCaseLabelsOnASingleLine: false
10+
AllowShortFunctionsOnASingleLine: Empty
11+
AllowShortIfStatementsOnASingleLine: Never
12+
AlwaysBreakAfterReturnType: None
13+
AlwaysBreakBeforeMultilineStrings: true
14+
BinPackArguments: false
15+
ColumnLimit: 100
16+
ContinuationIndentWidth: 4
17+
EmptyLineBeforeAccessModifier: LogicalBlock
18+
IndentWidth: 4
19+
IndentWrappedFunctionNames: true
20+
InsertTrailingCommas: Wrapped
21+
MaxEmptyLinesToKeep: 1
22+
NamespaceIndentation: All
23+
PointerAlignment: Left
24+
ReflowComments: true
25+
SeparateDefinitionBlocks: Always
26+
SpacesBeforeTrailingComments: 1
27+
28+
# Don't change include blocks, we want to control this manually.
29+
# Sorting headers however is allowed as all our headers should be standalone.
30+
IncludeBlocks: Preserve
31+
SortIncludes: CaseInsensitive

src/main.cpp

Lines changed: 54 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -7,78 +7,76 @@
77
#include <rerun.hpp>
88

99
template <>
10-
struct rerun::ComponentBatchAdapter<rerun::components::Position3D,
11-
std::vector<Eigen::Vector3f>> {
12-
// Sanity check that this is binary compatible.
13-
static_assert(sizeof(components::Position3D) == sizeof(Eigen::Vector3f));
14-
static_assert(alignof(components::Position3D) <= alignof(Eigen::Vector3f));
10+
struct rerun::ComponentBatchAdapter<rerun::components::Position3D, std::vector<Eigen::Vector3f>> {
11+
// Sanity check that this is binary compatible.
12+
static_assert(sizeof(components::Position3D) == sizeof(Eigen::Vector3f));
13+
static_assert(alignof(components::Position3D) <= alignof(Eigen::Vector3f));
1514

16-
ComponentBatch<components::Position3D>
17-
operator()(const std::vector<Eigen::Vector3f> &container) {
18-
return ComponentBatch<components::Position3D>::borrow(
19-
reinterpret_cast<const components::Position3D *>(container.data()),
20-
container.size());
21-
}
15+
ComponentBatch<components::Position3D> operator()(const std::vector<Eigen::Vector3f> &container
16+
) {
17+
return ComponentBatch<components::Position3D>::borrow(
18+
reinterpret_cast<const components::Position3D *>(container.data()),
19+
container.size()
20+
);
21+
}
2222

23-
ComponentBatch<components::Position3D>
24-
operator()(std::vector<Eigen::Vector3f> &&container) {
25-
throw std::runtime_error("Not implemented for temporaries");
26-
}
23+
ComponentBatch<components::Position3D> operator()(std::vector<Eigen::Vector3f> &&container) {
24+
throw std::runtime_error("Not implemented for temporaries");
25+
}
2726
};
2827

2928
template <>
30-
struct rerun::ComponentBatchAdapter<rerun::components::Position3D,
31-
Eigen::MatrixX3f> {
32-
// Sanity check that this is binary compatible.
33-
static_assert(sizeof(components::Position3D) ==
34-
sizeof(Eigen::MatrixX3f::Scalar) *
35-
Eigen::MatrixX3f::ColsAtCompileTime);
36-
static_assert(alignof(components::Position3D) <= alignof(Eigen::MatrixX3f));
29+
struct rerun::ComponentBatchAdapter<rerun::components::Position3D, Eigen::MatrixX3f> {
30+
// Sanity check that this is binary compatible.
31+
static_assert(
32+
sizeof(components::Position3D) ==
33+
sizeof(Eigen::MatrixX3f::Scalar) * Eigen::MatrixX3f::ColsAtCompileTime
34+
);
35+
static_assert(alignof(components::Position3D) <= alignof(Eigen::MatrixX3f));
3736

38-
ComponentBatch<components::Position3D>
39-
operator()(const Eigen::MatrixX3f &matrix) {
40-
return ComponentBatch<components::Position3D>::borrow(
41-
reinterpret_cast<const components::Position3D *>(matrix.data()),
42-
matrix.rows());
43-
}
37+
ComponentBatch<components::Position3D> operator()(const Eigen::MatrixX3f &matrix) {
38+
return ComponentBatch<components::Position3D>::borrow(
39+
reinterpret_cast<const components::Position3D *>(matrix.data()),
40+
matrix.rows()
41+
);
42+
}
4443

45-
ComponentBatch<components::Position3D>
46-
operator()(std::vector<Eigen::MatrixX3f> &&container) {
47-
throw std::runtime_error("Not implemented for temporaries");
48-
}
44+
ComponentBatch<components::Position3D> operator()(std::vector<Eigen::MatrixX3f> &&container) {
45+
throw std::runtime_error("Not implemented for temporaries");
46+
}
4947
};
5048

5149
std::vector<Eigen::Vector3f> generate_random_points_vector(int num_points) {
52-
std::vector<Eigen::Vector3f> points(num_points);
53-
for (auto &point : points) {
54-
point.setRandom();
55-
}
56-
return points;
50+
std::vector<Eigen::Vector3f> points(num_points);
51+
for (auto &point : points) {
52+
point.setRandom();
53+
}
54+
return points;
5755
}
5856

5957
int main() {
60-
auto rec = rerun::RecordingStream("rerun_cpp_example_opencv_eigen");
61-
rec.connect("127.0.0.1:9876").throw_on_failure();
58+
auto rec = rerun::RecordingStream("rerun_cpp_example_opencv_eigen");
59+
rec.connect("127.0.0.1:9876").throw_on_failure();
6260

63-
const int num_points = 1000;
61+
const int num_points = 1000;
6462

65-
// Points represented by std::vector<Eigen::Vector3f>
66-
auto points3d_vector = generate_random_points_vector(1000);
67-
rec.log("points_from_vector", rerun::Points3D(points3d_vector));
63+
// Points represented by std::vector<Eigen::Vector3f>
64+
auto points3d_vector = generate_random_points_vector(1000);
65+
rec.log("points_from_vector", rerun::Points3D(points3d_vector));
6866

69-
// Points represented by Eigen::MatX3f (Nx3 matrix)
70-
Eigen::MatrixX3f points3d_matrix = Eigen::MatrixX3f::Random(num_points, 3);
71-
rec.log("points_from_matrix", rerun::Points3D(points3d_matrix));
67+
// Points represented by Eigen::MatX3f (Nx3 matrix)
68+
Eigen::MatrixX3f points3d_matrix = Eigen::MatrixX3f::Random(num_points, 3);
69+
rec.log("points_from_matrix", rerun::Points3D(points3d_matrix));
7270

73-
// Image
74-
std::string image_path = "rerun-logo.png";
75-
cv::Mat img = imread(image_path, cv::IMREAD_COLOR);
76-
if (img.empty()) {
77-
std::cout << "Could not read the image: " << image_path << std::endl;
78-
return 1;
79-
}
80-
imshow("Display window", img);
81-
cv::waitKey(0);
71+
// Image
72+
std::string image_path = "rerun-logo.png";
73+
cv::Mat img = imread(image_path, cv::IMREAD_COLOR);
74+
if (img.empty()) {
75+
std::cout << "Could not read the image: " << image_path << std::endl;
76+
return 1;
77+
}
78+
imshow("Display window", img);
79+
cv::waitKey(0);
8280

83-
return 0;
81+
return 0;
8482
}

0 commit comments

Comments
 (0)