This is an automated email from the ASF dual-hosted git repository.
markt-asf pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push:
new 43e30d288a Fix drawboard rendering for axis-aligned shapes
43e30d288a is described below
commit 43e30d288a683ebea0dc1596e2dd980dd3fbcf89
Author: sainadh777 <[email protected]>
AuthorDate: Fri Aug 21 23:05:22 2026 -0700
Fix drawboard rendering for axis-aligned shapes
---
TODO.md | 10 ----
.../apache/tomcat/websocket/TestDrawMessage.java | 55 ++++++++++++++++++++++
webapps/docs/changelog.xml | 4 ++
.../classes/websocket/drawboard/DrawMessage.java | 7 ++-
4 files changed, 64 insertions(+), 12 deletions(-)
diff --git a/TODO.md b/TODO.md
index d530518c83..7e3dcc6536 100644
--- a/TODO.md
+++ b/TODO.md
@@ -966,16 +966,6 @@ These are bugs, correctness issues, or missing
functionality that may affect pro
---
-### 90. Example WebSocket Draw Message (1 item)
-
-| # | File:Line | Description | Fix Idea | Effort | Difficulty |
-|---|-----------|-------------|----------|--------|------------|
-| 90.1 | `DrawMessage.java:163` | Axis-aligned rectangles should be drawn as
lines | Add a check: if `x1 == x2` or `y1 == y2`, draw a line instead of a
rectangle. | 0.25 day | Low |
-
-**Total estimated effort: 0.25 day, Low difficulty**
-
----
-
### 91. Example WebSocket Client Blocking (2 items)
| # | File:Line | Description | Fix Idea | Effort | Difficulty |
diff --git a/test/org/apache/tomcat/websocket/TestDrawMessage.java
b/test/org/apache/tomcat/websocket/TestDrawMessage.java
new file mode 100644
index 0000000000..b1091fa328
--- /dev/null
+++ b/test/org/apache/tomcat/websocket/TestDrawMessage.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tomcat.websocket;
+
+import java.awt.Graphics2D;
+import java.awt.Shape;
+import java.awt.geom.Line2D;
+
+import org.easymock.Capture;
+import org.easymock.EasyMock;
+import org.junit.Assert;
+import org.junit.Test;
+
+import websocket.drawboard.DrawMessage;
+
+public class TestDrawMessage {
+
+ @Test
+ public void testAxisAlignedRectangleDrawnAsLine() {
+ assertDrawsLine(3, 5, 20, 5, 30);
+ }
+
+ @Test
+ public void testAxisAlignedEllipseDrawnAsLine() {
+ assertDrawsLine(4, 20, 5, 30, 5);
+ }
+
+ private static void assertDrawsLine(int type, double x1, double y1, double
x2, double y2) {
+ Graphics2D graphics = EasyMock.createNiceMock(Graphics2D.class);
+ Capture<Shape> shape = EasyMock.newCapture();
+ graphics.draw(EasyMock.capture(shape));
+ EasyMock.expectLastCall().once();
+ EasyMock.replay(graphics);
+
+ DrawMessage message = new DrawMessage(type, (byte) 0, (byte) 0, (byte)
0, (byte) 0, 1, x1, x2, y1, y2);
+ message.draw(graphics);
+
+ EasyMock.verify(graphics);
+ Assert.assertTrue(shape.getValue() instanceof Line2D);
+ }
+}
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 1c3922e6a9..5482c850e0 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -502,6 +502,10 @@
</subsection>
<subsection name="Web applications">
<changelog>
+ <fix>
+ Examples: Draw axis-aligned rectangles and ellipses as lines in the
+ WebSocket drawboard. (sainadh777)
+ </fix>
<update>
Manager: Drop session handling dedicated to extracting the locale from
Tapestry attributes, used for locale session sorting. (remm)
diff --git
a/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawMessage.java
b/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawMessage.java
index 33de5572ee..4d4dd83872 100644
--- a/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawMessage.java
+++ b/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawMessage.java
@@ -160,9 +160,12 @@ public final class DrawMessage {
y2 = this.y1;
}
- // TODO: If (x1 == x2 || y1 == y2) draw as line.
+ if (x1 == x2 || y1 == y2) {
+ // Draw axis-aligned shapes as lines to match the behavior in
the HTML5 Canvas.
+ Line2D line = new Line2D.Double(x1, y1, x2, y2);
+ g.draw(line);
- if (type == 3) {
+ } else if (type == 3) {
// Draw a rectangle.
Rectangle2D rect = new Rectangle2D.Double(x1, y1,
x2 - x1, y2 - y1);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]