I notice that we have another way to write overload function in the project:
public DistanceTo(
other: Point3d | Line | Plane,
limitToFiniteSegment: boolean = false
): number {
if (other instanceof Line)
return Line.LineLineDistance(this, other, limitToFiniteSegment);
if (other instanceof Plane)
return Line.LinePlaneDistance(this, other, limitToFiniteSegment);
return Line.LinePointDistance(this, other, limitToFiniteSegment);
}
Whereas in the old code I explicitly seperate overload functions into multiple functions, like:
/**
* Sums up a point and a vector, and returns a new point.
* @param vector A vector.
* @returns A new point that results from the addition of point and vector.
*/
public Add(vecotr: Vector3d): Point3d {
return Point3d.Add(this, vecotr);
}
/**
* Sums up a point and a point, and returns a new point.
* @param point A point.
* @returns A new point that results from the addition of point and point.
*/
public AddPoint(point: Point3d): Point3d {
return Point3d.AddPoint(this, point);
}
Now I think it's an interesting discussion which pattern we are going to keep.
At first sight the first method is cleaner for the user. Question is can it handle more complex cases?
What I can think of:
- What if it returns different types depending on the input? (like point-point->vector, point-vector->point)
- What if we have different lengths of input arguments?
- What if some arguments can be undefined?
I notice that we have another way to write overload function in the project:
Whereas in the old code I explicitly seperate overload functions into multiple functions, like:
Now I think it's an interesting discussion which pattern we are going to keep.
At first sight the first method is cleaner for the user. Question is can it handle more complex cases?
What I can think of: