Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 239717

Summary: Clipping Error
Product: [Tools] GEF Reporter: Sven Wende <s.wende>
Component: GEF-Legacy Draw2dAssignee: Alexander Nyßen <nyssen>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: nyssen
Version: 3.4   
Target Milestone: 3.7.1 (Indigo) M6   
Hardware: All   
OS: All   
Whiteboard:

Description Sven Wende CLA 2008-07-06 11:34:49 EDT
Build ID: N/A

Steps To Reproduce:

I think there is a bug in class org.eclipse.draw2d.SWTGraphics.RectangleClipping which causes strange drawing behaviour with child figures that clip the drawing area using graphics.clipRect(..).

This is the current code: 

public void intersect(int left, int top, final int right, final int bottom) {
 this.left = Math.max(this.left, left);
 this.right = Math.min(this.right, right);
 this.top = Math.max(this.top, top);
 this.bottom = Math.min(this.bottom, bottom);
 if (right < left || bottom < top) {
 //width and height of -1 to avoid ceiling function from  re-adding a pixel.
  this.right = left - 1;
  this.bottom = top - 1;
  }
}

This is the code that was probably intended and should work:

public void intersect(int left, int top, final int right, final int bottom) {
 this.left = Math.max(this.left, left);
 this.right = Math.min(this.right, right);
 this.top = Math.max(this.top, top);
 this.bottom = Math.min(this.bottom, bottom);
 if (this.right < left || this.bottom < top) {
 //width and height of -1 to avoid ceiling function from  re-adding a pixel.
  this.right = left - 1;
  this.bottom = top - 1;
  }
}


More information:
Comment 1 Alexander Nyßen CLA 2011-03-08 16:32:00 EST
Yes, this seems to be the case. Especially as the former implementation (reversion 1.29) was implemented as follows:

public void intersect(Rectangle rect) {
		left = Math.max(left, rect.x);
		rt = Math.min(rt, rect.right());
		top = Math.max(top, rect.y);
		botm = Math.min(botm, rect.bottom());
		if (rt < left || botm < top) {
			rt = left - 1;//Use negative size to ensure ceiling function doesn't add a pixel
			botm = top - 1;
		}
	}

However, I am wondering why left and bottom are handled in the same if clause. Wouldn't it be appropriate to handle them individually? I will investigate...
Comment 2 Alexander Nyßen CLA 2011-03-08 17:27:13 EST
> However, I am wondering why left and bottom are handled in the same if clause.
> Wouldn't it be appropriate to handle them individually? I will investigate...
Well, I suppose that doesn't matter, as the rectangle is empty anyway in case it is empty "in one direction".
Comment 3 Alexander Nyßen CLA 2011-03-08 17:28:10 EST
> However, I am wondering why left and bottom are handled in the same if clause.
> Wouldn't it be appropriate to handle them individually? I will investigate...
Well, I suppose that doesn't matter, as the rectangle is empty anyway in case it is empty "in one direction".
Comment 4 Alexander Nyßen CLA 2011-03-08 17:37:20 EST
(In reply to comment #1)
> Yes, this seems to be the case. Especially as the former implementation
> (reversion 1.29) was implemented as follows:
> 
> public void intersect(Rectangle rect) {
>         left = Math.max(left, rect.x);
>         rt = Math.min(rt, rect.right());
>         top = Math.max(top, rect.y);
>         botm = Math.min(botm, rect.bottom());
>         if (rt < left || botm < top) {
>             rt = left - 1;//Use negative size to ensure ceiling function
> doesn't add a pixel
>             botm = top - 1;
>         }
>     }
> 

So actually, it will have to be as follows:

public void intersect(int left, int top, final int right,
				final int bottom) {
			this.left = Math.max(this.left, left);
			this.right = Math.min(this.right, right);
			this.top = Math.max(this.top, top);
			this.bottom = Math.min(this.bottom, bottom);
			// use left/top -1 to ensure ceiling function doesn't add a pixel
			if (this.right < this.left || this.bottom < this.top) {
				this.right = this.left - 1;
				this.bottom = this.top - 1;
			}
}
Comment 5 Alexander Nyßen CLA 2011-03-08 17:39:03 EST
Committed changes to cvs HEAD (3.7M6). Resolving as fixed.