001 /*
002 * MoveTo.java
003 *
004 *
005 * The Salamander Project - 2D and 3D graphics libraries in Java
006 * Copyright (C) 2004 Mark McKay
007 *
008 * This library is free software; you can redistribute it and/or
009 * modify it under the terms of the GNU Lesser General Public
010 * License as published by the Free Software Foundation; either
011 * version 2.1 of the License, or (at your option) any later version.
012 *
013 * This library is distributed in the hope that it will be useful,
014 * but WITHOUT ANY WARRANTY; without even the implied warranty of
015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016 * Lesser General Public License for more details.
017 *
018 * You should have received a copy of the GNU Lesser General Public
019 * License along with this library; if not, write to the Free Software
020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
021 *
022 * Mark McKay can be contacted at mark@kitfox.com. Salamander and other
023 * projects can be found at http://www.kitfox.com
024 *
025 * Created on January 26, 2004, 8:40 PM
026 */
027
028 package com.kitfox.svg.pathcmd;
029
030 //import org.apache.batik.ext.awt.geom.ExtendedGeneralPath;
031 import java.awt.geom.*;
032
033 /**
034 * @author Mark McKay
035 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
036 */
037 public class CubicSmooth extends PathCommand {
038
039 public float x = 0f;
040 public float y = 0f;
041 public float k2x = 0f;
042 public float k2y = 0f;
043
044 /** Creates a new instance of MoveTo */
045 public CubicSmooth() {
046 }
047
048 public CubicSmooth(boolean isRelative, float k2x, float k2y, float x, float y) {
049 super(isRelative);
050 this.k2x = k2x;
051 this.k2y = k2y;
052 this.x = x;
053 this.y = y;
054 }
055
056 // public void appendPath(ExtendedGeneralPath path, BuildHistory hist)
057 public void appendPath(GeneralPath path, BuildHistory hist)
058 {
059 float offx = isRelative ? hist.history[0].x : 0f;
060 float offy = isRelative ? hist.history[0].y : 0f;
061
062 float oldKx = hist.history.length >= 2 ? hist.history[1].x : hist.history[0].x;
063 float oldKy = hist.history.length >= 2 ? hist.history[1].y : hist.history[0].y;
064 float oldX = hist.history[0].x;
065 float oldY = hist.history[0].y;
066 //Calc knot as reflection of old knot
067 float k1x = oldX * 2f - oldKx;
068 float k1y = oldY * 2f - oldKy;
069
070 path.curveTo(k1x, k1y, k2x + offx, k2y + offy, x + offx, y + offy);
071 hist.setPointAndKnot(x + offx, y + offy, k2x + offx, k2y + offy);
072 }
073
074 public int getNumKnotsAdded()
075 {
076 return 6;
077 }
078 }