示例#1
0
 public void Grow(int growBy = 1)
 {
     for (var i = 0; i < growBy; i++)
     {
         Body.Add(new Point(Head.X, Head.Y));
     }
 }
        // System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator ()
        // {
        //  return GetEnumerator ();
        // }
        public CharSequenceEnumeratorMethod()
        {
            Name       = "System.Collections.IEnumerable.GetEnumerator";
            ReturnType = new TypeReferenceWriter("System.Collections.IEnumerator");

            Body.Add("return GetEnumerator ();");
        }
示例#3
0
 public Snake()
 {
     for (var i = 0; i <= Length; i++)
     {
         Body.Add(new Point(10, 10));
     }
 }
示例#4
0
        public LegalTreatyCard(string treatyName, List <TextEntity> legal)
        {
            Version = new AdaptiveSchemaVersion(1, 0);
            Body.Add(new AdaptiveTextBlock(treatyName)
            {
                Color     = AdaptiveTextColor.Accent,
                Height    = new AdaptiveHeight(24),
                Separator = true
            });

            foreach (var procedure in legal)
            {
                if (procedure.Type == "link")
                {
                    Body.Add(new AdaptiveMedia()
                    {
                        AltText = "Link",
                        Sources = new List <AdaptiveMediaSource>()
                        {
                            new AdaptiveMediaSource("url", procedure.Value)
                        }
                    });
                }
                Body.Add(new AdaptiveTextBlock(procedure.Value)
                {
                    Wrap      = true,
                    Color     = procedure.Type == "title" ? AdaptiveTextColor.Accent : AdaptiveTextColor.Default,
                    Separator = procedure.Type == "title"
                });
            }
        }
示例#5
0
 public Login()
 {
     Title.Value = "Pickle Rick!";
     UserName    = (Text)Body.Add(new Text());
     Password    = (PasswordText)Body.Add(new PasswordText());
     LoginButton = (Button)Body.Add(new Button("Log In", new FrameRequestHandler(LoginClicked)));
 }
示例#6
0
        async Task InitializeComponents()
        {
            Data["TopMenu"] = "MainMenu";
            Title           = "About us";

            await Body.Add(new TextView { Text = "Hello world!" });
        }
示例#7
0
        private void CreateBorders(Body root)
        {
            Color wallsColor = Color.FromArgb(50, 0, 0, 0);

            for (int i = 0; i < 4; ++i)
            {
                var sizeX = i / 2 == 0 ? 303 : 3;
                var sizeY = i / 2 == 1 ? 203 : 3;
                var lX    = i / 2 == 0 ? 203 : 3;
                var lY    = i / 2 == 1 ? 303 : 3;
                var pos   = i % 2 == 0 ? 1 : -1;
                root.Add(new Box
                {
                    XSize        = sizeX,
                    YSize        = sizeY,
                    ZSize        = 3,
                    DefaultColor = wallsColor,
                    IsStatic     = true,
                    Type         = "wall",
                    IsMaterial   = true,
                    Location     = new Frame3D(
                        pos * lY / 2,
                        pos * lX / 2,
                        3)
                });
            }
        }
示例#8
0
        public void Grow()
        {
            var lastBody = Body.Last();

            Body.Add(new BodyPart(BodySymbol, lastBody.PosX, lastBody.PosY));
            count++;
        }
示例#9
0
        public void Grow()
        {
            Part newPart = new Part();
            Part oldPart = Body[Body.Count - 1];

            switch (Direction)
            {
            case Direction.RIGHT:
                newPart.Y = oldPart.Y;
                newPart.X = oldPart.X + 1;
                break;

            case Direction.LEFT:
                newPart.Y = oldPart.Y;
                newPart.X = oldPart.X - 1;
                break;

            case Direction.UP:
                newPart.Y = oldPart.Y - 1;
                newPart.X = oldPart.X;
                break;

            case Direction.DOWN:
                newPart.Y = oldPart.Y + 1;
                newPart.X = oldPart.X;
                break;
            }
            Body.Add(newPart);
            newPart.Draw();
        }
示例#10
0
            public void TestLocation()
            {
                var root = new Body();
                var box  = new Box();

                root.Add(box);
                var      lo        = new LoggingObject(box, root);
                Movement movement1 = GetMovement(0, new Frame3D(1, 0, 0));

                lo.Movements.Add(movement1);
                Movement movement2 = GetMovement(300, new Frame3D(0, 1, 0));

                lo.Movements.Add(movement2);
                var     ol          = new ObjectLoader(lo, new Body());
                Frame3D expectedLoc = Frame3D.Identity;

                for (int i = 0; i <= _expectedLocations.Keys.Max(); i++)
                {
                    if (_expectedLocations.ContainsKey(i))
                    {
                        expectedLoc = _expectedLocations[i];
                    }
                    ol.LoadLocation(i);
                    Assert.AreEqual(expectedLoc, ol._loadedBody.Location);
                }
            }
