/* --------------------------------------------------------- *
* __________ D E L T A S C R I P T *
* (_________() *
* / === / - A fast, dynamic scripting language *
* | == | - Version 4.13.11.0 *
* / === / - Developed by Adam R. Nelson *
* | = = | - 2011-2013 *
* / === / - Distributed under GNU LGPL v3 *
* (________() - http://github.com/ar-nelson/deltascript *
* *
* --------------------------------------------------------- */
package com.sector91.delta.script.objects.geom;
import com.sector91.delta.script.annotations.DSDynamicField;
import com.sector91.delta.script.annotations.DSInaccessible;
import com.sector91.delta.script.annotations.DSName;
import com.sector91.delta.script.objects.DS_Vector;
import com.sector91.geom.Curve2D;
import com.sector91.geom.DimensionMismatchException;
import com.sector91.geom.Shape2D;
import com.sector91.geom.Vector;
import com.sector91.geom.algorithms.Algorithms;
public abstract class DS_AbstractCurve2D extends DS_AbstractCurve
implements DS_Curve2D
{
@DSInaccessible
DS_AbstractCurve2D(DeltaScriptGeometry geom)
{super(geom);}
@DSName("center") @DSDynamicField
public DS_Vector center()
{return boundingBox().center();}
@DSName("curved") @DSDynamicField
public boolean curved()
{return true;}
@DSName("dimensions") @DSDynamicField
public final int dimensions()
{return 2;}
@DSName("intersects")
public boolean intersects(Shape2D other)
{
DimensionMismatchException.check("intersects", this, other);
if (other instanceof Curve2D)
return Algorithms.testCurveIntersection(this, (Curve2D)other, 1.0f);
else
return Algorithms.testPathIntersection(this, other, 1.0f);
}
@Override public abstract DS_Rect boundingBox();
@DSName("translate")
public DS_Curve2D translate(float x, float y)
{return transform(geom.vec(Algorithms.translateMatrix2D(x, y)));}
@DSName("translate")
public DS_Curve2D translate(Vector vec)
{return translate(vec.x(), vec.y());}
@DSName("scale")
public DS_Curve2D scale(float x, float y)
{return transform(geom.vec(Algorithms.scaleMatrix2D(x, y)));}
@DSName("scale")
public DS_Curve2D scale(Vector vec)
{return scale(vec.x(), vec.y());}
@DSName("shear")
public DS_Curve2D shear(float x, float y)
{return transform(geom.vec(Algorithms.shearMatrix2D(x, y)));}
@DSName("shear")
public DS_Curve2D shear(Vector vec)
{return shear(vec.x(), vec.y());}
@DSName("rotate")
public DS_Curve2D rotate(float radians)
{return transform(geom.vec(Algorithms.rotateMatrix2D(radians)));}
@DSName("rotate")
public DS_Curve2D rotate(float radians, float cx, float cy)
{return translate(-cx, -cy).rotate(radians).translate(cx, cy);}
@DSName("rotate")
public DS_Curve2D rotate(float radians, Vector center)
{return rotate(radians, center.x(), center.y());}
@DSName("perimeter") @DSDynamicField
public final float perimeter()
{return length();}
@DSName("area") @DSDynamicField
public final float area()
{return 0;}
@DSName("length") @DSDynamicField
public float length()
{
return Algorithms.approximateBezierLength(
geom.bezierApproximationSubdivisions(), this);
}
@DSName("curves") @DSDynamicField
@Override public DS_Curve2D[] curves()
{return new DS_Curve2D[] {this};}
@DSName("splitAt")
@Override public DS_Curve2D[] splitAt(float t)
{
final Vector[][] splitCurve = Algorithms.splitCurve(geom, this, t);
final Vector startA = splitCurve[0][0];
final Vector endA = splitCurve[0][splitCurve[0].length-1];
final Vector startB = splitCurve[1][0];
final Vector endB = splitCurve[1][splitCurve[1].length-1];
final Vector[] cpA = new Vector[splitCurve[0].length-2];
System.arraycopy(splitCurve[0], 1, cpA, 0, cpA.length);
final Vector[] cpB = new Vector[splitCurve[1].length-2];
System.arraycopy(splitCurve[1], 1, cpB, 0, cpB.length);
return new DS_Curve2D[] {
(DS_Curve2D)geom.curve(startA, cpA, endA),
(DS_Curve2D)geom.curve(startB, cpB, endB)
};
}
@Override public DS_Vector random()
{return Algorithms.bezierPoint(geom, (float)Math.random(), this);}
}