From ae17ff411f82eb9b0c0677e4655719bbec67b31b Mon Sep 17 00:00:00 2001 From: kuuube Date: Thu, 20 Oct 2022 11:05:38 -0400 Subject: [PATCH] Refactor: Remove interp from smooth version Previously interp was required to get raw tablet coordinates which the smooth version uses. Now, any filter can get raw coords. Removing interp has been tested to change coords by AT MOST 50 lines (nearly always far below this) and only when the distance hit the flat part of the funcion at Y = 15. (50 lines is around 0.5-0.25mm) --- .../Chatter_Exterminator_Smooth.cs | 90 +++++++------------ 1 file changed, 30 insertions(+), 60 deletions(-) diff --git a/Kuuube's_Chatter_Exterminator/Chatter_Exterminator_Smooth.cs b/Kuuube's_Chatter_Exterminator/Chatter_Exterminator_Smooth.cs index 5ac6db2..c9ffc22 100644 --- a/Kuuube's_Chatter_Exterminator/Chatter_Exterminator_Smooth.cs +++ b/Kuuube's_Chatter_Exterminator/Chatter_Exterminator_Smooth.cs @@ -6,86 +6,56 @@ namespace Kuuube_s_Chatter_Exterminator { - using static MathF; - [PluginName("Kuuube's CHATTER EXTERMINATOR SMOOTH")] - public class Kuuube_s_CHATTER_EXTERMINATOR_SMOOTH : AsyncPositionedPipelineElement + public class Kuuube_s_CHATTER_EXTERMINATOR_SMOOTH : IPositionedPipelineElement { - public Kuuube_s_CHATTER_EXTERMINATOR_SMOOTH() { } - - private bool isReady; - private Vector2 position; - private Vector2 targetPos, calcTarget; - private readonly float threshold = 0.9f; - private readonly float _AntichatterOffsetY = 15; - private readonly float _Xoffset = 1.96f; - private readonly float _FuncStretch = 1.7f; - private uint pressure; + private Vector2 LastPos; + private readonly float weight = 0.9f; + private readonly float Y_Offset = 15; + private readonly float Stretch = 1.96f; + private readonly float X_Offset = 1.7f; - public Vector2 Filter(Vector2 calcTarget) + public Vector2 Filter(Vector2 input) { - if (!this.isReady) - { - this.position = calcTarget; - this.isReady = true; - return calcTarget; - } - - var delta = calcTarget - this.position; - var distance = Vector2.Distance(this.position, calcTarget); - - float target = 1 - threshold; - float weight = (float)(1.0 - (1.0 / Pow((float)(1.0 / target), (float)1 / 1000))); + Vector2 Delta = new Vector2(); + { + Delta.X = input.X - LastPos.X; + Delta.Y = input.Y - LastPos.Y; + } - var weightModifier = (float)Pow(((distance * -1 + (Chatter_Extermination_Strength - _FuncStretch)) / _Xoffset), 19) + _AntichatterOffsetY; + float distance = (float)MathF.Sqrt(MathF.Pow(Delta.X, 2) + MathF.Pow(Delta.Y, 2)); - // Limit minimum - if (weightModifier + _AntichatterOffsetY < 0) - weightModifier = 0; - else - weightModifier += _AntichatterOffsetY; + float function = MathF.Pow(((distance * -1 + (Chatter_Extermination_Strength - X_Offset)) / Stretch), 19) + Y_Offset; - weightModifier = weight / weightModifier; - weightModifier = Math.Clamp(weightModifier, 0, 1); - this.position += delta * weightModifier; + float weightModifier = Math.Clamp(function + Y_Offset, 0, float.MaxValue); - return this.position; - } + weightModifier = Math.Clamp(weight / weightModifier, 0, 1); + + LastPos.X += (Delta.X * weightModifier); + LastPos.Y += (Delta.Y * weightModifier); - protected override void ConsumeState() - { - if (State is ITabletReport report) - { - this.targetPos = report.Position; - this.pressure = report.Pressure; - calcTarget = targetPos; - } - else - calcTarget = targetPos; + return LastPos; } - protected override void UpdateState() + public event Action Emit; + + public void Consume(IDeviceReport value) { - if (State is ITabletReport report) + if (value is ITabletReport report) { - report.Position = Filter(calcTarget); - report.Pressure = this.pressure; - State = report; + report.Position = Filter(report.Position); + value = report; } - if (PenIsInRange() || State is not ITabletReport) - { - OnEmit(); - } + Emit?.Invoke(value); } - public override PipelinePosition Position => PipelinePosition.PreTransform; + public PipelinePosition Position => PipelinePosition.PreTransform; [Property("Chatter Extermination Strength"), DefaultPropertyValue(6f), ToolTip ("Kuuube's CHATTER EXTERMINATOR SMOOTH:\n\n" + "Recommended settings are 6-7 for dragging and 15-16 for hovering.\n" + - "However, any value above zero is accepted.\n" + - "Frequency is unused and only present due to restrictions on OTD's plugin system.")] - public float Chatter_Extermination_Strength { set; get; } = 3; + "However, any value above zero is accepted.")] + public float Chatter_Extermination_Strength { set; get; } } }