FileDocCategorySizeDatePackage
FloatSegment.javaAPI DocphoneME MR2 API (J2ME)8366Wed May 02 18:00:36 BST 2007com.sun.perseus.model

FloatSegment

public class FloatSegment extends Object implements Segment
Represents float segment in an animation. A float segment may have multiple components and multiple dimensions. For example, an rgb color segment is represented with one component and 3 dimensions. A stroke dash array value is represented with as many components as there are dashes and one dimension for each component.
version
$Id: FloatSegment.java,v 1.3 2006/06/29 10:47:31 ln156897 Exp $

Fields Summary
float[]
start
The segment's begin value. There is an array for each component and an value in the array for each dimension.
float[]
end
The segment's end value.
Constructors Summary
Methods Summary
public voidaddToEnd(java.lang.Object[] by)
Adds the input value to this Segment's end value.

param
by the value to add. Throws IllegalArgumentException if this Segment type is not additive or if the input value is incompatible (e.g., different number of components or different number of dimensions on a component).

        if (by == null || !(by instanceof float[][])) {
            throw new IllegalArgumentException();
        }

        float[][] add = (float[][]) by;
        if (add.length != end.length) {
            throw new IllegalArgumentException();
        }

        for (int ci = 0; ci < add.length; ci++) {
            float[] v = end[ci];
            float[] av = add[ci];
            int vl = v != null ? v.length : 0;
            int avl = av != null ? av.length : 0;
            if (vl != avl) {
                throw new IllegalArgumentException();
            }

            for (int di = 0; di < vl; di++) {
                v[di] += av[di];
            }
        }
    
public voidcollapse(Segment seg, Animation anim)
Collapses this segment with the one passed as a parameter. Note that if the input segment is not of the same class as this one, an IllegalArgumentException is thrown. The method also throws an exception if the input segment's end does not have the same number of components as this segment's end. After this method is called, this segment's end value is the one of the input seg parameter.

param
seg the Segment to collapse with this one.
param
anim the Animation this segment is part of.

        FloatSegment mseg = (FloatSegment) seg;
        if (mseg.end.length != end.length) {
            throw new IllegalArgumentException();
        }

        end = mseg.end;
    
public voidcompute(float p, float[][] w)
Computes an interpolated value for the given penetration in the segment. Note that the start and end segment values must be set before calling this method. Otherwise, a NullPointerException is thrown.

param
p the segment penetration. Should be in the [0, 1] range.
param
w array where the computed value should be stored.

        // For each component
        int nc = w.length;
        int nd = 0;
        for (int ci = 0; ci < nc; ci++) {
            // For each dimension 
            nd = w[ci].length;
            for (int di = 0; di < nd; di++) {
                w[ci][di] = p * end[ci][di] + (1 - p) * start[ci][di]; 
            }
        }
    
public java.lang.Object[]getEnd()

return
set end value.

        return end;
    
public floatgetLength()

return
the length of the segment.

        float length = 0;
        final int nc = start.length;

        for (int ci = 0; ci < nc; ci++) {
            // Start value for the requested component.
            float[] s = start[ci];
            
            // End value for the requested component.
            float[] e = end[ci];
            
            // Number of dimensions.
            int nd = s.length;
            
            float clength = 0;
            for (int di = 0; di < nd; di++) {
                clength += (e[di] - s[di]) * (e[di] - s[di]);
            }
        
            length += MathSupport.sqrt(clength);
        }

        return length;
    
public java.lang.Object[]getStart()

return
the start value.

        return start;
    
public voidinitialize()
Should be called after the segment's configuration is complete to give the segment's implementation a chance to initialize internal data and cache values.

    
public booleanisAdditive()

return
true if this segment type supports addition. false otherwise.

        return true;
    
public voidsetStart(java.lang.Object[] newStart)
Sets the start value.

param
newStart the new segment start value.

        start = (float[][]) newStart;
    
public voidsetZeroStart()
Sets the start value to its notion of 'zero'. For a FloatSegment, a 'zero' start means zero all all dimensions for all components.

        for (int ci = 0; ci < start.length; ci++) {
            for (int di = 0; di < start[ci].length; di++) {
                start[ci][di] = 0;
            }
        }
    
public java.lang.StringtoString()
Debug helper.

        StringBuffer sb = new StringBuffer();
        sb.append("FloatSegment[");
        if (start == null) {
            sb.append("null");
        } else {
            sb.append("start[" + start.length + "] : {");
            for (int ci = 0; ci < start.length; ci++) {
                float[] fc = start[ci];
                if (fc == null) {
                    sb.append("null");
                } else {
                    sb.append("float[" + fc.length + "{");
                    for (int di = 0; di < fc.length; di++) {
                        sb.append(fc[di]);
                        if (di < fc.length - 1) {
                            sb.append(", ");
                        }
                    }
                    sb.append("}");
                }
                if (ci < start.length - 1) {
                    sb.append(", ");
                }
            }
            sb.append("} ");
        }

        if (end == null) {
            sb.append("null");
        } else {
            sb.append("end[" + end.length + "] : {");
            for (int ci = 0; ci < end.length; ci++) {
                float[] fc = end[ci];
                if (fc == null) {
                    sb.append("null");
                } else {
                    sb.append("float[" + fc.length + "{");
                    for (int di = 0; di < fc.length; di++) {
                        sb.append(fc[di]);
                        if (di < fc.length - 1) {
                            sb.append(", ");
                        }
                    }
                    sb.append("}");
                }
                if (ci < end.length - 1) {
                    sb.append(", ");
                }
            }
            sb.append("}");
        }

        return sb.toString();