public void Transform(IEnumerable <UV> values)
 {
     UnitConversion.Transform(values, this.FromUnit, this.ToUnit);
 }
 public void Transform(UV val)
 {
     UnitConversion.Transform(val, this.FromUnit, this.ToUnit);
 }
 public void Transform(IList <double> values)
 {
     UnitConversion.Transform(values, this.FromUnit, this.ToUnit);
 }
 public double Convert(double length, int decimalRoundingFactor)
 {
     return(UnitConversion.Convert(length, this.FromUnit, this.ToUnit, decimalRoundingFactor));
 }
 public double Convert(double length)
 {
     return(UnitConversion.Convert(length, this.FromUnit, this.ToUnit));
 }
        /// <summary>
        /// Gets the Isovist polygon.
        /// </summary>
        /// <param name="vantagePoint">The vantage point.</param>
        /// <param name="viewDepth">The view depth.</param>
        /// <param name="edges">The edges.</param>
        /// <returns>BarrierPolygons.</returns>
        public BarrierPolygon IsovistPolygon(UV vantagePoint, double viewDepth, HashSet <UVLine> edges)
        {
            /*first and expand and shrink operation is performed to merge the shadowing edges*/
            double expandShrinkFactor = Math.Pow(10.0, this.PolygonalBooleanPrecision) * UnitConversion.Convert(0.075, Length_Unit_Types.FEET, UnitType);
            //offsetting the excluded area of each edge
            INTPolygons   offsetedPolygons = new INTPolygons();
            ClipperOffset clipperOffset    = new ClipperOffset();

            foreach (UVLine edgeItem in edges)
            {
                clipperOffset.AddPath(this.excludedArea(vantagePoint, viewDepth + 1, edgeItem), ClipperLib.JoinType.jtMiter, EndType.etClosedPolygon);
                INTPolygons plygns = new INTPolygons();
                clipperOffset.Execute(ref plygns, expandShrinkFactor);
                offsetedPolygons.AddRange(plygns);
                clipperOffset.Clear();
            }
            //Unioning the expanded exclusions
            INTPolygons offsetUnioned = new INTPolygons();
            Clipper     c             = new Clipper();

            c.AddPaths(offsetedPolygons, PolyType.ptSubject, true);
            c.Execute(ClipType.ctUnion, offsetUnioned, PolyFillType.pftNonZero, PolyFillType.pftNonZero);
            //shrink the polygons to retain their original size
            INTPolygons results = new INTPolygons();

            clipperOffset.Clear();
            clipperOffset.AddPaths(offsetUnioned, JoinType.jtMiter, EndType.etClosedPolygon);
            clipperOffset.Execute(ref results, -expandShrinkFactor);
            clipperOffset.Clear();
            offsetUnioned.Clear();

            /*
             * What ever is a hole in the resulting mereged polygon is the visibility polygon
             * Now we classify the polygons based on being a hole or not
             */
            //filtering out the holes that do not include the center
            INTPolygons holesNOT             = new INTPolygons();
            INTPolygons holesIncludingCenter = new INTPolygons();
            IntPoint    iCenter = ConvertUVToIntPoint(vantagePoint);

            foreach (INTPolygon item in results)
            {
                if (!Clipper.Orientation(item))
                {
                    if (Clipper.PointInPolygon(iCenter, item) == 1)
                    {
                        holesIncludingCenter.Add(item);
                    }
                }
                else
                {
                    holesNOT.Add(item);
                }
            }
            if (holesIncludingCenter.Count == 0)
            {
                //there is no hole. The shadow polygones should clip the potential field of visibility (i.e. circle) by an subtraction operation
                INTPolygon circle = createCircle(vantagePoint, viewDepth);
                //subtraction
                c.Clear();
                c.AddPath(circle, PolyType.ptSubject, true);
                c.AddPaths(holesNOT, PolyType.ptClip, true);
                INTPolygons isovistPolygon = new INTPolygons();
                c.Execute(ClipType.ctDifference, isovistPolygon);
                //searching for a polygon that includes the center
                foreach (INTPolygon item in isovistPolygon)
                {
                    if (Clipper.PointInPolygon(iCenter, item) == 1)
                    {
                        BarrierPolygon isovist = this.ConvertINTPolygonToBarrierPolygon(item);
                        results              = null;
                        c                    = null;
                        clipperOffset        = null;
                        offsetedPolygons     = null;
                        circle               = null;
                        holesNOT             = null;
                        holesIncludingCenter = null;
                        isovistPolygon       = null;
                        return(isovist);
                    }
                }
                MessageBox.Show(string.Format("Isovist not found!\nNo hole detected\n{0} polygons can be isovist", isovistPolygon.Count.ToString()));
            }
            else if (holesIncludingCenter.Count == 1)
            {
                INTPolygons isovistPolygon = holesIncludingCenter;
                foreach (INTPolygon item in isovistPolygon)
                {
                    if (Clipper.PointInPolygon(iCenter, item) == 1)
                    {
                        item.Reverse();
                        BarrierPolygon isovist = this.ConvertINTPolygonToBarrierPolygon(item);
                        results              = null;
                        c                    = null;
                        clipperOffset        = null;
                        offsetedPolygons     = null;
                        holesNOT             = null;
                        holesIncludingCenter = null;
                        isovistPolygon       = null;
                        return(isovist);
                    }
                }
                MessageBox.Show(string.Format("Isovist not found!\nOne hole detected\n{0} polygons can be isovist", isovistPolygon.Count.ToString()));
            }
            else if (holesIncludingCenter.Count > 1)
            {
                MessageBox.Show("Isovist not found!\nMore than one hole found that can include the vantage point");
            }
            return(null);
        }
        /// <summary>
        /// Simplifies an list INTPolygons using expand and shrink technique.
        /// </summary>
        /// <param name="polygons">The INTPolygons.</param>
        /// <param name="value">The value used for expand and shrink.</param>
        /// <returns>INTPolygons.</returns>
        public INTPolygons SimplifyINTPolygons(INTPolygons polygons, double value)
        {
            double        simplificationFactor = Math.Pow(10.0, this.PolygonalBooleanPrecision) * UnitConversion.Convert(value, Length_Unit_Types.FEET, UnitType);
            ClipperOffset clipperOffset        = new ClipperOffset();

            clipperOffset.AddPaths(polygons, ClipperLib.JoinType.jtMiter, EndType.etClosedPolygon);
            INTPolygons shrink = new INTPolygons();

            clipperOffset.Execute(ref shrink, -simplificationFactor);
            //expanding to return the polygons to their original position
            clipperOffset.Clear();
            clipperOffset.AddPaths(shrink, ClipperLib.JoinType.jtMiter, EndType.etClosedPolygon);
            INTPolygons expand = new INTPolygons();

            clipperOffset.Execute(ref expand, simplificationFactor);
            shrink        = null;
            clipperOffset = null;
            return(expand);
        }