TIP #415 Version 1.2: Enable Easy Creation of Circular Arc Segments

This is not necessarily the current version of this TIP.


TIP:415
Title:Enable Easy Creation of Circular Arc Segments
Version:$Revision: 1.2 $
Author:Simon Geard <simon at whiteowl dot co dot uk>
State:Draft
Type:Project
Tcl-Version:8.7
Vote:Pending
Created:Tuesday, 16 October 2012
Keywords:Tk

Abstract

Creating a segment of a circular arc is unnecessarily difficult using the canvas arc. This TIP proposes a simple extension of the syntax to support the creation of circular arc segments in a natural way. A similar extension to support the more general elliptical arc segments is outside the scope of this TIP.

Rationale

There is scope to enhance arc creation to make it much more useful as was shown by a recent discussion on news:comp.lang.tcl. The proposal here is the simplest enhancement to enable creation of circular arc segments from a single parameter.

Proposal

Enhance arc creation to support a new -height option

canvas create arc x1 y1 x2 y2 -chord | -bbox -height h ?options?

The interpretation of the coordinates can be controlled by specifying either -chord or -bbox; if neither is specified -bbox is assumed.

-bbox causes the coordinates to be interpreted as the corners of a bounding box as per the current behaviour.

-chord causes the coordinates to be interpreted as the start and end points of the arc chord.

If -chord is specified a new option -height h can be used to specify the distance in canvas coordinates of the required circular arc's mid-point from its chord. The direction of the arc is determined by the sign of h: h>0 => clockwise h<0 => anticlockwise

If h=0 is not valid and will give the calling code the opportunity to handle the condition appropriately.

If -height is present the -start and -extent options are invalid (so that they can be used in future enhancements).

Example

A pretty pattern can be created with the following:

set c [canvas .c -width 700 -height 700 -bg grey]
pack $c -fill both -expand 1

$c create line 300 100 400 500 -fill magenta
array set colours {0 red 1 yellow 2 green 3 cyan 4 blue 5 magenta}
for {set i 1} {$i <= 24} {incr i} {
    set col [expr {$i % 6}]
    $c create arc 400 500 300 100 -chord -height [expr {$i*10}] \
            -outline $colours($col) -style arc -tags a_$i
    $c create arc 400 500 300 100 -chord -height [expr {-$i*10}] \
            -outline $colours($col) -style arc -tags b_$i
}

Reference Implementation

A reference implementation for the functionality is available, but handling the option combinations, manual updates and unit testing is still to do.

Copyright

This document has been placed in the public domain.


Powered by TclThis is not necessarily the current version of this TIP.

TIP AutoGenerator - written by Donal K. Fellows