refactor!: remove Undefined sentinels and isDefined, use std::optional (#216)
- refactor!: remove Undefined sentinels and isDefined from geometry, Angle, Interval and NumericalSolver
The “undefined” state (a NaN-backed object, an empty ring, or an Undefined enumerator) is removed from every class that carried it. Code that needs “no value” now uses std::optional at the use site, as already done for Composite and Intersection.
Removed (C++ and Python):
- static Undefined() / undefined() on Point, Line, Segment, Polygon (2D, 3D), MultiPolygon, Sphere, Ellipsoid, Cone, Cuboid, Plane, Pyramid, Ray, Transformation (2D, 3D), Quaternion, RotationMatrix, RotationVector, EulerAngle, Angle, Interval and NumericalSolver
- isDefined() / is_defined() on all of the above, on LineString, PointSet, Composite, and the pure virtual on geometry::d2::Object and d3::Object
- every
if (!x.isDefined()) throw Undefined(...)guard and thereturn false/return trueshortcuts in comparison operators- Transformation::Type::Undefined (2D, 3D), Angle::Unit::Undefined, EulerAngle::AxisSequence::Undefined, Interval::Type::Undefined
- private default constructors of RotationVector and RotationMatrix, which only existed to build an undefined value
New std::optional signatures:
- Interval::getIntersectionWith() and getUnionWith() return std::optional<Interval> (std::nullopt when disjoint). Python returns None.
- Interval::GetGaps() takes std::optional<Interval> for the clip interval (default std::nullopt) instead of Interval::Undefined().
Invariants that isDefined() used to encode and that moved into constructors:
- d2::Polygon: an outer ring with fewer than 3 points, including an empty one, now throws in the constructor (it used to build an “undefined” polygon).
Behaviour that changes because the guard is gone:
- NaN inputs no longer throw Undefined in Angle::isZero / isNegative, Interval::contains(NaN) / isDegenerate, and similar; they follow normal floating-point semantics. Explicit NaN checks on raw double arguments are kept.
- An empty LineString, PointSet or MultiPolygon is a valid empty value rather than an undefined one, so methods on it no longer throw Undefined (for example LineString::Empty().contains(point) is false).
- Interval no longer requires bound types to provide isDefined() / Undefined().
- Enumerators following a removed Undefined value shift by one.
Tests that exercised the sentinel are removed; the Python tests, bindings and reference notebooks are updated accordingly.
BREAKING CHANGE: removed Undefined()/isDefined() and the Undefined enumerators listed above. Use std::optional where “no value” is a real state. Python: removed undefined() and is_defined() everywhere, and removed the Undefined members of Angle.Unit, Transformation.Type, EulerAngle.AxisSequence and RealInterval.Type; RealInterval.get_intersection_with / get_union_with return None for disjoint intervals.
Co-Authored-By: Claude Sonnet 5.5 noreply@anthropic.com
- refactor!: remove Undefined() and isDefined() from the Eigen matrix extension
Matrix/vector types had a NaN-backed “undefined” state (Undefined(), Undefined(size), Undefined(rows, cols)) and isDefined() (no NaN and no Inf). Nothing in this library uses them any more now that the geometry classes no longer have an undefined state.
- Remove Undefined(), Undefined(Index) and Undefined(Index, Index) (use NaN(), NaN(size) and NaN(rows, cols), which already exist)
- Remove isDefined() (use !isNaN() && !isInf() if that is what is meant)
- isNear() no longer throws “Object is undefined.” for NaN or Inf operands; a NaN difference compares false. It still throws on a size mismatch.
BREAKING CHANGE: removed Undefined() / isDefined() on Eigen matrices and vectors (Vector2d, Vector3d, Vector4d, VectorXd, Matrix3d, …). Downstream users should use NaN() and isNaN() / isInf().
Co-Authored-By: Claude Sonnet 5.5 noreply@anthropic.com
Co-authored-by: Claude Sonnet 5.5 noreply@anthropic.com
Open Space Toolkit 数学组件(几何、曲线、插值等)。镜像收录自 https://github.com/open-space-collective/open-space-toolkit-mathematics,License:Apache-2.0
版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9
京公网安备 11010802047560号
Open Space Toolkit ▸ Mathematics
Geometry, curve fitting, optimization.
Getting Started
Want to get started? This is the simplest and quickest way:
Nothing to download or install! This will automatically start a JupyterLab environment in your browser with Open Space Toolkit libraries and example notebooks ready to use.
Alternatives
Docker Images
Docker must be installed on your system.
iPython
The following command will start an iPython shell within a container where the OSTk components are already installed:
Once the shell is up and running, playing with it is easy:
Tip: Use tab for auto-completion!
JupyterLab
The following command will start a JupyterLab server within a container where the OSTk components are already installed:
Once the container is running, access http://localhost:8888/lab and create a Python 3 Notebook.
Installation
C++
The binary packages are hosted using GitHub Releases:
open-space-toolkit-mathematics-X.Y.Z-1.x86_64-runtimeopen-space-toolkit-mathematics-X.Y.Z-1.x86_64-developen-space-toolkit-mathematics-X.Y.Z-1.x86_64-pythonDebian / Ubuntu
After downloading the relevant
.debbinary packages, install:Python
Install from PyPI:
Documentation
Documentation is available here:
Structure
The library exhibits the following structure:
Tutorials
Tutorials are available here:
Features
Geometry Queries
○: query only✔: query / intersection set: to be implemented-: undefined3D
Setup
Development Environment
Using Docker for development is recommended, to simplify the installation of the necessary build tools and dependencies. Instructions on how to install Docker are available here.
To start the development environment:
This will:
openspacecollective/open-space-toolkit-mathematics-developmentDocker image.bashshell from the./buildworking directory.If installing Docker is not an option, you can manually install the development tools (GCC, CMake) and all required dependencies, by following a procedure similar to the one described in the Development Dockerfile.
Build
From the
./builddirectory:Tip:
ostk-buildsimplifies building from within the development environment.Test
To start a container to build and run the tests:
Or to run them manually:
Tip:
ostk-testsimplifies running tests from within the development environment.Dependencies
3.1.03.3.73.28mainContribution
Contributions are more than welcome!
Please read our contributing guide to learn about our development process, how to propose fixes and improvements, and how to build and test the code.
Special Thanks
License
Apache License 2.0