Module shape_matcher
Enables a Canvas to detect drawn shapes by letting the user play a dynamic game of connect-the-dots.
I'll think of a better explanation later.
ShapeMatcher extends BoundObject
Properties
| state | (readonly) The current ShapeMatcher state |
| vertex_catch_tolerance | The coefficient by which "dot" radii are calculated. |
| slop_tolerance | The coefficient by which a sloppy line is considered too long for the approach to the next "dot". |
| initial_segment_angle | (readonly) The absolute trajectory angle of the first segment in degrees. |
| initial_segment_length | (readonly) The length of the initial segment, in pixels. |
| intended_convex_winding | (readonly) The detected winding of the shape the user is drawing. |
| debug_shapes | (bool) Whether to render a debug overlay that reveals all of the shapes. |
| debug_shape_color | An {r, g, b, a} vector representing the debug_shapes render
color. |
| debug_shape_z | The z value for the debug shapes. |
| debug_shape_width | The width of the debug_shapes stroke. |
| dot_color | An {r, g, b, a} vector representing the dot color. |
| dot_z | The z value for the dots. |
| dot_width | The width of the dot stroke. |
| shapes | (readonly) The Shapes being matched |
Class Methods
| ShapeMatcher:new (...) | Create a new ShapeMatcher intended to match the given shapes. |
Hooks
| state_changed (self, state) | Called when the ShapeMatcher changes its state |
| got_initial_segment (self) | Called when the ShapeMatcher gets its initial segment |
| dot_connected (self, shape, index, count) | Called when the ShapeMatcher connects a dot |
| matched (self, shape, accuracy) | Called when the ShapeMatcher matches a shape successfully |
| failed (self) | Called when the ShapeMatcher fails to match a shape. |
Constants
| STATE_NEW | A ShapeMatcher state in which it is not running and has no data. |
| STATE_RUNNING | A ShapeMatcher state in which it is running and gathering data. |
| STATE_ENDED | A ShapeMatcher state in which it is no longer running and has data. |
| WINDING_COUNTERCLOCKWISE | Denotes a counterclockwise winding. |
| WINDING_AMBIGUOUS | Denotes an ambiguous winding. |
| WINDING_CLOCKWISE | Denotes a clockwise winding. |
Properties
Properties. Significant fields on an instance.- state
-
(readonly) The current ShapeMatcher state
see also:
- vertex_catch_tolerance
-
The coefficient by which "dot" radii are calculated.
The actual radius is figured by multiplying
vertex_catch_tolerance and initial_segment_length.
Default
0.2 - slop_tolerance
-
The coefficient by which a sloppy line is considered too
long for the approach to the next "dot".
Default
1.1 - initial_segment_angle
-
(readonly) The absolute trajectory angle of the first segment
in degrees.
0degrees points right.If no segment has been drawn, this is
0. - initial_segment_length
-
(readonly) The length of the initial segment, in pixels.
If no segment has been drawn, this is
0. - intended_convex_winding
-
(readonly) The detected winding of the shape the user is
drawing.
see also:
- debug_shapes
- (bool) Whether to render a debug overlay that reveals all of the shapes. Helpful when designing new shapes.
- debug_shape_color
-
An
{r, g, b, a}vector representing the debug_shapes render color. - debug_shape_z
-
The z value for the debug shapes.
Default
-6.0 - debug_shape_width
- The width of the debug_shapes stroke.
- dot_color
-
An
{r, g, b, a}vector representing the dot color. - dot_z
-
The z value for the dots.
Default
-5.0 - dot_width
- The width of the dot stroke.
- shapes
- (readonly) The Shapes being matched
Class Methods
Class Methods. Must be called onClass, with a capital leading character.
e.g. Class:method("foo")
- ShapeMatcher:new (...)
-
Create a new
ShapeMatcherintended to match the given shapes.Parameters:
- ... number A variable list of Shapes to match.
Returns:
-
ShapeMatcher
Usage:
local matcher = ShapeMatcher:new(square, zigzag, triangle)
Hooks
Hooks. Callbacks implemented in subclasses to customize behavior. Hooks are called on individual instances.- state_changed (self, state)
-
Called when the ShapeMatcher changes its state
Parameters:
- self
ShapeMatcher
The
ShapeMatcherinstance - state The new state
- self
ShapeMatcher
The
- got_initial_segment (self)
-
Called when the ShapeMatcher gets its initial segment
Parameters:
- self
ShapeMatcher
The
ShapeMatcherinstance
- self
ShapeMatcher
The
- dot_connected (self, shape, index, count)
-
Called when the ShapeMatcher connects a dot
Parameters:
- self
ShapeMatcher
The
ShapeMatcherinstance - shape Shape The shape whose dot was connected
- index number The '1'-based index of which dot was connected
- count number How many dots there are to connect
- self
ShapeMatcher
The
- matched (self, shape, accuracy)
-
Called when the ShapeMatcher matches a shape successfully
Parameters:
- self
ShapeMatcher
The
ShapeMatcherinstance - shape Shape The shape that was matched
- accuracy
A number (percentage) between
0and1reflecting how accurately the user matched the shape.
- self
ShapeMatcher
The
- failed (self)
-
Called when the ShapeMatcher fails to match a shape.
Parameters:
- self
ShapeMatcher
The
ShapeMatcherinstance
- self
ShapeMatcher
The
Constants
Constants. Accessed at the class level e.g.Class.CONSTANT
- STATE_NEW
- A ShapeMatcher state in which it is not running and has no data.
- STATE_RUNNING
- A ShapeMatcher state in which it is running and gathering data.
- STATE_ENDED
- A ShapeMatcher state in which it is no longer running and has data.
- WINDING_COUNTERCLOCKWISE
- Denotes a counterclockwise winding.
- WINDING_AMBIGUOUS
- Denotes an ambiguous winding.
- WINDING_CLOCKWISE
- Denotes a clockwise winding.