[kaffe] CVS kaffe (dalibor): Resynced with GNU Classpath

Kaffe CVS cvs-commits at kaffe.org
Sat Oct 25 11:39:02 PDT 2003


PatchSet 4124 
Date: 2003/10/25 18:30:20
Author: dalibor
Branch: HEAD
Tag: (none) 
Log:
Resynced with GNU Classpath

Members: 
	ChangeLog:1.1716->1.1717 
	libraries/javalib/gnu/java/nio/FileLockImpl.java:1.1->1.2 
	libraries/javalib/gnu/java/nio/PipeImpl.java:1.1->1.2 
	libraries/javalib/gnu/java/nio/SelectorImpl.java:1.4->1.5 
	libraries/javalib/gnu/java/nio/SelectorProviderImpl.java:1.2->1.3 
	libraries/javalib/gnu/java/nio/SocketChannelImpl.java:1.7->1.8 
	libraries/javalib/java/awt/geom/CubicCurve2D.java:1.2->1.3 
	libraries/javalib/java/awt/geom/GeneralPath.java:1.2->1.3 
	libraries/javalib/java/awt/geom/QuadCurve2D.java:1.3->1.4 
	libraries/javalib/java/io/File.java:1.39->1.40 
	libraries/javalib/java/lang/StringBuffer.java:1.23->1.24 
	libraries/javalib/java/net/InetSocketAddress.java:1.6->1.7 
	libraries/javalib/java/nio/ByteOrder.java:1.3->1.4 
	libraries/javalib/java/nio/channels/FileChannelImpl.java:1.2->1.3 
	libraries/javalib/java/text/DateFormat.java:1.16->1.17 
	libraries/javalib/java/text/FormatCharacterIterator.java:1.1->1.2 
	libraries/javalib/java/text/SimpleDateFormat.java:1.26->1.27 
	libraries/javalib/java/util/logging/ErrorManager.java:1.1->1.2 
	libraries/javalib/javax/naming/spi/NamingManager.java:1.4->1.5 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.1716 kaffe/ChangeLog:1.1717
--- kaffe/ChangeLog:1.1716	Sat Oct 25 12:52:41 2003
+++ kaffe/ChangeLog	Sat Oct 25 18:30:20 2003
@@ -1,3 +1,25 @@
+2003-10-25  Dalibor Topic <robilad at kaffe.org>
+
+	* libraries/javalib/gnu/java/nio/FileLockImpl.java,
+        libraries/javalib/gnu/java/nio/PipeImpl.java,
+        libraries/javalib/gnu/java/nio/SelectorImpl.java,
+        libraries/javalib/gnu/java/nio/SelectorProviderImpl.java,
+        libraries/javalib/gnu/java/nio/SocketChannelImpl.java,
+        libraries/javalib/java/awt/geom/CubicCurve2D.java,
+        libraries/javalib/java/awt/geom/GeneralPath.java,
+        libraries/javalib/java/awt/geom/QuadCurve2D.java,
+        libraries/javalib/java/io/File.java,
+        libraries/javalib/java/lang/StringBuffer.java,
+        libraries/javalib/java/net/InetSocketAddress.java,
+        libraries/javalib/java/nio/ByteOrder.java,
+        libraries/javalib/java/nio/channels/FileChannelImpl.java,
+        libraries/javalib/java/text/DateFormat.java,
+        libraries/javalib/java/text/FormatCharacterIterator.java,
+        libraries/javalib/java/text/SimpleDateFormat.java,
+        libraries/javalib/java/util/logging/ErrorManager.java,
+        libraries/javalib/javax/naming/spi/NamingManager.java:
+	Resynced with GNU Classpath.
+
 2003-10-25  Helmer Kraemer  <hkraemer at freenet.de>
 
 	* config/arm/linux/jit-md.h:
Index: kaffe/libraries/javalib/gnu/java/nio/FileLockImpl.java
diff -u kaffe/libraries/javalib/gnu/java/nio/FileLockImpl.java:1.1 kaffe/libraries/javalib/gnu/java/nio/FileLockImpl.java:1.2
--- kaffe/libraries/javalib/gnu/java/nio/FileLockImpl.java:1.1	Sun Sep 28 19:54:10 2003
+++ kaffe/libraries/javalib/gnu/java/nio/FileLockImpl.java	Sat Oct 25 18:30:21 2003
@@ -42,6 +42,7 @@
 import java.io.IOException;
 import java.nio.channels.FileChannel;
 import java.nio.channels.FileLock;
