History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: LPP-1588
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: P1 P1
Assignee: Max Carlson
Reporter: Oliver Steele
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
OpenLaszlo

arc does not match WHATWG specification

Created: 15/Feb/06 08:24 AM   Updated: 17/Jul/06 04:39 PM
Component/s: Extensions - drawview
Affects Version/s: None
Fix Version/s: 3.2 (Sage)

Time Tracking:
Not Specified

Severity: Minor
Fixed in Change#: 40,589
Runtime: N/A
Fix in hand: True


 Description  « Hide
Drawview was specified as a subset of the WHATWG drawing API, but the implementation of arc is not compatible with it. This means that WHATWG libraries cannot be used with OpenLaszlo. (I ran across this while trying to use the JavaScript graph layout library here <http://ajaxian.com/archives/new-javascriptcanvas-graph-library> with OpenLaszlo. It can be used with an adapter layer, except that it would require a reimplementation of arc to match WHATWG.)

The WHATWG specification says <http://www.whatwg.org/specs/web-apps/current-work/#paths&gt;:
The arc(x, y, radius, startAngle, endAngle, anticlockwise) method adds an arc to the current path. The arc is given by the circle that has its origin at (x, y) and that has radius radius. The points at startAngle and endAngle along the circle, measured in radians clockwise from the positive x-axis, are the start and end points. The arc is the path along the circumference of the circle from the start point to the end point going anti-clockwise if the anticlockwise argument is true, and clockwise otherwise.

OpenLaszlo deviates in two ways:
- In WHATWG, the angle is measured in radians. In OpenLaszlo, it is measured in degrees.
- In WHATWG, the first two parameters specify the center of the circle. In OpenLaszlo, they specify the start position. (This is correct for the WHATWG arcTo() function, but not for arc().)

The following program should circumscribe a circle within the square. Instead, it draws a smudge inside the rectangle. If 2*Math.PI is replaced by 360, it draws a semicircle (since the left half of the circle is off the screen).
<canvas>
  <drawview width="100" height="100">
    <method event="oninit">
      beginPath();
      rect(0, 0, 100, 100);
      arc(50, 50, 50, 0, 2*Math.PI, true);
      stroke();
    </method>
  </drawview>
</canvas>

Compare this to the WHATWG program:
<html>
<body onLoad="start()">

<canvas id="canvas" width="100" height="100"></canvas>

<script type="text/javascript">
function start() {
  var ctx = document.getElementById('canvas').getContext('2d');
  ctx.beginPath();
  ctx.rect(0, 0, 100, 100);
  ctx.arc(50, 50, 50, 0, 2*Math.PI, true);
  ctx.stroke();
}
</script>

</body>
</html>


 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Oliver Steele - 15/Feb/06 03:06 PM
The following modification to LzDrawview.arc() fixes both problems:
  LzDrawView.prototype.arc = function(x, y, radius, startAngle, endAngle, clockwise) {
    // increment (x,y) while startAngle is still in radians
    x += radius * Math.cos(startAngle);
    y += radius * Math.sin(startAngle);
    // convert angles to degrees, for Flash
    startAngle *= 180/Math.PI;
    endAngle *= 180/Math.PI;
    var arc = clockwise == true ? startAngle - endAngle : endAngle - startAngle;
    this.moveTo(x, y);
    this._drawArc(x, y, radius, arc, startAngle);
  }

To update the test case in test/drawing/drawing.lzx:
  this.arc(100, 100, 50, 0, 90) =>
  this.arc(50, 100, 50, 0, Math.PI/2)

The docs should be updated to match the WHATWG description.

There don't appear to be any uses of arc(), including in the incubator (roundrects use drawview.rect, which uses a private method) or pie charts (they do their own circle computation, which is one reason they've got so much code).

Jim Grandy - 10/Mar/06 12:10 PM
We need to decide whether this is something to take for Sage, and whether we can do something to reduce the impact of an incompatible change. We will also need to revert or amend my documentation change (LPP-1281) when we make this change.

Max Carlson - 13/Mar/06 05:25 PM
Any word on a decision Jim? Heard back from the studios folks?

Max Carlson - 17/Jul/06 04:39 PM
Nevermind. It looks like the original change was merged over to trunk after all...