Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
7970663
refactor(physics): move reference-ball drag constants to physics_cons…
gdifiore May 30, 2026
bdac903
Merge branch 'refactor/aero-context-dep' into development
gdifiore May 30, 2026
b27ddb4
feat(ball): add configurable BallProperties
gdifiore May 30, 2026
345f2af
Merge branch 'feat/ball-properties' into development
gdifiore May 30, 2026
e566cd7
fix(aero): make default Cd continuous at the low-Reynolds threshold
gdifiore May 30, 2026
ecac9f6
Merge branch 'fix/cd-smoothing' into development
gdifiore May 30, 2026
0038b87
refactor(physics): split overloaded MIN_VELOCITY_THRESHOLD by dimension
gdifiore May 30, 2026
fe6e5dc
Merge branch 'refactor/split-thresholds' into development
gdifiore May 30, 2026
a2db6ec
feat(atmos): default AtmosphericData to a sea-level standard day
gdifiore May 30, 2026
e746070
Merge branch 'feat/standard-atmosphere' into development
gdifiore May 30, 2026
5e80b76
feat(sim): make gravity configurable and wire it into flight integration
gdifiore May 30, 2026
2aff37b
Merge branch 'feat/gravity-wired' into development
gdifiore May 30, 2026
2532030
feat(build): export an installable CMake package with namespaced target
gdifiore May 30, 2026
0414843
Merge branch 'feat/cmake-export' into development
gdifiore May 30, 2026
6057bd5
refactor(flight): share the aero step instead of nesting AerialPhase …
gdifiore May 30, 2026
2ba8511
Merge branch 'refactor/denest-aerialphase' into development
gdifiore May 30, 2026
e883ff6
feat(flight): add a pluggable Integrator for the flight phases
gdifiore May 30, 2026
5f35e56
Merge branch 'feat/aerial-integrator' into development
gdifiore May 30, 2026
e4f3e86
build: drop redundant CMAKE_CXX_FLAGS_RELEASE override
gdifiore May 30, 2026
ef9a1ef
tidy: re-order main header
gdifiore May 30, 2026
b8a9c66
perf(flight): build the flight accel field once
gdifiore May 30, 2026
79ee0b0
version bump
gdifiore May 30, 2026
acae96e
fix: cppcheck, use const reference for atmospheric data
gdifiore May 30, 2026
7c4b26b
bump actions for nodejs 20 deprication
gdifiore May 30, 2026
b775ede
build: add -t/--test flag to run suite after build
gdifiore May 30, 2026
f9f6a8d
build: keep gtest out of the install prefix
gdifiore May 31, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build_and_test_libshotscope.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5

- name: Cache CMake build
uses: actions/cache@v4
uses: actions/cache@v5
with:
path: |
build
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ci-multi-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
compiler: default

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5

- name: Set up compiler (Linux)
if: runner.os == 'Linux' && matrix.compiler != 'default'
Expand All @@ -50,7 +50,7 @@ jobs:
fi

- name: Cache CMake build
uses: actions/cache@v4
uses: actions/cache@v5
with:
path: |
build
Expand Down Expand Up @@ -79,7 +79,7 @@ jobs:

- name: Upload build artifacts
if: matrix.os == 'ubuntu-latest' && matrix.compiler == 'gcc'
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v7
with:
name: libgolf-${{ runner.os }}
path: |
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/code-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5

- name: Install dependencies
run: |
Expand Down Expand Up @@ -50,13 +50,13 @@ jobs:
lcov --summary coverage.info 2>&1 | tee -a coverage-summary.txt

- name: Upload coverage HTML
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v7
with:
name: coverage-report
path: coverage_html/

- name: Upload coverage summary
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v7
with:
name: coverage-summary
path: coverage-summary.txt
10 changes: 5 additions & 5 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5

- name: Configure Pages
uses: actions/configure-pages@v5
uses: actions/configure-pages@v6

- name: Set up Emscripten
uses: mymindstorm/setup-emsdk@v14
uses: mymindstorm/setup-emsdk@v16

