Skip to content

Commit 191ef4d

Browse files
author
YCode
committed
feat: 直线计算点位
1 parent 69a2516 commit 191ef4d

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

YCode.Designer.Demo/Demo/Playground/Playground.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
Mounting="OnMounting"
3939
Mounted="OnMounted"
4040
GridType="Dot"
41+
LineType="Straight"
4142
Orientation="Vertical"
4243
ToolTemplate="{StaticResource ToolDataTemplate}"
4344
ItemContainerStyle="{StaticResource FluxoNodeStyle}"

YCode.Designer.Fluxo/Lines/FluxoLine.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,21 @@ protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
149149
base.OnPropertyChanged(e);
150150
}
151151

152+
protected override void OnRender(DrawingContext drawingContext)
153+
{
154+
base.OnRender(drawingContext);
155+
156+
var line = _factory.GetLine(_designer.LineType);
157+
158+
var p = line?.GetPoint(0.1);
159+
160+
if (p.HasValue)
161+
{
162+
drawingContext.DrawRectangle(Brushes.Orange, new Pen(Brushes.Transparent, 1),
163+
new Rect(p.Value.X-5, p.Value.Y-5, 10, 10));
164+
}
165+
}
166+
152167
private (Point, Point) DrawLine(StreamGeometryContext context, FluxoNode source, FluxoNode target)
153168
{
154169
var line = _factory.GetLine(_designer.LineType);

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

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,10 @@ public override Point GetPoint(double target)
6161
var start = this.Points.FirstOrDefault();
6262
var end = this.Points.LastOrDefault();
6363

64-
var currentLength = this.GetLength();
64+
var x = start.X + (end.X - start.X) * target;
65+
var y = start.Y + (end.Y - start.Y) * target;
6566

66-
var targetLength = currentLength * target;
67-
68-
var distance = Point.Subtract(end, start).Length;
69-
70-
if (currentLength + distance >= targetLength)
71-
{
72-
var extra = targetLength - currentLength;
73-
74-
var factor = extra / distance;
75-
76-
return new Point(start.X + factor * (end.X - start.X), start.Y + factor * (end.Y - start.Y));
77-
}
78-
79-
return default;
67+
return new Point(x, y);
8068
}
8169

8270
public override double GetLength()

0 commit comments

Comments
 (0)