|
|
c3ebff |
using System;
|
|
|
c3ebff |
using System.Collections.Generic;
|
|
|
c3ebff |
|
|
|
c3ebff |
namespace Assistance {
|
|
|
ed66f8 |
public class InputModifierSegmentation: InputManager.Modifier {
|
|
|
72d2fd |
public static readonly int maxRecursion = 10;
|
|
|
0f2bf8 |
|
|
|
c3ebff |
public readonly double precision;
|
|
|
c3ebff |
public readonly double precisionSqr;
|
|
|
c3ebff |
|
|
|
ed66f8 |
public InputModifierSegmentation(double precision = 1.0) {
|
|
|
1d3aae |
this.precision = Math.Max(precision, Geometry.precision);
|
|
|
1d3aae |
this.precisionSqr = this.precision*this.precision;
|
|
|
c3ebff |
}
|
|
|
c3ebff |
|
|
|
ed66f8 |
public void addSegments(Track track, Track.Point p0, Track.Point p1, int level = 0) {
|
|
|
72d2fd |
if (level >= maxRecursion || (p1.position - p0.position).lenSqr() <= precisionSqr) {
|
|
|
72d2fd |
track.add(p1);
|
|
|
72d2fd |
return;
|
|
|
72d2fd |
}
|
|
|
702257 |
Track.Point p = track.modifier.calcPoint(0.5*(p0.originalIndex + p1.originalIndex));
|
|
|
ed66f8 |
addSegments(track, p0, p, level + 1);
|
|
|
ed66f8 |
addSegments(track, p, p1, level + 1);
|
|
|
c3ebff |
}
|
|
|
c3ebff |
|
|
|
589f9a |
public override void modify(Track track, InputManager.KeyPoint keyPoint, List<track> outTracks) {
|
|
|
72d2fd |
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 |
outTracks.Add(subTrack);
|
|
|
c3ebff |
|
|
|
72d2fd |
if (!track.wasChanged)
|
|
|
c3ebff |
return;
|
|
|
c3ebff |
|
|
|
c3ebff |
// remove points
|
|
|
72d2fd |
int start = track.count - track.pointsAdded;
|
|
|
c3ebff |
if (start < 0) start = 0;
|
|
|
72d2fd |
int subStart = subTrack.floorIndex(subTrack.indexByOriginalIndex(start-1)) + 1;
|
|
|
72d2fd |
subTrack.truncate(subStart);
|
|
|
c3ebff |
|
|
|
c3ebff |
// add points
|
|
|
702257 |
Track.Point p0 = subTrack.modifier.calcPoint(start - 1);
|
|
|
72d2fd |
for(int i = start; i < track.count; ++i) {
|
|
|
702257 |
Track.Point p1 = subTrack.modifier.calcPoint(i);
|
|
|
ed66f8 |
addSegments(subTrack, p0, p1);
|
|
|
c3ebff |
p0 = p1;
|
|
|
c3ebff |
}
|
|
|
72d2fd |
|
|
|
72d2fd |
track.resetCounters();
|
|
|
c3ebff |
}
|
|
|
c3ebff |
}
|
|
|
c3ebff |
}
|
|
|
c3ebff |
|