|
|
@@ -32,6 +32,7 @@ type Point struct { |
|
|
Between *BetweenPoint `yaml:"between"` |
|
|
Between *BetweenPoint `yaml:"between"` |
|
|
Extend *ExtendPoint `yaml:"extend"` |
|
|
Extend *ExtendPoint `yaml:"extend"` |
|
|
Hide bool `yaml:"hide"` |
|
|
Hide bool `yaml:"hide"` |
|
|
|
|
|
Polar *PolarPoint `yaml:"polar"` |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var ErrInvalidPointID = errors.New("type cannot be converted to a PointID") |
|
|
var ErrInvalidPointID = errors.New("type cannot be converted to a PointID") |
|
|
@@ -141,6 +142,11 @@ func (p Points) addSingleToPattern(id point.ID, pat *pattern.Pattern, depth int) |
|
|
var newPoint point.Point |
|
|
var newPoint point.Point |
|
|
|
|
|
|
|
|
switch { |
|
|
switch { |
|
|
|
|
|
case templatePoint.RelativeTo != nil && templatePoint.Polar != nil: |
|
|
|
|
|
newPoint, err = p.createPolar(id, pat, depth) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
case templatePoint.RelativeTo != nil: |
|
|
case templatePoint.RelativeTo != nil: |
|
|
newPoint, err = p.createRelative(id, pat, depth) |
|
|
newPoint, err = p.createRelative(id, pat, depth) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
@@ -282,8 +288,52 @@ func (p Points) createExtend(id point.ID, pat *pattern.Pattern, depth int) (poin |
|
|
return point.NewExtendPoint(fromPoint, toPoint, offset, id), nil |
|
|
return point.NewExtendPoint(fromPoint, toPoint, offset, id), nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (p Points) createPolar(id point.ID, pat *pattern.Pattern, depth int) (point.Point, error) { |
|
|
|
|
|
templatePoint, ok := p[id] |
|
|
|
|
|
if !ok { |
|
|
|
|
|
return nil, ErrPointNotFound |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
relativePointID := *templatePoint.RelativeTo |
|
|
|
|
|
if relativePointID == id || depth > maxRecursionDepth { |
|
|
|
|
|
return nil, ErrRelativePointRecursion |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
relativePoint, err := p.getOrCreate(relativePointID, pat, depth) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return nil, err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
x, y, err := templatePoint.Polar.evaluate(pat.Parameters(), p.Functions(pat)) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return nil, err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return point.NewRelativePoint(relativePoint). |
|
|
|
|
|
WithXOffset(x).WithYOffset(y).MarkWith(id), nil |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
type ExtendPoint struct { |
|
|
type ExtendPoint struct { |
|
|
From point.ID `yaml:"from"` |
|
|
From point.ID `yaml:"from"` |
|
|
To point.ID `yaml:"to"` |
|
|
To point.ID `yaml:"to"` |
|
|
Offset *Value `yaml:"offset"` |
|
|
Offset *Value `yaml:"offset"` |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type PolarPoint struct { |
|
|
|
|
|
Length *Value `yaml:"length"` |
|
|
|
|
|
Rotation *Value `yaml:"rotation"` |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (p PolarPoint) evaluate(params govaluate.MapParameters, funcs map[string]govaluate.ExpressionFunction) (x, y float64, err error) { |
|
|
|
|
|
rotation, err := p.Rotation.Evaluate(params, funcs) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return 0, 0, err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
length, err := p.Length.Evaluate(params, funcs) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return 0, 0, err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return math.Sin(rotation) * -length, math.Cos(rotation) * -length, nil |
|
|
|
|
|
} |