示例#11
0
 public SignedXmlDocument(XDocument document)
 {
     Document = document;
     AddNamespaces();
     Body.Add(new XAttribute(wsu + "Id", "body"));
     CreateSecurityElement();
 }
示例#12
0
        public MethodExtensionAsyncWrapper(Method method, CodeGenerationOptions opt, string selfType)
        {
            Name     = method.AdjustedName + "Async";
            IsStatic = true;

            SetVisibility(method.Visibility);

            ReturnType = new TypeReferenceWriter("global::System.Threading.Tasks.Task");

            if (!method.IsVoid)
            {
                ReturnType.Name += "<" + opt.GetTypeReferenceName(method.RetVal) + ">";
            }

            SourceWriterExtensions.AddSupportedOSPlatform(Attributes, method, opt);

            Body.Add($"return global::System.Threading.Tasks.Task.Run (() => self.{method.AdjustedName} ({method.Parameters.GetCall (opt)}));");

            Parameters.Add(new MethodParameterWriter("self", new TypeReferenceWriter(selfType))
            {
                IsExtension = true
            });

            this.AddMethodParameters(method.Parameters, opt);
        }
示例#13
0
        public PersonAdaptiveCard(Person person, string fieldToAccent = "") : base()
        {
            Version = new AdaptiveSchemaVersion(1, 0);
            Body.Add(new AdaptiveTextBlock($"{person.FullName}")
            {
                Weight   = AdaptiveTextWeight.Bolder,
                IsSubtle = false
            });

            if (!string.IsNullOrEmpty(person.Image))
            {
                Body.Add(new AdaptiveImage(person.Image)
                {
                    PixelWidth  = 32,
                    PixelHeight = 32
                });
            }

            TryAddField(
                "Cumpleaños: {0}",
                person.BirthDate.ToString("dd-MM-yyyy"),
                fieldToAccent.NormalizeString() == "birthdate");

            TryAddField("Area: {0}", person.Area, fieldToAccent.NormalizeString() == "area");
            TryAddField("Interno: {0}", person.Intern, fieldToAccent.NormalizeString() == "intern");
            TryAddField("Móvil: {0}", person.Mobile, fieldToAccent.NormalizeString() == "mobile");
            TryAddField("Telefono: {0}", person.Phone, fieldToAccent.NormalizeString() == "phone");
            TryAddField("Email: {0}", person.Email, fieldToAccent.NormalizeString() == "email");
            TryAddField("Direccion {0}", person.Address, fieldToAccent.NormalizeString() == "address");
        }
示例#14
0
			public void TestSaveVisibility()
			{
				var root = new Body
				           	{
				           		Location = new Frame3D(10, 0, 0)
				           	};
				Body box = new Box
				           	{
				           		Location = new Frame3D(10, 20, 30)
				           	};
				root.Add(box);
				var lo = new LoggingObject(box, root);
				lo.SaveVisibilityState(_totalTime);
				Assert.AreEqual(1, lo.VisibilityStates.Count);
				Assert.AreEqual(_totalTime, lo.VisibilityStates[0].StartTime);
				_totalTime ++;
				lo.SaveVisibilityState(_totalTime);
				Assert.AreEqual(1, lo.VisibilityStates.Count);
				Assert.AreEqual(true, lo.VisibilityStates[0].IsVisible);
				root.Remove(box);
				_totalTime++;
				lo.SaveVisibilityState(_totalTime);
				Assert.AreEqual(_totalTime, lo.VisibilityStates.Last().StartTime);
				Assert.AreEqual(2, lo.VisibilityStates.Count);
				Assert.AreEqual(false, lo.VisibilityStates.Last().IsVisible);
			}
示例#15
0
 void CreateWalls(Body root, WallSettings[,] array, int width, int height, int weight, string prefix, Func<int, int, Point> cooMaker)
 {
     for (int x = 0; x < array.GetLength(0); x++)
         for (int y = 0; y < array.GetLength(1); y++)
         {
             var wall = array[x, y];
             if (wall == WallSettings.NoWall) continue;
             Color color = Color.LightGray;
             string name = prefix;
             switch (wall)
             {
                 case WallSettings.RedSocket: name += "R"; color = Color.DarkRed; break;
                 case WallSettings.BlueSocket: name += "B"; color = Color.DarkBlue; break;
                 case WallSettings.GreenSocket: name += "G"; color = Color.DarkGreen; break;
             }
             var coo = cooMaker(x, y);
             root.Add(new Box
             {
                 XSize = width,
                 YSize = height,
                 ZSize = weight,
                 Location = new Frame3D(coo.X, coo.Y, 0),
                 DefaultColor = color,
                 Type = name,
                 IsMaterial = true,
                 IsStatic = true,
             });
         }
 }
