public void FreeBoundTest()
        {
            var mAttach = new Molecule(habitat);
            mAttach.Position = mZero.Position.PointOfAngle(Molecule.TETRAHEDRON_SITE, Math.PI * 5 / 6);

            Assert.AreEqual(1, mZero.FreeBound(mAttach));
        }
Beispiel #2
0
 public Position(double x, double y)
 {
     X = x;
     Y = y;
     Direction = null;
     Molecule = null;
 }
Beispiel #3
0
 public Position(double x, double y, V direction, Molecule molecule)
 {
     X = x;
     Y = y;
     Direction = direction;
     Molecule = molecule;
 }
 public void MoleculeAdded(Molecule molecule)
 {
     var presenter = new MoleculePresenter(molecule);
     view.AllMoleculePresenters.Add(presenter);
     Logger.Log("All molecules count", view.AllMoleculePresenters.Count);
     view.StatusMessage(String.Format("{0}", view.AllMoleculePresenters.Count));
 }
        public void BoundPositionTest(Molecule molecule, int boundNr, double xExp, double yExp)
        {
            var poz = molecule.BoundPosition(boundNr);

            var poz_expected = new Position(xExp, yExp);

            AssertExtensions.AreAlmostEqual(poz_expected, poz);
        }
            public void NewBinding(Molecule molecule)
            {
                var presenter = new MoleculePresenter(molecule);

                Logger.Log("Flake point", presenter.Point);
                view.StatusMessage(String.Format("{0}", presenter.Point));

                view.MoleculePresenters.Add(presenter);
                view.RepaintBindings();
            }
        public void SetUp()
        {
            habitat = new Habitat(1, 1, 1, 150, 150, 1, 2*Molecule.RADIUS);

            mZero = new Molecule(habitat);
            mZero.Position.X = 0;
            mZero.Position.Y = 0;
            mZero.AttachedIteration = 0;
            mZero.BoundType = BoundType.I;
        }
Beispiel #8
0
        public static Position NextRandomPosition(double centerX, double centerY, double radius, double speed, Molecule molecule, bool fromBorder)
        {
            var alpha = 2 * Math.PI * random.NextDouble();
            var distance = fromBorder ? (radius - Molecule.TETRAHEDRON_SITE) :
                (radius - Molecule.TETRAHEDRON_SITE) * Math.Sqrt(random.NextDouble()) + Molecule.TETRAHEDRON_SITE;

            var x = distance * Math.Cos(alpha) + centerX;
            var y = distance * Math.Sin(alpha) + centerY;

            return new Position(x, y, Position.NextRandomDirection(speed), molecule);
        }
        public void TryToAttachDefinitelyTest()
        {
            Molecule mTo, mAttach;

            mTo = mZero;
            mAttach = new Molecule(habitat);
            mAttach.Position = mTo.Position.PointOfAngle(Molecule.TETRAHEDRON_SITE, Math.PI * 5 / 6);

            TryToAttachDefinitelyTest(mTo, mAttach, 1, BoundType.II);

            //------

            mTo = mAttach;
            mAttach = new Molecule(habitat);
            mAttach.Position = mTo.Position.PointOfAngle(Molecule.TETRAHEDRON_SITE, Math.PI);

            TryToAttachDefinitelyTest(mTo, mAttach, 0, BoundType.I);

            //------

            mTo = mAttach;
            mAttach = new Molecule(habitat);
            mAttach.Position = mTo.Position.PointOfAngle(Molecule.TETRAHEDRON_SITE, 3 * Math.PI / 2);

            TryToAttachDefinitelyTest(mTo, mAttach, 2, BoundType.II);

            //------

            mTo = mAttach;
            mAttach = new Molecule(habitat);
            mAttach.Position = mTo.Position.PointOfAngle(Molecule.TETRAHEDRON_SITE, 3 * Math.PI / 2);

            TryToAttachDefinitelyTest(mTo, mAttach, 1, BoundType.I);

            //------

            mTo = mAttach;
            mAttach = new Molecule(habitat);
            mAttach.Position = mTo.Position.PointOfAngle(Molecule.TETRAHEDRON_SITE, 11 * Math.PI / 6);

            Assert.AreEqual(5, mAttach.Position.TetrahedronPart(mTo.Position));

            Assert.AreEqual(0, mTo.FreeBound(mAttach));

            TryToAttachDefinitelyTest(mTo, mAttach, 0, BoundType.II);

            Assert.AreEqual(2, mZero.GetBoundNr(mAttach));

            Assert.AreEqual(2, mAttach.GetBoundNr(mZero));
        }
Beispiel #10
0
 public bool IsNearConflict(Molecule other)
 {
     return Distanse(other) <= RADIUS * 2;
 }
Beispiel #11
0
 public bool IsDesired(Molecule other)
 {
     return Distanse(other) <= habitat.DesireRadius;
 }
Beispiel #12
0
 public bool IsDesired(Molecule other, out double dist)
 {
     dist = Distanse(other);
     return dist <= habitat.DesireRadius;
 }
Beispiel #13
0
 public int? GetBoundNr(Molecule other)
 {
     for (int b = 0; b < Neigbours.Length; b++)
     {
         if (Neigbours[b] == other)
             return b;
     }
     return null;
 }
