Skip to content

Commit

Permalink
Add precommit
Browse files Browse the repository at this point in the history
  • Loading branch information
griswaldbrooks committed Sep 5, 2024
1 parent d1f48de commit 4a77769
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 28 deletions.
Empty file added .codespell_words
Empty file.
71 changes: 71 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# To use:
#
# pre-commit run -a
#
# Or:
#
# pre-commit install # (runs every time you commit in git)
#
# To update this file:
#
# pre-commit autoupdate
#
# See https://github.com/pre-commit/pre-commit

exclude: 'third_party/.*'
repos:
# Standard hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
hooks:
- id: check-added-large-files
args: ['--maxkb=1000']
- id: check-ast
- id: check-byte-order-marker
- id: check-builtin-literals
- id: check-case-conflict
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-json
- id: check-executables-have-shebangs
- id: pretty-format-json
- id: check-merge-conflict
- id: check-symlinks
- id: check-toml
- id: check-vcs-permalinks
- id: check-yaml
- id: debug-statements
- id: destroyed-symlinks
- id: detect-private-key
- id: end-of-file-fixer
- id: mixed-line-ending
- id: fix-byte-order-marker
- id: fix-encoding-pragma
- id: forbid-new-submodules
- id: mixed-line-ending
- id: name-tests-test
- id: no-commit-to-branch
- id: requirements-txt-fixer
- id: sort-simple-yaml
- id: trailing-whitespace

- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black

- repo: local
hooks:
- id: clang-format
name: clang-format
description: Format files with ClangFormat.
entry: clang-format
language: system
files: \.(c|cc|cxx|cpp|frag|glsl|h|hpp|hxx|ih|ispc|ipp|java|js|m|proto|vert)$
args: ['-fallback-style=none', '-i']

- repo: https://github.com/codespell-project/codespell
rev: v2.0.0
hooks:
- id: codespell
args: ['--write-changes', '--ignore-words=.codespell_words']
6 changes: 3 additions & 3 deletions include/tooly/tooly.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ auto transform_window(T const * begin, T const * end, F op) {
// Check that there are at least window_size elements in the collection
if constexpr (window_size > std::distance(begin, end)) {
// don't compile?
}
}
// Should we take a single span instead of two pointers?
// How will U be deduced?
// Should F be constrained using a concept or std::function?
Expand All @@ -31,7 +31,7 @@ auto transform_window(T const * begin, T const * end, F op) {
// current to window_size only known at compile time
// output.push_back(std::apply(op, std::range_n(begin, window_size)));
// begin = std::next(begin);
}
}
return output;
}

Expand All @@ -42,7 +42,7 @@ auto transform_window(T const * begin, T const * end, F op) {
* @tparam F type of binary operator
* @param begin
* @param end
* @param op binary operator that receives two T and returns U
* @param op binary operator that receives two T and returns U
*/
template <typename T, typename U, typename F>
auto transform_adjacent(T const * begin, T const * end, F op) {
Expand Down
6 changes: 3 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ struct robot_arm {
auto const result = std::stoi(serial_.readline());
if (result == 1) {
return bin_occupancy::OCCUPIED;
}
}
return bin_occupancy::EMPTY;
}

serial::Serial serial_;
};

Expand Down Expand Up @@ -82,7 +82,7 @@ struct bin_checker {
}
};

using bin_view = stdex::mdspan<bin_state,
using bin_view = stdex::mdspan<bin_state,
// We're treating our 6 bins as a 3x2 matrix
stdex::extents<uint32_t, 3, 2>,
// Our layout should do bounds-checking
Expand Down
44 changes: 22 additions & 22 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace geometry {

// Which direction to step towards for the x and y functions
int steps [2] = {sgn(deltas[0]), sgn(deltas[1])};

// Array that dictates the dominant direction
int idx [2] = {0};

Expand Down Expand Up @@ -117,7 +117,7 @@ namespace geometry {
return {};
}
// Get the interpolated pixels bresenham
const auto pixels = bresenham_conversion(start, end);
const auto pixels = bresenham_conversion(start, end);

return {pixels.begin(), pixels.begin() + std::min(static_cast<int>(pixels.size()),max_length)};

Expand All @@ -130,7 +130,7 @@ namespace geometry {
}

// The output vector of cells
std::vector<Cell> out;
std::vector<Cell> out;

// Iterator to the next vertex
auto next_vrtx = polygon.begin();
Expand All @@ -139,7 +139,7 @@ namespace geometry {
// If the next vertex is not the end iterator, advance the next_vertex to point to the next iterator
if (next_vrtx != polygon.end()) {
std::advance(next_vrtx,1);
}
}
// After advancing, if the iterator points to the end, go back to the beginning, essentially closing the polygon
if (next_vrtx == polygon.end()) {
next_vrtx = polygon.begin();
Expand All @@ -158,7 +158,7 @@ namespace geometry {

}
return out;
}
}

