Bug 1283 : P2D bug: strokeWeight lines 2X too wide (v1.05)
Last modified: 2009-07-13 11:03




Status:
RESOLVED
Resolution:
FIXED -
Priority:
P2
Severity:
normal

 

Reporter:
djones
Assigned To:
fry

Attachment Type Created Size Actions

Description:   Opened: 2009-06-26 18:16
Like many others, I often switch between JAVA2D, P2D, P3D, and OPENGL to
trade off quality and speed when drawing. Therefore, it is important for
drawing functions to be as consistent as possible.

There is a bug in the "P2D" implementation of strokeWeight.
It draws lines twice as wide as they should be.

In JAVA2D and P3D, using strokeWeight(40) lines are drawn correctly (40
pixels wide).

In P2D, using StrokeWeight(40), lines are drawn incorrectly (80 pixels wide).

Since the error seems to be a simple factor of 2, I am hoping it will be
easy for someone (who knows how to navigate the Processing source code) to
track down and correct this bug.

(Note: This bug is different from the documented limitation in OPENGL where
the max line width (e.g., 10 px) is limited by your graphics card.)

my setup: Processing 1.0.5, Mac OS X 10.5.7, Mac PowerBook Pro, 2.6 GHz
Intel Core 2 Duo, NVidea GeForce 8600M GT

In the following code, try changing the "mode" from P2D (which illustrates
strokeWeight error)
to JAVA2D or P3D (where strokeWeight works as advertised).

[code]
import processing.opengl.*;
// stroke_demo


final int Npoints = 4;
float [] x = {
70, 150, 70, 70 };
float [] y = {
40, 100, 160, 200 };

void setup() {
size(400,300, P2D);
hint(DISABLE_OPENGL_2X_SMOOTH);
smooth();
drawBackground();
}

void drawBackground() {
int i, j;

background(190);
noStroke();
fill(160);
for (i = 0 ; i < width ; i += 20) {
for (j = 0 ; j < height ; j += 10) {
rect(i+(j%20),j, 10,10);
}
}
}

void draw() {

noFill();
strokeJoin(ROUND);
strokeCap(SQUARE);
strokeShape();
if (frameCount > 10) {
saveFrame("stroke.tif");
noLoop();
}
}

void strokeShape() {
stroke(0,90);
strokeWeight(40);
drawShape();

stroke(255);
strokeWeight(2);
drawShape();

drawBox();
}

void drawShape() {
int i;

if (frameCount == 1) {
beginShape();
for (i = 0 ; i < Npoints ; ++i) {
vertex(x[i],y[i]);
}
endShape();

for (i = 1 ; i < Npoints ; ++i) {
line(x[i-1]+100,y[i-1], x[i]+100,y[i]);
}
}

for (i = 1 ; i < Npoints ; ++i) {
if (i == frameCount) {
line(x[i-1]+200,y[i-1], x[i]+200,y[i]);
}
}
}

void drawBox() {
int i;

if (frameCount == 1) {
stroke(255);
strokeWeight(2);
fill(0,90);
rectMode(CENTER);
for (i = 0 ; i < 3 ; ++i) {
rect(x[3]+i*100,y[3]+50, 40,40);
}
}
}
[/code]
Additional Comment #1 From fry 2009-06-29 13:39
weird, i thought that had been fixed a couple releases ago when some other
line weight changes were fixed. oh well, i should be able to fix it for the
next round.
Additional Comment #2 From fry 2009-07-13 11:03
fixed for the next release (probably called 1.0.6).