示例#16
0
            public void TestSaveVisibility()
            {
                var root = new Body
                {
                    Location = new Frame3D(10, 0, 0)
                };
                Body box = new Box
                {
                    Location = new Frame3D(10, 20, 30)
                };

                root.Add(box);
                var lo = new LoggingObject(box, root);

                lo.SaveVisibilityState(_totalTime);
                Assert.AreEqual(1, lo.VisibilityStates.Count);
                Assert.AreEqual(_totalTime, lo.VisibilityStates[0].StartTime);
                _totalTime++;
                lo.SaveVisibilityState(_totalTime);
                Assert.AreEqual(1, lo.VisibilityStates.Count);
                Assert.AreEqual(true, lo.VisibilityStates[0].IsVisible);
                root.Remove(box);
                _totalTime++;
                lo.SaveVisibilityState(_totalTime);
                Assert.AreEqual(_totalTime, lo.VisibilityStates.Last().StartTime);
                Assert.AreEqual(2, lo.VisibilityStates.Count);
                Assert.AreEqual(false, lo.VisibilityStates.Last().IsVisible);
            }
示例#17
0
        public override void ForwardDeclare(Context upperContext)
        {
            upperContext.AddGlobal(Name, this);
            Context = upperContext.StackNewContext(this);

            if (ExtensionBase != null)
            {
                AddThisPointer();
            }

            if (ReturnType.Name == TypesExtension.Unit ||
                ReturnType.Name == TypesExtension.Void)
            {
                var unitReturnValue = new ReturnStatement
                {
                    Column   = Column,
                    Line     = Line,
                    FilePath = FilePath,
                    Value    = new CppBlock("unit{}", Line, Column)
                };

                Body.Add(unitReturnValue);
            }

            foreach (var i in GetElements())
            {
                i.ForwardDeclare(Context);
            }
        }
示例#18
0
		public void Apply(Body loadedBody, Body world)
		{
			if(IsVisible)
				world.Add(loadedBody);
			else
				world.Remove(loadedBody);
		}
示例#19
0
        public FallingLine(Point2D center, Rotation rotation, char symbol, ConsoleColor color, int length)
        {
            this.Center       = center;
            this.Rotation     = rotation;
            this.relativeBody = new List <Pixel>();

            //Here should come the body definitions in relative to center coordinates for creating new shape!
            relativeBody.Add(new Pixel(0, 0, symbol, color));
            for (int i = 1; i < length; i++)
            {
                if (i % 2 == 0)
                {
                    relativeBody.Add(new Pixel((i + 1) / 2, 0, symbol, color));
                }
                else
                {
                    relativeBody.Add(new Pixel(-(i + 1) / 2, 0, symbol, color));
                }
            }


            this.Body = new List <Pixel>();
            for (int i = 0; i < relativeBody.Count; i++)
            {
                Body.Add(new Pixel(0, 0, '@', ConsoleColor.Gray));
            }
            this.ReCalculateBody();
        }
示例#20
0
        public ContentBrowserForm()
        {
            FilterOut.Add(".texdat");
            FilterOut.Add(".texdatsmall");

            Resized = () =>
            {
                Body.ViewX  = GX;
                Body.ViewY  = GY;
                Body.ViewW  = W;
                Body.ViewH  = H;
                Title.ViewX = GX;
                Title.ViewY = GY;
                Title.ViewW = W;
                Title.ViewH = H;
            };

            Area      = new ContentArea();
            Area.Root = this;
            AfterSet  = () =>
            {
                Area.Set(0, 0, Body.W, Body.H);
            };

            Body.Add(Area);
            Set(20, 400, 500, 250, "Content");
        }
示例#21
0
            public void TestSavingVisibility2()
            {
                var root = new Body
                {
                    Location = new Frame3D(10, 0, 0)
                };
                Body box = new Box
                {
                    Location = new Frame3D(10, 20, 30)
                };
                var lo = new LoggingObject(box, root);

                for (int i = 0; i < 100; i++)
                {
                    lo.SaveVisibilityState(i);
                    Assert.AreEqual(false, lo.VisibilityStates.Last().IsVisible);
                    Assert.AreEqual(0, lo.VisibilityStates.Last().StartTime);
                }
                //body suddenly appears.
                const int updateTime = 100;

                root.Add(box);
                lo.SaveVisibilityState(updateTime);
                Assert.AreEqual(2, lo.VisibilityStates.Count);
                Assert.AreEqual(true, lo.VisibilityStates.Last().IsVisible);
                Assert.AreEqual(updateTime, lo.VisibilityStates.Last().StartTime);
            }
示例#22
0
        public void Grow()
        {
            //Add a new snake part
            SnakePart first = Body.Last();

            Body.Add(new SnakePart(Body.Last().Coordinates));
        }
示例#23
0
 public void Creat(IEnumerable <T> Group)
 {
     foreach (T child in Group)
     {
         Body.Add(child.key, child);
     }
 }
示例#24
0
            public Node(IEnumerable <string> contents)
            {
                NodeId = int.Parse(contents.First().Substring(12, 2));
                foreach (string str in contents)
                {
                    bool skip = false;
                    foreach (string check in Blacklist)
                    {
                        if (str.Contains(check))
                        {
                            skip = true;
                        }
                    }
                    if (skip)
                    {
                        continue;
                    }

                    Body.Add(str);
                    if (str.Contains("return"))
                    {
                        Returns.Add(int.Parse(str.Split('n')[1].Split(';')[0]));
                    }
                }
                Body.Add("}");
            }
