|
|
c3ebff |
using System;
|
|
|
c3ebff |
using System.Collections.Generic;
|
|
|
c3ebff |
|
|
|
c3ebff |
namespace Assistance {
|
|
|
c3ebff |
public class InputModifierInterpolation: InputManager.Modifier {
|
|
|
c3ebff |
public readonly double precision;
|
|
|
c3ebff |
public readonly double precisionSqr;
|
|
|
c3ebff |
|
|
|
1d3aae |
public InputModifierInterpolation(double precision = 1.0) {
|
|
|
1d3aae |
this.precision = Math.Max(precision, Geometry.precision);
|
|
|
1d3aae |
this.precisionSqr = this.precision*this.precision;
|
|
|
c3ebff |
}
|
|
|
c3ebff |
|
|
|
c3ebff |
public void addSegment(Track track, Track.WayPoint p0, Track.WayPoint p1) {
|
|
|
c3ebff |
if ((p1.point.position - p0.point.position).lenSqr() <= precisionSqr)
|
|
|
c3ebff |
{ track.points.Add(p1); return; }
|
|
|
c3ebff |
Track.WayPoint p = track.modifier.calcWayPoint(0.5*(p0.originalIndex + p1.originalIndex));
|
|
|
c3ebff |
addSegment(track, p0, p);
|
|
|
c3ebff |
addSegment(track, p, p1);
|
|
|
c3ebff |
}
|
|
|
c3ebff |
|
|
|
c3ebff |
public override List<track> modify(Track track, InputManager.KeyPoint keyPoint, List<track> outTracks) {
|
|
|
c3ebff |
if (track.handler == null) {
|
|
|
c3ebff |
track.handler = new Track.Handler(this, track);
|
|
|
c3ebff |
track.handler.tracks.Add(new Track( new Track.Modifier(track.handler) ));
|
|
|
c3ebff |
}
|
|
|
c3ebff |
|
|
|
c3ebff |
Track subTrack = track.handler.tracks[0];
|
|
|
c3ebff |
Modifier modifier = (Modifier)subTrack.modifier;
|
|
|
c3ebff |
outTracks.Add(subTrack);
|
|
|
c3ebff |
|
|
|
c3ebff |
if (!track.isChanged)
|
|
|
c3ebff |
return;
|
|
|
c3ebff |
|
|
|
c3ebff |
// remove points
|
|
|
c3ebff |
int start = track.points.Count - track.wayPointsAdded;
|
|
|
c3ebff |
if (start < 0) start = 0;
|
|
|
c3ebff |
int subStart = subTrack.floorIndex(subTrack.indexByOriginalIndex(start));
|
|
|
c3ebff |
if (subTrack.points.Count < subStart) {
|
|
|
1d3aae |
subTrack.points.RemoveRange(subStart, subTrack.points.Count - subStart);
|
|
|
c3ebff |
subTrack.wayPointsRemoved += subTrack.points.Count - subStart;
|
|
|
c3ebff |
}
|
|
|
c3ebff |
|
|
|
c3ebff |
// add points
|
|
|
c3ebff |
Track.WayPoint p0 = track.getWayPoint(start - 1);
|
|
|
c3ebff |
for(int i = start; i < track.points.Count; ++i) {
|
|
|
c3ebff |
Track.WayPoint p1 = track.points[i];
|
|
|
c3ebff |
addSegment(subTrack, p0, p1);
|
|
|
c3ebff |
p0 = p1;
|
|
|
c3ebff |
}
|
|
|
c3ebff |
subTrack.wayPointsAdded += subTrack.points.Count - subStart;
|
|
|
c3ebff |
}
|
|
|
c3ebff |
}
|
|
|
c3ebff |
}
|
|
|
c3ebff |
|