Home Reference Source Repository
import {SketchMatcher} from 'awv3/src/plugins/sketcher/unittests.js'
public class | source

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:

  1. 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
                            //note: there are helpers in SketcherAutomation
    
    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).
  2. 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.
  3. 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:

  1. List of all unmatched objects.
  2. 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
public

objects: *[]

public
public
public

sketch: *

public

Method Summary

Public Methods
public
public
public

getObjectType(obj: *): *

public
public
public

isCompatible(obj: *, pat: *): boolean

public

isPositionSame(pos: *, expect: *): *

public
public

matchUnnamed(typesList: *)

public
public
public

resolveRef(arg: *, relaxed: *): *

public
public

Static Public Methods

public static run(sketch: *, patterns: *, settings: *): * source

Params:

NameTypeAttributeDescription
sketch *
patterns *
settings *

Return:

*

Public Constructors

public constructor(sketch: *, patterns: *) source

Params:

NameTypeAttributeDescription
sketch *
patterns *

Public Members

public constraintTypes: * source

public geometryTypes: string[] source

public linearTolerance: number 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 getObjectType(obj: *): * source

Params:

NameTypeAttributeDescription
obj *

Return:

*

public getUnmatchedObjects(): * source

Return:

*

public getUnmatchedPatterns(): * source

Return:

*

public isCompatible(obj: *, pat: *): boolean source

Params:

NameTypeAttributeDescription
obj *
pat *

Return:

boolean

public isPositionSame(pos: *, expect: *): * source

Params:

NameTypeAttributeDescription
pos *
expect *

Return:

*

public matchNamed() source

public matchUnnamed(typesList: *) source

Params:

NameTypeAttributeDescription
typesList *

public preprocessPatterns() source

public preprocessSketch() source

public resolveRef(arg: *, relaxed: *): * source

Params:

NameTypeAttributeDescription
arg *
relaxed *

Return:

*

public unmatchedNamedObject(obj: *) source

Params:

NameTypeAttributeDescription
obj *

public unmatchedNamedPattern(pat: *) source

Params:

NameTypeAttributeDescription
pat *