std::vector<Cell> convexFill(const std::vector<Cell>& polygon, window const& bounds) {
// we need a minimum polygon of a triangle
Expand All @@ -177,11 +177,11 @@ namespace geometry {
for (const auto pixel: outline) {
// Check if the x value for the pixel is in extrema
if (extrema.find(pixel.x) == extrema.end()) {
// if it isnt in extrema push the x in and with the y value as both the min and the max
// if it isn't in extrema push the x in and with the y value as both the min and the max
extrema[pixel.x] = {pixel.y, pixel.y};
} else if (pixel.y < extrema.at(pixel.x).first) { // If it get here that must mean the x value was found.
// if it is in extrema, check the y value. If the y value is lower than the minima,
// replace the first value, else if it is greater than the maxima, replace the second
// replace the first value, else if it is greater than the maxima, replace the second
// value, else do nothing
extrema.at(pixel.x).first = pixel.y;
} else if (pixel.y > extrema.at(pixel.x).second) {
Expand All @@ -204,7 +204,7 @@ namespace geometry {

return out;

}
}


double degrees_to_radians(double degrees) {
Expand Down Expand Up @@ -255,7 +255,7 @@ struct layout_rotatable {
auto ty = static_cast<double>(y);
double const alpha = -std::tan(theta_/2.);
double const beta = std::sin(theta_);
tx += std::round(alpha * ty);
tx += std::round(alpha * ty);
ty += std::round(beta * tx);
tx += std::round(alpha * ty);
x = static_cast<size_type>(std::round(tx)) + translation_.x;
Expand All @@ -271,7 +271,7 @@ struct layout_rotatable {
static constexpr bool is_always_unique() noexcept { return false; }
static constexpr bool is_always_exhaustive() noexcept { return true; }
static constexpr bool is_always_strided() noexcept { return false; }

constexpr bool is_unique() const noexcept { return false; }
constexpr bool is_exhaustive() const noexcept { return true; }
constexpr bool is_strided() const noexcept { return false; }
Expand All @@ -280,7 +280,7 @@ struct layout_rotatable {
window size_;
coordinate translation_;
double theta_;
extents_type extents_;
extents_type extents_;
};
};
template <std::size_t Height, std::size_t Width>
Expand Down Expand Up @@ -323,14 +323,14 @@ struct layout_polygonal {
static constexpr bool is_always_unique() noexcept { return false; }
static constexpr bool is_always_exhaustive() noexcept { return true; }
static constexpr bool is_always_strided() noexcept { return false; }

constexpr bool is_unique() const noexcept { return false; }
constexpr bool is_exhaustive() const noexcept { return true; }
constexpr bool is_strided() const noexcept { return false; }

private:
std::vector<geometry::Cell> polygon_;
extents_type extents_;
extents_type extents_;
};
};

Expand All @@ -351,7 +351,7 @@ struct occupancy_grid {
* @brief If requested window would go out of bounds, a smaller inbounds map is returned
*/
subgrid window_from_layout_stride(window size, coordinate corner) {
// If the corner is not within bounds, then there is nothing we can do
// If the corner is not within bounds, then there is nothing we can do
// return std expected error
corner.x = std::clamp(corner.x, std::size_t{0}, Width);
corner.y = std::clamp(corner.y, std::size_t{0}, Height);
Expand All @@ -372,7 +372,7 @@ struct occupancy_grid {
std::advance(first, row + col);
return {first, submap_layout};
}

subgrid window_from_layout_right(window size, coordinate corner) {
// Constrain the window to the grid map
corner.x = std::clamp(corner.x, std::size_t{0}, Width);
Expand Down Expand Up @@ -422,7 +422,7 @@ struct occupancy_grid {
private:
friend std::ostream& operator<<(std::ostream& os, occupancy_grid<Height, Width> const& occ){
for (auto i = 0u; i != occ.grid_.extent(0); i++) {
for (auto j = 0u; j != occ.grid_.extent(1); j++) {
for (auto j = 0u; j != occ.grid_.extent(1); j++) {
auto v = occ.grid_(i, j);
if (v == 0) {
os << ".";
Expand All @@ -441,11 +441,11 @@ struct occupancy_grid {
int main (int /* argc */, char** /* argv[] */) {
// height, width
auto map = occupancy_grid<20, 30>{};

// This one doesn't work. Show this as the negative example (both layout_right and layout_left)
auto window_bad = map.window_from_layout_right({5, 4}, {10, 15});
for (auto i = 0u; i != window_bad.extent(0); i++) {
for (auto j = 0u; j != window_bad.extent(1); j++) {
for (auto j = 0u; j != window_bad.extent(1); j++) {
window_bad(i, j) = 2;
}
}
Expand All @@ -455,7 +455,7 @@ int main (int /* argc */, char** /* argv[] */) {
// This doesn't feel quite right and need to explain why layout_left != layout_stride for this simple case
auto window = map.window_from_layout_stride({4, 4}, {5, 10});
for (auto i = 0u; i != window.extent(0); i++) {
for (auto j = 0u; j != window.extent(1); j++) {
for (auto j = 0u; j != window.extent(1); j++) {
// window(i, j) = 1;
}
}
Expand All @@ -464,15 +464,15 @@ int main (int /* argc */, char** /* argv[] */) {
auto local_map = map.window_submdspan({4, 4}, {10, 5});
std::cout << "local_map.extent = " << local_map.extent(0) << ", " << local_map.extent(1) << "\n";
for (auto i = 0u; i != local_map.extent(0); i++) {
for (auto j = 0u; j != local_map.extent(1); j++) {
for (auto j = 0u; j != local_map.extent(1); j++) {
// local_map(i, j) = 3;
}
}

int c = 1;
for (auto angle : {0, 12, 22, 30, 45, 58, 67, 79, 90}) {
// create footprint
// rotates around upper left corner
// rotates around upper left corner
std::vector<geometry::Cell> vertices = {{0,0},{3,0},{3,3},{0,3}};
// rotates somewhere around center
// std::vector<geometry::Cell> vertices = {{-2,-2},{3,-2},{3,3},{-2,3}};
Expand Down Expand Up @@ -513,7 +513,7 @@ int main (int /* argc */, char** /* argv[] */) {
}
std::cin.get();
}

int d = 1;
for (auto angle : {0, 12, 22, 30, 45, 58, 67, 79, 90}) {
double const theta = geometry::degrees_to_radians(angle);
Expand Down

0 comments on commit 4a77769

Please sign in to comment.