+import gnu.classpath.Configuration;
 
 /**
  * @author Michael Koch
@@ -49,6 +50,15 @@
  */
 public class FileLockImpl extends FileLock
 {
+  static
+  {
+    // load the shared library needed for native methods.
+    if (Configuration.INIT_LOAD_LIBRARY)
+      {
+        System.loadLibrary ("javanio");
+      }
+  }
+  
   private FileDescriptor fd;
   private boolean released;
   
Index: kaffe/libraries/javalib/gnu/java/nio/PipeImpl.java
diff -u kaffe/libraries/javalib/gnu/java/nio/PipeImpl.java:1.1 kaffe/libraries/javalib/gnu/java/nio/PipeImpl.java:1.2
--- kaffe/libraries/javalib/gnu/java/nio/PipeImpl.java:1.1	Thu Nov 28 13:39:26 2002
+++ kaffe/libraries/javalib/gnu/java/nio/PipeImpl.java	Sat Oct 25 18:30:21 2003
@@ -1,5 +1,5 @@
 /* PipeImpl.java -- 
-   Copyright (C) 2002 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2003 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -37,12 +37,16 @@
 
 package gnu.java.nio;
 
+import java.io.IOException;
 import java.nio.channels.Pipe;
+import java.nio.channels.spi.SelectorProvider;
 
 class PipeImpl extends Pipe
 {
-  public PipeImpl()
+  public PipeImpl (SelectorProvider provider)
+    throws IOException
   {
+    super();
   }
     
   public Pipe.SinkChannel sink()
Index: kaffe/libraries/javalib/gnu/java/nio/SelectorImpl.java
diff -u kaffe/libraries/javalib/gnu/java/nio/SelectorImpl.java:1.4 kaffe/libraries/javalib/gnu/java/nio/SelectorImpl.java:1.5
--- kaffe/libraries/javalib/gnu/java/nio/SelectorImpl.java:1.4	Wed Oct 22 10:34:47 2003
+++ kaffe/libraries/javalib/gnu/java/nio/SelectorImpl.java	Sat Oct 25 18:30:21 2003
@@ -49,9 +49,19 @@
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Set;
+import gnu.classpath.Configuration;
 
 public class SelectorImpl extends AbstractSelector
 {
+  static
+  {
+    // load the shared library needed for native methods.
+    if (Configuration.INIT_LOAD_LIBRARY)
+      {
+        System.loadLibrary ("javanio");
+      }
+  }
+  
   private Set keys;
   private Set selected;
 
@@ -59,8 +69,8 @@
   {
     super (provider);
     
-    keys = new HashSet ();
-    selected = new HashSet ();
+    keys = new HashSet();
+    selected = new HashSet();
   }
 
   protected void finalize() throws Throwable
@@ -100,32 +110,32 @@
   {
     int[] result;
     int counter = 0;
-    Iterator it = keys.iterator ();
+    Iterator it = keys.iterator();
 
     // Count the number of file descriptors needed
-    while (it.hasNext ())
+    while (it.hasNext())
       {
-        SelectionKeyImpl key = (SelectionKeyImpl) it.next ();
+        SelectionKeyImpl key = (SelectionKeyImpl) it.next();
 
-        if ((key.interestOps () & ops) != 0)
+        if ((key.interestOps() & ops) != 0)
           {
             counter++;
           }
       }
 
-    result = new int[counter];
+    result = new int [counter];
 
     counter = 0;
-    it = keys.iterator ();
+    it = keys.iterator();
 
     // Fill the array with the file descriptors
-    while (it.hasNext ())
+    while (it.hasNext())
       {
-        SelectionKeyImpl key = (SelectionKeyImpl) it.next ();
+        SelectionKeyImpl key = (SelectionKeyImpl) it.next();
 
-        if ((key.interestOps () & ops) != 0)
+        if ((key.interestOps() & ops) != 0)
           {
-            result[counter] = key.getNativeFD();
+            result [counter] = key.getNativeFD();
             counter++;
           }
       }
@@ -136,12 +146,12 @@
   public int select (long timeout)
   {
     if (!isOpen())
-      throw new ClosedSelectorException ();
+      throw new ClosedSelectorException();
 
     if (keys == null)
-	    {
+      {
         return 0;
-	    }
+      }
 
     deregisterCancelledKeys();
 
@@ -156,25 +166,25 @@
     int result = implSelect (read, write, except, timeout);
     end();
 
-    Iterator it = keys.iterator ();
+    Iterator it = keys.iterator();
 
-    while (it.hasNext ())
+    while (it.hasNext())
       {
         int ops = 0;
-        SelectionKeyImpl key = (SelectionKeyImpl) it.next ();
+        SelectionKeyImpl key = (SelectionKeyImpl) it.next();
 
         // If key is already selected retrieve old ready ops.
         if (selected.contains (key))
           {
-            ops = key.readyOps ();
+            ops = key.readyOps();
           }
 
         // Set new ready read/accept ops
         for (int i = 0; i < read.length; i++)
           {
-            if (key.getNativeFD() == read[i])
+            if (key.getNativeFD() == read [i])
               {
-                if (key.channel () instanceof ServerSocketChannelImpl)
+                if (key.channel() instanceof ServerSocketChannelImpl)
                   {
                     ops = ops | SelectionKey.OP_ACCEPT;
                   }
@@ -188,11 +198,11 @@
         // Set new ready write ops
         for (int i = 0; i < write.length; i++)
           {
-            if (key.getNativeFD() == write[i])
+            if (key.getNativeFD() == write [i])
               {
                 ops = ops | SelectionKey.OP_WRITE;
                 
-//                 if (key.channel ().isConnected ())
+//                 if (key.channel().isConnected())
 //                   {
 //                     ops = ops | SelectionKey.OP_WRITE;
 //                   }
@@ -212,7 +222,7 @@
           }
 
         // Set new ready ops
-        key.readyOps (key.interestOps () & ops);
+        key.readyOps (key.interestOps() & ops);
       }
 
     deregisterCancelledKeys();
@@ -233,10 +243,10 @@
   {
     Iterator it = cancelledKeys().iterator();
 
-    while (it.hasNext ())
+    while (it.hasNext())
       {
-        keys.remove ((SelectionKeyImpl) it.next ());
-        it.remove ();
+        keys.remove ((SelectionKeyImpl) it.next());
+        it.remove();
       }
   }
 
Index: kaffe/libraries/javalib/gnu/java/nio/SelectorProviderImpl.java
diff -u kaffe/libraries/javalib/gnu/java/nio/SelectorProviderImpl.java:1.2 kaffe/libraries/javalib/gnu/java/nio/SelectorProviderImpl.java:1.3
--- kaffe/libraries/javalib/gnu/java/nio/SelectorProviderImpl.java:1.2	Wed May 14 23:20:06 2003
+++ kaffe/libraries/javalib/gnu/java/nio/SelectorProviderImpl.java	Sat Oct 25 18:30:22 2003
@@ -1,5 +1,5 @@
 /* SelectorProviderImpl.java -- 
-   Copyright (C) 2002 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2003 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -60,7 +60,7 @@
   public Pipe openPipe ()
     throws IOException
   {
-    return new PipeImpl ();
+    return new PipeImpl (this);
   }
     
   public AbstractSelector openSelector ()
Index: kaffe/libraries/javalib/gnu/java/nio/SocketChannelImpl.java
diff -u kaffe/libraries/javalib/gnu/java/nio/SocketChannelImpl.java:1.7 kaffe/libraries/javalib/gnu/java/nio/SocketChannelImpl.java:1.8
--- kaffe/libraries/javalib/gnu/java/nio/SocketChannelImpl.java:1.7	Wed Oct 22 10:34:47 2003
+++ kaffe/libraries/javalib/gnu/java/nio/SocketChannelImpl.java	Sat Oct 25 18:30:22 2003
@@ -66,7 +66,6 @@
   private PlainSocketImpl impl;
   private NIOSocket socket;
   private boolean blocking = true;
-  private boolean connected = false;
   private boolean connectionPending = false;
 
   SocketChannelImpl (SelectorProvider provider)
@@ -84,7 +83,6 @@
     super (provider);
     this.impl = socket.getImpl();
     this.socket = socket;
-    this.connected = socket.isConnected();
   }
 
   public void finalizer()
@@ -113,7 +111,6 @@
 
   protected void implCloseSelectableChannel () throws IOException
   {
-    connected = false;
     socket.close();
   }
 
@@ -144,7 +141,6 @@
       {
         // Do blocking connect.
         socket.connect (remote);
-        connected = true;
         return true;
       }
 
@@ -152,7 +148,6 @@
     try
       {
         socket.connect (remote, NIOConstants.DEFAULT_TIMEOUT);
-        connected = true;
         return true;
       }
     catch (SocketTimeoutException e)
@@ -182,7 +177,6 @@
     if (isBlocking())
       {
         selector.select(); // blocking until channel is connected.
-        connected = true;
         connectionPending = false;
         return true;
       }
@@ -190,7 +184,6 @@
     int ready = selector.selectNow(); // non-blocking
     if (ready == 1)
       {
-        connected = true;
         connectionPending = false;
         return true;
       }
@@ -200,7 +193,7 @@
 
   public boolean isConnected ()
   {
-    return connected;
+    return socket.isConnected();
   }
     
   public boolean isConnectionPending ()
@@ -215,13 +208,21 @@
 
   public int read (ByteBuffer dst) throws IOException
   {
-    if (!connected)
+    if (!isConnected())
       throw new NotYetConnectedException();
     
     byte[] data;
     int offset = 0;
+    InputStream input = socket.getInputStream();
+    int available = input.available();
     int len = dst.remaining();
 	
+    if (available == 0)
+      return 0;
+    
+    if (len > available)
+      len = available;
+
     if (dst.hasArray())
       {
         offset = dst.arrayOffset() + dst.position();
@@ -232,15 +233,6 @@
         data = new byte [len];
       }
 
-    InputStream input = socket.getInputStream();
-    int available = input.available();
-
-    if (available == 0)
-      return 0;
-    
-    if (len > available)
-      len = available;
-
     int readBytes = 0;
     boolean completed = false;
 
@@ -255,11 +247,15 @@
         end (completed);
       }
 
-    if (readBytes > 0
-        && !dst.hasArray())
-      {
-        dst.put (data);
-      }
+    if (readBytes > 0)
+      if (dst.hasArray())
+	{
+	  dst.position (dst.position() + readBytes);
+	}
+      else
+        {
+          dst.put (data, offset, len);
+        }
 
     return readBytes;
   }
@@ -267,7 +263,7 @@
   public long read (ByteBuffer[] dsts, int offset, int length)
     throws IOException
   {
-    if (!connected)
+    if (!isConnected())
       throw new NotYetConnectedException();
     
     if ((offset < 0)
@@ -287,7 +283,7 @@
   public int write (ByteBuffer src)
     throws IOException
   {
-    if (!connected)
+    if (!isConnected())
       throw new NotYetConnectedException();
     
     byte[] data;
@@ -309,13 +305,19 @@
     
     OutputStream output = socket.getOutputStream();
     output.write (data, offset, len);
+
+    if (src.hasArray())
+      {
+	src.position (src.position() + len);
+      }
+    
     return len;
   }
 
   public long write (ByteBuffer[] srcs, int offset, int length)
     throws IOException
   {
-    if (!connected)
+    if (!isConnected())
       throw new NotYetConnectedException();
     
     if ((offset < 0)
Index: kaffe/libraries/javalib/java/awt/geom/CubicCurve2D.java
diff -u kaffe/libraries/javalib/java/awt/geom/CubicCurve2D.java:1.2 kaffe/libraries/javalib/java/awt/geom/CubicCurve2D.java:1.3
--- kaffe/libraries/javalib/java/awt/geom/CubicCurve2D.java:1.2	Sun Aug 10 18:47:50 2003
+++ kaffe/libraries/javalib/java/awt/geom/CubicCurve2D.java	Sat Oct 25 18:30:22 2003
@@ -1,5 +1,5 @@
 /* CubicCurve2D.java -- represents a parameterized cubic curve in 2-D space
-   Copyright (C) 2002 Free Software Foundation
+   Copyright (C) 2002, 2003 Free Software Foundation
 
 This file is part of GNU Classpath.
 
@@ -42,31 +42,168 @@
 import java.awt.Shape;
 import java.util.NoSuchElementException;
 
+
 /**
- * STUBS ONLY
- * XXX Implement and document.
+ * A two-dimensional curve that is parameterized with a cubic
+ * function.
+ *
+ * <p><img src="doc-files/CubicCurve2D-1.png" width="350" height="180"
+ * alt="A drawing of a CubicCurve2D" />
+ *
+ * @author Eric Blake (ebb9 at email.byu.edu)
+ * @author Graydon Hoare (graydon at redhat.com)
+ * @author Sascha Brawer (brawer at dandelis.ch)
+ *
+ * @since 1.2
  */
-public abstract class CubicCurve2D implements Shape, Cloneable
+public abstract class CubicCurve2D
+  implements Shape, Cloneable
 {
+  /**
+   * Constructs a new CubicCurve2D. Typical users will want to
+   * construct instances of a subclass, such as {@link
+   * CubicCurve2D.Float} or {@link CubicCurve2D.Double}.
+   */
   protected CubicCurve2D()
   {
   }
 
+
+  /**
+   * Returns the <i>x</i> coordinate of the curve&#x2019;s start
+   * point.
+   */
   public abstract double getX1();
+
+
+  /**
+   * Returns the <i>y</i> coordinate of the curve&#x2019;s start
+   * point.
+   */
   public abstract double getY1();
+
+
+  /**
+   * Returns the curve&#x2019;s start point.
+   */
   public abstract Point2D getP1();
+
+
+  /**
+   * Returns the <i>x</i> coordinate of the curve&#x2019;s first
+   * control point.
+   */
   public abstract double getCtrlX1();
+
+
+  /**
+   * Returns the <i>y</i> coordinate of the curve&#x2019;s first
+   * control point.
+   */
   public abstract double getCtrlY1();
+
+
+  /**
+   * Returns the curve&#x2019;s first control point.
+   */
   public abstract Point2D getCtrlP1();
+
+
+  /**
+   * Returns the <i>x</i> coordinate of the curve&#x2019;s second
+   * control point.
+   */
   public abstract double getCtrlX2();
+
+
+  /**
+   * Returns the <i>y</i> coordinate of the curve&#x2019;s second
+   * control point.
+   */
   public abstract double getCtrlY2();
+
+
+  /**
+   * Returns the curve&#x2019;s second control point.
+   */
   public abstract Point2D getCtrlP2();
+
+
+  /**
+   * Returns the <i>x</i> coordinate of the curve&#x2019;s end
+   * point.
+   */
   public abstract double getX2();
+
+
+  /**
+   * Returns the <i>y</i> coordinate of the curve&#x2019;s end
+   * point.
+   */
   public abstract double getY2();
+
+
+  /**
+   * Returns the curve&#x2019;s end point.
+   */
   public abstract Point2D getP2();
 
+
+  /**
+   * Changes the curve geometry, separately specifying each coordinate
+   * value.
+   *
+   * <p><img src="doc-files/CubicCurve2D-1.png" width="350" height="180"
+   * alt="A drawing of a CubicCurve2D" />
+   *
+   * @param x1 the <i>x</i> coordinate of the curve&#x2019;s new start
+   * point.
+   *
+   * @param y1 the <i>y</i> coordinate of the curve&#x2019;s new start
+   * point.
+   *
+   * @param cx1 the <i>x</i> coordinate of the curve&#x2019;s new
+   * first control point.
+   *
+   * @param cy1 the <i>y</i> coordinate of the curve&#x2019;s new
+   * first control point.
+   *
+   * @param cx2 the <i>x</i> coordinate of the curve&#x2019;s new
+   * second control point.
+   *
+   * @param cy2 the <i>y</i> coordinate of the curve&#x2019;s new
+   * second control point.
+   *
+   * @param x2 the <i>x</i> coordinate of the curve&#x2019;s new end
+   * point.
+   *
+   * @param y2 the <i>y</i> coordinate of the curve&#x2019;s new end
+   * point.
+   */
   public abstract void setCurve(double x1, double y1, double cx1, double cy1,
                                 double cx2, double cy2, double x2, double y2);
+
+
+  /**
+   * Changes the curve geometry, specifying coordinate values in an
+   * array.
+   *
+   * @param coords an array containing the new coordinate values.  The
+   * <i>x</i> coordinate of the new start point is located at
+   * <code>coords[offset]</code>, its <i>y</i> coordinate at
+   * <code>coords[offset + 1]</code>.  The <i>x</i> coordinate of the
+   * new first control point is located at <code>coords[offset +
+   * 2]</code>, its <i>y</i> coordinate at <code>coords[offset +
+   * 3]</code>.  The <i>x</i> coordinate of the new second control
+   * point is located at <code>coords[offset + 4]</code>, its <i>y</i>
+   * coordinate at <code>coords[offset + 5]</code>.  The <i>x</i>
+   * coordinate of the new end point is located at <code>coords[offset
+   * + 6]</code>, its <i>y</i> coordinate at <code>coords[offset +
+   * 7]</code>.
+   *
+   * @param offset the offset of the first coordinate value in
+   * <code>coords</code>.
+   */
   public void setCurve(double[] coords, int offset)
   {
     setCurve(coords[offset++], coords[offset++],
@@ -74,11 +211,51 @@
              coords[offset++], coords[offset++],
              coords[offset++], coords[offset++]);
   }
+
+
+  /**
+   * Changes the curve geometry, specifying coordinate values in
+   * separate Point objects.
+   *
+   * <p><img src="doc-files/CubicCurve2D-1.png" width="350" height="180"
+   * alt="A drawing of a CubicCurve2D" />
+   *
+   * <p>The curve does not keep any reference to the passed point
+   * objects. Therefore, a later change to <code>p1</code>,
+   * <code>c1</code>, <code>c2</code> or <code>p2</code> will not
+   * affect the curve geometry.
+   *
+   * @param p1 the new start point.
+   * @param c1 the new first control point.
+   * @param c2 the new second control point.
+   * @param p2 the new end point.
+   */
   public void setCurve(Point2D p1, Point2D c1, Point2D c2, Point2D p2)
   {
     setCurve(p1.getX(), p1.getY(), c1.getX(), c1.getY(),
              c2.getX(), c2.getY(), p2.getX(), p2.getY());
   }
+
+
+  /**
+   * Changes the curve geometry, specifying coordinate values in an
+   * array of Point objects.
+   *
+   * <p><img src="doc-files/CubicCurve2D-1.png" width="350" height="180"
+   * alt="A drawing of a CubicCurve2D" />
+   *
+   * <p>The curve does not keep references to the passed point
+   * objects. Therefore, a later change to the <code>pts</code> array
+   * or any of its elements will not affect the curve geometry.
+   *
+   * @param pts an array containing the points. The new start point
+   * is located at <code>pts[offset]</code>, the new first control
+   * point at <code>pts[offset + 1]</code>, the new second control
+   * point at <code>pts[offset + 2]</code>, and the new end point
+   * at <code>pts[offset + 3]</code>.
+   *
+   * @param offset the offset of the start point in <code>pts</code>.
+   */
   public void setCurve(Point2D[] pts, int offset)
   {
     setCurve(pts[offset].getX(), pts[offset++].getY(),
@@ -86,24 +263,115 @@
              pts[offset].getX(), pts[offset++].getY(),
              pts[offset].getX(), pts[offset++].getY());
   }
+  
+
+  /**
+   * Changes the curve geometry to that of another curve.
+   *
+   * @param c the curve whose coordinates will be copied.
+   */
   public void setCurve(CubicCurve2D c)
   {
     setCurve(c.getX1(), c.getY1(), c.getCtrlX1(), c.getCtrlY1(),
              c.getCtrlX2(), c.getCtrlY2(), c.getX2(), c.getY2());
   }
+
+
+  /**
+   * Calculates the squared flatness of a cubic curve, directly
+   * specifying each coordinate value. The flatness is the maximal
+   * distance of a control point to the line between start and end
+   * point.
+   *
+   * <p><img src="doc-files/CubicCurve2D-4.png" width="350" height="180"
+   * alt="A drawing that illustrates the flatness" />
+   *
+   * <p>In the above drawing, the straight line connecting start point
+   * P1 and end point P2 is depicted in gray.  In comparison to C1,
+   * control point C2 is father away from the gray line. Therefore,
+   * the result will be the square of the distance between C2 and the
+   * gray line, i.e. the squared length of the red line.
+   *
+   * @param x1 the <i>x</i> coordinate of the start point P1.
+   * @param y1 the <i>y</i> coordinate of the start point P1.
+   * @param cx1 the <i>x</i> coordinate of the first control point C1.
+   * @param cy1 the <i>y</i> coordinate of the first control point C1.
+   * @param cx2 the <i>x</i> coordinate of the second control point C2.
+   * @param cy2 the <i>y</i> coordinate of the second control point C2.
+   * @param x2 the <i>x</i> coordinate of the end point P2.
+   * @param y2 the <i>y</i> coordinate of the end point P2.
+   */
   public static double getFlatnessSq(double x1, double y1, double cx1,
                                      double cy1, double cx2, double cy2,
                                      double x2, double y2)
   {
-    // XXX Implement.
-    throw new Error("not implemented");
+    return Math.max(Line2D.ptSegDistSq(x1, y1, x2, y2, cx1, cy1),
+                    Line2D.ptSegDistSq(x1, y1, x2, y2, cx2, cy2));
   }
+
+
+  /**
+   * Calculates the flatness of a cubic curve, directly specifying
+   * each coordinate value. The flatness is the maximal distance of a
+   * control point to the line between start and end point.
+   *
+   * <p><img src="doc-files/CubicCurve2D-4.png" width="350" height="180"
+   * alt="A drawing that illustrates the flatness" />
+   *
+   * <p>In the above drawing, the straight line connecting start point
+   * P1 and end point P2 is depicted in gray.  In comparison to C1,
+   * control point C2 is father away from the gray line. Therefore,
+   * the result will be the distance between C2 and the gray line,
+   * i.e. the length of the red line.
+   *
+   * @param x1 the <i>x</i> coordinate of the start point P1.
+   * @param y1 the <i>y</i> coordinate of the start point P1.
+   * @param cx1 the <i>x</i> coordinate of the first control point C1.
+   * @param cy1 the <i>y</i> coordinate of the first control point C1.
+   * @param cx2 the <i>x</i> coordinate of the second control point C2.
+   * @param cy2 the <i>y</i> coordinate of the second control point C2.
+   * @param x2 the <i>x</i> coordinate of the end point P2.
+   * @param y2 the <i>y</i> coordinate of the end point P2.
+   */
   public static double getFlatness(double x1, double y1, double cx1,
                                    double cy1, double cx2, double cy2,
                                    double x2, double y2)
   {
     return Math.sqrt(getFlatnessSq(x1, y1, cx1, cy1, cx2, cy2, x2, y2));
   }
+
+
+  /**
+   * Calculates the squared flatness of a cubic curve, specifying the
+   * coordinate values in an array. The flatness is the maximal
+   * distance of a control point to the line between start and end
+   * point.
+   *
+   * <p><img src="doc-files/CubicCurve2D-4.png" width="350" height="180"
+   * alt="A drawing that illustrates the flatness" />
+   *
+   * <p>In the above drawing, the straight line connecting start point
+   * P1 and end point P2 is depicted in gray.  In comparison to C1,
+   * control point C2 is father away from the gray line. Therefore,
+   * the result will be the square of the distance between C2 and the
+   * gray line, i.e. the squared length of the red line.
+   *
+   * @param coords an array containing the coordinate values.  The
+   * <i>x</i> coordinate of the start point P1 is located at
+   * <code>coords[offset]</code>, its <i>y</i> coordinate at
+   * <code>coords[offset + 1]</code>.  The <i>x</i> coordinate of the
+   * first control point C1 is located at <code>coords[offset +
+   * 2]</code>, its <i>y</i> coordinate at <code>coords[offset +
+   * 3]</code>. The <i>x</i> coordinate of the second control point C2
+   * is located at <code>coords[offset + 4]</code>, its <i>y</i>
+   * coordinate at <code>coords[offset + 5]</code>. The <i>x</i>
+   * coordinate of the end point P2 is located at <code>coords[offset
+   * + 6]</code>, its <i>y</i> coordinate at <code>coords[offset +
+   * 7]</code>.
+   *
+   * @param offset the offset of the first coordinate value in
+   * <code>coords</code>.
+   */
   public static double getFlatnessSq(double[] coords, int offset)
   {
     return getFlatnessSq(coords[offset++], coords[offset++],
@@ -111,6 +379,39 @@
                          coords[offset++], coords[offset++],
                          coords[offset++], coords[offset++]);
   }
+
+
+  /**
+   * Calculates the flatness of a cubic curve, specifying the
+   * coordinate values in an array. The flatness is the maximal
+   * distance of a control point to the line between start and end
+   * point.
+   *
+   * <p><img src="doc-files/CubicCurve2D-4.png" width="350" height="180"
+   * alt="A drawing that illustrates the flatness" />
+   *
+   * <p>In the above drawing, the straight line connecting start point
+   * P1 and end point P2 is depicted in gray.  In comparison to C1,
+   * control point C2 is father away from the gray line. Therefore,
+   * the result will be the distance between C2 and the gray line,
+   * i.e. the length of the red line.
+   *
+   * @param coords an array containing the coordinate values.  The
+   * <i>x</i> coordinate of the start point P1 is located at
+   * <code>coords[offset]</code>, its <i>y</i> coordinate at
+   * <code>coords[offset + 1]</code>.  The <i>x</i> coordinate of the
+   * first control point C1 is located at <code>coords[offset +
+   * 2]</code>, its <i>y</i> coordinate at <code>coords[offset +
+   * 3]</code>. The <i>x</i> coordinate of the second control point C2
+   * is located at <code>coords[offset + 4]</code>, its <i>y</i>
+   * coordinate at <code>coords[offset + 5]</code>. The <i>x</i>
+   * coordinate of the end point P2 is located at <code>coords[offset
+   * + 6]</code>, its <i>y</i> coordinate at <code>coords[offset +
+   * 7]</code>.
+   *
+   * @param offset the offset of the first coordinate value in
+   * <code>coords</code>.
+   */
   public static double getFlatness(double[] coords, int offset)
   {
     return Math.sqrt(getFlatnessSq(coords[offset++], coords[offset++],
@@ -118,11 +419,43 @@
                                    coords[offset++], coords[offset++],
                                    coords[offset++], coords[offset++]));
   }
+
+
+  /**
+   * Calculates the squared flatness of this curve.  The flatness is
+   * the maximal distance of a control point to the line between start
+   * and end point.
+   *
+   * <p><img src="doc-files/CubicCurve2D-4.png" width="350" height="180"
+   * alt="A drawing that illustrates the flatness" />
+   *
+   * <p>In the above drawing, the straight line connecting start point
+   * P1 and end point P2 is depicted in gray.  In comparison to C1,
+   * control point C2 is father away from the gray line. Therefore,
+   * the result will be the square of the distance between C2 and the
+   * gray line, i.e. the squared length of the red line.
+   */
   public double getFlatnessSq()
   {
     return getFlatnessSq(getX1(), getY1(), getCtrlX1(), getCtrlY1(),
                          getCtrlX2(), getCtrlY2(), getX2(), getY2());
   }
+
+
+  /**
+   * Calculates the flatness of this curve.  The flatness is the
+   * maximal distance of a control point to the line between start and
+   * end point.
+   *
+   * <p><img src="doc-files/CubicCurve2D-4.png" width="350" height="180"
+   * alt="A drawing that illustrates the flatness" />
+   *
+   * <p>In the above drawing, the straight line connecting start point
+   * P1 and end point P2 is depicted in gray.  In comparison to C1,
+   * control point C2 is father away from the gray line. Therefore,
+   * the result will be the distance between C2 and the gray line,
+   * i.e. the length of the red line.
+   */
   public double getFlatness()
   {
     return Math.sqrt(getFlatnessSq(getX1(), getY1(), getCtrlX1(),
@@ -130,75 +463,266 @@
                                    getX2(), getY2()));
   }
 
-  public void subdivide(CubicCurve2D l, CubicCurve2D r)
+
+  /**
+   * Subdivides this curve into two halves.
+   *
+   * <p><img src="doc-files/CubicCurve2D-3.png" width="700"
+   * height="180" alt="A drawing that illustrates the effects of
+   * subdividing a CubicCurve2D" />
+   *
+   * @param left a curve whose geometry will be set to the left half
+   * of this curve, or <code>null</code> if the caller is not
+   * interested in the left half.
+   *
+   * @param right a curve whose geometry will be set to the right half
+   * of this curve, or <code>null</code> if the caller is not
+   * interested in the right half.
+   */
+  public void subdivide(CubicCurve2D left, CubicCurve2D right)
   {
-    if (l == null)
-      l = new CubicCurve2D.Double();
-    if (r == null)
-      r = new CubicCurve2D.Double();
     // Use empty slots at end to share single array.
     double[] d = new double[] { getX1(), getY1(), getCtrlX1(), getCtrlY1(),
                                 getCtrlX2(), getCtrlY2(), getX2(), getY2(),
                                 0, 0, 0, 0, 0, 0 };
     subdivide(d, 0, d, 0, d, 6);
-    l.setCurve(d, 0);
-    r.setCurve(d, 6);
+    if (left != null)
+      left.setCurve(d, 0);
+    if (right != null)
+      right.setCurve(d, 6);
   }
+
+
+  /**
+   * Subdivides a cubic curve into two halves.
+   *
+   * <p><img src="doc-files/CubicCurve2D-3.png" width="700"
+   * height="180" alt="A drawing that illustrates the effects of
+   * subdividing a CubicCurve2D" />
+   *
+   * @param src the curve to be subdivided.
+   *
+   * @param left a curve whose geometry will be set to the left half
+   * of <code>src</code>, or <code>null</code> if the caller is not
+   * interested in the left half.
+   *
+   * @param right a curve whose geometry will be set to the right half
+   * of <code>src</code>, or <code>null</code> if the caller is not
+   * interested in the right half.
+   */
   public static void subdivide(CubicCurve2D src,
-                               CubicCurve2D l, CubicCurve2D r)
+                               CubicCurve2D left, CubicCurve2D right)
   {
-    src.subdivide(l, r);
+    src.subdivide(left, right);
   }
+
+
+  /**
+   * Subdivides a cubic curve into two halves, passing all coordinates
+   * in an array.
+   *
+   * <p><img src="doc-files/CubicCurve2D-3.png" width="700"
+   * height="180" alt="A drawing that illustrates the effects of
+   * subdividing a CubicCurve2D" />
+   *
+   * <p>The left end point and the right start point will always be
+   * identical. Memory-concious programmers thus may want to pass the
+   * same array for both <code>left</code> and <code>right</code>, and
+   * set <code>rightOff</code> to <code>leftOff + 6</code>.
+   *
+   * @param src an array containing the coordinates of the curve to be
+   * subdivided.  The <i>x</i> coordinate of the start point P1 is
+   * located at <code>src[srcOff]</code>, its <i>y</i> at
+   * <code>src[srcOff + 1]</code>.  The <i>x</i> coordinate of the
+   * first control point C1 is located at <code>src[srcOff +
+   * 2]</code>, its <i>y</i> at <code>src[srcOff + 3]</code>.  The
+   * <i>x</i> coordinate of the second control point C2 is located at
+   * <code>src[srcOff + 4]</code>, its <i>y</i> at <code>src[srcOff +
+   * 5]</code>. The <i>x</i> coordinate of the end point is located at
+   * <code>src[srcOff + 6]</code>, its <i>y</i> at <code>src[srcOff +
+   * 7]</code>.
+   *
+   * @param srcOff an offset into <code>src</code>, specifying
+   * the index of the start point&#x2019;s <i>x</i> coordinate.
+   *
+   * @param left an array that will receive the coordinates of the

*** Patch too long, truncated ***




More information about the kaffe mailing list