Skip to content

Commit

Permalink
Merge pull request #51 from BardoBard/hotfix
Browse files Browse the repository at this point in the history
Hotfix
  • Loading branch information
BardoBard authored Jul 13, 2024
2 parents 8c49829 + 021da63 commit 8296f20
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 23 deletions.
36 changes: 19 additions & 17 deletions Bardrix/include/bardrix/algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ namespace bardrix {
/// 1
/// \note Use this function for a balanced binary tree.
/// \details O(n) time complexity assuming the values are sorted.
void build(const T* values, std::size_t size) noexcept;
void build(const T* values, std::size_t size);

/// \brief Builds a balanced binary tree from the given values. \n
/// For a balanced tree the values should be sorted in ascending order. (e.g 1, 2, 3, 4, 5, 6, 7, 8) \n
Expand All @@ -109,7 +109,7 @@ namespace bardrix {
/// \note Use this function for a balanced binary tree.
/// \details O(n) time complexity assuming the values are sorted.
template<typename Iterator, typename = std::enable_if_t<std::is_same_v<T, typename std::iterator_traits<Iterator>::value_type>>>
void build(Iterator begin, Iterator end) noexcept;
void build(Iterator begin, Iterator end);

/// \brief Builds a balanced binary tree from the given values. \n
/// For a balanced tree the values should be sorted in ascending order. (e.g 1, 2, 3, 4, 5, 6, 7, 8) \n
Expand Down Expand Up @@ -187,7 +187,7 @@ namespace bardrix {
/// \note Do not use this function for a balanced binary tree, use the build function instead.
/// \details O(log n) time complexity assuming the binary tree is balanced. \n
/// O(n) time complexity in the worst case (when the tree is unbalanced).
void insert(const T* values, std::size_t size) noexcept;
void insert(const T* values, std::size_t size);

/// \brief Inserts the given values into the binary tree. \n
/// The values are inserted in the order they are given. \n
Expand All @@ -208,7 +208,7 @@ namespace bardrix {
/// \details O(log n) time complexity assuming the binary tree is balanced. \n
/// O(n) time complexity in the worst case (when the tree is unbalanced).
template<typename Iterator, typename = std::enable_if_t<std::is_same_v<T, typename std::iterator_traits<Iterator>::value_type>>>
void insert(Iterator begin, Iterator end) noexcept;
void insert(Iterator begin, Iterator end);

/// \brief Deletes a node from the binary tree. \n
/// The node is replaced with a bigger value from the right child or a smaller value from the left child. \n
Expand Down Expand Up @@ -496,7 +496,7 @@ namespace bardrix {
template<typename Iterator, typename = std::enable_if_t<
std::is_base_of_v<bardrix::shape, typename std::iterator_traits<Iterator>::value_type::element_type> &&
std::is_same_v<std::shared_ptr<typename std::iterator_traits<Iterator>::value_type::element_type>, typename std::iterator_traits<Iterator>::value_type>>>
void construct_longest_axis(const Iterator& begin, const Iterator& end) noexcept;
void construct_longest_axis(const Iterator& begin, const Iterator& end);

/// \brief Gives all the shapes that intersect with the given ray, in the form of out_hits.
/// \param ray The ray to check for intersections with the shapes.
Expand Down Expand Up @@ -525,7 +525,7 @@ namespace bardrix {
template<typename Iterator, typename = std::enable_if_t<
std::is_base_of_v<bardrix::shape, typename std::iterator_traits<Iterator>::value_type::element_type> &&
std::is_same_v<std::shared_ptr<typename std::iterator_traits<Iterator>::value_type::element_type>, typename std::iterator_traits<Iterator>::value_type>>>
void construct_longest_axis(std::unique_ptr<bvh_tree::node>& current, const Iterator& begin, const Iterator& end) noexcept;
void construct_longest_axis(std::unique_ptr<bvh_tree::node>& current, const Iterator& begin, const Iterator& end);

/// \brief Gives all the shapes that intersect with the given ray, in the form of out_hits. \n
/// This function is a helper function for the public intersect function.
Expand All @@ -552,15 +552,17 @@ namespace bardrix {

template<typename T>
template<typename Iterator, typename>
void binary_tree<T>::build(const Iterator begin, const Iterator end) noexcept {
void binary_tree<T>::build(const Iterator begin, const Iterator end) {
clear();
if (begin >= end) return;

build(&(*begin), std::distance(begin, end));
}

template<typename T>
void binary_tree<T>::build(const T* values, std::size_t size) noexcept {
void binary_tree<T>::build(const T* values, std::size_t size) {
clear();
if (size == 0) return;
if (size == 0 || values == nullptr) return;

std::size_t mid = size / 2;
root = std::make_unique<node>(values[mid]);
Expand All @@ -584,16 +586,17 @@ namespace bardrix {
}

template<typename T>
void binary_tree<T>::insert(const T* values, std::size_t size) noexcept {
void binary_tree<T>::insert(const T* values, std::size_t size) {
if (values == nullptr) return;

if (!root && size > 0) { // If the tree is empty
root = std::make_unique<node>(values[0]);
++values;
--size;
}

for (std::size_t i = 0; i < size; ++i) {
for (std::size_t i = 0; i < size; ++i)
insert(root, values[i]);
}
}

template<typename T>
Expand All @@ -605,7 +608,7 @@ namespace bardrix {

template<typename T>
template<typename Iterator, typename>
void binary_tree<T>::insert(Iterator begin, Iterator end) noexcept {
void binary_tree<T>::insert(Iterator begin, Iterator end) {
if (begin >= end) return;
insert(&(*begin), std::distance(begin, end));
}
Expand Down Expand Up @@ -728,7 +731,7 @@ namespace bardrix {
// helper function for build
template<typename T>
void binary_tree<T>::build(std::unique_ptr<node>& current, const T* values, std::size_t size) {
if (size == 0) return;
if (size == 0 || values == nullptr) return;
if (size == 1) {
current = std::make_unique<node>(values[0]);
return;
Expand Down Expand Up @@ -797,7 +800,7 @@ namespace bardrix {
// bvh_tree implementation start

template<typename Iterator, typename>
void bvh_tree::construct_longest_axis(const Iterator& begin, const Iterator& end) noexcept {
void bvh_tree::construct_longest_axis(const Iterator& begin, const Iterator& end) {
clear();
if (begin >= end) return;

Expand All @@ -823,8 +826,7 @@ namespace bardrix {

// helper function for construct_longest_axis
template<typename Iterator, typename>
void bvh_tree::construct_longest_axis(std::unique_ptr<bvh_tree::node>& current, const Iterator& begin,
const Iterator& end) noexcept {
void bvh_tree::construct_longest_axis(std::unique_ptr<bvh_tree::node>& current, const Iterator& begin, const Iterator& end) {
if (begin >= end) {
current = nullptr;
return;
Expand Down
6 changes: 5 additions & 1 deletion Bardrix_Tests/tests/algorithm_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ TEST(binary_tree, build_iterators) {
// 2 10 12 14 62 64 66 68
std::vector<int> values2 = { 2, 9, 10, 11, 12, 13, 14, 24, 62, 63, 64, 65, 66, 67, 68 };

tree.build(values2.begin(), values2.end());
tree.build(values2.begin(), values2.begin() - 1);
tree.build(values2.begin(), values2.end());

EXPECT_EQ(tree.root->data, 24);
EXPECT_EQ(tree.root->left->data, 11);
Expand Down Expand Up @@ -141,6 +141,10 @@ TEST(binary_tree, build_array) {
EXPECT_EQ(tree.root->left->right->data, 4);
EXPECT_EQ(tree.root->left->left->data, 2);
EXPECT_EQ(tree.root->left->left->left->data, 1);

tree.build(nullptr, 1);

EXPECT_EQ(tree.root, nullptr);
}

/// \brief Test the building of a binary tree, with multiple values
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.27)
project(Bardrix)
set(BARDRIX_VERSION 0.4.1)
set(BARDRIX_VERSION 0.4.2)

# Set C++ standard
set(CMAKE_CXX_STANDARD 17)
Expand Down
2 changes: 1 addition & 1 deletion Docs/Examples/Introduction/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ include(FetchContent) # Include the FetchContent module
FetchContent_Declare(
Bardrix
GIT_REPOSITORY https://github.com/bardobard/Bardrix.git
GIT_TAG v0.4.0
GIT_TAG v0.4.2
)

FetchContent_MakeAvailable(Bardrix)
Expand Down
4 changes: 4 additions & 0 deletions Docs/Examples/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Examples

- [Introduction](Introduction/README.md)
- [Raytracing (Basics)](Raytracing/README.md)
- [Raytracing (Phong)](Raytracing-Reflections/README.md)

This folder contains examples of how to use Bardrix in a simple raytracing application. The examples are meant to be
simple and easy to understand for students who are learning about raytracing. \
Build using Cmake and run the executable to see the output.
2 changes: 1 addition & 1 deletion Docs/Examples/Raytracing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ include(FetchContent) # Include the FetchContent module
FetchContent_Declare(
Bardrix
GIT_REPOSITORY https://github.com/bardobard/Bardrix.git
GIT_TAG v0.4.0
GIT_TAG v0.4.2
)

FetchContent_MakeAvailable(Bardrix)
Expand Down
Binary file added Docs/Images/visual_studio_cpp_version.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Docs/Images/visual_studio_properties.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 11 additions & 2 deletions Docs/Installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Assuming you follow this guide, you will be able to use Bardrix in your project
#include <iostream>

int main(){
std::cout << bardrix::vector3(1,2,3) << std::endl;
std::cout << bardrix::vector3(1, 2, 3) << std::endl;
}
```

Expand Down Expand Up @@ -68,7 +68,7 @@ include(FetchContent) # Include the FetchContent module
FetchContent_Declare(
Bardrix
GIT_REPOSITORY https://github.com/bardobard/Bardrix.git
# GIT_TAG comes here # e.g. v0.0.4
# GIT_TAG v0.4.2 # Set the tag to a specific version (optional)
)
FetchContent_MakeAvailable(Bardrix)
Expand All @@ -92,6 +92,15 @@ You can search for Bardio.Bardrix and install it, everything will be set up for

![nuget_package_manager_install.png](Images/nuget_package_manager_install.png)

Make sure the c++ version is set to 17 or higher in your project settings, you can do this by right-clicking on your
project and selecting properties. Then go to C/C++ -> Language and set the C++ Language Standard to C++17 or higher.

![visual_studio_properties.png](Images/visual_studio_properties.png)

![visual_studio_cpp_version.png](Images/visual_studio_cpp_version.png)

Then click apply/ok and you are ready to use Bardrix in your project.

## Manual

You can also download the source code and include it in your project manually. This is not recommended as it is harder
Expand Down
21 changes: 21 additions & 0 deletions Docs/Release_Notes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
# [v0.4.2](https://github.com/BardoBard/Bardrix/releases/tag/v0.4.2)

**Full Changelog**: https://github.com/BardoBard/Bardrix/compare/v0.4.1...v0.4.2

## Overview

Fixed noexcept edge cases for `binary_tree`. \
Updated installation guide to include C++17+ requirement.

## Documentation Changes

Added C++17+ requirement to [Installation](https://github.com/bardobard/bardrix/blob/v0.4.2/Docs/Installation.md). \
Added table of contents to Examples for navigation.

## Code Changes

### Minor Changes

Removed `noexcept` from `binary_tree` to avoid crashes on edge cases (e.g. `tree.build(v.begin() - 1, v.end())`). \
Added `clear()` to `build(Iterator begin, Iterator end)` in `binary_tree` to avoid not clearing if begin >= end.

# [v0.4.1](https://github.com/BardoBard/Bardrix/releases/tag/v0.4.1)

**Full Changelog**: https://github.com/BardoBard/Bardrix/compare/v0.4.0...v0.4.1
Expand Down

0 comments on commit 8296f20

Please sign in to comment.