jfcurvepoint.java

来自「用Java开发的、实现类似Visio功能的应用程序源码」· Java 代码 · 共 220 行

JAVA
220
字号
/**
 *    $Id:JFCurvePoint.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;
 
 /**
 * JFCurvePoint 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 JFCurvePoint extends JFPoint {
   
   /**
    *  We'll consider that a point on a bezier curve is at
    *  a specified time interval and a specified segment of curve.
    */
  
   /**
    *   the serial number of the curve segments.
    */
   private	int	m_segmentId	=0;

   /**
    *   total number of curve segments.
    */
   private	int	m_totalSegments	=0;

   /**
    *   time interval of the position.
    */
   private	double	m_timeInterval	=0;


   /**
    *   Get the serial number of the curve segments.
    *
    *   @return  The serial number.
    *
    */ 	
   public int getSegmentId(){
   	return m_segmentId;
   }

   /**
    *   Set the serial number of the curve segments.
    *
    *   @param segmentId   A new segment serial number.
    *
    */ 	
   public void setSegmentId(int segmentId){
   	m_segmentId	=segmentId;
   }

   /**
    *   Get total segments of the curve.
    *
    *   @return  The total segments.
    *
    */ 	
   public int getTotalSegments(){
   	return m_totalSegments;
   }

   /**
    *   Set total segments of the curve.
    *
    *   @param  New total segments.
    *
    */ 	
   public void setTotalSegments(int totalSegments){
   	m_totalSegments	=totalSegments;
   }

   /**
    *   Get time interval
    *
    *   @return  The time interval
    *
    */ 	
   public double getTimeInterval(){
   	return m_timeInterval;
   }

   /**
    *   Set time interval
    *
    *   @param  A new time interval.
    *
    */ 	
   public void setTimeInterval(double timeInterval){
   	m_timeInterval	=timeInterval;
   }

	
   /**
    *   Set value of current JFCurvePoint.
    *
    *   @param val  A new JFCurvePoint object.
    *
    */ 	
   public void setValue(JFCurvePoint pnt){
   	if (pnt==null)
   		return;
   		
   	super.setValue(pnt.getX(),pnt.getY());
   	m_segmentId	=pnt.getSegmentId();
   	m_totalSegments	=pnt.getTotalSegments();
   	m_timeInterval	=pnt.getTimeInterval();
   }

   /**
    *   Constructor for JFCurvePoint.
    *   Default to 0 for x and y coordinates.
    *
    */ 	
   public JFCurvePoint(){
   }

   /**
    *   Constructor for JFCurvePoint.
    *
    *   @param pnt A JFCurvePoint.
    *
    */ 	
   public JFCurvePoint(JFCurvePoint 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(";segmentId=");  	buf.append(m_segmentId);
  	buf.append(";totalSegments="); 	buf.append(m_totalSegments);
  	buf.append(";timeInterval=");  	buf.append(m_timeInterval);
  	
  	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 JFCurvePoint(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  interval   =Double.doubleToLongBits(m_timeInterval);
  	
  	return 	super.hashCode() ^
  		m_segmentId ^ 
  		m_totalSegments ^
  		(int)(interval ^ (interval >>> 32));
  }



   /**
    *   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 JFCurvePoint))
            	return false;

      JFCurvePoint	pnt	=(JFCurvePoint)obj;
      
      return    m_segmentId==pnt.getSegmentId() && 
      		m_totalSegments==pnt.getTotalSegments() &&
      		m_timeInterval==pnt.getTimeInterval();
      		
  }



}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?