public static FuzzySet[] CreateFuzzySets(FuzzySetGroupDesc group) { FuzzySet[] sets = new FuzzySet[group.Sets.Count]; for (int i = 0; i < group.Sets.Count; i++) { FuzzySetDesc desc = group.Sets[i]; sets[i] = new FuzzySet(desc.Name, new PiecewiseLinearFunction(desc.Points)); } return(sets); }
public FuzzySetChart(FuzzySetDesc set, float chartMin, float chartMax) { this.Name = set.Name; foreach (Point p in set.Points) { Debug.Log(set.Name + " " + p.X + " " + p.Y); } List <Keyframe> frames = new List <Keyframe>(set.Points.Length + 2); Keyframe? last = null; if (!Mathf.Approximately(set.Points[0].X, chartMin)) { last = new Keyframe(chartMin, set.Points[0].Y, 0, 0); frames.Add(last.Value); } for (int i = 0; i < set.Points.Length; i++) { Point p = set.Points[i]; float outTangent = 0; if (last.HasValue) { outTangent = (p.Y - last.Value.value) / (p.X - last.Value.time); Keyframe kf = last.Value; kf.outTangent = outTangent; last = kf; frames[frames.Count - 1] = kf; } Keyframe next = new Keyframe(p.X, p.Y, outTangent, 0); frames.Add(next); last = next; } if (last.HasValue && !Mathf.Approximately(last.Value.time, 1f)) { Keyframe next = new Keyframe(chartMax, last.Value.value, 0, 0); frames.Add(next); } this.Curve = new AnimationCurve(frames.ToArray()); }
// currently requires the points to be pre-sorted public FuzzySetDesc Add(FuzzySetDesc desc) { this.Sets.Add(desc); float min = desc.Points[0].X; float max = desc.Points[desc.Points.Length - 1].X; if (min < this.ActualMin) { this.ActualMin = min; } if (max > this.ActualMax) { this.ActualMax = max; } return(desc); }