This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 13277 - canvas '2d' context needs a getter for current point in path
Summary: canvas '2d' context needs a getter for current point in path
Status: ASSIGNED
Alias: None
Product: HTML WG
Classification: Unclassified
Component: HTML Canvas 2D Context (show other bugs)
Version: unspecified
Hardware: PC Linux
: P2 enhancement
Target Milestone: ---
Assignee: Jay Munro
QA Contact: HTML WG Bugzilla archive list
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-16 17:25 UTC by Patrick
Modified: 2014-06-20 22:22 UTC (History)
6 users (show)

See Also:


Attachments

Description Patrick 2011-07-16 17:25:44 UTC
Several methods in the '2d' context are of the To variety, for example moveTo, lineTo, and arcTo which take as an implicit first argument the current point in the path being constructed.  It's not possible to make similar methods from javascript if you need to do something to the end at the initial point, because it's not possible to find out what that point is.  As an example, if you wanted to make an 
arrowTo(x,y,angle,which,length,type)
  (x,y) - destination of arrow
  angle - angle between shaft of line and barb of one side of arrow
  which - which end, could be 0,1,2,3
    0 would operate like lineTo 
    1 put arrow head on destination end
    2 put arrow head on source end
    3 both ends get arrow
  length - length of the arrow head
  type   - curved bezier or block straight line

You couldn't do it.  You don't know the originating current point in the path and there's no way to ask for it.  Same would apply to arcArrowTo.  It forces you to ask the user to supply both points.

Here's http://stackoverflow.com/questions/4577410/find-current-point-on-path-for-html-canvas-context a link to someone else who wants the current point to be able to do a dashTo.  

I could create a wrapper around the context and have my uber context keep track of the information, but adding one getter to the context2d would solve the problem.

context2d.currentPoint or perhaps currentPointX, and currentPointY

Thanks:)
Patrick
Comment 1 Patrick 2011-07-18 22:05:32 UTC
Another example of where it could be useful came up today.  I wanted to do something like:

CanvasRenderingContext2D.prototype.drawLineAtAngle =
                        function(ctx,x0,y0,angle,length)
{
    this.save();
    this.lineTo(curpointX+length*Math.cos(angle),curPointY+length*Math.sin(angle));
    this.stroke();
    this.restore();
}

But of course there's no way to get the current point, so the context2D is not extensible like this.  If the getter method(s) would just supply this it would be great!
Comment 2 Robin Berjon 2013-01-21 15:59:10 UTC
Mass move to "HTML WG"
Comment 3 Robin Berjon 2013-01-21 16:01:57 UTC
Mass move to "HTML WG"
Comment 4 Edward O'Connor 2013-02-07 18:54:04 UTC
Moving to the Canvas 2d Context spec component.
Comment 5 Jay Munro 2014-06-20 22:22:45 UTC
Maybe something like this: 

//  System current path point
interface context {
readonly attribute double  currentPointX;
readonly attribute double  currentPointY;
}

// Path2D current point
interface Path2D {
readonly attribute double  currentPointX;
readonly attribute double  currentPointY; 
}


currentX = context.currentPointX;
currentY = context.currentPointY;
Return the current starting point of a system subpath.


currentPathX = Path2D.currentPointX;
currentPathY = Path2D.currentPointY;
Return the current starting point of a path object's subpath.