/* * $Id$ * This file is a part of the Arakhne Foundation Classes, http://www.arakhne.org/afc * * Copyright (c) 2000-2012 Stephane GALLAND. * Copyright (c) 2005-10, Multiagent Team, Laboratoire Systemes et Transports, * Universite de Technologie de Belfort-Montbeliard. * Copyright (c) 2013-2016 The original authors, and other authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.arakhne.afc.math.discrete.object2d; import org.arakhne.afc.math.generic.PathElement2D; import org.arakhne.afc.math.generic.PathElementType; import org.arakhne.afc.vmutil.ReflectionUtil; /** An element of the path. * * @author $Author: sgalland$ * @version $FullVersion$ * @mavengroupid $GroupId$ * @mavenartifactid $ArtifactId$ * @deprecated see {@link org.arakhne.afc.math.geometry.d2.i.PathElement2i} */ @Deprecated @SuppressWarnings("all") public abstract class PathElement2i implements PathElement2D { private static final long serialVersionUID = 7757419973445894032L; /** Create an instance of path element. * * @param type is the type of the new element. * @param lastX is the coordinate of the last point. * @param lastY is the coordinate of the last point. * @param coords are the coordinates. * @return the instance of path element. */ public static PathElement2i newInstance(PathElementType type, int lastX, int lastY, int[] coords) { switch(type) { case MOVE_TO: return new MovePathElement2i(coords[0], coords[1]); case LINE_TO: return new LinePathElement2i(lastX, lastY, coords[0], coords[1]); case QUAD_TO: return new QuadPathElement2i(lastX, lastY, coords[0], coords[1], coords[2], coords[3]); case CURVE_TO: return new CurvePathElement2i(lastX, lastY, coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]); case CLOSE: return new ClosePathElement2i(lastX, lastY, coords[0], coords[1]); default: } throw new IllegalArgumentException(); } /** Type of the path element. */ public final PathElementType type; /** Source point. */ public final int fromX; /** Source point. */ public final int fromY; /** Target point. */ public final int toX; /** Target point. */ public final int toY; /** First control point. */ public final int ctrlX1; /** First control point. */ public final int ctrlY1; /** Second control point. */ public final int ctrlX2; /** Second control point. */ public final int ctrlY2; /** * @param type is the type of the element. * @param fromx is the source point. * @param fromy is the source point. * @param ctrlx1 is the first control point. * @param ctrly1 is the first control point. * @param ctrlx2 is the first control point. * @param ctrly2 is the first control point. * @param tox is the target point. * @param toy is the target point. */ public PathElement2i(PathElementType type, int fromx, int fromy, int ctrlx1, int ctrly1, int ctrlx2, int ctrly2, int tox, int toy) { assert(type!=null); this.type = type; this.fromX = fromx; this.fromY = fromy; this.ctrlX1 = ctrlx1; this.ctrlY1 = ctrly1; this.ctrlX2 = ctrlx2; this.ctrlY2 = ctrly2; this.toX = tox; this.toY = toy; } /** Copy the coords into the given array, except the source point. * * @param array */ public abstract void toArray(int[] array); /** Copy the coords into the given array, except the source point. * * @param array */ public abstract void toArray(float[] array); /** Copy the coords into an array, except the source point. * * @return the array of the points, except the source point. */ public abstract int[] toArray(); /** An element of the path that represents a <code>MOVE_TO</code>. * * @author $Author: sgalland$ * @version $FullVersion$ * @mavengroupid $GroupId$ * @mavenartifactid $ArtifactId$ */ public static class MovePathElement2i extends PathElement2i { private static final long serialVersionUID = -8591881826671557331L; /** * @param x * @param y */ public MovePathElement2i(int x, int y) { super(PathElementType.MOVE_TO, 0, 0, 0, 0, 0, 0, x, y); } @Override public final PathElementType getType() { return PathElementType.MOVE_TO; } @Override public boolean isEmpty() { return (this.fromX==this.toX) && (this.fromY==this.toY); } @Override public boolean isDrawable() { return false; } @Override public void toArray(int[] array) { array[0] = this.toX; array[1] = this.toY; } @Override public void toArray(float[] array) { array[0] = this.toX; array[1] = this.toY; } @Override public int[] toArray() { return new int[] {this.toX, this.toY}; } @Override public String toString() { return ReflectionUtil.toString(this); } } /** An element of the path that represents a <code>LINE_TO</code>. * * @author $Author: sgalland$ * @version $FullVersion$ * @mavengroupid $GroupId$ * @mavenartifactid $ArtifactId$ */ public static class LinePathElement2i extends PathElement2i { private static final long serialVersionUID = 497492389885992535L; /** * @param fromx * @param fromy * @param tox * @param toy */ public LinePathElement2i(int fromx, int fromy, int tox, int toy) { super(PathElementType.LINE_TO, fromx, fromy, 0, 0, 0, 0, tox, toy); } @Override public final PathElementType getType() { return PathElementType.LINE_TO; } @Override public boolean isEmpty() { return (this.fromX==this.toX) && (this.fromY==this.toY); } @Override public boolean isDrawable() { return !isEmpty(); } @Override public void toArray(int[] array) { array[0] = this.toX; array[1] = this.toY; } @Override public void toArray(float[] array) { array[0] = this.toX; array[1] = this.toY; } @Override public int[] toArray() { return new int[] {this.toX, this.toY}; } @Override public String toString() { return ReflectionUtil.toString(this); } } /** An element of the path that represents a <code>QUAD_TO</code>. * * @author $Author: sgalland$ * @version $FullVersion$ * @mavengroupid $GroupId$ * @mavenartifactid $ArtifactId$ */ public static class QuadPathElement2i extends PathElement2i { private static final long serialVersionUID = 6341899683730854257L; /** * @param fromx * @param fromy * @param ctrlx * @param ctrly * @param tox * @param toy */ public QuadPathElement2i(int fromx, int fromy, int ctrlx, int ctrly, int tox, int toy) { super(PathElementType.QUAD_TO, fromx, fromy, ctrlx, ctrly, 0, 0, tox, toy); } @Override public final PathElementType getType() { return PathElementType.QUAD_TO; } @Override public boolean isEmpty() { return (this.fromX==this.toX) && (this.fromY==this.toY) && (this.ctrlX1==this.toX) && (this.ctrlY1==this.toY); } @Override public boolean isDrawable() { return !isEmpty(); } @Override public void toArray(int[] array) { array[0] = this.ctrlX1; array[1] = this.ctrlY1; array[2] = this.toX; array[3] = this.toY; } @Override public void toArray(float[] array) { array[0] = this.ctrlX1; array[1] = this.ctrlY1; array[2] = this.toX; array[3] = this.toY; } @Override public int[] toArray() { return new int[] {this.ctrlX1, this.ctrlY1, this.toX, this.toY}; } @Override public String toString() { return ReflectionUtil.toString(this); } } /** An element of the path that represents a <code>CURVE_TO</code>. * * @author $Author: sgalland$ * @version $FullVersion$ * @mavengroupid $GroupId$ * @mavenartifactid $ArtifactId$ */ public static class CurvePathElement2i extends PathElement2i { private static final long serialVersionUID = 1043302430176113524L; /** * @param fromx * @param fromy * @param ctrlx1 * @param ctrly1 * @param ctrlx2 * @param ctrly2 * @param tox * @param toy */ public CurvePathElement2i(int fromx, int fromy, int ctrlx1, int ctrly1, int ctrlx2, int ctrly2, int tox, int toy) { super(PathElementType.CURVE_TO, fromx, fromy, ctrlx1, ctrly1, ctrlx2, ctrly2, tox, toy); } @Override public final PathElementType getType() { return PathElementType.CURVE_TO; } @Override public boolean isEmpty() { return (this.fromX==this.toX) && (this.fromY==this.toY) && (this.ctrlX1==this.toX) && (this.ctrlY1==this.toY) && (this.ctrlX2==this.toX) && (this.ctrlY2==this.toY); } @Override public boolean isDrawable() { return !isEmpty(); } @Override public void toArray(int[] array) { array[0] = this.ctrlX1; array[1] = this.ctrlY1; array[2] = this.ctrlX2; array[3] = this.ctrlY2; array[4] = this.toX; array[5] = this.toY; } @Override public void toArray(float[] array) { array[0] = this.ctrlX1; array[1] = this.ctrlY1; array[2] = this.ctrlX2; array[3] = this.ctrlY2; array[4] = this.toX; array[5] = this.toY; } @Override public int[] toArray() { return new int[] {this.ctrlX1, this.ctrlY1, this.ctrlX2, this.ctrlY2, this.toX, this.toY}; } @Override public String toString() { return ReflectionUtil.toString(this); } } /** An element of the path that represents a <code>CLOSE</code>. * * @author $Author: sgalland$ * @version $FullVersion$ * @mavengroupid $GroupId$ * @mavenartifactid $ArtifactId$ */ public static class ClosePathElement2i extends PathElement2i { private static final long serialVersionUID = 2745123226508569279L; /** * @param fromx * @param fromy * @param tox * @param toy */ public ClosePathElement2i(int fromx, int fromy, int tox, int toy) { super(PathElementType.CLOSE, fromx, fromy, 0, 0, 0, 0, tox, toy); } @Override public final PathElementType getType() { return PathElementType.CLOSE; } @Override public boolean isEmpty() { return (this.fromX==this.toX) && (this.fromY==this.toY); } @Override public boolean isDrawable() { return false; } @Override public void toArray(int[] array) { // } @Override public void toArray(float[] array) { // } @Override public int[] toArray() { return new int[0]; } @Override public String toString() { return ReflectionUtil.toString(this); } } }