Skip to content

Commit a20de58

Browse files
committed
properly update stroke weights for lines and points in PShape objects
1 parent 291f7c8 commit a20de58

2 files changed

Lines changed: 41 additions & 23 deletions

File tree

core/src/processing/opengl/PGraphicsOpenGL.java

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3797,6 +3797,30 @@ static protected void invTranslate(PMatrix3D matrix,
37973797
}
37983798

37993799

3800+
static protected float matrixScale(PMatrix matrix) {
3801+
// Volumetric scaling factor that is associated to the given
3802+
// transformation matrix, which is given by the absolute value of its
3803+
// determinant:
3804+
float factor = 1;
3805+
3806+
if (matrix != null) {
3807+
if (matrix instanceof PMatrix2D) {
3808+
PMatrix2D tr = (PMatrix2D)matrix;
3809+
float areaScaleFactor = Math.abs(tr.m00 * tr.m11 - tr.m01 * tr.m10);
3810+
factor = (float) Math.sqrt(areaScaleFactor);
3811+
} else if (matrix instanceof PMatrix3D) {
3812+
PMatrix3D tr = (PMatrix3D)matrix;
3813+
float volumeScaleFactor =
3814+
Math.abs(tr.m00 * (tr.m11 * tr.m22 - tr.m12 * tr.m21) +
3815+
tr.m01 * (tr.m12 * tr.m20 - tr.m10 * tr.m22) +
3816+
tr.m02 * (tr.m10 * tr.m21 - tr.m11 * tr.m20));
3817+
factor = (float) Math.pow(volumeScaleFactor, 1.0f / 3.0f);
3818+
}
3819+
}
3820+
return factor;
3821+
}
3822+
3823+
38003824
/**
38013825
* Two dimensional rotation. Same as rotateZ (this is identical to a 3D
38023826
* rotation along the z-axis) but included for clarity -- it'd be weird for
@@ -10683,6 +10707,7 @@ void applyMatrixOnLineGeometry(PMatrix2D tr, int first, int last) {
1068310707
if (first < last) {
1068410708
int index;
1068510709

10710+
float scaleFactor = matrixScale(tr);
1068610711
for (int i = first; i <= last; i++) {
1068710712
index = 4 * i;
1068810713
float x = lineVertices[index++];
@@ -10699,6 +10724,7 @@ void applyMatrixOnLineGeometry(PMatrix2D tr, int first, int last) {
1069910724
index = 4 * i;
1070010725
lineDirections[index++] = dx*tr.m00 + dy*tr.m01;
1070110726
lineDirections[index ] = dx*tr.m10 + dy*tr.m11;
10727+
lineDirections[index + 2] *= scaleFactor;
1070210728
}
1070310729
}
1070410730
}
@@ -10707,6 +10733,7 @@ void applyMatrixOnPointGeometry(PMatrix2D tr, int first, int last) {
1070710733
if (first < last) {
1070810734
int index;
1070910735

10736+
float matrixScale = matrixScale(tr);
1071010737
for (int i = first; i <= last; i++) {
1071110738
index = 4 * i;
1071210739
float x = pointVertices[index++];
@@ -10715,6 +10742,10 @@ void applyMatrixOnPointGeometry(PMatrix2D tr, int first, int last) {
1071510742
index = 4 * i;
1071610743
pointVertices[index++] = x*tr.m00 + y*tr.m01 + tr.m02;
1071710744
pointVertices[index ] = x*tr.m10 + y*tr.m11 + tr.m12;
10745+
10746+
index = 2 * i;
10747+
pointOffsets[index++] *= matrixScale;
10748+
pointOffsets[index] *= matrixScale;
1071810749
}
1071910750
}
1072010751
}
@@ -10780,6 +10811,7 @@ void applyMatrixOnLineGeometry(PMatrix3D tr, int first, int last) {
1078010811
if (first < last) {
1078110812
int index;
1078210813

10814+
float scaleFactor = matrixScale(tr);
1078310815
for (int i = first; i <= last; i++) {
1078410816
index = 4 * i;
1078510817
float x = lineVertices[index++];
@@ -10801,7 +10833,8 @@ void applyMatrixOnLineGeometry(PMatrix3D tr, int first, int last) {
1080110833
index = 4 * i;
1080210834
lineDirections[index++] = dx*tr.m00 + dy*tr.m01 + dz*tr.m02;
1080310835
lineDirections[index++] = dx*tr.m10 + dy*tr.m11 + dz*tr.m12;
10804-
lineDirections[index ] = dx*tr.m20 + dy*tr.m21 + dz*tr.m22;
10836+
lineDirections[index++] = dx*tr.m20 + dy*tr.m21 + dz*tr.m22;
10837+
lineDirections[index] *= scaleFactor;
1080510838
}
1080610839
}
1080710840
}
@@ -10810,6 +10843,7 @@ void applyMatrixOnPointGeometry(PMatrix3D tr, int first, int last) {
1081010843
if (first < last) {
1081110844
int index;
1081210845

10846+
float matrixScale = matrixScale(tr);
1081310847
for (int i = first; i <= last; i++) {
1081410848
index = 4 * i;
1081510849
float x = pointVertices[index++];
@@ -10822,6 +10856,10 @@ void applyMatrixOnPointGeometry(PMatrix3D tr, int first, int last) {
1082210856
pointVertices[index++] = x*tr.m10 + y*tr.m11 + z*tr.m12 + w*tr.m13;
1082310857
pointVertices[index++] = x*tr.m20 + y*tr.m21 + z*tr.m22 + w*tr.m23;
1082410858
pointVertices[index ] = x*tr.m30 + y*tr.m31 + z*tr.m32 + w*tr.m33;
10859+
10860+
index = 2 * i;
10861+
pointOffsets[index++] *= matrixScale;
10862+
pointOffsets[index] *= matrixScale;
1082510863
}
1082610864
}
1082710865
}
@@ -11963,28 +12001,7 @@ boolean noCapsJoins() {
1196312001

1196412002
float transformScale() {
1196512003
if (-1 < transformScale) return transformScale;
11966-
11967-
// Volumetric scaling factor that is associated to the current
11968-
// transformation matrix, which is given by the absolute value of its
11969-
// determinant:
11970-
float factor = 1;
11971-
11972-
if (transform != null) {
11973-
if (transform instanceof PMatrix2D) {
11974-
PMatrix2D tr = (PMatrix2D)transform;
11975-
float areaScaleFactor = Math.abs(tr.m00 * tr.m11 - tr.m01 * tr.m10);
11976-
factor = (float) Math.sqrt(areaScaleFactor);
11977-
} else if (transform instanceof PMatrix3D) {
11978-
PMatrix3D tr = (PMatrix3D)transform;
11979-
float volumeScaleFactor =
11980-
Math.abs(tr.m00 * (tr.m11 * tr.m22 - tr.m12 * tr.m21) +
11981-
tr.m01 * (tr.m12 * tr.m20 - tr.m10 * tr.m22) +
11982-
tr.m02 * (tr.m10 * tr.m21 - tr.m11 * tr.m20));
11983-
factor = (float) Math.pow(volumeScaleFactor, 1.0f / 3.0f);
11984-
}
11985-
}
11986-
11987-
return transformScale = factor;
12004+
return transformScale = matrixScale(transform);
1198812005
}
1198912006

1199012007
boolean segmentIsAxisAligned(int i0, int i1) {

core/src/processing/opengl/PShapeOpenGL.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,6 +1459,7 @@ protected void applyMatrixImpl(PMatrix matrix) {
14591459
tessGeo.applyMatrixOnPointGeometry(matrix,
14601460
firstPointVertex, lastPointVertex);
14611461
root.setModifiedPointVertices(firstPointVertex, lastPointVertex);
1462+
root.setModifiedPointAttributes(firstPointVertex, lastPointVertex);
14621463
}
14631464
}
14641465
}

0 commit comments

Comments
 (0)