示例#25
0
        private void Parse(byte[] data, bool readable)
        {
            try
            {
                using (var memStream = new MemoryStream(data))
                {
                    using (var binaryReader = new BinaryReader(memStream, Encoding.Unicode))
                    {
                        Head = new TextSubfileHead(binaryReader);
                        for (var i = 0; i < Head.Fragments; ++i)
                        {
                            var limb = new TextSubfileBody(binaryReader);
                            Body.Add(limb.Token, limb);
                        }
                    }
                }

                IsValid = true;

                if (readable)
                {
                    PrepareReadable();
                }
            }
            catch (Exception ex)
            {
                IsValid = false;
                Logger.Write(ex.Message);
            }
        }
示例#26
0
 /// <summary>
 /// Add multiple <see cref="CodeObject"/>s to the embedded code <see cref="Block"/>.
 /// </summary>
 public void Add(params CodeObject[] objects)
 {
     CreateBody();
     foreach (CodeObject obj in objects)
     {
         Body.Add(obj);
     }
 }
        public InterfaceListenerEventHandlerHelper(InterfaceGen iface, string add, CodeGenerationOptions opt)
        {
            Name = add + "_Event_With_Handler_Helper";
            Parameters.Add(new MethodParameterWriter("value", new TypeReferenceWriter(opt.GetOutputName(iface.FullName))));
            ReturnType = TypeReferenceWriter.Void;

            Body.Add($"{add} (value, null);");
        }
示例#28
0
 public void Increase(Point point)
 {
     Body.Add(new Point {
         X = point.X, Y = point.Y
     });
     LengthOfWorm++;
     CountOfPoints++;
 }
示例#29
0
        public CreateImplementorMethod(InterfaceGen iface, CodeGenerationOptions opt)
        {
            Name = $"__Create{iface.Name}Implementor";

            ReturnType = new TypeReferenceWriter($"{opt.GetOutputName (iface.FullName)}Implementor");

            Body.Add($"return new {opt.GetOutputName (iface.FullName)}Implementor ({(iface.NeedsSender ? "this" : "")});");
        }
示例#30
0
		public void TreeMovingConstantLocation()
		{
			var world = new Body();
			var boxLocation = new Frame3D(10, 0, 0);
			var ballLocation = new Frame3D(20, 10, 0);
			var box = new Box {Location = boxLocation};
			var ball = new Ball {Location = ballLocation};
			world.Add(box);
			world.Add(ball);
			box.DetachAttachMaintaingLoction(ball);
			Assert.AreEqual(boxLocation, box.Location);
			Assert.AreEqual(ballLocation, ball.GetAbsoluteLocation());
			Assert.AreEqual(new Frame3D(10, 10, 0), ball.Location);
			world.DetachAttachMaintaingLoction(ball);
			Assert.AreEqual(ballLocation, ball.Location);
			Assert.AreEqual(ballLocation, ball.GetAbsoluteLocation());
		}
示例#31
0
        async Task InitializeComponents()
        {
            Data["TopMenu"] = "MainMenu";
            Title           = "Page 1";

            await Body.Add(ContactsList = new Modules.ContactsList {
                Id = "ContactsList"
            });
        }
示例#32
0
        public override void SetPosition(int pos)
        {
            if (Body.Count >= Size)
            {
                return;
            }

            Body.Add(pos);
        }
示例#33
0
 public virtual void GenerateBody()
 {
     BodyElement = new Body(Compatibility);
     BodyElement.GlobalAttributes.Class.Value = "epub";
     if (_content != null)
     {
         BodyElement.Add(_content);
     }
 }
示例#34
0
文件: Food.cs 项目: diable201/ICT
        public Food(char sign, ConsoleColor color) : base(sign, color)
        {
            var location = new Point {
                X = _random.Next(2, Game.Width - 2), Y = _random.Next(2, Game.Height - 2)
            };

            Body.Add(location);
            Draw();
        }
示例#35
0
		public void AbsoluteLocationLinear()
		{
			var root = new Body {Location = new Frame3D(0, 0, 10)};
			Assert.AreEqual(root.Location, root.GetAbsoluteLocation());
			var box = new Box {Location = new Frame3D(10, 0, 0)};
			Assert.AreEqual(box.Location, box.GetAbsoluteLocation());
			root.Add(box);
			Assert.AreEqual(box.Location.Apply(root.Location), box.GetAbsoluteLocation());
			int sum = 0;
			for(int i = 0; i < 10; i++)
			{
				sum += i;
				Body child = new Box {Location = new Frame3D(i, 0, 0)};
				root.Add(child);
				Assert.AreEqual(sum, child.GetAbsoluteLocation().X);
				root = child;
			}
		}
