Exemple #1
0
 public void should_bind_a_observable_collection_to_the_menu_when_creating_the_controller_that_will_notify_whenever_a_change_occurs()
 {
     var constraint = new GenericConstraint<ObservableCollection<MenuItem>>();
     menu.Expect(x => x.Bind(null)).Constraints(constraint);
     CreateSUT();
     var menuItems = constraint.GetParameter();
     Assert.That(menuItems.Count, Is.EqualTo(0));
 }
        public override AstNode?VisitTypeParamConstraint(TypeParamConstraintContext context)
        {
            var constraint = new GenericConstraint
            {
                GenericParameterName = GetId(context.name),
                ParseContext         = context
            };

            foreach (var clause in context.typeParamConstraintClause())
            {
                if (clause is TypeParamConstraintClauseClassContext)
                {
                    if (constraint.IsClass)
                    {
                        _contracts.AddError(clause, "Duplicate class constraint");
                    }

                    constraint.IsClass = true;
                    continue;
                }

                if (clause is TypeParamConstraintClauseStructContext)
                {
                    if (constraint.IsStruct)
                    {
                        _contracts.AddError(clause, "Duplicate struct constraint");
                    }

                    constraint.IsStruct = true;
                    continue;
                }

                if (clause is TypeParamConstraintClauseNewContext)
                {
                    if (constraint.HasDefaultConstructor)
                    {
                        _contracts.AddError(clause, "Duplicate new() constraint");
                    }

                    constraint.HasDefaultConstructor = true;
                    continue;
                }

                if (clause is TypeParamConstraintClauseTypeContext typeClause)
                {
                    var typeName = new TypeName(typeClause.typeName().GetText());
                    if (!constraint.Types.Add(typeName))
                    {
                        _contracts.AddError(clause, "Duplicate type constraint: '{0}'", typeName);
                    }
                }
            }

            return(constraint);
        }
Exemple #3
0
 public void should_notify_the_menu_whenever_a_new_menu_item_has_been_added()
 {
     var constraint = new GenericConstraint<ObservableCollection<MenuItem>>();
     menu.Expect(x=>x.Bind(null)).Constraints(constraint);
     var sut = CreateSUT();
     var menuItems = constraint.GetParameter();
     bool aMenuItemWasAdded = false;
     menuItems.CollectionChanged += (sender, args) =>
                                        {
                                            aMenuItemWasAdded = true;
                                            Assert.That(args.Action, Is.EqualTo(NotifyCollectionChangedAction.Add));
                                        };
     sut.Register(openLogFileNameMenuItem);
     Assert.That(aMenuItemWasAdded);
 }
