コード例 #1
0
        private Edge GetOutForOpposite(Edge inEdge, CellBitmask cellVal, double value, ValuesInCell cellValues, IrregularCell rect)
        {
            Edge outEdge;

            SubCell subCell = GetSubCell(inEdge, value, cellValues);

            int iters = 1000;             // max number of iterations

            do
            {
                ValuesInCell  subValues = cellValues.GetSubCell(subCell);
                IrregularCell subRect   = rect.GetSubRect(subCell);
                outEdge = GetOutEdge(inEdge, subValues, subRect, value);
                bool isAppropriate = subCell.IsAppropriate(outEdge);
                if (isAppropriate)
                {
                    ValuesInCell sValues = subValues.GetSubCell(subCell);

                    Point point = GetPointXY(outEdge, value, subValues, subRect);
                    segments.AddPoint(point);
                    return(outEdge);
                }
                else
                {
                    subCell = GetAdjacentEdge(subCell, outEdge);
                }

                byte e = (byte)outEdge;
                inEdge = (Edge)((e > 2) ? (e >> 2) : (e << 2));
                iters--;
            } while (iters >= 0);

            throw new IsolineGenerationException(Properties.Resources.IsolinesDataIsUndetailized);
        }
コード例 #2
0
        private static SubCell GetSubCell(Edge inEdge, double value, ValuesInCell vc)
        {
            double lb = vc.LeftBottom;
            double rb = vc.RightBottom;
            double rt = vc.RightTop;
            double lt = vc.LeftTop;

            SubCell res = SubCell.LeftBottom;

            switch (inEdge)
            {
            case Edge.Left:
                res = (Math.Abs(value - lb) < Math.Abs(value - lt)) ? SubCell.LeftBottom : SubCell.LeftTop;
                break;

            case Edge.Top:
                res = (Math.Abs(value - lt) < Math.Abs(value - rt)) ? SubCell.LeftTop : SubCell.RightTop;
                break;

            case Edge.Right:
                res = (Math.Abs(value - rb) < Math.Abs(value - rt)) ? SubCell.RightBottom : SubCell.RightTop;
                break;

            case Edge.Bottom:
            default:
                res = (Math.Abs(value - lb) < Math.Abs(value - rb)) ? SubCell.LeftBottom : SubCell.RightBottom;
                break;
            }

            ValuesInCell subValues   = vc.GetSubCell(res);
            bool         valueInside = subValues.ValueBelongTo(value);

            if (!valueInside)
            {
                throw new IsolineGenerationException(Properties.Resources.IsolinesDataIsUndetailized);
            }

            return(res);
        }