示例#36
0
		public void Location()
		{
			var world = new Body();
			var loc = new Frame3D(10, 0, 0);
			world.Add(new Box {Location = loc});
			Body box = world.Nested.First();
			Assert.AreEqual(loc, box.Location);
			Assert.AreEqual(loc, box.GetAbsoluteLocation());
			box.Add(new Ball {Location = new Frame3D(0, 0, 30)});
			Body ball = box.Nested.First();
			Assert.AreEqual(new Frame3D(0, 0, 30), ball.Location);
			Assert.AreEqual(new Frame3D(10, 0, 30), ball.GetAbsoluteLocation());
		}
示例#37
0
 private void CreateBorders(Body root)
 {
     Color wallsColor = Color.FromArgb(50, 0, 0, 0);
     for (int i = 0; i < 4; ++i)
     {
         var sizeX = i / 2 == 0 ? 303 : 3;
         var sizeY = i / 2 == 1 ? 203 : 3;
         var lX = i / 2 == 0 ? 203 : 3;
         var lY = i / 2 == 1 ? 303 : 3;
         var pos = i % 2 == 0 ? 1 : -1;
         root.Add(new Box
         {
             XSize = sizeX,
             YSize = sizeY,
             ZSize = 3,
             DefaultColor = wallsColor,
             IsStatic = true,
             Type = "wall",
             IsMaterial = true,
             Location = new Frame3D(
                 pos * lY / 2,
                 pos * lX / 2,
                 3)
         });
     }
 }
        public ICollection<DesignBody> CreateSolid(Part mainPart)
        {
            var bands = new List<ICollection<Body>>();
            var cutters = new List<Body[]>();
            double newScale = 0.094;
            double cutterHeight = 0.01 / newScale;
            double cutterWidth = 0.0005 / newScale;

            bool swap = false;
            for (int i = 0; i < iSteps; i++) {
                var band = new List<Body>();

                //if (i == 4) {
                //        DesignCurve.Create(Window.ActiveWindow.Scene as Part, CurveSegment.Create(points[i][0], points[i][1]));
                //        DesignCurve.Create(Window.ActiveWindow.Scene as Part, CurveSegment.Create(points[i + iSteps / 2][jSteps / 2], points[i + iSteps / 2][jSteps / 2 + 1]));
                //}

                for (int j = 0; j < jSteps; j++) {
                    // Main ring
                    Point p00 = points[i][j];
                    Point p01 = points[i][j + 1];
                    Point p10 = points[i + 1][j];
                    Point p11 = points[i + 1][j + 1];

                    Body b0, b1;
                    if ((p00 - p11).Magnitude < (p10 - p01).Magnitude) {
                        b0 = ShapeHelper.CreatePolygon(new Point[] { p00, p01, p11 }, 0);
                        b1 = ShapeHelper.CreatePolygon(new Point[] { p00, p11, p10 }, 0);
                    }
                    else {
                        b0 = ShapeHelper.CreatePolygon(new Point[] { p01, p10, p00 }, 0);
                        b1 = ShapeHelper.CreatePolygon(new Point[] { p01, p11, p10 }, 0);
                    }

                    // Tabs
                    /*            Male      Female      Male
                     * ---p00last-------p00--------p01-------p10next--- v+
                     *       |           |          |           |
                     *       |    pn0    |          |    pn1    |
                     *       |           |          |           |
                     * ---p10last-------p10--------p11-------p11next---
                     *
                     */
                    Point pn0 = (new Point[] { points[i - 1][j], points[i - 1][j + 1] }).Average();
                    Point pn1 = (new Point[] { points[i + 2][j], points[i + 2][j + 1] }).Average();

                    Direction normal0 = Vector.Cross(p01 - pn0, p00 - pn0).Direction;
                    Direction normal1 = Vector.Cross(p10 - pn1, p11 - pn1).Direction;

                    Body tab0 = Tabs.CreateCircularTab(p01, p00, -normal0, tabAngles[i][j], swap);
                    Body tab1 = Tabs.CreateCircularTab(p10, p11, -normal1, tabAngles[i + 1][j], !swap);

                    //DesignBody annotateMe = DesignBody.Create(mainPart, "annotatme", (swap ? tab0 : tab1).Copy());
                    //NoteHelper.AnnotateFace(mainPart, annotateMe.Faces.First(), string.Format("{0},{1}", i, j), 0.02, null);
                    //annotateMe.Delete();

                    //DesignBody.Create(Window.ActiveWindow.Scene as Part, "test", b0.Copy());
                    //DesignBody.Create(Window.ActiveWindow.Scene as Part, "test", b1.Copy());
                    //DesignBody.Create(Window.ActiveWindow.Scene as Part, "test", tab0.Copy());
                    //DesignBody.Create(Window.ActiveWindow.Scene as Part, "test", tab1.Copy());

                    try {
                        b0.Unite(new Body[] { b1, tab0, tab1 });
                    }
                    catch {
                        DesignBody.Create(Window.ActiveWindow.Scene as Part, "test", b0.Copy());
                        DesignBody.Create(Window.ActiveWindow.Scene as Part, "test", b1.Copy());
                        DesignBody.Create(Window.ActiveWindow.Scene as Part, "test", tab0.Copy());
                        DesignBody.Create(Window.ActiveWindow.Scene as Part, "test", tab1.Copy());
                        return null;
                    }

                    //	Debug.Assert(b0.Shells.Count == 1);
                    band.Add(b0);

                    swap = !swap;
                }

                bands.Add(band.TryUnionBodies());

                // Cutters
                Point p0ThisSide0 = points[i][0];
                Point p0ThisSide1 = points[i][1];
                Point p0OtherSide0 = points[i + iSteps / 2][jSteps / 2];
                Point p0OtherSide1 = points[i + iSteps / 2][1 + jSteps / 2];

                Point p1ThisSide0 = points[i + 1][0];
                Point p1ThisSide1 = points[i + 1][1];
                Point p1OtherSide0 = points[i + 1 + iSteps / 2][jSteps / 2];
                Point p1OtherSide1 = points[i + 1 + iSteps / 2][1 + jSteps / 2];

                Point p0 = CurveSegment.Create(p0ThisSide0, p0ThisSide1).GetInBetweenPoint(
                    CurveSegment.Create(p0OtherSide0, p0OtherSide1
                ));

                Point p1 = CurveSegment.Create(p1ThisSide0, p1ThisSide1).GetInBetweenPoint(
                    CurveSegment.Create(p1OtherSide0, p1OtherSide1
                ));

                //Point p0 = CurveSegment.Create(p0ThisSide0, p0ThisSide1).IntersectCurve(
                //    CurveSegment.Create(p0OtherSide0, p0OtherSide1
                //)).First().Point;

                //Point p1 = CurveSegment.Create(p1ThisSide0, p1ThisSide1).IntersectCurve(
                //    CurveSegment.Create(p1OtherSide0, p1OtherSide1
                //)).First().Point;

                Direction n0 = (p0OtherSide1 - p0OtherSide0).Direction;
                Direction n1 = (p1OtherSide1 - p1OtherSide0).Direction;

                Direction d0 = (p0ThisSide1 - p0ThisSide0).Direction;
                Direction d1 = (p1ThisSide1 - p1ThisSide0).Direction;

                var profiles = new List<ICollection<ITrimmedCurve>>();
                profiles.Add(p0.GetRectanglePointsAround(d0 * cutterHeight, n0 * cutterWidth).GetProfile());
                profiles.Add(p1.GetRectanglePointsAround(d1 * cutterHeight, n1 * cutterWidth).GetProfile());
                Body cutterA = Body.LoftProfiles(profiles, false, true);

                profiles = new List<ICollection<ITrimmedCurve>>();
                profiles.Add(p0.GetRectanglePointsAround(n0 * cutterHeight, d0 * cutterWidth).GetProfile());
                profiles.Add(p1.GetRectanglePointsAround(n1 * cutterHeight, d1 * cutterWidth).GetProfile());
                Body cutterB = Body.LoftProfiles(profiles, false, true);

                cutters.Add(new Body[] { cutterA, cutterB });
            }

            var designBands = new List<DesignBody>();
            Layer cutterLayer = NoteHelper.CreateOrGetLayer(mainPart.Document, "Cutters", System.Drawing.Color.DarkViolet);
            Matrix scaleMatrix = Matrix.CreateScale(scale, Point.Origin);

            for (int i = 0; i < bands.Count; i++) {
                int whichCutter = i % 2;

                Part part = Part.Create(mainPart.Document, string.Format("Band {0:00}", i));
                Component.Create(mainPart, part);

                int ii = i;
                if (whichCutter == 0)
                    ii = i + iSteps / 2;

                List<Body> mergedCutters = new Body[] {
                    cutters[(ii + iSteps - 1) % iSteps][whichCutter].Copy(),
                    cutters[ii % iSteps][whichCutter].Copy(),
                    cutters[(ii + 1) % iSteps][whichCutter].Copy()
                }.TryUnionBodies().ToList();

                Debug.Assert(mergedCutters.Count == 1, "Couldn't merge cutters");

                double nominalRadius = 0.02;
                double innerRadius = (nominalRadius - cutterWidth / 2) / newScale;
                double outerRadius = (nominalRadius + cutterWidth / 2) / newScale;

                var edgeRounds = new List<KeyValuePair<Edge, EdgeRound>>();
                foreach (Edge edge in mergedCutters[0].Edges) {
                    if (edge.Length > cutterHeight * 1.1 || edge.Length < cutterHeight * 0.9)
                        continue;

                    double angle = edge.GetAngle();
                    if (Math.Abs(angle) > Math.PI / 4 || angle == 0)
                        continue;

                    edgeRounds.Add(new KeyValuePair<Edge, EdgeRound>(edge, new FixedRadiusRound(angle > 0 ? outerRadius : innerRadius)));
                }

                mergedCutters[0].RoundEdges(edgeRounds);

                mergedCutters.Add(cutters[(ii - 1 + iSteps / 2) % iSteps][1 - whichCutter].Copy());
                mergedCutters.Add(cutters[(ii + 1 + iSteps / 2) % iSteps][1 - whichCutter].Copy());

                HSBColor hsbColor = new HSBColor(0, 100, 200);
                hsbColor.H = (float) ((double) i / bands.Count * 360);

                var cutBand = new List<Body>();
                foreach (Body body in bands[i]) {
                    foreach (Body cutterBody in mergedCutters) {
                        body.Imprint(cutterBody);
                        foreach (Face face in body.Faces) {
                            if (!IsSpanningBody(face, cutterBody))
                                continue;

                            body.DeleteFaces(new Face[] { face }, RepairAction.None);
                            //	DesignBody designBody = DesignBody.Create(part, "Cutter", cutterBody.Copy());
                            //	designBody.SetColor(null, hsbColor.Color);
                        }
                    }

                    cutBand.AddRange(body.SeparatePieces());
                }

                cutBand = cutBand.TryUnionBodies().ToList();

                //foreach (Body body in bands[i]) {
                foreach (Body body in cutBand) {
                    body.Transform(scaleMatrix);
                    DesignBody designBody = DesignBody.Create(part, "Band", body);
                    designBody.SetColor(null, hsbColor.Color);
                    designBands.Add(designBody);
                }

                //foreach (Body body in mergedCutters) {
                //    DesignBody designBody = DesignBody.Create(part, "Cutter", body);
                //    designBody.Layer = cutterLayer;
                //    hsbColor.H += 180 * whichCutter;
                //    designBody.SetColor(null, hsbColor.Color);
                ////	designBands[i].Shape.Imprint(designBody.Shape);
                //}

            }

            Trace.WriteLine("vParameters");
            for (int j = 0; j < jSteps; j++) {
                for (int i = 0; i < iSteps; i++)
                    Trace.Write(vParameters[i][j] + " ");

                Trace.WriteLine("");
            }

            Trace.WriteLine("tabAngles");
            for (int j = 0; j < jSteps; j++) {
                for (int i = 0; i < iSteps; i++)
                    Trace.Write(tabAngles[i][j] + " ");

                Trace.WriteLine("");
            }

            return designBands;
        }
