CompGeoJS Parametric Line
I’ve been traveling on business the last two months, so little time has been available to work on the CompGeoJS project. A recent break in the routine gave me an opportunity to begin work on parametric curves, the most basic of which is a line in 2D space. The line equation is merely (1-t)P0 + tP1 where P0 and P1 are vectors. While a line may appear relatively simple in scope, I devoted a substantial amount of thought to the IPlanarCurve interface that specifies all methods that any parametric curve must implement. The Curve class serves as a pseudo-abstract base class from which all other planar curves such as Line derive.
CompGeoJS will support up to cubic curves in the 1.0 release, which require a maximum of four control points. In the case of a line that requires only two points for its definition, accessors for the middle two control points always return zero from the superclass and mutators for these points are empty.
The LineExample demo uses a solid-line decorator that serves as a placeholder for easy insertion of more complex decorators in future examples. This demo also brings together EaselJS-based tools such as graph markers and the slice tool. Interactive markers are used to define endpoints of a line segment. The slice tool may be moved left and right across the graph to query the natural parameter at the current x-coordinate as well as the point on the line at that parameter. While only the segment is rendered, the line is completely defined for parameters outside [0,1].