I am stumbling upon many, many programming gems which are needed to implement my B-spline library. Here is a simple one, of which only the API description is included, not the implementation. I am wondering if there is something like this in OpenCascade?
# Returns the center point of circle which passes through A, B, and C. If the
# three input points are such that there exists a line which contains (or
# nearly contains) the three input points, then the special Python 'None' value
# is returned instead.
#
# Regarding degenerate cases: the only thing that this code inhibits is a
# division by zero. Otherwise the computation will proceed. Therefore, the
# caller may specify an 'epsilon' value which, if set to be strictly greater
# than zero, will filter out results where bounding box perimeter ratios are
# less than epsilon, by returning the special Python value 'None' in those
# cases. The perimeter ratio compared is the ratio of bounding box perimeter
# containing only A,B,C versus perimeter of bounding box containing A,B,C,Ψ,
# where Ψ is the computed center of circle. This is a post-computation
# filtering approach which excludes results that are blowing up towards
# infinity. Setting 'epsilon' to be closer to zero will cause circle centers
# that are further away to be accepted as accurate. A good value for epsilon
# [in my opinion] is in the range of 1e-5 to 1e-6.
#
def compute_circle_center(point_A: gp_Pnt2d,
point_B: gp_Pnt2d,
point_C: gp_Pnt2d,
epsilon: float= 1.0e-6) -> gp_Pnt2d:
My opinion of OpenCascade is that it's very powerful when used properly, but there are many unimplemented APIs, or the implementation does not agree with what the API states, or the implementation is outright buggy. Using OpenCascade is akin to stepping through a field of landmines in order to reach the ultimate paradise; you need to be very careful where you step but the outcome is very wonderful.
There is another sub-problem "gem" that I've also solved, and this one is too complicated so even the API comment is too big to include here, so I'll state it in plain English while omitting the details of how to handle degenerate or fringe cases.
You have four points A, B, C, D in 2D given as inputs. Return an affine 2D transformation, based on those four input points, which causes the transformed points A', B', C', D' to lie perfectly on a circle. The definition of an affine transformation in 2D is that a pair of parallel lines gets transformed to parallel lines, and that there is an inverse to the transform.
This is a non-trivial problem and I have the solution, which is needed to properly implement elliptical B-spline curves. I have no idea what OpenCascade or what other implementations employ. The main computation involves a transcendental [I think] formula which cannot be expressed in closed form; a binary search approach, taking at most 48 or so steps, is employed to come up with a numeric value for the "shear" operation.
The reason I need this ability is for curve prediction and curve fitting. If I am given a sequence of points A, B, C, D, E, F... which all more or less lie on an elliptical curve, or where sections of it lie on elliptical curves, then I want to return a B-spline which preserves those elliptical curves as much as possible. This all boils down to my desire to draw perfect SVG curves for outline drawings that employ the perspective projection:
https://github.com/CadQuery/cadquery/issues/1524 .