Beispiel #14
0
        public int? FreeBound(Molecule other)
        {
            int tetrahedronPart = other.Position.TetrahedronPart(Position);
            habitat.Logger.Log1(String.Format("{0} {1} {2}", tetrahedronPart, other.Position, Position));
            int b = BoundType == BoundType.I ? (tetrahedronPart + 1) % 6 / 2 :
                (tetrahedronPart + 4) % 6 / 2;

            return Neigbours[b] == null ? (int?)b : null;
        }
Beispiel #15
0
 public double Distanse(Molecule other)
 {
     return (Position - other.Position).Speed;
 }
Beispiel #16
0
        public void Bump(Molecule other)
        {
            /*double v2v2 = Math.Pow(this.Position.Direction.Speed, 2) + Math.Pow(other.Position.Direction.Speed, 2);
            var s1 = Position.NextRandomSpeed(Math.Sqrt(v2v2));
            this.Position.Direction = Position.NextRandomDirection(s1);
            var s2 = Math.Sqrt(v2v2 - s1 * s1);
            other.Position.Direction = Position.NextRandomDirection(s2);*/

            Collision.DoElasticCollisionOfTwoBalls(1, this.Position, 1, other.Position);
        }
Beispiel #17
0
 public void CreateMolecule(Molecule.InitMoleculeType type)
 {
     Molecules.Add(new Molecule(this, type));
 }
Beispiel #18
0
 public Molecule FindMostDesiredOrInterfering(Molecule molecule)
 {
     return Molecules.FindMostDesiredOrInterfering(molecule);
 }
Beispiel #19
0
 public void FireMoleculeAdded(Molecule molecule)
 {
     foreach (NewBindingListener listener in NewBindingListeners)
     {
         listener.MoleculeAdded(molecule);
     }
 }
Beispiel #20
0
 public void TryToAttach(Molecule boundMember1)
 {
     var dist = this.Distanse(boundMember1);
     if (random.NextDouble() <= habitat.Desire)
     {
         TryToAttachDefinitely(boundMember1);
     }
 }
Beispiel #21
0
 public void MoleculeAdded(Molecule molecule)
 {
     habitat.FireMoleculeAdded(molecule);
 }
Beispiel #22
0
 void CreateCondensationCenter()
 {
     Molecule mTo = CondensationCenter, mAttach;
     foreach (var angle in new double[] { Math.PI * 5 / 6, Math.PI, 3 * Math.PI / 2, 3 * Math.PI / 2, 11 * Math.PI / 6 })
     {
         mAttach = new Molecule(this, Molecule.InitMoleculeType.Center);
         mAttach.Position = mTo.Position.PointOfAngle(Molecule.TETRAHEDRON_SITE, angle);
         Molecules.Add(mAttach);
         mAttach.TryToAttachDefinitely(mTo);
         mTo = mAttach;
     }
 }
Beispiel #23
0
 public void FireNewBinding(Molecule molecule)
 {
     foreach (NewBindingListener listener in NewBindingListeners)
     {
         listener.NewBinding(molecule);
     }
     CreateMolecule(Molecule.InitMoleculeType.Additional);
 }
Beispiel #24
0
        public void TryToAttachDefinitely(Molecule boundMember1)
        {
            int? bound1 = boundMember1.FreeBound(this);
            if (bound1 != null)
            {
                int count2 = 0, bound2 = 0;
                var boundMember2 = boundMember1.LastInCell((int)bound1, true, ref count2, ref bound2);
                int count3 = 0, bound3 = 0;
                var boundMember3 = boundMember1.LastInCell((int)bound1, true, ref count3, ref bound3);

                AttachedIteration = habitat.Iteration;
                boundMember1.Neigbours[(int)bound1] = this;
                this.Neigbours[(int)bound1] = boundMember1;
                this.BoundType = boundMember1.BoundType == BoundType.I ? BoundType.II : BoundType.I;
                this.Position = boundMember1.BoundPosition((int)bound1);
                if (count2 == 5)
                {
                    boundMember2.Neigbours[bound2] = this;
                    this.Neigbours[bound2] = boundMember2;
                }
                if (count3 == 5)
                {
                    boundMember3.Neigbours[bound3] = this;
                    this.Neigbours[bound3] = boundMember3;
                }
                FireMoleculeAttached();
                habitat.Logger.Log("ATTACHED");
            }
        }
Beispiel #25
0
        public void TryToAttachDefinitelyTest(Molecule mTo, Molecule mAttach, int boundNr_expected, BoundType boudType_expected)
        {
            mAttach.TryToAttachDefinitely(mTo);

            Assert.AreEqual(boundNr_expected, mTo.GetBoundNr(mAttach));

            Assert.AreEqual(boundNr_expected, mAttach.GetBoundNr(mTo));

            Assert.AreEqual(boudType_expected, mAttach.BoundType);

            var poz_expected = mTo.BoundPosition(boundNr_expected);

            AssertExtensions.AreAlmostEqual(poz_expected, mAttach.Position);

            // Assert.AreEqual(tetraNr_expected, mAttach.Position.TetrahedronPart(mTo.Position));
        }