SketchMatcher
Sample format for patterns array: var patterns = [ {name: "pA", type: "point", position: [10, 20]}, //point with precise location {name: "pB", type: "point"}, //point (location may be arbitrary) {name: "lCD", type: "line", ends: [[0, 0], [50, 0]]}, //line with precise location of endpoints {name: "a1", type: "arc", ends: [[0, 0], [50, 0]]}, //arc with precise location of endpoints (arbitrary center) {type: "arc", ends: [[30, 0], [50, 0]], middle: [40, 10]}, //unnamed curve with precise geometric state (endpoints + middle point) {type: "line", ends: [[0, -10], [50, -10]], undir: true}, //unnamed line with given endpoints (maybe in reversed order) {name: "lST", type: "line", middle: [50, 50]}, //line with prescribed middle point {type: "fixation", args: "pA"}, //fixation constraint on point named "pA" {type: "incidence", args: ["lCD", "lST"]}, //lines "lCD" and "lST" have collinearity constraint on them {type: "distance", args: [1, "lCD"], value: 50}, //distance constraint from "pB" (second pattern in array) to "lCD" with value = 50 {type: "incidence", args: ["lST.e", "3.c"]}, //'c'enter of arc a1 (by index 3) is coincident with 'e'ndpoint of line lST ];
General plan of matching things:
- Named objects are matched to named patterns.
This is the preferred way of matching things.
You can give (test) names in unit tests by writing:
{name: "...", ...}, //pattern with name
setTestName(obj, "..."); //sketch object got a name
Names must be unique among objects and unique among patterns. Any object or pattern with name must have a match of same name (otherwise error is triggered).//note: there are helpers in SketcherAutomation - Unnamed patterns of geometric objects are matched to unnamed sketch objects. Each pattern is compared to all yet unmatched sketch objects. If any compatible sketch object is found, it is considered a match. Patterns are checked in order of definition, but order of objects on sketch may change. That's why this method is not very reliable.
- Unnamed patterns of constraints are matched to unnamed constraints on sketch. Commutativity of many constraint types is taken into account. This is usually a good way of matching constraints.
After all the matching is complete, we check that for each matching pair all the additional info is compatible (e.g. positions, etc). Finally, you can get the following info:
- List of all unmatched objects.
- List of all unmatched patterns. Generally, these lists should be empty for a fully specified sketch description. But you can e.g. avoid describing constraints and check that list 1 contains only constraints.
Static Method Summary
| Static Public Methods | ||
| public static |
run(sketch: *, patterns: *, settings: *): * |
|
Constructor Summary
| Public Constructor | ||
| public |
constructor(sketch: *, patterns: *) |
|
Member Summary
| Public Members | ||
| public |
|
|
| public |
|
|
| public |
|
|
| public |
objectByName: {} |
|
| public |
objects: *[] |
|
| public |
patternByName: {} |
|
| public |
patterns: * |
|
| public |
sketch: * |
|
| public |
unnamedPatterns: *[] |
|
Method Summary
| Public Methods | ||
| public |
|
|
| public |
compute() |
|
| public |
getObjectType(obj: *): * |
|
| public |
getUnmatchedObjects(): * |
|
| public |
getUnmatchedPatterns(): * |
|
| public |
isCompatible(obj: *, pat: *): boolean |
|
| public |
isPositionSame(pos: *, expect: *): * |
|
| public |
|
|
| public |
matchUnnamed(typesList: *) |
|
| public |
|
|
| public |
|
|
| public |
resolveRef(arg: *, relaxed: *): * |
|
| public |
unmatchedNamedObject(obj: *) |
|
| public |
unmatchedNamedPattern(pat: *) |
|
Static Public Methods
public static run(sketch: *, patterns: *, settings: *): * source
Params:
| Name | Type | Attribute | Description |
| sketch | * | ||
| patterns | * | ||
| settings | * |
Return:
| * |
Public Constructors
public constructor(sketch: *, patterns: *) source
Params:
| Name | Type | Attribute | Description |
| sketch | * | ||
| patterns | * |
Public Members
public constraintTypes: * source
public objectByName: {} source
public objects: *[] source
public patternByName: {} source
public patterns: * source
public sketch: * source
public unnamedPatterns: *[] source
Public Methods
public checkMatches() source
public compute() source
public isCompatible(obj: *, pat: *): boolean source
Params:
| Name | Type | Attribute | Description |
| obj | * | ||
| pat | * |
public isPositionSame(pos: *, expect: *): * source
Params:
| Name | Type | Attribute | Description |
| pos | * | ||
| expect | * |
Return:
| * |
public matchNamed() source
public matchUnnamed(typesList: *) source
Params:
| Name | Type | Attribute | Description |
| typesList | * |
public preprocessPatterns() source
public preprocessSketch() source
public resolveRef(arg: *, relaxed: *): * source
Params:
| Name | Type | Attribute | Description |
| arg | * | ||
| relaxed | * |
Return:
| * |
public unmatchedNamedObject(obj: *) source
Params:
| Name | Type | Attribute | Description |
| obj | * |
public unmatchedNamedPattern(pat: *) source
Params:
| Name | Type | Attribute | Description |
| pat | * |