/* --------------------------------------------------------- * * __________ 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.DeltaScript; import com.sector91.delta.script.NumberTypes; import com.sector91.delta.script.objects.DS_Vector; import com.sector91.delta.script.objects.VectorFactory; import com.sector91.geom.GenericGeometry; import com.sector91.geom.Path; import com.sector91.geom.PathData; import com.sector91.geom.Shape; import com.sector91.geom.Shape2D; import com.sector91.geom.Vector; public class DeltaScriptGeometry extends GenericGeometry< DS_Vector, DS_Shape , DS_Shape2D, DS_Line, DS_Line2D, DS_Curve, DS_Curve2D, DS_Box, DS_Rect, DS_Ellipse, DS_Circle> { private static final long serialVersionUID = DeltaScript.VERSION.majorVersion(); private final DS_Path2D EMPTY_SHAPE_2D = new DS_Path2D(this, PathData.emptyPath(this, 2)); private final DS_PathND EMPTY_SHAPE_3D = new DS_PathND(this, PathData.emptyPath(this, 3)); public static final DeltaScriptGeometry GEOM = new DeltaScriptGeometry(); public static final int NUMBER_TYPE = NumberTypes.SHORT_FLOAT; protected DeltaScriptGeometry() {} @Override public DS_Vector vec(float x, float y) {return vec(new float[] {x, y});} @Override public DS_Vector vec(float x, float y, float z) {return vec(new float[] {x, y, z});} @Override public DS_Vector vec(float[] c) {return VectorFactory.fromArray(c, NUMBER_TYPE);} @Override public DS_Shape convert(Shape s) {return (DS_Shape)defaultConvert(s);} @Override public DS_Shape2D convert(Shape2D d) {return (DS_Shape2D)defaultConvert(d);} @Override public DS_Line2D line(float x1, float y1, float x2, float y2) {return new DS_Line2D(this, x1, y1, x2, y2);} @Override public DS_Line line(Vector v1, Vector v2) { if (v1.dimensions() == 2) return line2(v1, v2); else return new DS_LineND(this, convert(v1), convert(v2)); } @Override public DS_Rect rect(float x, float y, float width, float height) {return new DS_Rect(this, x, y, width, height);} @Override public DS_Box box(Vector origin, Vector span) { if (origin.dimensions() == 2) return rect(origin, span); else return new DS_BoxND(this, convert(origin), convert(span)); } @Override public DS_Ellipse ellipse(float x, float y, float rx, float ry) {return new DS_Ellipse(this, x, y, rx, ry);} @Override public DS_Circle circle(float x, float y, float r) {return new DS_Circle(this, x, y, r);} @Override public DS_QuadCurve quadCurve(float x1, float y1, float cx, float cy, float x2, float y2) {return new DS_QuadCurve(this, x1, y1, cx, cy, x2, y2);} @Override public DS_CubicCurve cubicCurve(float x1, float y1, float c1x, float c1y, float c2x, float c2y, float x2, float y2) {return new DS_CubicCurve(this, x1, y1, c1x, c1y, c2x, c2y, x2, y2);} @Override public DS_CurveND curve(Vector start, Vector[] cp, Vector end) { final DS_Vector[] newcps = new DS_Vector[cp.length]; for (int i=0; i<cp.length; i++) newcps[i] = convert(cp[i]); return new DS_CurveND(this, convert(start), newcps, convert(end)); } @Override public DS_Shape path(PathData data) { if (data.dimensions() == 2) return path2(data); return new DS_PathND(this, data); } @Override public DS_Path2D path2(PathData data) {return new DS_Path2D(this, data);} @Override public DS_Path2DBuilder path() {return new DS_Path2DBuilder(this);} @Override public DS_PathBuilder<? extends Path> path(int dimensions) { if (dimensions == 2) return path(); return new DS_PathNDBuilder(this, dimensions); } @Override public DS_Shape2D emptyShape2D() {return EMPTY_SHAPE_2D;} @Override public DS_Shape emptyShape(int dimensions) { switch (dimensions) { case 2: return EMPTY_SHAPE_2D; case 3: return EMPTY_SHAPE_3D; default: if (dimensions < 2) throw new IllegalArgumentException("A shape must have at least" + " 2 dimensions."); return new DS_PathND(this, PathData.emptyPath(this, dimensions)); } } }