Exemple #4
0
        public void CreateScene(int sceneNumber)
        {
            _physics.Clear();
            _markers.Clear();

            Room room = new Room(this);

            _physics.Add(room);
            _physics.Gravity = new Vector3(0f, 0f, -9.8f);

            Model cubeModel     = this.Content.Load <Model>("models/small_cube");
            Model obeliskModel  = this.Content.Load <Model>("models/obelisk");
            Model sphereModel   = this.Content.Load <Model>("models/sphere");
            Model capsuleModel  = this.Content.Load <Model>("models/capsule");
            Model torusModel    = this.Content.Load <Model>("models/torus");
            Model slabModel     = this.Content.Load <Model>("models/slab");
            Model triangleModel = this.Content.Load <Model>("models/triangle");

            switch (sceneNumber)
            {
            case 1:
            {
                for (int i = 0; i < 12; i++)
                {
                    var cube = new SolidThing(this, cubeModel);
                    cube.SetWorld(new Vector3(0f, 0f, 0.25f + 0.51f * i));
                    _physics.Add(cube);
                }
            }
            break;

            case 2:
            {
                for (int i = 0; i < 7; i++)
                {
                    for (int j = 0; j < 7 - i; j++)
                    {
                        var cube = new SolidThing(this, cubeModel);
                        cube.SetWorld(new Vector3(0f, 0.501f * j + 0.25f * i, 0.5f + 0.55f * i));
                        _physics.Add(cube);
                    }
                }
            }
            break;

            case 3:
            {
                for (int i = 0; i < 6; i++)
                {
                    for (int j = 0; j < 6 - i; j++)
                    {
                        var cube = new SolidThing(this, cubeModel);
                        cube.SetWorld(new Vector3(0f, 2.2f * j + 1f * i - 4.1f, 0.75f * i + 0.25f));
                        _physics.Add(cube);
                    }
                }
                for (int i = 0; i < 6; i++)
                {
                    for (int j = 0; j < 5 - i; j++)
                    {
                        var plank = new SolidThing(this, obeliskModel);
                        plank.SetWorld(new Vector3(0f, 2.2f * j + 1f * i + 1f - 4f, 0.75f * i + 0.65f),
                                       Quaternion.CreateFromAxisAngle(Vector3.UnitZ, MathHelper.ToRadians(90f)));
                        _physics.Add(plank);
                    }
                }
            }
            break;

            case 4:
            {
                int size = 9;
#if WINDOWS
#else
                size = 4;
#endif
                for (int i = 0; i < size; i++)
                {
                    for (int j = 0; j < size - i; j++)
                    {
                        for (int k = 0; k < size - i; k++)
                        {
                            var sphere = new SolidThing(this, sphereModel);
                            sphere.SetWorld(new Vector3(
                                                0.501f * j + 0.25f * i,
                                                0.501f * k + 0.25f * i,
                                                0.501f * i + 0.5f
                                                ), Quaternion.Identity);
                            _physics.Add(sphere);
                        }
                    }
                }
            }
            break;

            case 5:
            {
                var plank = new SolidThing(this, obeliskModel);
                plank.SetWorld(new Vector3(0.0f, 0.0f, 4.0f),
                               Quaternion.CreateFromAxisAngle(Vector3.UnitY, MathHelper.ToRadians(15f)));
                MassProperties immovableMassProperties = new MassProperties(float.PositiveInfinity, Matrix.Identity);
                plank.MassProperties = immovableMassProperties;
                _physics.Add(plank);

                var sphere = new SolidThing(this, sphereModel);
                sphere.SetWorld(new Vector3(-4.9f, 0.0f, 9.0f), Quaternion.Identity);
                _physics.Add(sphere);


//                        int size = 9;
//#if WINDOWS
//#else
//                        size = 4;
//#endif
//                        var models = new Model[] { cubeModel, sphereModel };
//                        for (int i = 0; i < size; i++)
//                        {
//                            for (int j = 0; j < size - i; j++)
//                            {
//                                for (int k = 0; k < size - i; k++)
//                                {
//                                    var sphere = new SolidThing(this, i % 2 == 0 ? sphereModel : cubeModel);
//                                    sphere.SetWorld(new Vector3(
//                                        0.501f * j + 0.25f * i,
//                                        0.501f * k + 0.25f * i,
//                                        0.501f * i + 0.5f
//                                        ), Quaternion.Identity);
//                                    _physics.Add(sphere);
//                                }
//                            }
//                        }
            }
            break;

            case 6:
            {
                int size = 9;
#if WINDOWS
#else
                size = 4;
#endif
                var models = new Model[] { cubeModel, sphereModel, capsuleModel };
                for (int i = 0; i < size; i++)
                {
                    for (int j = 0; j < size - i; j++)
                    {
                        for (int k = 0; k < size - i; k++)
                        {
                            var sphere = new SolidThing(this, models[_rand.Next(3)]);
                            sphere.SetWorld(new Vector3(
                                                0.501f * j + 0.25f * i,
                                                0.501f * k + 0.25f * i,
                                                1f * i + 0.5f));
                            _physics.Add(sphere);
                        }
                    }
                }
            }
            break;

            case 7:
            {
                var o = new SolidThing(this, torusModel);
                o.SetWorld(new Vector3(0f, 0f, 0.5f), Quaternion.CreateFromAxisAngle(Vector3.UnitY, -MathHelper.PiOver2));
                _physics.Add(o);

                o = new SolidThing(this, torusModel);
                o.SetWorld(new Vector3(0f, 0f, 4f), Quaternion.CreateFromAxisAngle(Vector3.UnitY, -MathHelper.PiOver4));
                _physics.Add(o);

                o = new SolidThing(this, slabModel);
                o.SetWorld(new Vector3(-4f, 4f, 2f));
                _physics.Add(o);

                o = new SolidThing(this, this.Content.Load <Model>("models/cone"));
                o.SetWorld(new Vector3(-4f, -4f, 1f), Quaternion.CreateFromAxisAngle(Vector3.UnitZ, MathHelper.PiOver2));
                _physics.Add(o);

                o = new SolidThing(this, cubeModel);
                o.SetWorld(new Vector3(-4f, 6.1f, 3f));
                _physics.Add(o);
            }
            break;

            case 8:
            {
                RigidBody oLast = null;
                for (int i = 0; i < 10; i++)
                {
                    var o = new SolidThing(this, capsuleModel);
                    o.SetWorld(new Vector3(0f, 0f, 9.5f - i));
                    _physics.Add(o);
                    if (i == 0)
                    {
                        var j = new PointConstraint(o, room, new Vector3(0f, 0f, 10f));
                        j.IsCollisionEnabled = false;
                        _physics.Add(j);
                    }
                    else
                    {
                        var j = new PointConstraint(oLast, o, new Vector3(0f, 0f, 10f - (float)i));
                        j.IsCollisionEnabled = false;
                        _physics.Add(j);
                    }
                    oLast = o;
                }

                var a = new SolidThing(this, cubeModel);
                a.SetWorld(new Vector3(1f, 0f, 0.25f));
                _physics.Add(a);
                var b = new SolidThing(this, cubeModel);
                b.SetWorld(new Vector3(1f, 0f, 0.75f));
                _physics.Add(b);
                var j2 = new RevoluteJoint(b, a, new Vector3(1.25f, 0f, 0.5f), Vector3.UnitY,
                                           0f, MathHelper.PiOver2);
                j2.IsCollisionEnabled = false;
                _physics.Add(j2);

                a = new SolidThing(this, cubeModel);
                a.SetWorld(new Vector3(1f, 1f, 0.25f));
                _physics.Add(a);
                b = new SolidThing(this, cubeModel);
                b.SetWorld(new Vector3(1f, 1f, 0.75f));
                _physics.Add(b);
                var j4 = new GenericConstraint(b, a, new Frame(new Vector3(1f, 1f, 0.5f)),
                                               Axes.All, Vector3.Zero, new Vector3(0f, 0f, 0.5f),
                                               Axes.All, Vector3.Zero, Vector3.Zero);
                j4.IsCollisionEnabled = false;
                _physics.Add(j4);

                a = new SolidThing(this, cubeModel);
                a.SetWorld(new Vector3(1f, 2f, 0.25f));
                _physics.Add(a);
                b = new SolidThing(this, cubeModel);
                b.SetWorld(new Vector3(1f, 2f, 0.75f));
                _physics.Add(b);
                var j5 = new GenericConstraint(b, a, new Frame(new Vector3(1f, 2f, 0.5f)),
                                               Axes.All, new Vector3(-0.125f, -0.125f, 0f), new Vector3(0.125f, 0.125f, 0f),
                                               Axes.All, Vector3.Zero, Vector3.Zero);
                j5.IsCollisionEnabled = false;
                _physics.Add(j5);

                a = new SolidThing(this, sphereModel);
                a.SetWorld(new Vector3(2f, 0f, 2f));
                _physics.Add(a);
                b = new SolidThing(this, sphereModel);
                b.SetWorld(new Vector3(2f, 0f, 1f));
                _physics.Add(b);
                var g1 = new SpringForce(a, b, Vector3.Zero, Vector3.Zero, 1f, 5f, 0.05f);
                _physics.Add(g1);
                var j3 = new WorldPointConstraint(a, new Vector3(2f, 0f, 2f));
                _physics.Add(j3);
            }
            break;

            case 9:
            {
                var a = new SolidThing(this, sphereModel);
                a.Skin.Remove(a.Skin[0]);
                a.Skin.Add(new SpherePart(new Sphere(Vector3.Zero, 0.25f)), new Material(0f, 0.5f));
                a.SetWorld(7.0f, new Vector3(0f, 0f, 5f), Quaternion.Identity);
                a.MassProperties = MassProperties.Immovable;
                _physics.Add(a);

                _physics.Add(new SingularityForce(new Vector3(0f, 0f, 5f), 1E12f));

                _physics.Gravity = Vector3.Zero;

                var b = new SolidThing(this, cubeModel);
                b.SetWorld(new Vector3(0f, 0f, 8f),
                           Quaternion.CreateFromAxisAngle(Vector3.UnitX, MathHelper.PiOver4 / 2.0f) *
                           Quaternion.CreateFromAxisAngle(Vector3.UnitY, MathHelper.PiOver4)
                           );
                _physics.Add(b);
            }
            break;

            default:
                break;
            }
        }