CAAT.Path

CAAT toolkit has advanced path capabilities. In its basic definition, a path is defined by the class CAAT.PathSegment. This class does not define any method implementation but is referred to as an interface, that is, just definition, no implementation.

Despite that, every path on CAAT will be composed by one or more path segments. These segments can be either straight lines, quadric or cubic bezier curves, catmull-rom curves or complex paths composed of an arbitrary number of segments. A path can have any level of complexity with the combination of such segments.

PathSegment has the following methods:


    CAAT.PathSegment.prototype =  {
        /**
         * Get path's last coordinate.
         */
		endCurvePosition : function() { },

        /**
         * Get path's starting coordinate.
         */
		startCurvePosition : function() { },

        /**
         * Get a coordinate on path.
         * The parameter time is normalized, that is, its values range from zero to one.
         * zero will mean startCurvePosition and one will be endCurvePosition. Other values
         * will be a position on the path relative to the path length. if the value is greater that 1, if will be set
         * to modulus 1.
         * @param time a float with a value between zero and 1 inclusive both.
         */
        getPosition : function(time) { },

        /**
         * Gets Path length.
         */
        getLength : function() { },

        /**
         * Gets the path bounding box (or the rectangle that contains the whole path).
         * @param rectangle a CAAT.Rectangle instance with the bounding box.
         */
		getBoundingBox : function(rectangle) { },

        /**
         * Gets the number of control points needed to create the path.
         * Each PathSegment type can have different control points.
         * @return an integer with the number of control points.
         */
		numControlPoints : function() { },

        /**
         * Gets CAAT.Point instance with the 2d position of a control point.
         * @param index an integer indicating the desired control point coordinate.
         */
		getControlPoint: function(index) { },

        /**
         * Instruments the path has finished building, and that no more segments will be added to it.
         * You could later add more PathSegments and endPath must be called again.
         */
        endPath : function() {},

        /**
         * Gets a polyline describing the path contour. The contour will be defined by as mush as iSize segments.
         * @param iSize an integer indicating the number of segments of the contour polyline.
         */
        getContour : function(iSize) {}
    }
            

By watching at this definition, it can be inferred that every path, regardless of its type:

  • Can get its bounding box. function getBoundingBox
  • Can get its length. function getLength
  • Can get a position on the path. function getPosition(time). The parameter time will be zero to get the starting path position and one, to get path's last position.
  • Get its contour as an array of points. function getContour()
  • Get the number of control points needed to handle/define the path. function numControlPoints().