This is an automated email from the ASF dual-hosted git repository.
markt-asf pushed a commit to branch 11.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/11.0.x by this push:
new 743aad8a0a Fix drawboard rendering for axis-aligned shapes
743aad8a0a is described below
commit 743aad8a0aef3dffc13a626c761e9ed38bc4c227
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 cfe8dfe129..07a4eee14f 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -265,6 +265,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]