jfarcpoint.java
来自「用Java开发的、实现类似Visio功能的应用程序源码」· Java 代码 · 共 218 行
JAVA
218 行
/**
* $Id:JFArcPoint.java $
*
* Copyright 2004 ~ 2005 JingFei International Cooperation LTD. All rights reserved. *
*/
package com.jfimagine.jfgraph.geom;
import com.jfimagine.jfgraph.geom.Angle;
import com.jfimagine.jfgraph.geom.JFVector;
/**
* JFArcPoint class. This class is an assistant class used to represent
* a certain position on a bezier curve.
*
* @author CookieMaker
*
* @version $Revision: 1.00 $
*/
public class JFArcPoint extends JFPoint {
/**
* Point on curve
*/
public static final int POINTTYPE_CURVE =1;
/**
* Point on chord
*/
public static final int POINTTYPE_CHORD =2;
/**
* Point on start pie side.
*/
public static final int POINTTYPE_PIE_START =3;
/**
* Point on end pie side.
*/
public static final int POINTTYPE_PIE_END =4;
/**
* A scale of a point.
* 1) if the point is on the curve, m_scale is the propotion
* of the angle of the point on the arc compares to the total angle.
*
* 2) if the point is on the chord, m_scale is the propotion of the length
* from start point to this point compares to the length from start point to end point.
*
* 3) if the point is on one of the pie side, m_scale is the propotion of the length
* from center to this point compares to the radius.
*
*/
private double m_scale =0;
/**
* Type of this point. A point will be point on curve, point on chord or on one pie side.
*/
private int m_type =0;
/**
* Get the angle scale.
*
* @return The angle scale.
*
*/
public double getScale(){
return m_scale;
}
/**
* Set the angle scale.
*
* @param A new angle scale.
*
*/
public void setScale(double scale){
m_scale =scale;
}
/**
* Get the point type.
*
* @return The point type.
*
*/
public int getType(){
return m_type;
}
/**
* Set the point type.
*
* @param A new point type.
*
*/
public void setType(int type){
m_type =type;
}
/**
* Set value of current JFArcPoint.
*
* @param val A new JFArcPoint object.
*
*/
public void setValue(JFArcPoint pnt){
if (pnt==null)
return;
super.setValue(pnt.getX(),pnt.getY());
m_scale =pnt.getScale();
m_type =pnt.getType();
}
/**
* Constructor for JFArcPoint.
* Default to 0 for x and y coordinates.
*
*/
public JFArcPoint(){
}
/**
* Constructor for JFArcPoint.
*
* @param pnt A JFArcPoint.
*
*/
public JFArcPoint(JFArcPoint pnt){
setValue(pnt);
}
/**
* Convert this object to String
*
* @return An string represents the content of the object
*
*/
public String toString(){
StringBuffer buf =new StringBuffer();
buf.append(super.toString());
buf.append(";scale="); buf.append(m_scale);
buf.append(";type="); buf.append(m_type);
return buf.toString();
}
/**
* Creates a new object of the same class and with the same contents as this object.
*
* @return A clone of this instance.
*
*/
public Object clone() throws CloneNotSupportedException{
try{
return new JFArcPoint(this);
}catch(Exception e){
throw new CloneNotSupportedException(e.getMessage());
}
}
/**
* Returns the hashcode for this Object.
*
* @return hash code for this Point2D.
*
*/
public int hashCode(){
long scale =Double.doubleToLongBits(m_scale);
return super.hashCode() ^
(int)(scale ^ (scale >>> 32))^
m_type;
}
/**
* Determines whether or not two objects are equal.
*
* @param obj an object to be compared with this object
* @param analog True if use integer type to compare two points,False use double.
*
* @return true if the object to be compared is an instance of Port and has the same values; false otherwise.
*
*/
public boolean equals(Object obj, boolean analog){
if (super.equals(obj,analog))
return true;
if (obj == this)
return true;
if (!(obj instanceof JFArcPoint))
return false;
JFArcPoint pnt =(JFArcPoint)obj;
if (analog)
return (float)m_scale==(float)pnt.getScale() && m_type==pnt.getType();
else
return m_scale==pnt.getScale() && m_type==pnt.getType();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?