Beispiel #1
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            bool centeredBool = false;

            DA.GetData(2, ref centeredBool);

            double distance = 0;

            DA.GetData(1, ref distance);

            Rhino.Geometry.Curve curveToOffset = null;
            DA.GetData(0, ref curveToOffset);

            Rhino.Geometry.Point3d firstStartPoint = curveToOffset.PointAtStart;
            Rhino.Geometry.Point3d firstEndPoint   = curveToOffset.PointAtEnd;

            Rhino.Geometry.Plane defaultPlane = Plane.WorldXY;

            Rhino.Geometry.Curve[] offsetCurves         = curveToOffset.Offset(defaultPlane, distance, 0.1, CurveOffsetCornerStyle.Sharp);
            Rhino.Geometry.Curve[] mirroredOffsetCurves = curveToOffset.Offset(defaultPlane, distance * -1, 0.1, CurveOffsetCornerStyle.Sharp);

            if (offsetCurves.Length > 1)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Curve is not clean.");

                return;
            }

            if (centeredBool == true && mirroredOffsetCurves.Length > 1)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Curve is not clean.");

                return;
            }

            Rhino.Geometry.Curve   offsetCurve   = offsetCurves[0];
            Rhino.Geometry.Point3d newStartPoint = offsetCurve.PointAtStart;
            Rhino.Geometry.Point3d newEndPoint   = offsetCurve.PointAtEnd;

            Rhino.Geometry.Curve   mirroredOffsetCurve   = mirroredOffsetCurves[0];
            Rhino.Geometry.Point3d mirroredNewStartPoint = mirroredOffsetCurve.PointAtStart;
            Rhino.Geometry.Point3d mirroredNewEndPoint   = mirroredOffsetCurve.PointAtEnd;

            Rhino.Geometry.Curve startCapCurve = null;
            Rhino.Geometry.Curve endCapCurve   = null;

            List <Rhino.Geometry.Curve> regionCurvePieces = new List <Curve>();

            if (centeredBool == false)
            {
                startCapCurve = new Rhino.Geometry.LineCurve(firstStartPoint, newStartPoint) as Rhino.Geometry.Curve;
                endCapCurve   = new Rhino.Geometry.LineCurve(firstEndPoint, newEndPoint) as Rhino.Geometry.Curve;

                regionCurvePieces.Add(curveToOffset);
            }
            else if (centeredBool == true)
            {
                startCapCurve = new Rhino.Geometry.LineCurve(mirroredNewStartPoint, newStartPoint) as Rhino.Geometry.Curve;
                endCapCurve   = new Rhino.Geometry.LineCurve(mirroredNewEndPoint, newEndPoint) as Rhino.Geometry.Curve;

                regionCurvePieces.Add(mirroredOffsetCurve);
            }

            regionCurvePieces.Add(startCapCurve);
            regionCurvePieces.Add(offsetCurve);
            regionCurvePieces.Add(endCapCurve);

            Rhino.Geometry.Curve[] regionOffset = Curve.JoinCurves(regionCurvePieces);

            if (regionOffset.Length > 1)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Join was unsuccessful.");

                return;
            }

            DA.SetData(0, regionOffset[0]);
        }