Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
olbender committed Dec 7, 2018
1 parent 98e076a commit 2dd826d
Show file tree
Hide file tree
Showing 6 changed files with 13,011 additions and 2 deletions.
35 changes: 35 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Prerequisites
*.d

# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app

build

54 changes: 54 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#MIT License
#
# Copyright (c) 2018 Ola Benderius
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

cmake_minimum_required(VERSION 3.2)

project(splinetoolbox)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
if(NOT WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
-D_XOPEN_SOURCE=700 \
-D_FORTIFY_SOURCE=2 \
-O2 \
-fstack-protector \
-fomit-frame-pointer \
-pipe \
-pedantic -pedantic-errors \
-Werror \
-Weffc++ \
-Wall -Wextra -Wshadow -Wdeprecated \
-Wdiv-by-zero -Wfloat-equal -Wsign-compare -Wpointer-arith \
-Wuninitialized -Wunreachable-code \
-Wunused -Wunused-function -Wunused-label -Wunused-parameter -Wunused-but-set-parameter -Wunused-but-set-variable \
-Wunused-value -Wunused-variable -Wunused-result \
-Wmissing-field-initializers -Wmissing-format-attribute -Wmissing-include-dirs -Wmissing-noreturn")
endif()

include_directories(${CMAKE_CURRENT_SOURCE_DIR})

enable_testing()
add_executable(${PROJECT_NAME}-runner ${CMAKE_CURRENT_SOURCE_DIR}/test/test-splinetoolbox.cpp)
target_link_libraries(${PROJECT_NAME}-runner)
add_test(NAME ${PROJECT_NAME}-runner COMMAND ${PROJECT_NAME}-runner)

36 changes: 34 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,34 @@
# splinetoolbox
A simple header-only, single-file spline toolbox library for C++
## splinetoolbox: a simple header-only, single-file spline toolbox library for C++

[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)

splinetoolbox is a small and efficient library written in modern C++ library to provide functionality for working with splines

splinetoolbox is available as single-file, header-only library. Insert [splinetoolbox.hpp](https://raw.githubusercontent.com/olbender/splinetoolbox/master/splinetoolbox.hpp) into your project, `#include "splinetoolbox.hpp"`, and compile your project with a modern C++ compiler (C++11 or newer).


## Table of Contents
* [Features](#features)
* [Dependencies](#dependencies)
* [Contributing](#contributing)
* [License](#license)


## Features
* Written in highly portable and high quality C++11
* **Available as header-only, single-file distribution. Insert [splinetoolbox.hpp](https://raw.githubusercontent.com/olbender/splinetoolbox/master/splinetoolbox.hpp) into your project, `#include "splinetoolbox.hpp"`, and compile your project with a modern C++ compiler (C++11 or newer)**
* Catmull-Rom spline: `double curve = splinetoolbox::catmullrom(p0, p1, p2, p3, t);` where p[0–3] are the control points (can be x, y, z or anything else), and t is the distance between p1 (t = 0.0) and p2 (t = 1.0), assuming that the distance betwwen all four points are the same. p0 and p3 are virtual points for this single segment, but can be part of a larger spline.


## Dependencies
No dependencies! All you need is a C++11-compliant compiler as the project ships the following dependencies as part of the source distribution:

* [Unit Test Framework Catch2](https://github.com/catchorg/Catch2/releases/tag/v2.1.1) - [![License: Boost Software License v1.0](https://img.shields.io/badge/License-Boost%20v1-blue.svg)](http://www.boost.org/LICENSE_1_0.txt) - [Source](https://github.com/olbender/splinetoolbox/blob/master/test/catch.hpp)


## Installation
### Installation as single-file, header-only library
splinetoolbox is provided as header-only, single-file library as well. Insert [splinetoolbox.hpp](https://raw.githubusercontent.com/olbender/splinetoolbox/master/splinetoolbox.hpp) into your project, `#include "splinetoolbox.hpp"`, and compile your project with a modern C++ compiler (C++11 or newer)

## License
* This project is released under the terms of the MIT License - [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
60 changes: 60 additions & 0 deletions splinetoolbox.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* MIT License
*
* Copyright (c) 2018 Ola Benderius
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#ifndef SPLINETOOLBOX_HPP
#define SPLINETOOLBOX_HPP

#include <algorithm>
#include <string>
#include <vector>

namespace splinetoolbox {

/**
* @return double for the point on the Catmull-Rom spline given four control points and t=0.0 at p1 and t=1.0 at p2, assuming equal distance between points.
*/
inline double catmullrom(double p0, double p1, double p2, double p3, double t) noexcept
{
return p1 + 0.5 * (p2 - p0) * t + 0.5 * (4 * p2 + 2 * p0 - p3 - 5 * p1) * t * t + 0.5 * (3 * p1 + p3 - p0 - 3 * p2) * t * t * t;
}

/**
* @return double for first derivative for the Catmull-Rom spline
*/
inline double catmullrom_d(double p0, double p1, double p2, double p3, double t) noexcept
{
return 0.5 * (p2 - p0) + (4 * p2 + 2 * p0 - p3 - 5 * p1) * t + 1.5 * (3 * p1 + p3 - p0 - 3 * p2) * t * t;
}

/**
* @return double for second derivative for the Catmull-Rom spline
*/
inline double catmullrom_dd(double p0, double p1, double p2, double p3, double t) noexcept
{
return (4 * p2 + 2 * p0 - p3 - 5 * p1) + 3 * (3 * p1 + p3 - p0 - 3 * p2) * t;
}

}

#endif
Loading

0 comments on commit 2dd826d

Please sign in to comment.