B-spline library with C++ backend
Project description
bspmap - B-spline Library
A high-performance B-spline library with C++ backend and Python bindings via ctypes.
Features
- Fast C++ implementation for B-spline computations
- Easy-to-use Python interface via ctypes
- Cross-platform support (Windows, Linux, macOS)
- Dynamic library (DLL/SO) for easy integration
- No compilation needed for Python package (pure Python wrapper)
- Comprehensive test suite
Project Structure
bspmap/
├── CMakeLists.txt # Root CMake configuration
├── pyproject.toml # Python package configuration
├── MANIFEST.in # Package manifest for Python distribution
├── copy_dll.py # Script to copy DLL for Python package
├── README.md # This file
├── src/
│ └── bspmap/ # C++ library source
│ ├── CMakeLists.txt # C++ library CMake configuration
│ ├── include/ # Public headers
│ │ ├── basisfunc.h
│ │ ├── bspmap.h
│ │ └── tensor.h
│ └── src/ # Implementation files
│ ├── basisfunc.cpp
│ ├── bspmap.cpp
│ └── tensor.cpp
├── python/
│ └── bspmap/ # Python package (ctypes wrapper)
│ ├── __init__.py
│ ├── bsp.py
│ ├── capi.py
│ └── bin/ # Binary files directory
├── cmake/
│ └── bspmapConfig.cmake.in # CMake package config template
├── docs/ # Documentation
├── tests/ # Test files
│ ├── test_bspmap.py
│ └── test_debug_cpp.py
└── build/ # Build output (generated)
├── bin/ # Executables and DLLs
├── lib/ # Libraries
└── CMakeFiles/ # CMake build files
Prerequisites
- CMake 3.16 or higher
- C++ compiler (GCC, Clang, MSVC)
- Python 3.8 or higher
- uv (recommended for Python package management) or pip
Building
1. Build C++ Library
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
cmake --build . --config Release
This will create bspmap.dll (Windows) or libbspmap.so (Linux/macOS) in build/bin/ or build/lib/.
CMake Options
CMAKE_BUILD_TYPE: Build type (Debug, Release, etc.)BUILD_SHARED_LIBS: Build as shared library (default: ON)BUILD_TESTS: Build C++ tests (default: OFF)
2. Install Python Package
# Using uv (recommended)
uv pip install -e .
# Or using pip
pip install -e .
The Python package will automatically find the DLL from the build directory during development.
Usage
Python
import bspmap
# Example usage (assuming the library provides these functions)
# Note: Update with actual API once implemented
# Get version
print(bspmap.get_version())
# Create a B-spline curve
# curve = bspmap.BSplineCurve(control_points, knots)
# result = curve.evaluate(t)
C++
#include <bspmap/bspmap.h>
// Example usage (assuming the library provides these classes)
// Note: Update with actual API once implemented
// Create a B-spline curve
// BSplineCurve curve(control_points, knots);
// double result = curve.evaluate(t);
Testing
Run the Python tests:
python -m pytest tests/
Or run specific test files:
python tests/test_bspmap.py
Development
Setting up Development Environment
# Clone or navigate to the project directory
cd bspmap
# Build C++ library
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug
cmake --build . --config Debug
cd ..
# Create virtual environment and install in editable mode
uv venv
# On Windows:
.venv\Scripts\activate
# On Unix:
source .venv/bin/activate
uv pip install -e .
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
License
[Specify your license here, e.g., MIT, BSD, etc.]
Contact
[Add contact information or issue tracker link]
source .venv/bin/activate # Linux/Mac
uv pip install -e ".[dev]"
Run tests
pytest
Format code (MSVC, GCC, Clang)
- Python >= 3.8 (for Python package)
- No additional dependencies for Python (uses standard library ctypes
## Python ctypes Wrapper Example
The Python package uses ctypes to call the C++ DLL. To add new functions:
1. **In C++ header** (`src/bspmap/include/bspmap/bspmap.h`):
```cpp
BSPMAP_API double evaluate_curve(const double* knots, int n_knots, double t);
- In Python wrapper (
python/bspmap/__init__.py):
# Declare function signature
_lib.evaluate_curve.argtypes = [
ctypes.POINTER(ctypes.c_double), # knots
ctypes.c_int, # n_knots
ctypes.c_double # t
]
_lib.evaluate_curve.restype = ctypes.c_double
# Create Python wrapper
def evaluate_curve(knots: list[float], t: float) -> float:
"""Evaluate B-spline curve at parameter t"""
knots_arr = (ctypes.c_double * len(knots))(*knots)
return _lib.evaluate_curve(knots_arr, len(knots), t)
black python/
ruff check python/
Requirements
- CMake >= 3.15
- C++17 compatible compiler
- Python >= 3.8 (for Python bindings)
- pybind11 >= 2.11.0 (automatically fetched if not found)
License
MIT License
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bspmap-0.1.0.tar.gz.
File metadata
- Download URL: bspmap-0.1.0.tar.gz
- Upload date:
- Size: 30.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
775b8bd509607e0b44f3711ab3897b3225bd27bc95ba32d11b5688e8cca6e8d8
|
|
| MD5 |
853c477eabc0d7348e14c2aa99ce7412
|
|
| BLAKE2b-256 |
4acbb0006ac51bb44830f3f1c0c5689edb9c220494e321509aa8b8b6b2db93e4
|
File details
Details for the file bspmap-0.1.0-py3-none-any.whl.
File metadata
- Download URL: bspmap-0.1.0-py3-none-any.whl
- Upload date:
- Size: 21.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f4c39e494a8098b21027a5b2ee4a50593cadd3adb917259ad02c3f3078c798d6
|
|
| MD5 |
a300b898df95f65b86c8623cb996c729
|
|
| BLAKE2b-256 |
831776c271c36d8dd43bc01ef9cacdc2d9980238a83eb91c823b5af7ce3bdcfc
|