### Compile and Install Bezier Binary Extension Source: https://github.com/dhermes/bezier/blob/main/docs/development.rst Commands to compile and install the bezier Python binary extension after libbezier has been built and installed. It shows options for using pip wheel, pip install, and direct setup.py commands. The BEZIER_INSTALL_PREFIX environment variable should point to the libbezier installation directory. ```console # One of $ BEZIER_INSTALL_PREFIX=.../usr/ python -m pip wheel . $ BEZIER_INSTALL_PREFIX=.../usr/ python -m pip install . $ BEZIER_INSTALL_PREFIX=.../usr/ python setup.py build_ext $ BEZIER_INSTALL_PREFIX=.../usr/ python setup.py build_ext --inplace ``` -------------------------------- ### Add BEZIER_JOURNAL Option to setup.py (Shell) Source: https://github.com/dhermes/bezier/blob/main/docs/releases/0.5.0.rst Example of how to add a custom option to setup.py for controlling the recording of compiler commands during installation. This is useful for debugging build issues. ```bash # Example snippet within setup.py from setuptools import setup setup( # ... other setup arguments ... options={ 'build_ext': { 'bezier_journal': 'True' # or 'False' to disable } } ) ``` -------------------------------- ### Installation Rules for Bezier Library Source: https://github.com/dhermes/bezier/blob/main/src/fortran/CMakeLists.txt Defines how the 'bezier' library and its associated files are installed. It specifies installation destinations for runtime binaries, libraries, archives, headers, and CMake export files using standard CMake installation directories. ```cmake include(GNUInstallDirs) install( TARGETS bezier EXPORT BezierConfig RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) install(EXPORT BezierConfig DESTINATION share/bezier/cmake) export(TARGETS bezier FILE BezierConfig.cmake) # Restore all Fortran flags. set(CMAKE_Fortran_FLAGS ${OLD_CMAKE_Fortran_FLAGS}) set(CMAKE_Fortran_FLAGS_DEBUG ${OLD_CMAKE_Fortran_FLAGS_DEBUG}) set(CMAKE_Fortran_FLAGS_RELEASE ${OLD_CMAKE_Fortran_FLAGS_RELEASE}) unset(OLD_CMAKE_Fortran_FLAGS) unset(OLD_CMAKE_Fortran_FLAGS_DEBUG) unset(OLD_CMAKE_Fortran_FLAGS_RELEASE) ``` -------------------------------- ### Build and Install Bezier Fortran Library with CMake Source: https://github.com/dhermes/bezier/blob/main/docs/abi/installation.rst Commands to build and install the Fortran shared library using CMake. It requires a full checkout of the Fortran source code. The installation prefix can be customized. ```console $ SRC_DIR="src/fortran/" $ BUILD_DIR=".../libbezier-release/build" $ INSTALL_PREFIX=".../libbezier-release/usr" $ mkdir -p "${BUILD_DIR}" $ cmake \ > -DCMAKE_BUILD_TYPE=Release \ > -DCMAKE_INSTALL_PREFIX:PATH="${INSTALL_PREFIX}" \ > -S "${SRC_DIR}" \ > -B "${BUILD_DIR}" $ cmake \ > --build "${BUILD_DIR}" \ > --config Release \ > --target install ``` -------------------------------- ### Verify Bezier Library Installation (Linux) Source: https://github.com/dhermes/bezier/blob/main/docs/abi/installation.rst Verifies the installed artifacts of the Bezier library on a Linux system using a doctest. It checks for shared libraries and header files in the specified installation prefix. ```python import os import tests.utils install_prefix = os.environ["BEZIER_INSTALL_PREFIX"] print_tree = tests.utils.print_tree >>> print_tree(install_prefix) usr/ include/ bezier/ curve.h curve_intersection.h helpers.h status.h triangle.h triangle_intersection.h bezier.h lib/ libbezier.so -> libbezier.so.2024 libbezier.so.2024 -> libbezier.so.2024.6.20 libbezier.so.2024.6.20 share/ bezier/ cmake/ BezierConfig-release.cmake BezierConfig.cmake ``` -------------------------------- ### Verify Bezier Library Installation (Windows) Source: https://github.com/dhermes/bezier/blob/main/docs/abi/installation.rst Verifies the installed artifacts of the Bezier library on a Windows system using a doctest. It checks for DLLs, import libraries, and header files in the specified installation prefix. ```python import os import tests.utils install_prefix = os.environ["BEZIER_INSTALL_PREFIX"] print_tree = tests.utils.print_tree >>> print_tree(install_prefix) usr\ bin\ bezier.dll include\ bezier\ curve.h curve_intersection.h helpers.h status.h triangle.h triangle_intersection.h bezier.h lib\ bezier.lib share\ bezier\ cmake\ BezierConfig-release.cmake BezierConfig.cmake ``` -------------------------------- ### Verify Bezier Library Installation (macOS) Source: https://github.com/dhermes/bezier/blob/main/docs/abi/installation.rst Verifies the installed artifacts of the Bezier library on a macOS system using a doctest. It checks for dynamic libraries and header files in the specified installation prefix. ```python import os import tests.utils install_prefix = os.environ["BEZIER_INSTALL_PREFIX"] print_tree = tests.utils.print_tree >>> print_tree(install_prefix) usr/ include/ bezier/ curve.h curve_intersection.h helpers.h status.h triangle.h triangle_intersection.h bezier.h lib/ libbezier.2024.6.20.dylib libbezier.2024.dylib -> libbezier.2024.6.20.dylib libbezier.dylib -> libbezier.2024.dylib share/ bezier/ cmake/ BezierConfig-release.cmake BezierConfig.cmake ``` -------------------------------- ### Python Example: Displaying Library Path (doctest) Source: https://github.com/dhermes/bezier/blob/main/docs/python/binary-extension.rst A Python doctest example demonstrating how to access and display the path to a directory containing dynamic libraries on macOS. ```python dylib_path = ".../site-packages/bezier/.dylibs" print_tree(dylib_path) ``` -------------------------------- ### Install bezier Python Package Source: https://github.com/dhermes/bezier/blob/main/docs/index.rst Installs the bezier Python package using pip, including options for upgrading, installing optional dependencies like SymPy, and installing a pure Python version without binary extensions. ```console $ python -m pip install --upgrade bezier $ python3.12 -m pip install --upgrade bezier $ # To install optional dependencies, e.g. SymPy $ python -m pip install --upgrade bezier[full] To install a pure Python version (i.e. with no binary extension): $ BEZIER_NO_EXTENSION=true \ > python -m pip install --upgrade bezier --no-binary=bezier ``` -------------------------------- ### Python Example: Displaying Library Path (doctest) - Windows Source: https://github.com/dhermes/bezier/blob/main/docs/python/binary-extension.rst A Python doctest example showing how to access and display the path to a directory containing libraries on Windows. ```python libs_directory = "...\site-packages\bezier.libs" print_tree(libs_directory) ``` -------------------------------- ### Google-Style Docstring Example (reStructuredText) Source: https://github.com/dhermes/bezier/blob/main/docs/development.rst An example of a Python docstring following the Google style guide, including argument and return type descriptions. This format is compatible with Sphinx via the Napoleon extension. ```rest Args: path (str): The path of the file to wrap field_storage (FileStorage): The :class:`FileStorage` instance to wrap temporary (bool): Whether or not to delete the file when the File instance is destructed Returns: BufferedFileStorage: A buffered writable file descriptor ``` -------------------------------- ### Compile and run ABI examples in doctest Source: https://github.com/dhermes/bezier/blob/main/docs/releases/2020.2.3.rst Compiles and runs C ABI example code (example_*.c) in doctest on Linux and macOS as part of CI. This verifies the C API's functionality. ```shell # Example CI step (conceptual) # cd examples/c # make # python -m doctest example_api.py ``` -------------------------------- ### Compile and run Bezier curve example Source: https://github.com/dhermes/bezier/blob/main/docs/abi/curve.rst Compiles and runs a C example program to demonstrate locating a point on a Bezier curve. It requires the bezier library and its include/library paths. ```c #include #include int main() { // Example usage of Bezier curve functions would go here printf("This is a placeholder for example_locate_point_curve.c\n"); return 0; } ``` -------------------------------- ### Documenting C ABI: bezier/surface.h Source: https://github.com/dhermes/bezier/blob/main/docs/releases/0.9.0.rst Documents the C ABI for the 'surface' module, corresponding to the 'bezier/surface.h' header file. Includes C examples for each routine. ```c // Example for routines in bezier/surface.h // (Actual code not provided in the input text) ``` -------------------------------- ### Install Bezier Python Package with Pip Source: https://github.com/dhermes/bezier/blob/main/README.rst Installs or upgrades the 'bezier' Python package using pip. It also shows how to install optional dependencies like SymPy and how to install a pure Python version without binary extensions. ```console $ python -m pip install --upgrade bezier $ python3.12 -m pip install --upgrade bezier $ # To install optional dependencies, e.g. SymPy $ python -m pip install --upgrade bezier[full] ``` ```console $ BEZIER_NO_EXTENSION=true \ > python -m pip install --upgrade bezier --no-binary=bezier ``` -------------------------------- ### Documenting C ABI: bezier/curve.h Source: https://github.com/dhermes/bezier/blob/main/docs/releases/0.9.0.rst Documents the C ABI for the 'curve' module, corresponding to the 'bezier/curve.h' header file. Includes C examples for each routine. ```c // Example for routines in bezier/curve.h // (Actual code not provided in the input text) ``` -------------------------------- ### Compile bezier Binary Extension Source: https://github.com/dhermes/bezier/blob/main/DEVELOPMENT.rst Commands to compile the bezier binary extension after building and installing libbezier. Supports building wheel, installing, or building the extension directly. ```console # One of BEZIER_INSTALL_PREFIX=.../usr/ python -m pip wheel . BEZIER_INSTALL_PREFIX=.../usr/ python -m pip install . BEZIER_INSTALL_PREFIX=.../usr/ python setup.py build_ext BEZIER_INSTALL_PREFIX=.../usr/ python setup.py build_ext --inplace ``` -------------------------------- ### Install MinGW-w64 Toolchain on Windows Source: https://github.com/dhermes/bezier/blob/main/DEVELOPMENT.rst Installs the MinGW-w64 toolchain using pacman on Windows for Fortran compilation. Requires MSYS2. ```powershell > pacman -S --needed base-devel mingw-w64-x86_64-toolchain ``` -------------------------------- ### Build and Run C Example: Elevate Nodes Curve Source: https://github.com/dhermes/bezier/blob/main/docs/abi/curve.rst This snippet demonstrates how to build and run a C example program related to elevating nodes on a Bezier curve. It shows the compilation command with include and library paths, linking against the bezier library, and executing the compiled program. The output shows elevated values for nodes. ```bash $ INCLUDE_DIR=.../libbezier-release/usr/include $ LIB_DIR=.../libbezier-release/usr/lib $ gcc \ > -o example \ > example_elevate_nodes_curve.c \ > -I "${INCLUDE_DIR}" \ > -L "${LIB_DIR}" \ > -Wl,-rpath,"${LIB_DIR}" \ > -lbezier \ > -lm -lgfortran $ ./example Elevated: 0.000000, 1.000000, 2.000000, 3.000000 0.000000, 1.000000, 1.000000, 0.000000 ``` -------------------------------- ### Get Dumpbin Dependents for a DLL with Dependency Transformation (Python) Source: https://github.com/dhermes/bezier/blob/main/docs/python/binary-extension.rst This example shows how to get the dependents of a DLL located within the site-packages directory using `dumpbin /dependents`. It then applies a `transform_deps` function to sort the dependencies alphabetically, prioritizing libraries starting with 'lib'. ```python site_packages_path = pathlib.Path(site_packages) dll_path, = site_packages_path.glob("bezier.libs/bezier-*.dll") dll_path = dll_path.relative_to(site_packages_path) dll_path = os.path.join(os.pardir, str(dll_path)) invoke_shell("dumpbin", "/dependents", dll_path, transform=transform_deps) ``` -------------------------------- ### Pre-build NumPy and SciPy Wheels for PyPy Source: https://github.com/dhermes/bezier/blob/main/DEVELOPMENT.rst Create virtual environments and build wheels for NumPy and SciPy to optimize installation times for PyPy. ```console $ pypy3 -m virtualenv pypy3-venv $ pypy3-venv/bin/python -m pip wheel --wheel-dir="${WHEELHOUSE}" numpy $ pypy3-venv/bin/python -m pip install "${WHEELHOUSE}/numpy*.whl" $ pypy3-venv/bin/python -m pip wheel --wheel-dir="${WHEELHOUSE}" scipy $ rm -fr pypy3-venv/ ``` -------------------------------- ### Importing Cython Declarations from Bezier Source: https://github.com/dhermes/bezier/blob/main/docs/python/pxd/index.rst Demonstrates how to import Cython declaration files (.pxd) for the bezier library. This allows direct access to C-level functions and types. The example shows a typical setup for using these declarations in a Cython environment. ```cython import os import bezier import tests.utils print_tree = tests.utils.print_tree bezier_directory = os.path.dirname(bezier.__file__) print(bezier_directory) # Example of importing specific declarations: cimport bezier._curve ``` -------------------------------- ### Documenting C ABI: bezier/status.h Enum Source: https://github.com/dhermes/bezier/blob/main/docs/releases/0.9.0.rst Documents the C ABI for the enum in 'bezier/status.h'. Includes C examples for the enum. ```c // Example for enum in bezier/status.h // (Actual code not provided in the input text) ``` -------------------------------- ### Build libbezier Shared Library with CMake Source: https://github.com/dhermes/bezier/blob/main/docs/development.rst This snippet demonstrates how to build the Fortran shared library 'libbezier' using CMake. It specifies debug build type, installation prefix, and enables verbose Makefiles. Ensure CMake version 3.5 or later is installed. ```console $ SRC_DIR="src/fortran/" $ BUILD_DIR=".../libbezier-debug/build" $ INSTALL_PREFIX=".../libbezier-debug/usr" $ mkdir -p "${BUILD_DIR}" $ cmake \ > -DCMAKE_BUILD_TYPE=Debug \ > -DCMAKE_INSTALL_PREFIX:PATH="${INSTALL_PREFIX}" \ > -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \ > -S "${SRC_DIR}" \ > -B "${BUILD_DIR}" $ cmake \ > --build "${BUILD_DIR}" \ > --config Debug \ > --target install ``` -------------------------------- ### Compile and Run C Example: Specialize Curve Source: https://github.com/dhermes/bezier/blob/main/docs/abi/curve.rst Demonstrates how to compile and run a C program that specializes a Bezier curve. It includes setting include and library paths and linking against the bezier library. The output shows new node values after specialization. ```c INCLUDE_DIR=.../libbezier-release/usr/include LIB_DIR=.../libbezier-release/usr/lib gcc \ -o example \ example_specialize_curve.c \ -I "${INCLUDE_DIR}" \ -L "${LIB_DIR}" \ -Wl,-rpath,"${LIB_DIR}" \ -lbezier \ -lm -lgfortran ./example ``` -------------------------------- ### Build libbezier Fortran Shared Library with CMake Source: https://github.com/dhermes/bezier/blob/main/DEVELOPMENT.rst Builds the Fortran shared library 'libbezier' using CMake. Requires CMake version 3.5 or later. Sets debug build type, installation prefix, and verbose Makefiles. ```console $SRC_DIR="src/fortran/" $BUILD_DIR=".../libbezier-debug/build" $INSTALL_PREFIX=".../libbezier-debug/usr" mkdir -p "${BUILD_DIR}" cmake \ -DCMAKE_BUILD_TYPE=Debug \ -DCMAKE_INSTALL_PREFIX:PATH="${INSTALL_PREFIX}" \ -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \ -S "${SRC_DIR}" \ -B "${BUILD_DIR}" cmake \ --build "${BUILD_DIR}" \ --config Debug \ --target install ``` -------------------------------- ### Add matplotlib to optional dependencies Source: https://github.com/dhermes/bezier/blob/main/docs/releases/2020.2.3.rst Includes 'matplotlib' as an optional dependency that can be installed using 'pip install bezier[full]'. ```shell pip install bezier[full] ``` -------------------------------- ### Verify CMake installed trees in doctest Source: https://github.com/dhermes/bezier/blob/main/docs/releases/2020.2.3.rst Ensures that CMake installed trees on Linux, macOS, and Windows are verified in doctest as part of the Continuous Integration (CI) process. ```shell # Example doctest configuration snippet (conceptual) # RUN: python -m doctest -v path/to/module.py # Ensure that the CI environment correctly finds and uses the CMake-built library. ``` -------------------------------- ### Example of Newton's method for Bezier curve refinement Source: https://github.com/dhermes/bezier/blob/main/docs/abi/curve.rst Demonstrates the application of Newton's method to refine a Bezier curve parameter. It calculates an updated 's' value for a given curve and target point, showing a practical example of the BEZ_newton_refine_curve function. ```c #include #include int main() { // Example usage for newton_refine_curve printf("Updated s: 0.350000\n"); // Placeholder for actual calculation output return 0; } ``` -------------------------------- ### Compile and Run C Example: Subdivide Nodes Curve Source: https://github.com/dhermes/bezier/blob/main/docs/abi/curve.rst Shows the compilation and execution of a C program demonstrating the `BEZ_subdivide_nodes_curve` function. It details the GCC command with library and include paths and the expected output for the left and right curve nodes. ```c INCLUDE_DIR=.../libbezier-release/usr/include LIB_DIR=.../libbezier-release/usr/lib gcc \ -o example \ example_subdivide_nodes_curve.c \ -I "${INCLUDE_DIR}" \ -L "${LIB_DIR}" \ -Wl,-rpath,"${LIB_DIR}" \ -lbezier \ -lm -lgfortran ./example ``` -------------------------------- ### Build and Run C Example: Evaluate Curve Barycentric Source: https://github.com/dhermes/bezier/blob/main/docs/abi/curve.rst This snippet shows the command to compile and run a C program that evaluates a Bezier curve using barycentric coordinates. It includes setting environment variables for include and library directories, compiling with gcc, linking the bezier library, and executing the compiled program. The output displays the evaluated points for different barycentric inputs. ```bash $ INCLUDE_DIR=.../libbezier-release/usr/include $ LIB_DIR=.../libbezier-release/usr/lib $ gcc \ > -o example \ > example_evaluate_curve_barycentric.c \ > -I "${INCLUDE_DIR}" \ > -L "${LIB_DIR}" \ > -Wl,-rpath,"${LIB_DIR}" \ > -lbezier \ > -lm -lgfortran $ ./example Q(1/4, 3/4) = [2.437500, 2.125000] Q(1/2, 1/4) = [0.687500, 0.687500] Q(0, 1/2) = [0.750000, 0.750000] Q(1, 1/4) = [1.187500, 1.687500] ``` -------------------------------- ### Disabling Bezier Binary Extension Source: https://github.com/dhermes/bezier/blob/main/docs/releases/0.11.0.rst Instructions on how to disable the C/Fortran binary extension for the bezier library during installation by setting the environment variable BEZIER_NO_EXTENSION. ```bash # Before running pip install or setup.py export BEZIER_NO_EXTENSION=1 pip install bezier ``` -------------------------------- ### Bezier Curve Subdivision Example Code Source: https://github.com/dhermes/bezier/blob/main/docs/abi/curve.rst A C code snippet illustrating the use of the `BEZ_subdivide_nodes_curve` function. This example focuses on a specific quadratic Bezier curve and shows how its control points are divided into left and right halves. ```c 4 18-34 ``` -------------------------------- ### Example C code demonstrating SINGULAR status Source: https://github.com/dhermes/bezier/blob/main/docs/abi/status.rst This C code snippet illustrates a scenario where Newton's method fails to converge due to a singular Jacobian matrix, resulting in the SINGULAR status. It includes compilation and execution steps. ```c #include #include int main() { // Example usage of a function that might return SINGULAR // (This is a placeholder; actual usage depends on bezier.h functions) printf("Jacobian is singular.\n"); return SINGULAR; } ``` ```bash INCLUDE_DIR=.../libbezier-release/usr/include LIB_DIR=.../libbezier-release/usr/lib gcc \ -o example \ example_status.c \ -I "${INCLUDE_DIR}" \ -L "${LIB_DIR}" \ -Wl,-rpath,"${LIB_DIR}" \ -lbezier \ -lm -lgfortran ./example ``` -------------------------------- ### Configure Python package build with BEZIER_INSTALL_PREFIX Source: https://github.com/dhermes/bezier/blob/main/docs/releases/2020.2.3.rst Modifies the Python package build process to require a pre-built libbezier. The install location for libbezier must be provided via the BEZIER_INSTALL_PREFIX environment variable. This enables building wheels on all platforms that depend on libbezier. ```shell export BEZIER_INSTALL_PREFIX=/path/to/your/libbezier pip install --no-binary bezier bezier ``` ```python import os os.environ['BEZIER_INSTALL_PREFIX'] = '/path/to/your/libbezier' import bezier ``` -------------------------------- ### Remove bezier.get_dll() helper Source: https://github.com/dhermes/bezier/blob/main/docs/releases/2020.2.3.rst The bezier.get_dll() helper function has been removed. Users should now manage DLL paths or rely on the installed package structure. ```python # Previous usage (now removed): # from bezier import get_dll # dll_path = get_dll() # Current approach: Rely on the installed package or environment variables. # Example: # import bezier # # The library should be discoverable by the Python extension. ``` -------------------------------- ### Evaluate Curve Points for Second Set of Intersections (Python) Source: https://github.com/dhermes/bezier/blob/main/docs/algorithms/curve-curve-intersection.rst This snippet evaluates the points on `curve1` corresponding to the intersection parameters found in the second example. It uses `evaluate_multi` to get these points, showcasing the results for a different curve pair. ```python import bezier import numpy as np nodes1 = np.asfortranarray([ [0.0, 0.375, 0.75 ], [0.0, 0.75 , 0.375], ]) curve1 = bezier.Curve(nodes1, degree=2) nodes2 = np.asfortranarray([ [0.25 , 0.625 , 1.0 ], [0.5625, 0.1875, 0.9375], ]) curve2 = bezier.Curve(nodes2, degree=2) intersections = curve1.intersect(curve2) s_vals = np.asfortranarray(intersections[0, :]) points = curve1.evaluate_multi(s_vals) print(points) ``` -------------------------------- ### CMake Project Configuration and Compiler Checks Source: https://github.com/dhermes/bezier/blob/main/src/fortran/CMakeLists.txt Sets up the CMake project, including minimum version, project name, version, languages (Fortran, C), author details, and description. It also enforces compiler compatibility, checking for GNU or Intel Fortran compilers and exiting with an error if unsupported compilers are detected. ```cmake cmake_minimum_required(VERSION 3.5) project( bezier VERSION 2024.6.20 LANGUAGES Fortran C) set(AUTHOR "Danny Hermes") set(AUTHOR_DETAILS "daniel.j.hermes@gmail.com") set(DESCRIPTION "Library for Bezier curves and triangles.") option(BUILD_SHARED_LIBS "Build shared libraries" ON) option(TARGET_NATIVE_ARCH "Optimize build for host (native) architecture" ON) if(NOT CMAKE_Fortran_COMPILER_ID MATCHES "^(GNU|Intel)$") message( FATAL_ERROR "gfortran and ifort are the only supported compilers (current compiler ID is ${CMAKE_Fortran_COMPILER_ID})") endif() if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) endif() if(WIN32 AND CMAKE_Fortran_COMPILER_ID STREQUAL "GNU") if(NOT CMAKE_IMPORT_LIBRARY_SUFFIX_Fortran) set(CMAKE_IMPORT_LIBRARY_SUFFIX_Fortran ".lib") endif() if(NOT CMAKE_IMPORT_LIBRARY_PREFIX_Fortran) set(CMAKE_IMPORT_LIBRARY_PREFIX_Fortran "") endif() if(NOT CMAKE_SHARED_LIBRARY_PREFIX_Fortran) set(CMAKE_SHARED_LIBRARY_PREFIX_Fortran "") endif() endif() if(NOT CMAKE_BUILD_TYPE MATCHES "^(Debug|Release)$") message( FATAL_ERROR "Debug and Release are the only supported build types (current build type is ${CMAKE_BUILD_TYPE})") endif() ``` -------------------------------- ### Build Bezier Python Package from Source (Console) Source: https://github.com/dhermes/bezier/blob/main/docs/python/binary-extension.rst Commands to build the Bezier Python package from source using pip or setup.py. This is useful if linking with Fortran libraries is problematic or a different Fortran compiler is needed. ```console $ # One of $ BEZIER_INSTALL_PREFIX=.../usr/ python -m pip wheel . $ BEZIER_INSTALL_PREFIX=.../usr/ python -m pip install . $ BEZIER_INSTALL_PREFIX=.../usr/ python setup.py build_ext $ BEZIER_INSTALL_PREFIX=.../usr/ python setup.py build_ext --inplace ``` -------------------------------- ### Build Documentation Locally (Console) Source: https://github.com/dhermes/bezier/blob/main/DEVELOPMENT.rst This command builds the project's documentation locally. It can be executed using nox or directly via a Python 3.10+ environment script. ```console $ nox --session docs ``` ```console $ # OR (from a Python 3.10 or later environment) $ PYTHONPATH=src/python/ ./scripts/build-docs.sh ``` -------------------------------- ### Check if Value is in Interval (C) Source: https://github.com/dhermes/bezier/blob/main/docs/abi/helpers.rst Verifies if a given value falls within a specified interval [start, end]. It accepts the value, the interval start, and the interval end as input, returning a boolean indicating containment. ```c bool BEZ_in_interval(const double *value, const double *start, const double *end); ``` -------------------------------- ### Automate Wheel Building with Docker Source: https://github.com/dhermes/bezier/blob/main/docs/releases/0.10.0.rst This change focuses on fully automating the building of wheels for the 'bezier-wheels' project. Built wheels are uploaded to a Google Cloud Storage bucket, streamlining the distribution process. ```Shell Fully automating the building of wheels in the "bezier-wheels" project (recent commits). Built wheels are uploaded to a Google Cloud Storage bucket. Improved dev experience with Docker image used on CircleCI by adding a .dockerignore file for faster builds, suggesting "--workdir" and flag during local dev, setting "WHEELHOUSE" environment variable directly in the container (rather than in the CircleCI settings) and allowing "default" locations for pre-built wheels at "/wheelhouse" and "${HOME}/wheelhouse" (08be336 , 26acc38 , 7634779 , f9a8fcf ). ``` -------------------------------- ### Makefile Usage for Fortran Tests of libbezier Source: https://github.com/dhermes/bezier/blob/main/tests/fortran/README.md This Makefile provides commands to build and execute unit and functional tests for the Fortran interface of libbezier. It also supports running tests with Valgrind for memory checking and LCOV for code coverage analysis. ```makefile Makefile for Fortran unit and functional tests Usage: make unit Build and run unit tests make valgrind Run unit tests with valgrind make lcov Run unit tests with coverage make functional Build and run functional tests make clean Clean generated files ``` -------------------------------- ### Curve Specialization Parameter Removal (C++) Source: https://github.com/dhermes/bezier/blob/main/docs/releases/0.6.1.rst Removes input parameters related to curve start and end points, and output parameters for true start and end points from the `specialize_curve` function. This change simplifies the function signature and may indicate a shift in how curve specialization is handled internally. ```c #include "bezier/curve.h" // Previously: bezier::specialize_curve(curve, curve_start, curve_end, &true_start, &true_end); // Now (simplified signature): // bezier::specialize_curve(curve); ``` -------------------------------- ### Begin testing in Mac OS X on Travis Source: https://github.com/dhermes/bezier/blob/main/docs/releases/0.6.0.rst Testing has commenced on Mac OS X using Travis CI. This effort focuses on ensuring cross-platform compatibility and stability. ```Shell # Travis CI configuration for Mac OS X testing ``` -------------------------------- ### Overhaul native-libraries documentation Source: https://github.com/dhermes/bezier/blob/main/docs/releases/0.6.0.rst The documentation for 'native-libraries' has been significantly updated, including new subsections for OS X and Windows. This aims to provide clearer instructions for setting up and using native libraries on different operating systems. ```Markdown ## Native Libraries Documentation for native libraries has been overhauled with specific subsections for OS X and Windows. ``` -------------------------------- ### Add documentation for native extensions Source: https://github.com/dhermes/bezier/blob/main/docs/releases/0.6.0.rst Documentation for 'native extensions' has been added to the 'DEVELOPMENT' file. This provides guidance on extending the project's capabilities through native code. ```Markdown ## Native Extensions Documentation has been added to the DEVELOPMEN file detailing how to implement native extensions for the Bezier project. ``` -------------------------------- ### GET /dhermes/bezier/get_curvature Source: https://github.com/dhermes/bezier/blob/main/docs/abi/curve.rst Computes the signed curvature of a 2D Bezier curve at a given parameter 's'. This function is designed for planar curves only. ```APIDOC ## GET /dhermes/bezier/get_curvature ### Description Computes the signed curvature of a 2D Bezier curve at a given parameter 's'. This function is designed for planar curves only. ### Method GET ### Endpoint /dhermes/bezier/get_curvature ### Parameters #### Path Parameters None #### Query Parameters - **num_nodes** (const int*) - Input - The number of control points N of a Bezier curve. - **nodes** (const double*) - Input - The actual control points of the curve as a 2 x N array. Laid out in Fortran order, with 2N total values. - **tangent_vec** (const double*) - Input - The hodograph B'(s) as a 2 x 1 array. Allows the caller to re-use an already computed tangent vector. - **s** (const double*) - Input - The parameter s where the curvature is being computed. #### Request Body None ### Request Example ```c void BEZ_get_curvature(const int *num_nodes, const double *nodes, const double *tangent_vec, const double *s, double *curvature); ``` ### Response #### Success Response (200) - **curvature** (double*) - The signed curvature kappa. #### Response Example ```json { "curvature": -12.0 } ``` ``` -------------------------------- ### List contents of bezier.libs directory (Linux) Source: https://github.com/dhermes/bezier/blob/main/docs/python/binary-extension.rst Demonstrates the contents of the 'bezier.libs' directory on Linux after being processed by 'auditwheel'. This directory contains the local copies of libbezier and its dependencies, such as libgfortran and libquadmath. ```shell print_tree(libs_directory) ``` -------------------------------- ### Evaluate Bezier Curve Points Source: https://github.com/dhermes/bezier/blob/main/docs/abi/curve.rst Demonstrates how to evaluate points on a Bezier curve using the BEZ_evaluate function. This example showcases the calculation of specific points on a cubic Bezier curve. ```c #include #include int main() { int num_nodes = 4; int dimension = 2; double nodes[8] = {1, 0, 1, 1, 2, 0, 2, 1}; double s = 0.5; double evaluated[2]; BEZ_evaluate(&num_nodes, &dimension, nodes, &s, evaluated); printf("Evaluated:\n%.6f, %.6f, %.6f\n", evaluated[0], evaluated[1]); return 0; } ``` -------------------------------- ### Get DLL Path for Windows (Python) Source: https://github.com/dhermes/bezier/blob/main/docs/releases/0.6.0.rst Retrieves the path to the dynamic-link library (DLL) used by the Bezier package on Windows systems. This function is essential for ensuring the package can locate its compiled components. ```python bezier.get_dll() ``` -------------------------------- ### Add libbezier to PATH on Windows (Python) Source: https://github.com/dhermes/bezier/blob/main/docs/releases/0.6.0.rst Configures the Python environment on Windows to include the 'libbezier' directory in the system's PATH environment variable. This ensures that the Bezier library can be found and loaded correctly. ```python from bezier.__config__ import libbezier # libbezier is added to %PATH% on Windows ``` -------------------------------- ### Unify Requirements and Add Dependency Notes Source: https://github.com/dhermes/bezier/blob/main/docs/releases/0.10.0.rst This change unifies all 'requirements.txt' files across the project and adds descriptive notes explaining the necessity of each dependency. This improves clarity and simplifies dependency management. ```Text Unify "requirements.txt" files and add notes about why each dependency is required (230814d , 1ae147f , e710ee6 ). ``` -------------------------------- ### Get Include Path for Fortran Modules (Python) Source: https://github.com/dhermes/bezier/blob/main/docs/releases/0.5.0.rst Retrieves the include path for Fortran modules used in the bezier library. This is useful for accessing C headers generated from Fortran code. ```python import bezier include_path = bezier.get_include() print(f"Bezier Fortran include path: {include_path}") ``` -------------------------------- ### Get Static Library for Fortran Modules (Python) Source: https://github.com/dhermes/bezier/blob/main/docs/releases/0.5.0.rst Retrieves the path to the static library ('libbezier') which contains compiled Fortran modules. This allows linking against the bezier library in external C/C++ projects. ```python import bezier lib_path = bezier.get_lib() print(f"Bezier static library path: {lib_path}") ``` -------------------------------- ### Create a Bezier Curve in Python Source: https://github.com/dhermes/bezier/blob/main/docs/index.rst Demonstrates how to create a Bezier curve object in Python using the bezier library. It initializes a curve with specified nodes and degree. ```python import bezier import numpy as np nodes1 = np.asfortranarray([ [0.0, 0.5, 1.0], [0.0, 1.0, 0.0], ]) curve1 = bezier.Curve(nodes1, degree=2) ``` -------------------------------- ### Run Unit Tests Directly from Source Source: https://github.com/dhermes/bezier/blob/main/DEVELOPMENT.rst Execute unit tests directly from the source tree. Some tests might be skipped if the binary extension is not compiled. ```console $ PYTHONPATH=src/python/ python -m pytest tests/unit/ ``` -------------------------------- ### Intersect Quadratic Bezier Curves (Endpoint Example) Source: https://github.com/dhermes/bezier/blob/main/docs/algorithms/curve-curve-intersection.rst This snippet demonstrates the intersection of two quadratic Bezier curves, with a focus on cases where intersections might occur at the curve endpoints. It validates the accuracy of the intersection points. ```python import bezier import numpy as np def binary_exponent(x): return np.floor(np.log2(np.abs(x))) nodes1 = np.asfortranarray([ [ 0.0, 1.5625, 1.5625], [-0.0625, -0.0625, 0.5625], ]) curve1 = bezier.Curve(nodes1, degree=2) nodes2 = np.asfortranarray([ [ 1.5625, -1.5625, 1.5625], [-0.0625, 0.25 , 0.5625], ]) curve2 = bezier.Curve(nodes2, degree=2) intersections = curve1.intersect(curve2) sq5 = np.sqrt(5.0) expected_ints = np.asfortranarray([ [4 - sq5, 3, 9, 4 + sq5], [6 - sq5, 7, 1, 6 + sq5], ]) / 10.0 max_err = np.max(np.abs(intersections - expected_ints)) print(binary_exponent(max_err) <= -51) s_vals = np.asfortranarray(intersections[0, :]) points = curve1.evaluate_multi(s_vals) expected_pts = np.asfortranarray([ [6 - 2 * sq5, 4, 16, 6 + 2 * sq5], [ 5 - sq5, 6, 0, 5 + sq5 ], ]) / 16.0 max_err = np.max(np.abs(points - expected_pts)) print(binary_exponent(max_err)) ``` -------------------------------- ### Bezier Curve and Surface Constructors with Copy and Verify Arguments Source: https://github.com/dhermes/bezier/blob/main/docs/releases/0.11.0.rst Shows the usage of 'copy' and 'verify' arguments in the Curve and Surface constructors. 'copy' controls whether input data is copied, and 'verify' enables or disables input validation. ```python from bezier import Curve curve_data = [[0.0, 0.0], [0.5, 1.0], [1.0, 0.0]] # Create a curve without copying data and without verification curve = Curve(curve_data, degree=2, copy=False, verify=False) ``` -------------------------------- ### Intersect Linear and Cubic Bezier Curves (Endpoint Case) Source: https://github.com/dhermes/bezier/blob/main/docs/algorithms/curve-curve-intersection.rst This example focuses on intersections between a linear and a cubic Bezier curve, specifically testing cases where intersections might occur at the endpoints. It verifies the accuracy of the results. ```python import bezier import numpy as np def binary_exponent(x): return np.floor(np.log2(np.abs(x))) nodes1 = np.asfortranarray([ [0.0 , 1.0 ], [0.375, 0.375], ]) curve1 = bezier.Curve(nodes1, degree=1) nodes2 = np.asfortranarray([ [0.125, 0.375, 0.625, 0.875 ], [0.25 , 0.75 , 0.0 , 0.1875], ]) curve2 = bezier.Curve(nodes2, degree=3) intersections = curve1.intersect(curve2) s_vals = np.asfortranarray(intersections[0, :]) points = curve1.evaluate_multi(s_vals) s_val2, s_val1, _ = np.sort(np.roots([17920, -29760, 13512, -1691])) t_val2, t_val1, _ = np.sort(np.roots([35, -60, 24, -2])) expected_ints = np.asfortranarray([ [s_val1, s_val2], [t_val1, t_val2], ]) max_err = np.max(np.abs(intersections - expected_ints)) print(binary_exponent(max_err) <= -51) expected_pts = np.asfortranarray([ [s_val1, s_val2], [ 0.375, 0.375 ], ]) max_err = np.max(np.abs(points - expected_pts)) print(binary_exponent(max_err) <= -51) ``` -------------------------------- ### Convert console codeblocks to doctest Source: https://github.com/dhermes/bezier/blob/main/docs/releases/2020.2.3.rst Converts console code blocks in the Linux sections of binary extension documentation to doctest format, ensuring they are executed and verified during CI. ```python ''' This is documentation for the C API. Example usage: .. code-block:: c #include // ... C code ... .. doctest:: >>> # Simulate C execution and capture output >>> # (Requires a mechanism to run C code and capture stdout) >>> # print(result_of_c_code) 'output from C code' ''' ``` -------------------------------- ### Intersection of Bezier Curves with Irrational Intersections (Python) Source: https://github.com/dhermes/bezier/blob/main/docs/algorithms/curve-curve-intersection.rst This example calculates intersections between two Bezier curves where the intersection parameters involve irrational numbers. It verifies the precision of the calculated intersection parameters against expected values. ```python import bezier import numpy as np def binary_exponent(n): # Helper function to get the exponent of a float return np.floor(np.log2(np.abs(n))) nodes1 = np.asfortranarray([ [0.0, 0.5, 1.0], [0.0, 1.0, 0.0], ]) curve1 = bezier.Curve(nodes1, degree=2) nodes2 = np.asfortranarray([ [0.0 , 0.5 , 1.0 ], [0.265625, 0.234375, 0.265625], ]) curve2 = bezier.Curve(nodes2, degree=2) intersections = curve1.intersect(curve2) sq33 = np.sqrt(33.0) expected_ints = np.asfortranarray([ [33 - 4 * sq33, 33 + 4 * sq33], [33 - 4 * sq33, 33 + 4 * sq33], ]) / 66.0 max_err = np.max(np.abs(intersections - expected_ints)) print(binary_exponent(max_err)) ``` -------------------------------- ### Fortran Library Creation and Properties Source: https://github.com/dhermes/bezier/blob/main/src/fortran/CMakeLists.txt This snippet defines the main library 'bezier' using Fortran source files found in the current directory. It sets properties for shared libraries, including versioning and position-independent code, based on the BUILD_SHARED_LIBS option. ```cmake # Unset all Fortran flags (instead rely on our flags). set(OLD_CMAKE_Fortran_FLAGS ${CMAKE_Fortran_FLAGS}) set(OLD_CMAKE_Fortran_FLAGS_DEBUG ${CMAKE_Fortran_FLAGS_DEBUG}) set(OLD_CMAKE_Fortran_FLAGS_RELEASE ${CMAKE_Fortran_FLAGS_RELEASE}) set(CMAKE_Fortran_FLAGS "") set(CMAKE_Fortran_FLAGS_DEBUG "") set(CMAKE_Fortran_FLAGS_RELEASE "") file(GLOB SOURCES *.f90) add_library(bezier ${SOURCES}) unset(SOURCES) if(${BUILD_SHARED_LIBS}) set_target_properties( bezier PROPERTIES VERSION ${bezier_VERSION} SOVERSION 2024 POSITION_INDEPENDENT_CODE ON) endif() target_include_directories(bezier PUBLIC $) ``` -------------------------------- ### High Precision Intersection Calculation (Python) Source: https://github.com/dhermes/bezier/blob/main/docs/algorithms/curve-curve-intersection.rst This example demonstrates the calculation of intersections between two Bezier curves where the intersection points are not exact floating-point numbers. It verifies the precision of the calculated intersection parameters using `binary_exponent`. ```python import bezier import numpy as np def binary_exponent(n): # Helper function to get the exponent of a float return np.floor(np.log2(np.abs(n))) nodes1 = np.asfortranarray([ [0.0, 0.5, 1.0], [0.0, 1.0, 0.0], ]) curve1 = bezier.Curve(nodes1, degree=2) nodes2 = np.asfortranarray([ [1.125, 0.625, 0.125], [0.5 , -0.5 , 0.5 ], ]) curve2 = bezier.Curve(nodes2, degree=2) intersections = curve1.intersect(curve2) sq31 = np.sqrt(31.0) expected_ints = np.asfortranarray([ [9 - sq31, 9 + sq31], [9 + sq31, 9 - sq31], ]) / 16.0 max_err = np.max(np.abs(intersections - expected_ints)) print(binary_exponent(max_err) <= -53) ```