Skip to content

Commit 01f051c

Browse files
author
YCode
committed
chore: 优化线的算法策略
1 parent 7e562bc commit 01f051c

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

YCode.Designer.Fluxo/FluxoLineContainer.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ static FluxoLineContainer()
1313
}
1414

1515
private FluxoDesigner? _designer;
16+
private FluxoLineFactory? _factory;
1617

1718
public override void OnApplyTemplate()
1819
{
@@ -21,6 +22,8 @@ public override void OnApplyTemplate()
2122
if (this.FindParent<FluxoDesigner>() is { } designer)
2223
{
2324
_designer = designer;
25+
26+
_factory = new FluxoLineFactory(_designer);
2427
}
2528
}
2629

@@ -31,6 +34,13 @@ protected override DependencyObject GetContainerForItemOverride()
3134

3235
protected override bool IsItemItsOwnContainerOverride(object item)
3336
{
34-
return _designer?.IsLineItsOwnContainerOverride(this,item) ?? base.IsItemItsOwnContainerOverride(item);
37+
return _designer?.IsLineItsOwnContainerOverride(this, item) ?? base.IsItemItsOwnContainerOverride(item);
38+
}
39+
40+
internal IFluxoLineGeometry GetLineProvider(LineType type)
41+
{
42+
return _factory?.GetLine(type) ??
43+
throw new InvalidOperationException(
44+
$"factory is missing {nameof(FluxoLineFactory)}.");
3545
}
3646
}

YCode.Designer.Fluxo/Lines/FluxoLine.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ static FluxoLine()
1616
private readonly FluxoDesigner _designer;
1717
private readonly FluxoLineContainer _container;
1818
private readonly StreamGeometry _geometry;
19-
private readonly FluxoLineFactory _factory;
2019

2120
public FluxoLine(FluxoDesigner designer, FluxoLineContainer container)
2221
{
@@ -29,8 +28,6 @@ public FluxoLine(FluxoDesigner designer, FluxoLineContainer container)
2928
FillRule = FillRule.EvenOdd
3029
};
3130

32-
_factory = new FluxoLineFactory(_designer);
33-
3431
this.Loaded += OnLoaded;
3532
}
3633

@@ -153,7 +150,7 @@ protected override void OnRender(DrawingContext drawingContext)
153150
{
154151
base.OnRender(drawingContext);
155152

156-
var line = _factory.GetLine(_designer.LineType);
153+
var line = _container.GetLineProvider(_designer.LineType);
157154

158155
var p = line?.GetPoint(0.1);
159156

@@ -166,7 +163,7 @@ protected override void OnRender(DrawingContext drawingContext)
166163

167164
private (Point, Point) DrawLine(StreamGeometryContext context, FluxoNode source, FluxoNode target)
168165
{
169-
var line = _factory.GetLine(_designer.LineType);
166+
var line = _container.GetLineProvider(_designer.LineType);
170167

171168
var @params = this.GetParameter(source, target);
172169

YCode.Designer.Fluxo/Lines/Impl/FluxoStepLine.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ static bool IsOppositePosition(FluxoLinePosition sourcePosition, FluxoLinePositi
160160
var factor = extra / distance;
161161

162162
return new Point(
163-
prePoint.X + (factor * this.Points[i].X - prePoint.X),
164-
prePoint.Y + (factor * this.Points[i].Y - prePoint.Y));
163+
prePoint.X + (factor * (this.Points[i].X - prePoint.X)),
164+
prePoint.Y + (factor * (this.Points[i].Y - prePoint.Y)));
165165
}
166166

167167
prePoint = this.Points[i];

0 commit comments

Comments
 (0)