This is an automated email from the ASF dual-hosted git repository.

markt-asf pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/10.1.x by this push:
     new 3611592250 Fix drawboard rendering for axis-aligned shapes
3611592250 is described below

commit 3611592250183b83795aa0ddf2a39bebef143965
Author: sainadh777 <[email protected]>
AuthorDate: Fri Aug 21 23:05:22 2026 -0700

    Fix drawboard rendering for axis-aligned shapes
---
 .../apache/tomcat/websocket/TestDrawMessage.java   | 56 ++++++++++++++++++++++
 webapps/docs/changelog.xml                         |  4 ++
 .../classes/websocket/drawboard/DrawMessage.java   |  7 ++-
 3 files changed, 65 insertions(+), 2 deletions(-)

diff --git a/test/org/apache/tomcat/websocket/TestDrawMessage.java 
b/test/org/apache/tomcat/websocket/TestDrawMessage.java
new file mode 100644
index 0000000000..4d777fbe85
--- /dev/null
+++ b/test/org/apache/tomcat/websocket/TestDrawMessage.java
@@ -0,0 +1,56 @@
+/*
+ * 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.junit.Assert;
+import org.junit.Test;
+
+import org.easymock.Capture;
+import org.easymock.EasyMock;
+
+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 df1344f147..f61f2d6d6d 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -266,6 +266,10 @@
         host header and TLS configuration matching via SNI are completely
         separate processes. (markt)
       </add>
+      <fix>
+        Examples: Draw axis-aligned rectangles and ellipses as lines in the
+        WebSocket drawboard. (sainadh777)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Tribes">
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]

Reply via email to