package cc.moveable_type.rectangular_area;

import java.awt.Shape;
import java.awt.geom.Area;
import java.awt.geom.PathIterator;

/**
 * 用來計算shape相關資訊的型態
 * 
 * @author Ihc
 */
public class ShapeInformation
{

	/**
	 * 目前累積的大致周長
	 */
	private double approximativeCircumference;
	/**
	 * 目前累積的大致面積
	 */
	private double approximativeRegion;

	/**
	 * 建立一個相關資訊物件
	 * 
	 * @param shape
	 *            要計算資訊的shape
	 */
	public ShapeInformation(Shape shape)
	{
		this(new Area(shape));// Area保證他的順逆時針
	}

	/**
	 * 建立一個相關資訊物件
	 * 
	 * @param area
	 *            要計算資訊的area
	 */
	public ShapeInformation(Area area)
	{
		approximativeCircumference = 0.0;
		approximativeRegion = 0.0;
		double[] coords = new double[6];
		SimplePolygon simplePolygon = new SimplePolygon();
		for (PathIterator pp = area.getPathIterator(null); !pp.isDone(); pp
				.next())
		{
			int type = pp.currentSegment(coords);
			switch (type)
			{
			case PathIterator.SEG_CUBICTO:
				simplePolygon.addPoint(coords[0], coords[1]);
				simplePolygon.addPoint(coords[2], coords[3]);
				simplePolygon.addPoint(coords[4], coords[5]);
				break;
			case PathIterator.SEG_QUADTO:
				simplePolygon.addPoint(coords[0], coords[1]);
				simplePolygon.addPoint(coords[2], coords[3]);
				break;
			case PathIterator.SEG_LINETO:
				simplePolygon.addPoint(coords[0], coords[1]);
				break;
			case PathIterator.SEG_MOVETO:
				simplePolygon.addPoint(coords[0], coords[1]);
				break;
			case PathIterator.SEG_CLOSE:
				simplePolygon.finish();
				approximativeCircumference += simplePolygon.getCircumference();
				approximativeRegion += simplePolygon.getRegionSize();
				simplePolygon.clear();
				break;
			}
		}
	}

	/**
	 * 取得目前累積的大致周長
	 * 
	 * @return 目前累積的大致周長
	 */
	public double getApproximativeCircumference()
	{
		return approximativeCircumference;
	}

	/**
	 * 取得目前累積的大致面積
	 * 
	 * @return 目前累積的大致面積
	 */
	public double getApproximativeRegion()
	{
		return approximativeRegion;
	}
}

@@ -681,20 +681,26 @@
 ble%5B%5D co
-ords
+ntrolPoint
  = new d
@@ -883,20 +883,26 @@
 gment(co
-ords
+ntrolPoint
 );%0A%09%09%09sw
@@ -977,39 +977,51 @@
 .addPoint(co
-ords%5B0%5D, coords
+ntrolPoint%5B0%5D, controlPoint
 %5B1%5D);%0A%09%09%09%09si
@@ -1039,39 +1039,51 @@
 .addPoint(co
-ords%5B2%5D, coords
+ntrolPoint%5B2%5D, controlPoint
 %5B3%5D);%0A%09%09%09%09si
@@ -1109,23 +1109,35 @@
 t(co
-ords%5B4%5D, coords
+ntrolPoint%5B4%5D, controlPoint
 %5B5%5D)
@@ -1207,39 +1207,51 @@
 .addPoint(co
-ords%5B0%5D, coords
+ntrolPoint%5B0%5D, controlPoint
 %5B1%5D);%0A%09%09%09%09si
@@ -1277,23 +1277,35 @@
 t(co
-ords%5B2%5D, coords
+ntrolPoint%5B2%5D, controlPoint
 %5B3%5D)
@@ -1375,39 +1375,51 @@
 .addPoint(co
-ords%5B0%5D, coords
+ntrolPoint%5B0%5D, controlPoint
 %5B1%5D);%0A%09%09%09%09br
@@ -1489,23 +1489,35 @@
 t(co
-ords%5B0%5D, coords
+ntrolPoint%5B0%5D, controlPoint
 %5B1%5D)

修改變數名稱 by Ihc