You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-dev@xmlgraphics.apache.org by vh...@apache.org on 2001/02/10 02:07:02 UTC
cvs commit: xml-batik/sources/org/apache/batik/gvt AbstractGraphicsNode.java CompositeGraphicsNode.java
vhardy 01/02/09 17:07:02
Modified: sources/org/apache/batik/gvt AbstractGraphicsNode.java
CompositeGraphicsNode.java
Log:
Modified the getXXBounds methods so that null bounds are possible,
to represent GraphicsNode with no content, which may happen on empty
group. Previously, empty groups were reporting a Rectangle(0, 0, 0, 0)
bounds which would cause potentially large errors/problems.
Benchmarks showed no performance degradation due to that change.
Revision Changes Path
1.13 +42 -31 xml-batik/sources/org/apache/batik/gvt/AbstractGraphicsNode.java
Index: AbstractGraphicsNode.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/gvt/AbstractGraphicsNode.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- AbstractGraphicsNode.java 2001/02/09 20:12:59 1.12
+++ AbstractGraphicsNode.java 2001/02/10 01:07:01 1.13
@@ -48,7 +48,7 @@
* @author <a href="mailto:Thierry.Kormann@sophia.inria.fr">Thierry Kormann</a>
* @author <a href="mailto:etissandier@ilog.fr">Emmanuel Tissandier</a>
* @author <a href="mailto:Thomas.DeWeeese@Kodak.com">Thomas DeWeese</a>
- * @version $Id: AbstractGraphicsNode.java,v 1.12 2001/02/09 20:12:59 vhardy Exp $
+ * @version $Id: AbstractGraphicsNode.java,v 1.13 2001/02/10 01:07:01 vhardy Exp $
*/
public abstract class AbstractGraphicsNode implements GraphicsNode, Cloneable {
@@ -370,10 +370,10 @@
Shape g2dClip = g2d.getClip();
if(g2dClip != null){
Rectangle2D clipBounds = g2dClip.getBounds2D();
- if(!bounds.intersects(clipBounds.getX(),
- clipBounds.getY(),
- clipBounds.getWidth(),
- clipBounds.getHeight())){
+ if(bounds != null && !bounds.intersects(clipBounds.getX(),
+ clipBounds.getY(),
+ clipBounds.getWidth(),
+ clipBounds.getHeight())){
paintNeeded = false;
}
}
@@ -784,8 +784,10 @@
*/
public Rectangle2D getTransformedBounds(AffineTransform txf,
GraphicsNodeRenderContext rc){
- AffineTransform t = new AffineTransform(txf);
+ // System.out.println("getTransformedBounds A:" + this.getClass().getName());
+ AffineTransform t = txf;
if(transform != null){
+ t = new AffineTransform(txf);
t.concatenate(transform);
}
@@ -795,31 +797,38 @@
// by the filter.
Rectangle2D tBounds = null;
if(filter == null){
- tBounds = getTransformedPrimitiveBounds(txf, rc);
+ // System.out.println("getTransformedBounds B:" + this.getClass().getName());
+ tBounds = getTransformedPrimitiveBounds(txf, rc); /* Use txf, not t */
+ // System.out.println("getTransformedBounds C:" + this.getClass().getName());
} else {
tBounds = t.createTransformedShape(filter.getBounds2D()).getBounds2D();
}
// Factor in the clipping area, if any
- if(clip != null) {
- tBounds.intersect(tBounds,
- t.createTransformedShape(clip.getClipPath()).getBounds2D(),
- tBounds);
- }
-
- // Factor in the mask, if any
- if(mask != null) {
- tBounds.intersect(tBounds,
- t.createTransformedShape(mask.getBounds2D()).getBounds2D(),
- tBounds);
+ if(tBounds != null){
+ // System.out.println("getTransformedBounds D:" + this.getClass().getName());
+ if(clip != null) {
+ tBounds.intersect(tBounds,
+ t.createTransformedShape(clip.getClipPath()).getBounds2D(),
+ tBounds);
+ }
+
+ // Factor in the mask, if any
+ if(mask != null) {
+ tBounds.intersect(tBounds,
+ t.createTransformedShape(mask.getBounds2D()).getBounds2D(),
+ tBounds);
+ }
}
+ // System.out.println("getTransformedBounds E:" + this.getClass().getName());
return tBounds;
}
public Rectangle2D getTransformedPrimitiveBounds(AffineTransform txf,
GraphicsNodeRenderContext rc){
Rectangle2D tpBounds = getPrimitiveBounds(rc);
- AffineTransform t = new AffineTransform(txf);
+ AffineTransform t = txf;
if(transform != null){
+ t = new AffineTransform(txf);
t.concatenate(transform);
}
@@ -829,8 +838,9 @@
public Rectangle2D getTransformedGeometryBounds(AffineTransform txf,
GraphicsNodeRenderContext rc){
Rectangle2D tpBounds = getGeometryBounds(rc);
- AffineTransform t = new AffineTransform(txf);
+ AffineTransform t = txf;
if(transform != null){
+ t = new AffineTransform(txf);
t.concatenate(transform);
}
@@ -857,18 +867,19 @@
bounds = filter.getBounds2D();
}
// Factor in the clipping area, if any
- if(clip != null) {
- bounds.intersect(bounds,
- clip.getClipPath().getBounds2D(),
- bounds);
- }
- // Factor in the mask, if any
- if(mask != null) {
- bounds.intersect(bounds,
- mask.getBounds2D(),
- bounds);
+ if(bounds != null){
+ if(clip != null) {
+ bounds.intersect(bounds,
+ clip.getClipPath().getBounds2D(),
+ bounds);
+ }
+ // Factor in the mask, if any
+ if(mask != null) {
+ bounds.intersect(bounds,
+ mask.getBounds2D(),
+ bounds);
+ }
}
-
}
return bounds;
}
1.14 +61 -37 xml-batik/sources/org/apache/batik/gvt/CompositeGraphicsNode.java
Index: CompositeGraphicsNode.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/gvt/CompositeGraphicsNode.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- CompositeGraphicsNode.java 2001/02/09 20:12:59 1.13
+++ CompositeGraphicsNode.java 2001/02/10 01:07:01 1.14
@@ -32,7 +32,7 @@
* A CompositeGraphicsNode is a graphics node that can contain graphics nodes.
*
* @author <a href="mailto:Thierry.Kormann@sophia.inria.fr">Thierry Kormann</a>
- * @version $Id: CompositeGraphicsNode.java,v 1.13 2001/02/09 20:12:59 vhardy Exp $
+ * @version $Id: CompositeGraphicsNode.java,v 1.14 2001/02/10 01:07:01 vhardy Exp $
*/
public class CompositeGraphicsNode extends AbstractGraphicsNode
implements List {
@@ -236,7 +236,8 @@
}
public GraphicsNode nodeHitAt(Point2D p, GraphicsNodeRenderContext rc) {
- if (count > 0 && getBounds(rc).contains(p)) {
+ Rectangle2D bounds = getBounds(rc);
+ if (count > 0 && bounds != null && bounds.contains(p)) {
//
// Go backward because the children are in rendering order
//
@@ -271,15 +272,22 @@
*/
public Rectangle2D getPrimitiveBounds(GraphicsNodeRenderContext rc) {
if (primitiveBounds == null) {
- if(count == 0){
- // With the following empty groups may have bad side effects.
- return new Rectangle(0, 0, 0, 0);
+ // System.out.println("primitiveBounds are null:" + this.getClass().getName());
+ int i=0;
+ while(primitiveBounds == null && i < count){
+ // System.out.println("XX");
+ primitiveBounds = children[i++].getTransformedBounds(IDENTITY, rc);
+ // System.out.println("child" + (i -1) + " bounds : " + primitiveBounds);
}
-
- primitiveBounds = children[0].getTransformedBounds(IDENTITY, rc);
- for (int i=1; i < count; ++i) {
- primitiveBounds.add(children[i].getTransformedBounds(IDENTITY, rc));
+ Rectangle2D ctb = null;
+ while(i < count){
+ ctb = children[i++].getTransformedBounds(IDENTITY, rc);
+ // System.out.println("YY");
+ // System.out.println("child add" + (i -1) + " bounds : " + ctb);
+ if(ctb != null){
+ primitiveBounds.add(ctb);
+ }
}
}
return primitiveBounds;
@@ -296,22 +304,29 @@
*/
public Rectangle2D getTransformedPrimitiveBounds(AffineTransform txf,
GraphicsNodeRenderContext rc) {
- AffineTransform t = new AffineTransform(txf);
+ AffineTransform t = txf;
if(transform != null){
+ t = new AffineTransform(txf);
t.concatenate(transform);
}
- if(count == 0)
- return new Rectangle(0, 0, 0, 0);
-
- Rectangle2D bounds = children[0].getTransformedBounds(t, rc);
-
- // System.out.println("SubBounds: " + bounds);
- for (int i=1; i < count; ++i) {
- bounds.add(children[i].getTransformedBounds(t, rc));
+ int i = 0;
+ Rectangle2D tpb = null;
+ while( tpb == null && i < count){
+ // System.out.println("XX22");
+ tpb = children[i++].getTransformedBounds(t, rc);
}
- return bounds;
+ Rectangle2D ctb = null;
+ while(i < count){
+ // System.out.println("YY22");
+ ctb = children[i++].getTransformedBounds(t, rc);
+ if(ctb != null){
+ tpb.add(ctb);
+ }
+ }
+
+ return tpb;
}
/**
@@ -326,19 +341,20 @@
*/
public Rectangle2D getGeometryBounds(GraphicsNodeRenderContext rc){
if(geometryBounds == null){
- if(count <= 0){
- System.out.println("Group is empty ...");
- // With the following empty groups may have bad side effects.
- // Note that we do not cache this value as this does not
- // have a performance impact and it is likely that this
- // group is under construction.
- return new Rectangle(0, 0, 0, 0);
+ // System.out.println("geometryBounds are null");
+ int i=0;
+ while(geometryBounds == null && i < count){
+ // System.out.println("XX33");
+ geometryBounds = children[i++].getTransformedGeometryBounds(IDENTITY, rc);
}
-
- geometryBounds = children[0].getTransformedGeometryBounds(IDENTITY, rc);
- for (int i=1; i < count; ++i) {
- geometryBounds.add(children[i].getTransformedGeometryBounds(IDENTITY, rc));
+ Rectangle2D cgb = null;
+ while(i<count){
+ // System.out.println("YY33");
+ cgb = children[i++].getTransformedGeometryBounds(IDENTITY, rc);
+ if(cgb != null){
+ geometryBounds.add(cgb);
+ }
}
}
return geometryBounds;
@@ -359,18 +375,26 @@
*/
public Rectangle2D getTransformedGeometryBounds(AffineTransform txf,
GraphicsNodeRenderContext rc){
- AffineTransform t = new AffineTransform(txf);
+ AffineTransform t = txf;
if(transform != null){
+ t = new AffineTransform(txf);
t.concatenate(transform);
}
- if(count <= 0){
- return new Rectangle(0, 0, 0, 0);
+ Rectangle2D gb = null;
+ int i=0;
+ while(gb == null && i < count){
+ // System.out.println("XX44");
+ gb = children[i++].getTransformedGeometryBounds(t, rc);
}
-
- Rectangle2D gb = children[0].getTransformedGeometryBounds(t, rc);
- for(int i=0; i<count; i++){
- gb.add(children[i].getTransformedGeometryBounds(t, rc));
+
+ Rectangle2D cgb = null;
+ while(i < count){
+ // System.out.println("YY44");
+ cgb = children[i++].getTransformedGeometryBounds(t, rc);
+ if(cgb != null){
+ gb.add(cgb);
+ }
}
return gb;