mathextensions.java

来自「用JGraph编的软件」· Java 代码 · 共 45 行

JAVA
45
字号
package org.jgraph.utils;

import java.awt.geom.Point2D;

/**
 * @author winkler
 *
 * To change this generated comment edit the template variable "typecomment":
 * Window>Preferences>Java>Templates.
 * To enable and disable the creation of type comments go to
 * Window>Preferences>Java>Code Generation.
 */


public abstract class MathExtensions {

/******************************************************************************/
/**
 * Extracts the leading sign of x.
 * 
 * @param x Any double value.
 * @return If x has a positive value <code>-1.0</code>, for <code>x = 0.0</code>
 * here comes <code>0.0</code> and if x has a negative the method returns 
 * <code>-1.0</code>.
 */
    public static double sgn(double x){
        if( x < 0.0 ) {
            return -1.0;
        }
        else if( x > 0.0 ){
            return 1.0;
        }
        else {
            return 0.0;
        }               
    }

/******************************************************************************/
/**
 * Computes the absolute value of <code>v</code>. Assuming <code>v</code> 
 * is a mathematical Vector, pointing from Point Zero to the Point, represented
 * by <code>x</code> and <code>y</code> in v, then this method returns the
 * length of v.
 * <p><blockquote><blockquote><code>
 * return sqrt( v.x

⌨️ 快捷键说明

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