示例#39
0
			public void TestSavingVisibility2()
			{
				var root = new Body
				           	{
				           		Location = new Frame3D(10, 0, 0)
				           	};
				Body box = new Box
				           	{
				           		Location = new Frame3D(10, 20, 30)
				           	};
				var lo = new LoggingObject(box, root);
				for (int i = 0; i < 100; i++)
				{
					lo.SaveVisibilityState(i);
					Assert.AreEqual(false, lo.VisibilityStates.Last().IsVisible);
					Assert.AreEqual(0, lo.VisibilityStates.Last().StartTime);
				}
				//body suddenly appears.
				const int updateTime = 100;
				root.Add(box);
				lo.SaveVisibilityState(updateTime);
				Assert.AreEqual(2, lo.VisibilityStates.Count);
				Assert.AreEqual(true, lo.VisibilityStates.Last().IsVisible);
				Assert.AreEqual(updateTime, lo.VisibilityStates.Last().StartTime);
			}
示例#40
0
        private static void CreateTreasure(Body root)
        {
            root.Add(new Box
            {
                XSize = 8,
                YSize = 8,
                ZSize = 8,
                Location = new Frame3D(50, 80, 3),
                DefaultColor = Color.YellowGreen,
                IsMaterial = true,
                Type = "part",
                FrictionCoefficient = 8,
                Density = Density.Aluminum,
            });
            root.Add(new Box
            {
                XSize = 8,
                YSize = 8,
                ZSize = 8,
                Location = new Frame3D(-50, 80, 3),
                DefaultColor = Color.YellowGreen,
                IsMaterial = true,
                Type = "part",
                FrictionCoefficient = 8,
                Density = Density.Aluminum,
            });
            root.Add(new Box
            {
                XSize = 8,
                YSize = 8,
                ZSize = 8,
                Location = new Frame3D(50, -80, 3),
                DefaultColor = Color.Red,
                IsMaterial = true,
                Type = "part",
                FrictionCoefficient = 8,
                Density = Density.Aluminum,
            });
            root.Add(new Box
            {
                XSize = 8,
                YSize = 8,
                ZSize = 8,
                Location = new Frame3D(-50, -80, 3),
                DefaultColor = Color.Red,
                IsMaterial = true,
                Type = "part",
                FrictionCoefficient = 8,
                Density = Density.Aluminum
            });
            var radius = 60.0;
            var rand = new Random();

            for (int k = -1; k < 2; k += 2)
            {
                var gems = new List<Tuple<string, Color>>
                    {
                        new Tuple<string, Color>("part", Color.Red),
                        new Tuple<string, Color>("part", Color.YellowGreen),
                        null,
                        null,
                        null,
                        null,
                    };
                for (int i = 0; i < 6; i++)
                {
                    var ind = rand.Next(gems.Count);
                    var gem = gems[ind];
                    gems.RemoveAt(ind);
                    if (gem == null) continue;
                    var angleCircle = Angle.FromGrad(15 + 30 * i);
                    root.Add(new Box
                    {
                        XSize = 8,
                        YSize = 8,
                        ZSize = 8,
                        Location = new Frame3D(radius * k * Math.Sin(angleCircle.Radian), radius * Math.Cos(angleCircle.Radian), 3),
                        DefaultColor = gem.Item2,
                        IsMaterial = true,
                        Type = gem.Item1,
                        FrictionCoefficient = 8
                    });
                }
            }
        }
