Android examples for Graphics:Path
translate Polygon
/******************************************************************************* * Copyright (c) 2011 MadRobot./*from ww w . j ava 2 s .com*/ * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Lesser Public License v2.1 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * * Contributors: * Elton Kent - initial API and implementation ******************************************************************************/ import android.graphics.PointF; public class Main{ /** * * * @param x * @param y * @param dx * @param dy * @throws IllegalArgumentException * if <code>x</code> or <code>y</code> is null or their array * lengths do not match */ public static void translate(float[] x, float[] y, float dx, float dy) throws IllegalArgumentException { if (isValidPolygon(x, y)) throw new IllegalArgumentException( "points length do not match or one of the points is null"); PointF temp; for (int i = 0; i < x.length; i++) { temp = new PointF(x[i], y[i]); PointUtils.translate(temp, dx, dy); x[i] = temp.x; y[i] = temp.y; } } public static boolean isValidPolygon(float[] x, float[] y) { if (x == null || y == null) { return false; } else if (x.length != y.length) { return false; } return true; } }