示例#1
0
 public StripedPath this[int i] {
     get {
         if (dbugSettings.makeVariations)
         {
             return(new StripedPath()
             {
                 stripeField = debugStripeField(i),
                 path = paths[i]
             });
         }
         StripeField sfield = null;
         if (diamondCalculator.getStripeFieldIterator(new PathData(paths[i]), out sfield))
         {
             return(new StripedPath()
             {
                 stripeField = sfield,
                 path = paths[i],
             });
         }
         return(new StripedPath());
     }
 }
示例#2
0
        //CONSIDER: analyze all of the paths and gen StripeFields based on some global data

        public bool getStripeFieldIterator(PathData pdata, out StripeField sfield)
        {
            float value = ColorUtil.valueFromUIntColor(pdata.path.fillColor);

            float lightRatio = stripeFieldConfig.lightAreaRatio(value);
            int   lineCount  = stripeFieldConfig.lineCountForLightRatio(lightRatio);
            float darkRatio  = 1f - lightRatio;

            if (lineCount == 0)
            {
                sfield = new StripeField(); return(false);
            }

            Vector2f primary = pdata.bounds.tallerThanWide ? pdata.highest - pdata.lowest : pdata.rightMost - pdata.leftMost;

            float priAngle = Mathf.PI * 2f / 3f; //  Mathf.Atan2(primary.y, primary.x);

            priAngle = Mathf.Abs(priAngle);

            Vector2f sz           = pdata.bounds.size;
            float    diamondAngle = Mathf.PI / 6f; // priAngle + pdata.bounds.smallerOverLargerDimension * Mathf.PI / 2.5f; //TODO: determine angle somehow

            // make sure diamond is sub 90 degrees?

            Vector2f secondary = new Vector2f(Mathf.Cos(diamondAngle), Mathf.Sin(diamondAngle));

            float targetWidth = stripeFieldConfig.targetWidthForValue(darkRatio);
            float targetArea  = targetWidth * targetWidth; // stripeFieldConfig.referenceArea(lightRatio);

            if (targetArea < Mathf.Epsilon)
            {
                sfield = new StripeField()
                {
                    angleRadians = priAngle,
                    interval     = stripeFieldConfig.lineWidth
                };
                return(true);
            }

            float mult = Mathf.Sqrt(targetArea / Mathf.Max(Mathf.Abs(secondary.y), 0.0001f));

            primary.Normalize();

            float interval = secondary.y * mult;

            secondary = new Matrix2f(priAngle) * secondary;

            StripeField _next = new StripeField()
            {
                angleRadians = diamondAngle,
                interval     = interval
            };

            if (dbugSettings.hatchCount == 1)
            {
                sfield = _next;
                return(true);
            }

            sfield = new StripeField()
            {
                angleRadians = priAngle,
                interval     = interval,
                next         = _next
            };

            return(true);
        }