- name: Configure CMake (wasm preset)
run: cmake --preset wasm
Expand Down Expand Up @@ -63,7 +63,7 @@ jobs:
destination: ./_site

- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v3
uses: actions/upload-pages-artifact@v5
with:
path: _site

Expand All @@ -76,4 +76,4 @@ jobs:
url: ${{ steps.deployment.outputs.page_url }}
steps:
- id: deployment
uses: actions/deploy-pages@v4
uses: actions/deploy-pages@v5
10 changes: 5 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
platform: Windows

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5

- name: Get version from tag
id: get_version
Expand Down Expand Up @@ -64,7 +64,7 @@ jobs:
7z a ../libgolf-${{ matrix.platform }}-${{ steps.get_version.outputs.version }}.zip .

- name: Upload release assets
uses: softprops/action-gh-release@v2
uses: softprops/action-gh-release@v3
with:
files: libgolf-${{ matrix.platform }}-${{ steps.get_version.outputs.version }}.${{ matrix.archive_ext }}
body: |
Expand All @@ -81,14 +81,14 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5

- name: Get version from tag
id: get_version
run: echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT

- name: Set up Emscripten
uses: mymindstorm/setup-emsdk@v14
uses: mymindstorm/setup-emsdk@v16

- name: Configure CMake (wasm preset)
run: cmake --preset wasm
Expand All @@ -105,6 +105,6 @@ jobs:
zip -r ../libgolf-wasm-${{ steps.get_version.outputs.version }}.zip .

- name: Upload release assets
uses: softprops/action-gh-release@v2
uses: softprops/action-gh-release@v3
with:
files: libgolf-wasm-${{ steps.get_version.outputs.version }}.zip
8 changes: 4 additions & 4 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5

- name: Install dependencies
run: |
Expand All @@ -31,7 +31,7 @@ jobs:

- name: Upload clang-tidy report
if: always()
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v7
with:
name: clang-tidy-report
path: clang-tidy-report.txt
Expand All @@ -41,7 +41,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5

- name: Install cppcheck
run: |
Expand All @@ -62,7 +62,7 @@ jobs:

- name: Upload cppcheck report
if: always()
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v7
with:
name: cppcheck-report
path: cppcheck-report.txt
74 changes: 56 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.14)
project(golf VERSION 4.5.2 LANGUAGES CXX)
project(golf VERSION 4.6.0 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand All @@ -21,9 +21,6 @@ configure_file(
@ONLY
)

include_directories(${PROJECT_INCLUDE_DIR})
include_directories(${PROJECT_BINARY_DIR}/include)

set(SOURCES
${PROJECT_SRC_DIR}/math_utils.cpp
${PROJECT_SRC_DIR}/ShotPhysicsContext.cpp
Expand All @@ -41,38 +38,41 @@ set(HEADERS
${PROJECT_INCLUDE_DIR}/FlightPhase.hpp
${PROJECT_INCLUDE_DIR}/FlightSimulator.hpp
${PROJECT_INCLUDE_DIR}/BallState.hpp
${PROJECT_INCLUDE_DIR}/BallProperties.hpp
${PROJECT_INCLUDE_DIR}/ground_surface.hpp
${PROJECT_INCLUDE_DIR}/terrain_interface.hpp
${PROJECT_INCLUDE_DIR}/ground_physics.hpp
${PROJECT_INCLUDE_DIR}/physics_constants.hpp
${PROJECT_INCLUDE_DIR}/RollModel.hpp
${PROJECT_INCLUDE_DIR}/DefaultRollModel.hpp
${PROJECT_INCLUDE_DIR}/Integrator.hpp
${PROJECT_INCLUDE_DIR}/DefaultIntegrator.hpp
)

# Create the static library
add_library(${PROJECT_NAME} STATIC ${SOURCES} ${HEADERS})
add_library(golf::golf ALIAS ${PROJECT_NAME})

# Publish the include paths as usage requirements so in-tree targets and
# downstream consumers (find_package / add_subdirectory) both resolve headers.
target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${PROJECT_INCLUDE_DIR}>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:include>
)

# Set library version properties
set_target_properties(${PROJECT_NAME} PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
)

# Set compilation flags based on compiler
# No -ffast-math: -ffinite-math-only folds NaN comparisons to a constant and
# breaks the convergence guards that rely on `NaN <= height` staying false.
if(MSVC)
# MSVC-specific flags
set(CMAKE_CXX_FLAGS "/W4")
set(CMAKE_CXX_FLAGS_RELEASE "/O2")
else()
# GCC/Clang flags
set(CMAKE_CXX_FLAGS "-Wall -Wextra")
# No -ffast-math: it implies -ffinite-math-only, which lets the compiler
# assume NaN/Inf never occur and fold NaN comparisons to a constant. The
# convergence guards (FlightSimulator run loop + *Phase::isPhaseComplete)
# rely on IEEE semantics — `NaN <= height` must stay false so a poisoned
# trajectory never falsely "completes". Apple Clang folded it the other way,
# breaking the hang guards on macOS.
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
endif()

# Code coverage option
Expand All @@ -92,6 +92,7 @@ if(NOT EMSCRIPTEN)
GIT_TAG v1.17.0
)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
set(INSTALL_GTEST OFF) # keep gtest/gmock out of our install prefix
FetchContent_MakeAvailable(googletest)

