/** * Utilities used by uk.ac.leeds.ccg.andyt.gws library that might be more generally useful. * Copyright (C) 2005 Andy Turner, CCG, University of Leeds, UK. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ package uk.ac.leeds.ccg.andyt.gws.utilities; // java dependencies import java.awt.geom.Point2D; import java.math.BigDecimal; // uk.ac.leeds.ccg.andyt.ext dependencies import uk.ac.leeds.ccg.andyt.ext.math.BigDecimal0; /** * A class like Point2D but with coordinates stored as BigDecimals. */ public class Point2DBigDecimal { private BigDecimal x; private BigDecimal y; /** Creates a new instance of BigDecimalPoint */ public Point2DBigDecimal( BigDecimal x, BigDecimal y ) { this.x = x; this.y = y; } /** Creates a new instance of BigDecimalPoint */ public Point2DBigDecimal( Point2D.Double point2DDouble ) { this.x = new BigDecimal( point2DDouble.getX() ); this.y = new BigDecimal( point2DDouble.getY() ); } public BigDecimal getX() { return this.x; } public BigDecimal getY() { return this.y; } /** * Returns the distance form Point2DBigDecimal to this as a BigDecimal */ public BigDecimal distance( Point2DBigDecimal point2DBigDecimal, int decimalPlaces ) { BigDecimal xdiff = this.x.subtract( point2DBigDecimal.getX() ); BigDecimal ydiff = this.y.subtract( point2DBigDecimal.getY() ); //return BigDecimal0.sqrt0( ( xdiff.multiply( xdiff ) ).add( ydiff.multiply( ydiff ) ), Math.max( xdiff.scale(), ydiff.scale() ) + 10 ); return BigDecimal0.sqrt0( ( xdiff.multiply( xdiff ) ).add( ydiff.multiply( ydiff ) ), decimalPlaces ); } }