Bug 292164 - GC.drawRectangle(x, y, 0, 0) should draw a point
Summary: GC.drawRectangle(x, y, 0, 0) should draw a point
Status: CLOSED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.6   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Silenio Quarti CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks: 175163
  Show dependency tree
 
Reported: 2009-10-13 12:03 EDT by Dani Megert CLA
Modified: 2019-11-14 03:07 EST (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dani Megert CLA 2009-10-13 12:03:41 EDT
R3.5.

GC.drawRectangle(x, y, 0, 0) should draw a point. Same if the arguments are passed in as rectangle to GC.drawRectangle(Rectangle).

Snippet:

/*******************************************************************************
 * Copyright (c) 2009 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package p;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class Snippet {
	public static void main(String[] args) {

		Display display= new Display();
		Shell shell= new Shell(display);
		shell.setLayout(new FillLayout());

		final Composite composite= new Composite(shell, SWT.NONE);
		composite.setSize(10, 200);
		composite.addPaintListener(new PaintListener() {

			public void paintControl(PaintEvent event) {
				GC gc= event.gc;
				gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_RED));
				Rectangle rect= new Rectangle(1, 1, 0, 0);
				gc.drawRectangle(rect);
			}
		});

		shell.pack();
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
	}

}
Comment 1 Felipe Heidrich CLA 2009-10-13 13:25:39 EDT
This is consistent on all platforms with advance on and off.

I'd say this is by design...
Comment 2 Dani Megert CLA 2009-10-14 02:58:45 EDT
>I'd say this is by design...
What design? ;-) For me the Javadoc is the design and according to that a point is expected. If not, then please updated the Javadoc.
Comment 3 Felipe Heidrich CLA 2009-10-14 09:57:04 EDT
(In reply to comment #2)
> What design? ;-) For me the Javadoc is the design and according to that a point
> is expected. If not, then please updated the Javadoc.

not every single detail can be in the doc... for example, all of these:
GDK: gdk_draw_rectangle()
Cairo: cairo_rectangle()
Carbon: CGContextStrokeRect()
Cocoa: NSBezierPath#appendBezierPathWithRect()
win32 gdi: Rectangle()
win32 gdi+: Graphics_DrawRectangle()
have the same 'design', yet nothing is said about it the doc.

I read our javadoc, not sure what part of it leads the user to believe that h=0 and w=0 should draw a point. GC#drawPoint() does that.
Comment 4 Dani Megert CLA 2009-10-14 10:03:54 EDT
>I read our javadoc, not sure what part of it leads the user to believe that h=0
>and w=0 should draw a point. GC#drawPoint() does that.
Note that h and w is not the amount of pixels that are drawn: according to the Javadoc the rectangle is from
x to x+w ==> pixel count = w-1
y to y+h ==> pixel count = h-1
==> x,y, w=0, h=0 should draw from x to x and y to y and hence result in a point.
Comment 5 Randy Hudson CLA 2011-06-20 16:35:01 EDT
If anything, I don't think it should draw a point (drawPoint() means a single pixel only), but rather a square the size of the current pen width.
Comment 6 Stephan Wahlbrink CLA 2011-12-22 10:22:21 EST
And if width xor height is 0 it should to draw a line.
Comment 7 Lars Vogel CLA 2019-11-14 03:07:21 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

If the bug is still relevant, please remove the "stalebug" whiteboard tag.