# Enable testing
Expand Down Expand Up @@ -163,6 +164,43 @@ if(EMSCRIPTEN)
)
endif()

install(TARGETS golf DESTINATION lib)
install(DIRECTORY include/ DESTINATION include)
install(FILES "${PROJECT_BINARY_DIR}/include/version.hpp" DESTINATION include)
# ----------------------------------------------------------------------------
# Install + export: make find_package(golf) and the golf::golf target work for
# downstream projects.
# ----------------------------------------------------------------------------
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

install(TARGETS ${PROJECT_NAME}
EXPORT golfTargets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(FILES "${PROJECT_BINARY_DIR}/include/version.hpp"
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

set(GOLF_CMAKE_CONFIG_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/golf)

install(EXPORT golfTargets
FILE golfTargets.cmake
NAMESPACE golf::
DESTINATION ${GOLF_CMAKE_CONFIG_DIR}
)

configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/golfConfig.cmake.in"
"${PROJECT_BINARY_DIR}/golfConfig.cmake"
INSTALL_DESTINATION ${GOLF_CMAKE_CONFIG_DIR}
)
write_basic_package_version_file(
"${PROJECT_BINARY_DIR}/golfConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)
install(FILES
"${PROJECT_BINARY_DIR}/golfConfig.cmake"
"${PROJECT_BINARY_DIR}/golfConfigVersion.cmake"
DESTINATION ${GOLF_CMAKE_CONFIG_DIR}
)
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@ chmod +x build.sh
./build.sh
```

## Using libgolf in your project

After installing (`cmake --install build`), consume it from another CMake
project with `find_package`:

```cmake
find_package(golf REQUIRED)

add_executable(my_app main.cpp)
target_link_libraries(my_app PRIVATE golf::golf)
```

`golf::golf` carries its include paths, so `#include <libgolf.hpp>` works with
no extra configuration. The same target name is available via
`add_subdirectory(libgolf)` for in-tree builds.

## Features

- Full trajectory simulation with automatic phase transitions (aerial → bounce → roll)
Expand Down
12 changes: 12 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#!/bin/bash

RUN_TESTS=0
for arg in "$@"; do
case "$arg" in
-t|--test) RUN_TESTS=1 ;;
esac
done

# Use Clang if available and not overridden, otherwise use system default
if [ -z "$CC" ] && [ -z "$CXX" ]; then
if command -v clang &> /dev/null; then
Expand All @@ -23,6 +30,11 @@ cmake ..
# Build the project
cmake --build .

if [ "$RUN_TESTS" -eq 1 ]; then
echo "Running tests"
./libgolf_tests
fi

# Optionally install (uncomment if you want to install system-wide)
# echo "Installing to system directories (password may be required)"
# sudo cmake --install .
5 changes: 5 additions & 0 deletions cmake/golfConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/golfTargets.cmake")

check_required_components(golf)
Loading
Loading