Merging mk branch rev 136:137 (tuning 2d-graphics)

This commit is contained in:
Marcel Kronfeld 2008-08-05 15:01:59 +00:00
parent 8ec49d3551
commit 18f3cb8620
14 changed files with 398 additions and 184 deletions

View File

@ -4,6 +4,8 @@ package eva2;
* Main product and version information strings.
*
* --- Changelog
* 2.029: Tuned the 2d-graphs which now paints quicker and changes size depending on the
* surrounding plot window.
* 2.028: Tuned the Population to sort only when necessary on calls to getBestN... Added StatisticsDummy.
* Slightly tuned SimpleProblemWrapper to call initProblem of simple problems if available.
* 2.027: Renamed SetData and SetDataLamarckian from individual datatype interfaces to SetGenotype and SetPhenotype.

View File

@ -20,7 +20,7 @@ public class DPointSetMultiIcon extends DComponent
{
//~ Instance fields ////////////////////////////////////////////////////////
protected ArrayList m_IconsMI = new ArrayList();
protected ArrayList<DPointIcon> m_IconsMI = new ArrayList<DPointIcon>();
protected DIntDoubleMap xMI;
protected DIntDoubleMap yMI;
protected DPointIcon iconMI = null;
@ -119,7 +119,7 @@ public class DPointSetMultiIcon extends DComponent
return new DPointSet(xMI, yMI);
}
public ArrayList getIconsMI() {
public ArrayList<DPointIcon> getIconsMI() {
return this.m_IconsMI;
}
@ -289,17 +289,11 @@ public class DPointSetMultiIcon extends DComponent
for (int i = interval[0]; i < interval[1]; i++)
{
p2 = m.getPoint(xMI.getImage(i), yMI.getImage(i));
if (p1 != null)
{
try
{
g.drawLine(p1.x, p1.y, p2.x, p2.y);
}
catch (java.lang.NullPointerException e)
{
// pff
}
if (p2!=null) {
g.drawLine(p1.x, p1.y, p2.x, p2.y);
}
}
if ((i < this.m_IconsMI.size()) && (this.m_IconsMI.get(i) != null))
@ -338,6 +332,7 @@ public class DPointSetMultiIcon extends DComponent
{
p = m.getPoint(xMI.getImage(i), yMI.getImage(i));
if (p==null) continue;
if (this.m_IconsMI.get(i) != null)
{
g.setStroke(new BasicStroke());

View File

@ -265,7 +265,7 @@ public class Plot implements PlotInterface, Serializable {
m_ButtonPanel.add(SaveJPGButton);
// getContentPane().smultetLayout( new GridLayout(1, 4) );
m_Frame.getContentPane().add(m_ButtonPanel,"South");
m_Frame.getContentPane().add(m_PlotArea,"North");
m_Frame.getContentPane().add(m_PlotArea,"Center"); // north was not so nice
m_Frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
m_PlotArea.clearAll(); // this was a memory leak

View File

@ -41,7 +41,12 @@ import wsi.ra.print.PagePrinter;
*/
public class DArea extends JComponent implements DParent, Printable
{
private static final boolean TRACE = false;
/**
*
*/
private static final long serialVersionUID = 1461387400381365146L;
private static final boolean TRACE = false;
/**
* the default minimal rectangle which is shown
@ -124,6 +129,19 @@ public class DArea extends JComponent implements DParent, Printable
return rect;
}
/**
* returns the currently visible rectangle in DArea coordinates
*
* @return DRectangle the size and position of the visible area
*/
public SlimRect getSlimRectangle(){
SlimRect srect = new SlimRect(visible_rect.x, visible_rect.y, visible_rect.width, visible_rect.height);
if( min_x != null ) srect.x = Math.max(srect.x, getMinX() );
if( min_y != null ) srect.y = Math.max(srect.y, getMinY() );
if( max_x != null ) srect.width = Math.min(srect.width, getMaxX() - getMinX());
if( max_y != null ) srect.height = Math.min(srect.height, getMaxY() - getMinY());
return srect;
}
/**
* switches the auto focus of this DArea on or off
*
@ -206,38 +224,38 @@ public class DArea extends JComponent implements DParent, Printable
return (DRectangle)min_rect.clone();
}
/**
* method sets the maximal rectangle whioch can be viewed with the
* DArea. This method can be used if the area is used with scale functions
* which are not invertible on all reals
*
* @param x the minmal x value
* @param y the minmal y value
* @param width of the maximal rectangle
* @param height of the maximal rectangle
*/
public void setMaxRectangle( double x, double y, double width, double height ){
setMaxRectangle( new DRectangle( x, y, width, height ) );
}
// /**
// * method sets the maximal rectangle whioch can be viewed with the
// * DArea. This method can be used if the area is used with scale functions
// * which are not invertible on all reals
// *
// * @param x the minmal x value
// * @param y the minmal y value
// * @param width of the maximal rectangle
// * @param height of the maximal rectangle
// */
// public void setMaxRectangle( double x, double y, double width, double height ){
// setMaxRectangle( new DRectangle( x, y, width, height ) );
// }
/**
* method sets the maximal rectangle whioch can be viewed with the
* DArea. This method can be used if the area is used with scale functions
* which are not invertible on all reals
*
* @param the rect maximal rectangle of the DArea
* @deprecated see setMinX, setMinY, setMaxX, setMaxY
*/
public void setMaxRectangle( DRectangle rect ){
if( !rect.contains( min_rect ) ) throw
new IllegalArgumentException("Maximal rectangle does not contain minmal rectangle");
setMinX( rect.x );
setMinY( rect.y );
setMaxX( rect.x + rect.width );
setMaxY( rect.y + rect.height );
}
// /**
// * method sets the maximal rectangle whioch can be viewed with the
// * DArea. This method can be used if the area is used with scale functions
// * which are not invertible on all reals
// *
// * @param the rect maximal rectangle of the DArea
// * @deprecated see setMinX, setMinY, setMaxX, setMaxY
// */
// public void setMaxRectangle( DRectangle rect ){
// if( !rect.contains( min_rect ) ) throw
// new IllegalArgumentException("Maximal rectangle does not contain minmal rectangle");
//
// setMinX( rect.x );
// setMinY( rect.y );
// setMaxX( rect.x + rect.width );
// setMaxY( rect.y + rect.height );
// }
/**
* method returns the maximal rectangle of the area
@ -695,30 +713,31 @@ public class DArea extends JComponent implements DParent, Printable
Graphics g = m.g;
g.setColor( grid.getColor() );
DRectangle rect = getDRectangle(),
src_rect = m.getSourceOf( rect );
SlimRect rect = getSlimRectangle();
SlimRect src_rect = m.getSourceOf( rect );
int x = (int)(src_rect.x / grid.hor_dist),
y = (int)(src_rect.y / grid.ver_dist);
if( x * grid.hor_dist < src_rect.x ) x++;
if( y * grid.ver_dist < src_rect.y ) y++;
DPoint min = new DPoint( rect.x, rect.y ),
max = new DPoint( min.x + rect.width, min.y + rect.height );
// DPoint min = new DPoint( rect.x, rect.y ),
// max = new DPoint( min.x + rect.width, min.y + rect.height );
double minx=rect.x, miny=rect.y, maxx=minx+rect.width, maxy=miny+rect.height;
double pos;
for( ; (pos = x * grid.hor_dist) < src_rect.x + src_rect.width; x++ ){
if( m.x_scale != null ) pos = m.x_scale.getImageOf( pos );
Point p1 = m.getPoint( pos, min.y ),
p2 = m.getPoint( pos, max.y );
Point p1 = m.getPoint( pos, miny ),
p2 = m.getPoint( pos, maxy );
g.drawLine( p1.x, p1.y, p2.x, p2.y );
}
for( ; (pos = y * grid.ver_dist) < src_rect.y + src_rect.height; y++ ){
if( m.y_scale != null ) pos = m.y_scale.getImageOf( pos );
Point p1 = m.getPoint( min.x, pos ),
p2 = m.getPoint( max.x, pos );
Point p1 = m.getPoint( minx, pos ),
p2 = m.getPoint( maxx, pos );
g.drawLine( p1.x, p1.y, p2.x, p2.y );
}
}

View File

@ -15,6 +15,11 @@ import java.awt.Insets;
public class DBorder extends Insets{
/**
*
*/
private static final long serialVersionUID = -1324717830324606364L;
public DBorder(){
this( 0, 0, 0, 0 );
}

View File

@ -16,9 +16,8 @@ package wsi.ra.chart2d;
* IMPORTS
*==========================================================================*/
import java.util.Vector ;
import java.awt.Color ;
import java.awt.Graphics;
import java.awt.Color;
import java.util.Vector;
/*==========================================================================*
* CLASS DECLARATION
@ -28,14 +27,15 @@ public class DContainer extends DComponent implements DParent{
/**
* the elements of the container and their keys ( Strings )
*/
protected Vector elements, keys;
protected Vector<DElement> elements;
protected Vector<String> keys;
public DContainer(){ this(10); }
public DContainer(int initial_capacity){
super();
elements = new Vector(initial_capacity);
keys = new Vector(initial_capacity);
elements = new Vector<DElement>(initial_capacity);
keys = new Vector<String>(initial_capacity);
}
public void repaint( DRectangle r ){
@ -155,7 +155,7 @@ public class DContainer extends DComponent implements DParent{
DElement e;
for( int i=0; i<elements.size(); i++ ){
e = (DElement)elements.elementAt(i);
if( e.isVisible() && !m.getDRectangle().getIntersection( e.getRectangle() ).isEmpty()){
if( e.isVisible() && !m.getSlimRectangle().hasEmptyIntersection(e.getRectangle())){
m.g.setColor( DEFAULT_COLOR );
e.paint( m );
}

View File

@ -16,9 +16,8 @@ package wsi.ra.chart2d;
* IMPORTS
*==========================================================================*/
import java.awt.Point ;
import java.awt.Color ;
import java.awt.Graphics ;
import java.awt.Graphics;
import java.awt.Point;
/*==========================================================================*
* ABSTRACT CLASS DECLARATION
@ -39,7 +38,7 @@ public abstract class DFunction extends DComponent
Graphics g = m.getGraphics();
if( color != null ) g.setColor( color );
DRectangle rect = m.getDRectangle(),
SlimRect rect = m.getSlimRectangle(),
src_rect = m.getSourceOf( rect );
Point sw = m.getPoint( rect.x, rect.y ),
ne = m.getPoint( rect.x + rect.width, rect.y + rect.height );

View File

@ -55,8 +55,8 @@ public class DLine extends DComponent
//System.out.println("DLine.paint(Measures): "+this);
Graphics g = m.getGraphics();
if( color != null ) g.setColor( color );
Point p1 = m.getPoint( start ),
p2 = m.getPoint( end ) ;
Point p1 = m.getPoint( start.x, start.y ),
p2 = m.getPoint( end.x, end.y ) ;
if ((p1!=null) && (p2!=null)) {
g.drawLine( p1.x, p1.y, p2.x, p2.y );
} else {

View File

@ -1,41 +1,27 @@
/**
* Filename: $RCSfile: DMeasures.java,v $
* Purpose:
* Language: Java
* Compiler: JDK 1.3
* Authors: Fabian Hennecke
* Version: $Revision: 1.1.1.1 $
* $Date: 2003/07/03 14:59:41 $
* $Author: ulmerh $
* Copyright (c) Dept. Computer Architecture, University of Tuebingen, Germany
*/
package wsi.ra.chart2d;
/*==========================================================================*
* IMPORTS
*==========================================================================*/
import java.awt.Point ;
import java.awt.Graphics ;
import java.awt.Dimension ;
import java.awt.Insets ;
import java.awt.Component ;
//import javax.swing.JComponent ;
import java.io.Serializable;
/*==========================================================================*
* CLASS DECLARATION
*==========================================================================*/
/**
* A class mainly for coordinate conversion. Replaced usage of DRectangle by SlimRect
* which makes it more efficient.
*
* @author Fabian Hennecke, ulmerh, mkron
*
*/
public class DMeasures implements Serializable
{
/**
*
*/
private static final long serialVersionUID = 243092480517044848L;
private boolean under_construction = false;
*
*/
private static final long serialVersionUID = 243092480517044848L;
private boolean under_construction = false;
// when in use for a DArea:
Graphics g;
// when in use for a ScaledBorder:
@ -60,21 +46,6 @@ private boolean under_construction = false;
this.sb = sb;
}
/**
* method returns the pixel-point which belongs to the DPoint in the
* D-coordinates
* it says where to paint a certain DPoint
* returns <code>null</code> if the double coordinates do not belong to the
* image of the scale functions
*
* @param p the DPoint
* @return the coresponding pixel Point
*/
public Point getPoint( DPoint p ){
//System.out.println("DMeasures.getPoint :"+org );
return getPoint( p.x, p.y );
}
/**
* method returns the pixel-point which belongs to the given D-coordinates
* it says where to paint a certain DPoint
@ -86,7 +57,7 @@ private boolean under_construction = false;
* @return the coresponding pixel Point
*/
public Point getPoint( double x, double y ){
DRectangle rect = getSourceOf( getDRectangle() );
SlimRect rect = getSourceOf(getSlimRectangle());
if (rect == null) {
return null;
}
@ -103,20 +74,6 @@ private boolean under_construction = false;
return dp;
}
/**
* method returns the point in D-coordinates which corresponds to the
* given pixel-point
* returns <code>null</code> if the given coordinates can not be calculated to
* the double coordinates, when they represent a point outside of the definition
* area of the scale functions
*
* @param p Point in pixel coordinates
* @return the coresponding DPoint
*/
public DPoint getDPoint( Point p ){
return getDPoint( p.x, p.y );
}
/**
* method returns the point in D-coordinates which corresponds to the
* given pixel-coordinates
@ -129,7 +86,7 @@ private boolean under_construction = false;
* @return the coresponding DPoint
*/
public DPoint getDPoint( int x, int y ){
DRectangle rect = getSourceOf( getDRectangle() );
SlimRect rect = getSourceOf(getSlimRectangle());
Dimension dim = getInner();
Insets insets = getInsets();
x -= insets.left;
@ -145,17 +102,27 @@ private boolean under_construction = false;
return new DPoint( dx, dy );
}
// /**
// * returns the visible rectangle in D-coordinates of the shown component
// *
// * @return the visible rectangle
// */
// public DRectangle getDRectangle(){
// if( under_construction ) System.out.println("DMeasures.getDRectangle");
// if( sb != null ) return getImageOf( sb.src_rect );
// return ((DArea)comp).getDRectangle();
// }
/**
* returns the visible rectangle in D-coordinates of the shown component
* Returns the visible rectangle in D-coordinates of the shown component as slim structure.
*
* return the visible rectangle
* @return the visible rectangle
*/
public DRectangle getDRectangle(){
if( under_construction ) System.out.println("DMeasures.getDRectangle");
if( sb != null ) return getImageOf( sb.src_rect );
return ((DArea)comp).getDRectangle();
}
public SlimRect getSlimRectangle(){
// if( under_construction ) System.out.println("DMeasures.getDRectangle");
if( sb != null ) return getImageOf(sb.src_rect.x, sb.src_rect.y, sb.src_rect.width, sb.src_rect.height);
return ((DArea)comp).getSlimRectangle();
}
/**
* returns the current Graphics object, which might be used by components to
* paint themselves
@ -205,70 +172,161 @@ private boolean under_construction = false;
return d;
}
/**
* method returns the source rectangle of the given rectangle
* they differ if there are scale functions selected which are not the identity
* if the given rectangle does not belong to the image area of the scale
* functions, the method returns <code>null</code>
*
* @param rect the image rectangle
* @return the source of it
*/
DRectangle getSourceOf( DRectangle rect ){
if( under_construction ) System.out.println("DMeasures.getSourceOf: "+rect);
if( !getDRectangle().contains( rect ) ) {
return null;
//throw new IllegalArgumentException("The rectangle lies not in the currently painted rectangle");
}
if( x_scale == null && y_scale == null ) return rect;
if( rect.isEmpty() ) return (DRectangle)rect.clone();
DPoint p1 = new DPoint( rect.x, rect.y ),
p2 = new DPoint( rect.x + rect.width, rect.y + rect.height );
try{
if( x_scale != null ){
p1.x = x_scale.getSourceOf( p1.x );
p2.x = x_scale.getSourceOf( p2.x );
}
if( y_scale != null ){
p1.y = y_scale.getSourceOf( p1.y );
p2.y = y_scale.getSourceOf( p2.y );
}
}
catch( IllegalArgumentException nde ){ return null; }
return new DRectangle( p1.x, p1.y, p2.x - p1.x, p2.y - p1.y );
}
// /**
// * method returns the image rectangle of the given rectangle
// * they differ if there are scale functions selected which are not the identity
// * if the given rectangle does not belong to the defintion area of the scale
// * functions, the method returns <code>null</code>
// *
// * @param rect the source rectangle
// * @return the source of it
// */
// DRectangle getImageOf( DRectangle rect ){
// if( under_construction ) System.out.println("DMeasures.getImageOf: "+rect);
// if( x_scale == null && y_scale == null ) return rect;
// if( rect.isEmpty() ) return (DRectangle)rect.clone();
// DPoint p1 = new DPoint( rect.x, rect.y ),
// p2 = new DPoint( rect.x + rect.width, rect.y + rect.height );
// try{
// if( x_scale != null ){
// p1.x = x_scale.getImageOf( p1.x );
// p2.x = x_scale.getImageOf( p2.x );
// }
// if( y_scale != null ){
// p1.y = y_scale.getImageOf( p1.y );
// p2.y = y_scale.getImageOf( p2.y );
// }
// }
// catch( IllegalArgumentException nde ){ return null; }
// return new DRectangle( p1.x, p1.y, p2.x - p1.x, p2.y - p1.y );
// }
/**
* method returns the image rectangle of the given rectangle
* they differ if there are scale functions selected which are not the identity
* if the given rectangle does not belong to the defintion area of the scale
* if the given rectangle does not belong to the definition area of the scale
* functions, the method returns <code>null</code>
*
* @param rect the source rectangle
* @return the source of it
*/
DRectangle getImageOf( DRectangle rect ){
if( under_construction ) System.out.println("DMeasures.getImageOf: "+rect);
if( x_scale == null && y_scale == null ) return rect;
if( rect.isEmpty() ) return (DRectangle)rect.clone();
DPoint p1 = new DPoint( rect.x, rect.y ),
p2 = new DPoint( rect.x + rect.width, rect.y + rect.height );
SlimRect getImageOf(double xpos, double ypos, double width, double height){
// if( under_construction ) System.out.println("DMeasures.getImageOf: "+rect);
if( x_scale == null && y_scale == null ) return new SlimRect(xpos, ypos, width, height);
double x1 = xpos, y1=ypos, x2=xpos + width, y2=ypos + height;
try{
if( x_scale != null ){
p1.x = x_scale.getImageOf( p1.x );
p2.x = x_scale.getImageOf( p2.x );
x1 = x_scale.getImageOf( x1 );
x2 = x_scale.getImageOf( x2 );
}
if( y_scale != null ){
p1.y = y_scale.getImageOf( p1.y );
p2.y = y_scale.getImageOf( p2.y );
y1 = y_scale.getImageOf( y1 );
y2 = y_scale.getImageOf( y2 );
}
}
catch( IllegalArgumentException nde ){ return null; }
return new DRectangle( p1.x, p1.y, p2.x - p1.x, p2.y - p1.y );
return new SlimRect( x1, y1, x2 - x1, y2 - y1 );
}
SlimRect getImageOf(SlimRect srect) {
return getImageOf(srect.x, srect.y, srect.width, srect.height);
}
// /**
// * method returns the source rectangle of the given rectangle
// * they differ if there are scale functions selected which are not the identity
// * if the given rectangle does not belong to the image area of the scale
// * functions, the method returns <code>null</code>
// *
// * @param rect the image rectangle
// * @return the source of it
// */
// DRectangle getSourceOf( DRectangle rect ){
// if( under_construction ) System.out.println("DMeasures.getSourceOf: "+rect);
// if( !getDRectangle().contains( rect ) ) {
//// System.out.println("case not contains");
// return null;
// //throw new IllegalArgumentException("The rectangle lies not in the currently painted rectangle");
// }
//
// if( x_scale == null && y_scale == null ) {
//// System.out.println("Case scale null");
// return rect;
// }
// if( rect.isEmpty() ) {
//// System.out.println("Case isEmpty");
// return (DRectangle)rect.clone();
// }
// DPoint p1 = new DPoint( rect.x, rect.y ),
// p2 = new DPoint( rect.x + rect.width, rect.y + rect.height );
// try{
// if( x_scale != null ){
// p1.x = x_scale.getSourceOf( p1.x );
// p2.x = x_scale.getSourceOf( p2.x );
// }
// if( y_scale != null ){
// p1.y = y_scale.getSourceOf( p1.y );
// p2.y = y_scale.getSourceOf( p2.y );
// }
// }
// catch( IllegalArgumentException nde ){ return null; }
// return new DRectangle( p1.x, p1.y, p2.x - p1.x, p2.y - p1.y );
// }
/**
* method returns the source rectangle of the given rectangle
* they differ if there are scale functions selected which are not the identity
* if the given rectangle does not belong to the image area of the scale
* functions, the method returns <code>null</code>
*
* Tuning: rect must not be empty
*
* @param rect the image rectangle
* @return the source of it
*/
SlimRect getSourceOf(double x, double y, double width, double height){
// if( under_construction ) System.out.println("DMeasures.getSourceOf: "+rect);
if( !getSlimRectangle().contains( x, y, width, height ) ) {
// System.out.println("case not contains");
return null;
//throw new IllegalArgumentException("The rectangle lies not in the currently painted rectangle");
}
if( x_scale == null && y_scale == null ) {
// System.out.println("Case scale null");
return new SlimRect(x, y, width, height);
}
double x1=x, y1=y, x2=x + width, y2=y + height;
try{
if( x_scale != null ){
x1 = x_scale.getSourceOf( x1 );
x2 = x_scale.getSourceOf( x2 );
}
if( y_scale != null ){
y1 = y_scale.getSourceOf( y1 );
y2 = y_scale.getSourceOf( y2 );
}
}
catch( IllegalArgumentException nde ){ return null; }
return new SlimRect( x1, y1, x2 - x1, y2 - y1 );
}
// SlimRect getSourceOf( double xpos, double ypos, double width, double height){
// if( !getSlimRectangle().contains( xpos, ypos, width, height ) ) {
// System.err.println("The rectangle lies not in the currently painted rectangle");
// return null;
// //throw new IllegalArgumentException("The rectangle lies not in the currently painted rectangle");
// }
// // MK: this now strangely does the same as getImageOf
// return getImageOf(xpos, ypos, width, height);
// }
SlimRect getSourceOf( SlimRect srect){
return getSourceOf(srect.x, srect.y, srect.width, srect.height);
}
private Insets getInsets(){
if( sb != null ) return insets;
return ((DArea)comp).getInsets();

View File

@ -12,7 +12,6 @@
package wsi.ra.chart2d;
import java.awt.Graphics;
/*==========================================================================*
* INTERFACE DECLARATION

View File

@ -43,7 +43,7 @@ public class DPoint extends DComponent
public void paint( DMeasures m ){
Graphics g = m.getGraphics();
if( color != null ) g.setColor( color );
Point dp = m.getPoint( this );
Point dp = m.getPoint( this.x, this.y );
if( label != null ){
FontMetrics fm = g.getFontMetrics();
g.drawString( label,

View File

@ -53,8 +53,7 @@ public class DRectangle extends DComponent
if( isEmpty() ) return;
Graphics g = m.getGraphics();
Color old_color = g.getColor();
DRectangle rect = m.getDRectangle();
rect = rect.getIntersection( this );
SlimRect rect = m.getSlimRectangle().getIntersection(this);
Point p1 = m.getPoint( rect.x, rect.y ),
p2 = m.getPoint( rect.x + rect.width, rect.y + rect.height );
if( fillColor != null ){
@ -78,15 +77,35 @@ public class DRectangle extends DComponent
if( p.y > y + height ) return false;
return true;
}
/**
* Faster contains withouth checking for ALL or EMPTY status.
*
* @param ox
* @param oy
* @return
*/
private boolean contains( double ox, double oy ){
if (( ox < x ) || ( oy < y ) || ( ox > x + width ) || ( oy > y + height )) return false;
else return true;
}
public boolean contains( DRectangle rect ){
if( status == ALL || rect.isEmpty() ) return true;
if( status == EMPTY || rect.isAll() ) return false;
if( !contains( new DPoint( rect.x, rect.y ) ) ) return false;
if( !contains( new DPoint( rect.x + rect.width, rect.y + rect.height ) ) ) return false;
if( !contains(rect.x, rect.y ) ) return false;
if( !contains(rect.x + rect.width, rect.y + rect.height ) ) return false;
return true;
}
public boolean contains( double ox, double oy, double width, double heigth){
if( status == ALL) return true;
if( status == EMPTY) return false;
if( !contains(ox, oy ) ) return false;
if( !contains(ox + width, oy + height ) ) return false;
return true;
}
public DRectangle getIntersection( DRectangle r ){
if( status == ALL ) return (DRectangle)r.clone();
if( status == EMPTY ) return DRectangle.getEmpty();

View File

@ -88,7 +88,7 @@ public class ScaledBorder implements Border
* the size of the source rectangle
* that means before the values are mdified by scale functions
*/
DRectangle src_rect;
SlimRect src_rect;
/**
* the minimal increment of the scales
@ -443,8 +443,7 @@ public class ScaledBorder implements Border
if( c instanceof DArea ){
DArea area = (DArea)c;
DMeasures m = area.getDMeasures();
DRectangle rect = m.getSourceOf( area.getDRectangle() );
src_rect = (DRectangle)rect.clone();
src_rect = m.getSourceOf(area.getSlimRectangle());
x_scale = area.getDMeasures().x_scale;
y_scale = area.getDMeasures().y_scale;
}

View File

@ -0,0 +1,119 @@
package wsi.ra.chart2d;
/**
* Encapsulates a slim rectangle structure with x, y, width and height and
* nothing else. Makes some painting calculations quite a bit faster.
*
* @author mkron
*
*/
public class SlimRect {
double x, y, width, height;
public SlimRect(double xpos, double ypos, double wd, double ht) {
x=xpos;
y=ypos;
width = wd;
height = ht;
}
public SlimRect(SlimRect o) {
x=o.x;
y=o.y;
width = o.width;
height = o.height;
}
/**
* Check whether a given point lies within the rectangle.
*
* @param ox
* @param oy
* @return true if the given point lies within the rectangle, else false
*/
public boolean contains( double ox, double oy ){
if (( ox < x ) || ( oy < y ) || ( ox > x + width ) || ( oy > y + height )) return false;
else return true;
}
/**
* Check whether a given rectangle lies within this rectangle.
*
* @param xpos
* @param ypos
* @param wd
* @param ht
* @return true if the given rectangle lies within the rectangle, else false
*/
public boolean contains(double xpos, double ypos, double wd, double ht) {
return (contains(xpos,ypos) && contains(xpos+wd, ypos+ht));
}
public String toString() {
return "SlimRect["+x+","+y+"/"+width+","+height+"]";
}
/**
* Intersect two rectangles. If the intersection is empty, null is returned.
*
* @param r
* @return A rectangle representing the intersection or null
*/
public SlimRect getIntersection( SlimRect r ){
return getIntersection(r.x, r.y, r.width, r.height);
}
/**
* Intersect two rectangles. If the intersection is empty, null is returned.
*
* @param r
* @return A rectangle representing the intersection or null
*/
public SlimRect getIntersection( DRectangle r ){
return getIntersection(r.x, r.y, r.width, r.height);
}
/**
* Intersect two rectangles. If the intersection is empty, null is returned.
*
* @param rx
* @param ry
* @param rwidth
* @param rheight
* @return A rectangle representing the intersection or null
*/
public SlimRect getIntersection(double rx, double ry, double rwidth, double rheight){
SlimRect s = new SlimRect(this);
if( s.x < rx ){
s.x = rx;
s.width -= rx - s.x;
}
if( s.y < ry ){
s.y = ry;
s.height -= ry - s.y;
}
if( s.x + s.width > rx + rwidth )
s.width = rx + rwidth - s.x;
if( s.y + s.height > ry + rheight )
s.height = ry + rheight - s.y;
if( s.width < 0 || s.height < 0 ) return null;
else return s;
}
/**
* Check for empty intersection.
* @param r
* @return true if the two rectangles do not intersect, else false
*/
public boolean hasEmptyIntersection(DRectangle r){
return (getIntersection(r.x, r.y, r.width, r.height)==null);
}
/**
* Check for empty intersection.
* @param r
* @return true if the two rectangles do not intersect, else false
*/
public boolean hasEmptyIntersection(SlimRect r){
return (getIntersection(r)==null);
}
}