Skip to content

Commit 7e562bc

Browse files
author
YCode
committed
chore: 折线求点位
1 parent c22eddb commit 7e562bc

File tree

1 file changed

+23
-26
lines changed

1 file changed

+23
-26
lines changed

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

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -137,44 +137,41 @@ static bool IsOppositePosition(FluxoLinePosition sourcePosition, FluxoLinePositi
137137
}
138138
}
139139

140-
public override Point GetPoint(double target)
141-
{
142-
var current = 0d;
143-
144-
var start = this.Points[0];
145-
146-
var length = this.GetLength();
140+
public override Point GetPoint(double target) { var current = 0d;
141+
var start = this.Points[0];
147142

148-
var targetLength = length * target;
143+
var length = this.GetLength();
149144

150-
var prePoint = new Point(start.X, start.Y);
151-
152-
for (var i = 1; i < this.Points.Count; i++)
153-
{
154-
var pointToLength = Math.Sqrt(Math.Pow(prePoint.X - this.Points[i].X, 2) +
155-
Math.Pow(prePoint.Y - this.Points[i].Y, 2));
145+
var targetLength = length * target;
156146

157-
var distance = Point.Subtract(this.Points[i], prePoint).Length;
147+
var prePoint = new Point(start.X, start.Y);
158148

159-
if (current + distance >= targetLength)
160-
{
161-
var extra = targetLength - current;
149+
for (var i = 1; i < this.Points.Count; i++)
150+
{
151+
var pointToLength = Math.Sqrt(Math.Pow(prePoint.X - this.Points[i].X, 2) +
152+
Math.Pow(prePoint.Y - this.Points[i].Y, 2));
162153

163-
var factor = extra / distance;
154+
var distance = Point.Subtract(this.Points[i], prePoint).Length;
164155

165-
return new Point(
166-
prePoint.X + (factor * this.Points[i].X - prePoint.X),
167-
prePoint.Y + (factor * this.Points[i].Y - prePoint.Y));
168-
}
156+
if (current + distance >= targetLength)
157+
{
158+
var extra = targetLength - current;
169159

170-
prePoint = this.Points[i];
160+
var factor = extra / distance;
171161

172-
current += pointToLength;
162+
return new Point(
163+
prePoint.X + (factor * this.Points[i].X - prePoint.X),
164+
prePoint.Y + (factor * this.Points[i].Y - prePoint.Y));
173165
}
174166

175-
return prePoint;
167+
prePoint = this.Points[i];
168+
169+
current += pointToLength;
176170
}
177171

172+
return prePoint;
173+
}
174+
178175
public override double GetLength()
179176
{
180177
var start = this.Points[0];

0 commit comments

Comments
 (0)