Exemplo n.º 1
0
        public float SampleSmart(Vector2D point, float threshold)
        {
            threshold = Math.Max(Spacing, threshold); //threshold can be smaller then spacing
            Probe probe;

            SampleProbe(point, out probe);
            //interpolate between the 4 corners (first 2x along X - then 1x along Y)
            float dxTop    = (probe.TopRight - probe.TopLeft);
            float dxBottom = (probe.BottomRight - probe.BottomLeft);
            float dx       = dxBottom * probe.V + (1 - probe.V) * dxTop;
            //the more the gradient dx approaches the threshold, the less we interpolate
            float sx      = CgMath.Linstep(Spacing, threshold, Math.Abs(dx));
            float uSmart  = CgMath.Lerp(probe.U, (float)Math.Round(probe.U), sx);
            float xTop    = probe.TopLeft + uSmart * dxTop;
            float xBottom = probe.BottomLeft + uSmart * dxBottom;
            float dy      = (xBottom - xTop);
            //the more the gradient approaches the threshold, the less we interpolate
            float sy     = CgMath.Linstep(Spacing, threshold, Math.Abs(dy));
            float vSmart = CgMath.Lerp(probe.V, (float)Math.Round(probe.V), sy);

            return(xTop + vSmart * dy);
        }
Exemplo n.º 2
0
        public Vector2D SampleSmoothStepped(Vector2D point, float edge0, float edge1)
        {
            Probe probe;

            SampleProbe(point, out probe);

            float tl = (1.0f - probe.U) * (1.0f - probe.V);
            float tr = probe.U * (1.0f - probe.V);
            float bl = (1.0f - probe.U) * probe.V;
            float br = probe.U * probe.V;

            float length = tl * probe.TopLeft.Length +
                           tr * probe.TopRight.Length +
                           bl * probe.BottomLeft.Length +
                           br * probe.BottomRight.Length;

            Vector2D result = tl * probe.TopLeft +
                              tr * probe.TopRight +
                              bl * probe.BottomLeft +
                              br * probe.BottomRight;

            return(result.Sized(CgMath.Linstep(edge0, edge1, length)));
        }
Exemplo n.º 3
0
        public Vector2D SampleLinStepped(Vector2D point, float edge0, float edge1)
        {
            Vector2D dir = Sample(point);

            return(dir.Sized(CgMath.Linstep(edge0, edge1, dir.Length)));
        }