示例#41
0
		private static Body GetTreeChildForTopDownLocations(IEnumerable<Frame3D> frames)
		{
			var currentChild = new Body();
			foreach(var frame3D in frames)
			{
				var newChild = new Body {Location = frame3D};
				currentChild.Add(newChild);
				currentChild = newChild;
			}
			return currentChild;
		}
示例#42
0
 private void CaptureDevicet(Body box, Body newChild)
 {
     var childAbsolute = newChild.GetAbsoluteLocation();
     if (newChild.Parent != null)
         newChild.Parent.Remove(newChild);
     newChild.Location = box.GetAbsoluteLocation().Invert().Apply(childAbsolute);
     newChild.Location = newChild.Location.NewYaw(Angle.Zero);
     newChild.Location = newChild.Location.NewX(14);
     newChild.Location = newChild.Location.NewY(0);
     frictionCoefficientsById.SafeAdd(newChild.Id, newChild.FrictionCoefficient);
     newChild.FrictionCoefficient = 0;
     box.Add(newChild);
 }
示例#43
0
        public Body CreateWorld(ICvarcEngine engine, ISceneSettings _settings)
        {
            Settings = (SceneSettings)_settings;
            var root = new Body();

            var first = new Cylinder
            {
                Height = 20,
                RTop = 10,
                RBottom = 10,
                Location = new Frame3D(-150 + 25 - 10, 100 - 25 + 10, 3),
                DefaultColor = Color.DarkViolet,
                IsMaterial = true,
                Density = Density.Iron,
                FrictionCoefficient = 0,
                Top = new PlaneImageBrush { Image = new Bitmap(GetResourceStream("red.png")) },
                Type = "Robot"
            };
            var second = new Cylinder
            {
                Height = 20,
                RTop = 10,
                RBottom = 10,
                Location = new Frame3D(150 - 25 + 10, 100 - 25 + 10, 3, Angle.Zero, Angle.Pi, Angle.Zero),
                DefaultColor = Color.DarkViolet,
                IsMaterial = true,
                Density = Density.Iron,
                FrictionCoefficient = 0,
                Top = new PlaneImageBrush { Image = new Bitmap(GetResourceStream("blue.png")) },
                Type = "Robot"
            };
            root.Add(first);
            root.Add(second);

            first.Collision += body => engine.RaiseOnCollision(first.Id.ToString(), body.Id.ToString(), CollisionType.RobotCollision);
            second.Collision += body => engine.RaiseOnCollision(second.Id.ToString(), body.Id.ToString(), CollisionType.RobotCollision);
            
            root.Add(new Box
            {
                XSize = 300,
                YSize = 200,
                ZSize = 3,
                DefaultColor = Color.White,
                Top = new SolidColorBrush { Color = Color.Yellow },
                IsStatic = true,
                Type = "floor",
            });

            foreach (var detail in Settings.Details)
            {
                Color color = Color.White;
                string name = "D";
                switch (detail.Color)
                {
                    case DetailColor.Red: color = Color.Red; name += "R"; break;
                    case DetailColor.Blue: color = Color.Blue; name += "B"; break;
                    case DetailColor.Green: color = Color.Green; name += "G"; break;
                }

                var box = new Box
                {
                    XSize = 15,
                    YSize = 15,
                    ZSize = 15,
                    Location = new Frame3D(-150 + 25 + detail.Location.X * 50, 100 - 25 - 50 * detail.Location.Y, 0),
                    DefaultColor = color,
                    Type = name,
                    IsMaterial = true,
                    IsStatic = false,
                    FrictionCoefficient = 8
                };
                root.Add(box);

                box.Collision += body =>
                    {
                        if (box.Parent.Id == first.Id && body.Id == second.Id)
                            engine.RaiseOnCollision(second.Id.ToString(), first.Id.ToString(), CollisionType.RobotCollision);
                        if (box.Parent.Id == second.Id && body.Id == first.Id)
                            engine.RaiseOnCollision(first.Id.ToString(), second.Id.ToString(), CollisionType.RobotCollision);
                    };
            }

            CreateWalls(root, Settings.HorizontalWalls, 50, 10, 15, "HW", (x, y) => new Point(-150 + 25 + x * 50, 100 - (y + 1) * 50));
            CreateWalls(root, Settings.VerticalWalls, 10, 50, 14, "VW", (x, y) => new Point(-150 + (x + 1) * 50, 100 - 25 - y * 50));


            CreateBorders(root);

            return root;
        }