コード例 #1
0
        public void Should_FailEqualityForDifferentNumericValues()
        {
            var numericItem  = new U1(1);
            var numericItem2 = new U1(2);

            Assert.IsFalse(numericItem.Equals(numericItem2));
        }
コード例 #2
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (U1 != 0)
            {
                hash ^= U1.GetHashCode();
            }
            if (U2 != 0)
            {
                hash ^= U2.GetHashCode();
            }
            if (U3.Length != 0)
            {
                hash ^= U3.GetHashCode();
            }
            if (U4.Length != 0)
            {
                hash ^= U4.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
コード例 #3
0
        public void Should_FailEqualityForDifferetObjectTypes()
        {
            var numericItem = new U1(1);
            var obj         = "test";

            Assert.IsFalse(numericItem.Equals(obj));
        }
コード例 #4
0
        public void Should_FailEqualityForDifferentDataTypes()
        {
            var numericItem  = new U1(1);
            var numericItem2 = new F4(5);

            Assert.IsFalse(numericItem.Equals(numericItem2));
        }
コード例 #5
0
        public void Should_BeEqualIfNumericItemsEqual()
        {
            var numericItem  = new U1(1);
            var numericItem2 = new U1(1);

            Assert.IsTrue(numericItem.Equals(numericItem2));
        }
コード例 #6
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (U1 != 0L)
            {
                hash ^= U1.GetHashCode();
            }
            if (U2 != 0L)
            {
                hash ^= U2.GetHashCode();
            }
            if (U3 != 0L)
            {
                hash ^= U3.GetHashCode();
            }
            if (U4 != 0L)
            {
                hash ^= U4.GetHashCode();
            }
            if (U5 != 0L)
            {
                hash ^= U5.GetHashCode();
            }
            if (ItemSetId != 0L)
            {
                hash ^= ItemSetId.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
コード例 #7
0
        public void Should_CreateCorrectU1Item()
        {
            var numericItem = new U1(1);

            Assert.IsTrue(numericItem.Value == 1);
            Assert.IsTrue(numericItem.Type == Format.U1);
        }
コード例 #8
0
ファイル: PassiveTypeRank.cs プロジェクト: kwsch/ReMasters
        public override int GetHashCode()
        {
            int hash = 1;

            if (U1 != 0)
            {
                hash ^= U1.GetHashCode();
            }
            if (U2 != 0)
            {
                hash ^= U2.GetHashCode();
            }
            if (Passive1Id != 0)
            {
                hash ^= Passive1Id.GetHashCode();
            }
            if (Passive2Id != 0)
            {
                hash ^= Passive2Id.GetHashCode();
            }
            if (Passive3Id != 0)
            {
                hash ^= Passive3Id.GetHashCode();
            }
            if (Passive4Id != 0)
            {
                hash ^= Passive4Id.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
コード例 #9
0
ファイル: Form1.cs プロジェクト: mazhanoff/Optimization-HW
        int z = 0; //flag


        private void recountBtn_Click(object sender, EventArgs e)
        {
            I1 -= 0.09;
            I2 -= 0.09;
            I3 -= 0.09;
            I4 -= 0.09;
            I5 -= 0.09;
            I6 -= 0.09;

            I1tb.Text = I1.ToString();
            I2tb.Text = I2.ToString();
            I3tb.Text = I3.ToString();
            I4tb.Text = I4.ToString();
            I5tb.Text = I5.ToString();
            I6tb.Text = I6.ToString();

            U2 = I2 * EU * IV / ((IV + I2 + I1) * (I2 + I3 + I4 + I5 - Math.Pow(I2, 2) / (IV + I2 + I1) - Math.Pow((I4 + I5), 2) / (I4 + I5 + I6)));
            U1 = U2 * I2 / (IV + I2 + I1) + EU * IV / (IV + I2 + I1);
            U3 = U2 * (I4 + I5) / (I4 + I5 + I6);
            U1 = Math.Round(U1, 3);
            U2 = Math.Round(U2, 3);
            U3 = Math.Round(U3, 3);

            U1label.Text = "U1 = " + U1.ToString();
            U2label.Text = "U2 = " + U2.ToString();
            U3label.Text = "U3 = " + U3.ToString();

            if (z == 1)
            {
                F1 = Math.Round(Math.Pow(U11 - U1, 2), 3);
            }
            if (z == 2)
            {
                F1 = Math.Round(Math.Pow(U22 - U2, 2), 3);
            }
            if (z == 3)
            {
                F1 = Math.Round(Math.Pow(U33 - U3, 2), 3);
            }

            if (F1 < F)
            {
                FTB.Text = F1.ToString();
                F        = F1;
                logsRTB.AppendText("Целевая функция уменьшается F=" + F1.ToString() + "\n");
                logsRTB.ScrollToCaret();
            }
            else
            {
                logsRTB.AppendText("Целевая функция увеличилась F=" + F1.ToString() + "\n");
                logsRTB.ScrollToCaret();
                recountBtn.Enabled = false;
            }
            Fz = 0;

            calculateGrad();
            calculateHessian();
        }
コード例 #10
0
        public override string GetStepParameters()
        {
            var parameters = new List <string>();

            parameters.Add(BasisSurface != null ? BasisSurface.ToStepValue() : "$");
            parameters.Add(U1 != null ? U1.ToStepValue() : "$");
            parameters.Add(V1 != null ? V1.ToStepValue() : "$");
            parameters.Add(U2 != null ? U2.ToStepValue() : "$");
            parameters.Add(V2 != null ? V2.ToStepValue() : "$");
            parameters.Add(Usense != null ? Usense.ToStepValue() : "$");
            parameters.Add(Vsense != null ? Vsense.ToStepValue() : "$");

            return(string.Join(", ", parameters.ToArray()));
        }
コード例 #11
0
ファイル: Calculations.cs プロジェクト: UraharaGin/CMMPh
        public List <GraphPoint> Imlicite()
        {
            var tempResult = new double[N + 1][];

            for (int i = 0; i <= N; i++)
            {
                tempResult[i] = new double[K + 1];
            }

            // initialize board conditions
            for (int i = 0; i <= N; i++)
            {
                tempResult[i][0] = U0.Value(XArg(i));
            }
            for (int n = 0; n <= K - 1; n++)
            {
                tempResult[0][n + 1] = U1.Value(TimeArg(n + 1));
                tempResult[N][n + 1] = U2.Value(TimeArg(n + 1));
            }


            for (int n = 0; n < K; n++)
            {
                for (int i = 1; i < N; i++)
                {
                    tempResult[i][n + 1] = tempResult[i][n] +
                                           Gamma * (tempResult[i + 1][n] - 2 * tempResult[i][n] + tempResult[i - 1][n]) +
                                           Tao * Fxt.Value(XArg(i), TimeArg(n));
                }
            }

            var result = new List <GraphPoint>();

            for (int i = 0; i <= N; i++)
            {
                result.Add(new GraphPoint
                {
                    X = XArg(i),
                    Y = tempResult[i][K]
                });
            }

            return(result);
        }
コード例 #12
0
        private void btConnexion_Click(object sender, EventArgs e)
        {
            string pseudo = Convert.ToString(txtPseudo.Text);
            string MDP    = Convert.ToString(txtMDP.Text);

            foreach (Utilisateur U1 in DonneesClass.GetListUtilisateur())
            {
                if (U1.GetPseudo() == pseudo && U1.GetMDP() == MDP)
                {
                    MessageBox.Show("Authentification réussite");
                    DonneesClass.SetUtilisateur(U1);
                    Menu frmMenu = new Menu();

                    if (frmMenu.ShowDialog() == DialogResult.OK)
                    {
                    }
                }
            }
        }
コード例 #13
0
        public override ArrayList GetItemInfo()
        {
            ArrayList itemInfo = new ArrayList
            {
                new InputText(this, "P1:", P1.ToString(), true, "p1"),
                new InputText(this, "U1:", U1.ToString(), true, "u1"),
                new InputText(this, "V1:", V1.ToString(), true, "v1"),

                new InputText(this, "P2:", P2.ToString(), true, "p2"),
                new InputText(this, "U2:", U2.ToString(), true, "u2"),
                new InputText(this, "V2:", V2.ToString(), true, "v2"),

                new InputText(this, "P3:", P3.ToString(), true, "p3"),
                new InputText(this, "U3:", U3.ToString(), true, "u3"),
                new InputText(this, "V3:", V3.ToString(), true, "v3"),

                new InputText(this, "Material:", Enum.GetName(typeof(P3DMaterial), Material), false, ""),
            };

            return(itemInfo);
        }
コード例 #14
0
ファイル: AreaSpot.cs プロジェクト: PMArkive/ReMasters
        public override int GetHashCode()
        {
            int hash = 1;

            if (U1 != 0)
            {
                hash ^= U1.GetHashCode();
            }
            if (U2 != 0)
            {
                hash ^= U2.GetHashCode();
            }
            if (Name.Length != 0)
            {
                hash ^= Name.GetHashCode();
            }
            if (U4.Length != 0)
            {
                hash ^= U4.GetHashCode();
            }
            if (U5.Length != 0)
            {
                hash ^= U5.GetHashCode();
            }
            if (TexBig.Length != 0)
            {
                hash ^= TexBig.GetHashCode();
            }
            if (TexSmall.Length != 0)
            {
                hash ^= TexSmall.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
コード例 #15
0
ファイル: Form1.cs プロジェクト: mazhanoff/Optimization-HW
        private void button1_Click(object sender, EventArgs e)
        {
            IV = Double.Parse(Ivtb.Text);
            I1 = Double.Parse(I1tb.Text);
            I2 = Double.Parse(I2tb.Text);
            I3 = Double.Parse(I3tb.Text);
            I4 = Double.Parse(I4tb.Text);
            I5 = Double.Parse(I5tb.Text);
            I6 = Double.Parse(I6tb.Text);
            EU = Double.Parse(Etb.Text);

            U2 = I2 * EU * IV / ((IV + I2 + I1) * (I2 + I3 + I4 + I5 - Math.Pow(I2, 2) / (IV + I2 + I1) - Math.Pow((I4 + I5), 2) / (I4 + I5 + I6)));
            U1 = U2 * I2 / (IV + I2 + I1) + EU * IV / (IV + I2 + I1);
            U3 = U2 * (I4 + I5) / (I4 + I5 + I6);

            U2 = Math.Round(U2, 3);
            U1 = Math.Round(U1, 3);
            U3 = Math.Round(U3, 3);

            U1label.Text = "U1 = " + U1.ToString();
            U2label.Text = "U2 = " + U2.ToString();
            U3label.Text = "U3 = " + U3.ToString();
        }
コード例 #16
0
    static int Main()
    {
        //This testcase ensures that we correctly generate one ReadUInt16() call
        //instead of two due to a bug in fgmorph which transformed a call result
        //as an index of an array incorrectly resulting in an unexpected index

        U1[] u1 = new U1[1];
        U2[] u2 = new U2[2];
        u2[1] = new U2();
        U1 obj = u1[ReadUInt16()];

        if (obj == null)
        {
            Console.WriteLine("PASS!");
            return(100);
        }
        else
        {
            Console.WriteLine("FAIL!");
            Console.WriteLine("obj is not null.");
            return(101);
        }
    }
コード例 #17
0
ファイル: DevDiv_794631.cs プロジェクト: l1183479157/coreclr
    static int Main()
    {
        //This testcase ensures that we correctly generate one ReadUInt16() call
        //instead of two due to a bug in fgmorph which transformed a call result 
        //as an index of an array incorrectly resulting in an unexpected index

        U1[] u1 = new U1[1];
        U2[] u2 = new U2[2];
        u2[1] = new U2();
        U1 obj = u1[ReadUInt16()];

        if (obj == null)
        {
            Console.WriteLine("PASS!");
            return 100;
        }
        else
        {
            Console.WriteLine("FAIL!");
            Console.WriteLine("obj is not null.");
            return 101;
        }
    }
コード例 #18
0
        public void problemConfig(int _np1, int _np2, int _layout_type)
        {
            setProblemClass();
            _np               = this.Ranks.Length;
            this._np1         = _np1;
            this._np2         = _np2;
            _ntdivnp          = ((nx * ny) / _np) * nz;
            this._layout_type = _layout_type;
            int layout_0D = Constants.layout_0D;
            int layout_1D = Constants.layout_1D;
            int layout_2D = Constants.layout_2D;

//            if(_np1 == 1 && _np2 == 1) {
//                _layout_type = layout_0D;
//            }
//            else if(_np1 == 1) {
//                _layout_type = layout_1D;
//            }
//            else {
//                _layout_type = layout_2D;
//            }

            if (_layout_type == layout_0D)
            {
                for (int i = 0; i < 3; i++)
                {
                    _dims[0, i] = nx;
                    _dims[1, i] = ny;
                    _dims[2, i] = nz;
                }
            }
            else if (_layout_type == layout_1D)
            {
                _dims[0, 0] = nx;
                _dims[1, 0] = ny;
                _dims[2, 0] = nz;

                _dims[0, 1] = nx;
                _dims[1, 1] = ny;
                _dims[2, 1] = nz;

                _dims[0, 2] = nz;
                _dims[1, 2] = nx;
                _dims[2, 2] = ny;
            }
            else if (_layout_type == layout_2D)
            {
                _dims[0, 0] = nx;
                _dims[1, 0] = ny;
                _dims[2, 0] = nz;

                _dims[0, 1] = ny;
                _dims[1, 1] = nx;
                _dims[2, 1] = nz;

                _dims[0, 2] = nz;
                _dims[1, 2] = nx;
                _dims[2, 2] = ny;
            }
            _dims[1, 0] = _dims[1, 0] / _np1;
            _dims[2, 0] = _dims[2, 0] / _np2;
            _dims[1, 1] = _dims[1, 1] / _np1;
            _dims[2, 1] = _dims[2, 1] / _np2;
            _dims[1, 2] = _dims[1, 2] / _np1;
            _dims[2, 2] = _dims[2, 2] / _np2;

            U0.initialize_field("u0", _dims[1, 0], _dims[2, 0], _dims[0, 0], 2);
            U1.initialize_field("u1", _dims[1, 0], _dims[2, 0], _dims[0, 0], 2);
            U2.initialize_field("u2", _dims[1, 0], _dims[2, 0], _dims[0, 0], 2);

            _u       = new double[nx, 2];
            _twiddle = new double[_ntdivnp];
        }
コード例 #19
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (U1 != 0)
            {
                hash ^= U1.GetHashCode();
            }
            if (U2 != 0)
            {
                hash ^= U2.GetHashCode();
            }
            if (U3 != 0)
            {
                hash ^= U3.GetHashCode();
            }
            if (U4 != 0)
            {
                hash ^= U4.GetHashCode();
            }
            if (U5 != 0)
            {
                hash ^= U5.GetHashCode();
            }
            if (U6 != 0)
            {
                hash ^= U6.GetHashCode();
            }
            if (U7 != 0)
            {
                hash ^= U7.GetHashCode();
            }
            if (U8 != 0)
            {
                hash ^= U8.GetHashCode();
            }
            if (U9 != 0)
            {
                hash ^= U9.GetHashCode();
            }
            if (U10 != 0)
            {
                hash ^= U10.GetHashCode();
            }
            if (U11 != 0)
            {
                hash ^= U11.GetHashCode();
            }
            if (U12 != 0)
            {
                hash ^= U12.GetHashCode();
            }
            if (U13 != 0)
            {
                hash ^= U13.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
コード例 #20
0
        public void Should_FailEqualityForNull()
        {
            var numericItem = new U1(1);

            Assert.IsFalse(numericItem.Equals(null));
        }
コード例 #21
0
ファイル: PulleyJoint.cs プロジェクト: pabllopf/Alis
        /// <summary>
        ///     Inits the velocity constraints using the specified step
        /// </summary>
        /// <param name="step">The step</param>
        internal override void InitVelocityConstraints(TimeStep step)
        {
            Body body1 = Body1;
            Body body2 = Body2;

            Vec2 mulR1 = Box2DXMath.Mul(body1.GetXForm().R, LocalAnchor1 - body1.GetLocalCenter());
            Vec2 mulR2 = Box2DXMath.Mul(body2.GetXForm().R, LocalAnchor2 - body2.GetLocalCenter());

            Vec2 body1SweepC = body1.Sweep.C + mulR1;
            Vec2 body2SweepC = body2.Sweep.C + mulR2;

            Vec2 groundAnchor1 = Ground.GetXForm().Position + GroundAnchor1;
            Vec2 groundAnchor2 = Ground.GetXForm().Position + GroundAnchor2;

            // Get the pulley axes.
            U1 = body1SweepC - groundAnchor1;
            U2 = body2SweepC - groundAnchor2;

            float length1 = U1.Length();
            float length2 = U2.Length();

            if (length1 > Settings.LinearSlop)
            {
                U1 *= 1.0f / length1;
            }
            else
            {
                U1.SetZero();
            }

            if (length2 > Settings.LinearSlop)
            {
                U2 *= 1.0f / length2;
            }
            else
            {
                U2.SetZero();
            }

            float c = Constant - length1 - Ratio * length2;

            if (c > 0.0f)
            {
                State   = LimitState.InactiveLimit;
                Impulse = 0.0f;
            }
            else
            {
                State = LimitState.AtUpperLimit;
            }

            if (length1 < MaxLength1)
            {
                LimitState1   = LimitState.InactiveLimit;
                LimitImpulse1 = 0.0f;
            }
            else
            {
                LimitState1 = LimitState.AtUpperLimit;
            }

            if (length2 < MaxLength2)
            {
                LimitState2   = LimitState.InactiveLimit;
                LimitImpulse2 = 0.0f;
            }
            else
            {
                LimitState2 = LimitState.AtUpperLimit;
            }

            // Compute effective mass.
            float cr1U1 = Vec2.Cross(mulR1, U1);
            float cr2U2 = Vec2.Cross(mulR2, U2);

            LimitMass1 = body1.InvMass + body1.InvI * cr1U1 * cr1U1;
            LimitMass2 = body2.InvMass + body2.InvI * cr2U2 * cr2U2;
            PulleyMass = LimitMass1 + Ratio * Ratio * LimitMass2;
            Box2DxDebug.Assert(LimitMass1 > Settings.FltEpsilon);
            Box2DxDebug.Assert(LimitMass2 > Settings.FltEpsilon);
            Box2DxDebug.Assert(PulleyMass > Settings.FltEpsilon);
            LimitMass1 = 1.0f / LimitMass1;
            LimitMass2 = 1.0f / LimitMass2;
            PulleyMass = 1.0f / PulleyMass;

            if (step.WarmStarting)
            {
                // Scale impulses to support variable time steps.
                Impulse       *= step.DtRatio;
                LimitImpulse1 *= step.DtRatio;
                LimitImpulse2 *= step.DtRatio;

                // Warm starting.
                Vec2 p1 = -(Impulse + LimitImpulse1) * U1;
                Vec2 p2 = (-Ratio * Impulse - LimitImpulse2) * U2;
                body1.LinearVelocity  += body1.InvMass * p1;
                body1.AngularVelocity += body1.InvI * Vec2.Cross(mulR1, p1);
                body2.LinearVelocity  += body2.InvMass * p2;
                body2.AngularVelocity += body2.InvI * Vec2.Cross(mulR2, p2);
            }
            else
            {
                Impulse       = 0.0f;
                LimitImpulse1 = 0.0f;
                LimitImpulse2 = 0.0f;
            }
        }
コード例 #22
0
        // B.3 pg 62
        public override ECPoint Add(ECPoint b)
        {
            if (this.IsInfinity)
            {
                return(b);
            }
            if (b.IsInfinity)
            {
                return(this);
            }
            if (this == b)
            {
                return(Twice());
            }

            ECCurve curve = this.Curve;
            int     coord = curve.CoordinateSystem;

            ECFieldElement X1 = this.RawXCoord, Y1 = this.RawYCoord;
            ECFieldElement X2 = b.RawXCoord, Y2 = b.RawYCoord;

            switch (coord)
            {
            case ECCurve.COORD_AFFINE:
            {
                ECFieldElement dx = X2.Subtract(X1), dy = Y2.Subtract(Y1);

                if (dx.IsZero)
                {
                    if (dy.IsZero)
                    {
                        // this == b, i.e. this must be doubled
                        return(Twice());
                    }

                    // this == -b, i.e. the result is the point at infinity
                    return(Curve.Infinity);
                }

                ECFieldElement gamma = dy.Divide(dx);
                ECFieldElement X3    = gamma.Square().Subtract(X1).Subtract(X2);
                ECFieldElement Y3    = gamma.Multiply(X1.Subtract(X3)).Subtract(Y1);

                return(new FpPoint(Curve, X3, Y3, IsCompressed));
            }

            case ECCurve.COORD_HOMOGENEOUS:
            {
                ECFieldElement Z1 = this.RawZCoords[0];
                ECFieldElement Z2 = b.RawZCoords[0];

                bool Z1IsOne = Z1.IsOne;
                bool Z2IsOne = Z2.IsOne;

                ECFieldElement u1 = Z1IsOne ? Y2 : Y2.Multiply(Z1);
                ECFieldElement u2 = Z2IsOne ? Y1 : Y1.Multiply(Z2);
                ECFieldElement u  = u1.Subtract(u2);
                ECFieldElement v1 = Z1IsOne ? X2 : X2.Multiply(Z1);
                ECFieldElement v2 = Z2IsOne ? X1 : X1.Multiply(Z2);
                ECFieldElement v  = v1.Subtract(v2);

                // Check if b == this or b == -this
                if (v.IsZero)
                {
                    if (u.IsZero)
                    {
                        // this == b, i.e. this must be doubled
                        return(this.Twice());
                    }

                    // this == -b, i.e. the result is the point at infinity
                    return(curve.Infinity);
                }

                // TODO Optimize for when w == 1
                ECFieldElement w          = Z1IsOne ? Z2 : Z2IsOne ? Z1 : Z1.Multiply(Z2);
                ECFieldElement vSquared   = v.Square();
                ECFieldElement vCubed     = vSquared.Multiply(v);
                ECFieldElement vSquaredV2 = vSquared.Multiply(v2);
                ECFieldElement A          = u.Square().Multiply(w).Subtract(vCubed).Subtract(Two(vSquaredV2));

                ECFieldElement X3 = v.Multiply(A);
                ECFieldElement Y3 = vSquaredV2.Subtract(A).Multiply(u).Subtract(vCubed.Multiply(u2));
                ECFieldElement Z3 = vCubed.Multiply(w);

                return(new FpPoint(curve, X3, Y3, new ECFieldElement[] { Z3 }, IsCompressed));
            }

            case ECCurve.COORD_JACOBIAN:
            case ECCurve.COORD_JACOBIAN_MODIFIED:
            {
                ECFieldElement Z1 = this.RawZCoords[0];
                ECFieldElement Z2 = b.RawZCoords[0];

                bool Z1IsOne = Z1.IsOne;

                ECFieldElement X3, Y3, Z3, Z3Squared = null;

                if (!Z1IsOne && Z1.Equals(Z2))
                {
                    // TODO Make this available as public method coZAdd?

                    ECFieldElement dx = X1.Subtract(X2), dy = Y1.Subtract(Y2);
                    if (dx.IsZero)
                    {
                        if (dy.IsZero)
                        {
                            return(Twice());
                        }
                        return(curve.Infinity);
                    }

                    ECFieldElement C = dx.Square();
                    ECFieldElement W1 = X1.Multiply(C), W2 = X2.Multiply(C);
                    ECFieldElement A1 = W1.Subtract(W2).Multiply(Y1);

                    X3 = dy.Square().Subtract(W1).Subtract(W2);
                    Y3 = W1.Subtract(X3).Multiply(dy).Subtract(A1);
                    Z3 = dx;

                    if (Z1IsOne)
                    {
                        Z3Squared = C;
                    }
                    else
                    {
                        Z3 = Z3.Multiply(Z1);
                    }
                }
                else
                {
                    ECFieldElement Z1Squared, U2, S2;
                    if (Z1IsOne)
                    {
                        Z1Squared = Z1; U2 = X2; S2 = Y2;
                    }
                    else
                    {
                        Z1Squared = Z1.Square();
                        U2        = Z1Squared.Multiply(X2);
                        ECFieldElement Z1Cubed = Z1Squared.Multiply(Z1);
                        S2 = Z1Cubed.Multiply(Y2);
                    }

                    bool           Z2IsOne = Z2.IsOne;
                    ECFieldElement Z2Squared, U1, S1;
                    if (Z2IsOne)
                    {
                        Z2Squared = Z2; U1 = X1; S1 = Y1;
                    }
                    else
                    {
                        Z2Squared = Z2.Square();
                        U1        = Z2Squared.Multiply(X1);
                        ECFieldElement Z2Cubed = Z2Squared.Multiply(Z2);
                        S1 = Z2Cubed.Multiply(Y1);
                    }

                    ECFieldElement H = U1.Subtract(U2);
                    ECFieldElement R = S1.Subtract(S2);

                    // Check if b == this or b == -this
                    if (H.IsZero)
                    {
                        if (R.IsZero)
                        {
                            // this == b, i.e. this must be doubled
                            return(this.Twice());
                        }

                        // this == -b, i.e. the result is the point at infinity
                        return(curve.Infinity);
                    }

                    ECFieldElement HSquared = H.Square();
                    ECFieldElement G        = HSquared.Multiply(H);
                    ECFieldElement V        = HSquared.Multiply(U1);

                    X3 = R.Square().Add(G).Subtract(Two(V));
                    Y3 = V.Subtract(X3).Multiply(R).Subtract(S1.Multiply(G));

                    Z3 = H;
                    if (!Z1IsOne)
                    {
                        Z3 = Z3.Multiply(Z1);
                    }
                    if (!Z2IsOne)
                    {
                        Z3 = Z3.Multiply(Z2);
                    }

                    // Alternative calculation of Z3 using fast square
                    //X3 = four(X3);
                    //Y3 = eight(Y3);
                    //Z3 = doubleProductFromSquares(Z1, Z2, Z1Squared, Z2Squared).multiply(H);

                    if (Z3 == H)
                    {
                        Z3Squared = HSquared;
                    }
                }

                ECFieldElement[] zs;
                if (coord == ECCurve.COORD_JACOBIAN_MODIFIED)
                {
                    // TODO If the result will only be used in a subsequent addition, we don't need W3
                    ECFieldElement W3 = CalculateJacobianModifiedW(Z3, Z3Squared);

                    zs = new ECFieldElement[] { Z3, W3 };
                }
                else
                {
                    zs = new ECFieldElement[] { Z3 };
                }

                return(new FpPoint(curve, X3, Y3, zs, IsCompressed));
            }

            default:
            {
                throw new InvalidOperationException("unsupported coordinate system");
            }
            }
        }
コード例 #23
0
ファイル: PulleyJoint.cs プロジェクト: pabllopf/Alis
        /// <summary>
        ///     Describes whether this instance solve position constraints
        /// </summary>
        /// <param name="baumgarte">The baumgarte</param>
        /// <returns>The bool</returns>
        internal override bool SolvePositionConstraints(float baumgarte)
        {
            Body body1 = Body1;
            Body body2 = Body2;

            Vec2 groundAnchor1 = Ground.GetXForm().Position + GroundAnchor1;
            Vec2 groundAnchor2 = Ground.GetXForm().Position + GroundAnchor2;

            float linearError = 0.0f;

            if (State == LimitState.AtUpperLimit)
            {
                Vec2 mulR1 = Box2DXMath.Mul(body1.GetXForm().R, LocalAnchor1 - body1.GetLocalCenter());
                Vec2 mulR2 = Box2DXMath.Mul(body2.GetXForm().R, LocalAnchor2 - body2.GetLocalCenter());

                Vec2 body1SweepC = body1.Sweep.C + mulR1;
                Vec2 body2SweepC = body2.Sweep.C + mulR2;

                // Get the pulley axes.
                U1 = body1SweepC - groundAnchor1;
                U2 = body2SweepC - groundAnchor2;

                float length1 = U1.Length();
                float length2 = U2.Length();

                if (length1 > Settings.LinearSlop)
                {
                    U1 *= 1.0f / length1;
                }
                else
                {
                    U1.SetZero();
                }

                if (length2 > Settings.LinearSlop)
                {
                    U2 *= 1.0f / length2;
                }
                else
                {
                    U2.SetZero();
                }

                float c = Constant - length1 - Ratio * length2;
                linearError = Box2DXMath.Max(linearError, -c);

                c = Box2DXMath.Clamp(c + Settings.LinearSlop, -Settings.MaxLinearCorrection, 0.0f);
                float impulse = -PulleyMass * c;

                Vec2 p1 = -impulse * U1;
                Vec2 p2 = -Ratio * impulse * U2;

                body1.Sweep.C += body1.InvMass * p1;
                body1.Sweep.A += body1.InvI * Vec2.Cross(mulR1, p1);
                body2.Sweep.C += body2.InvMass * p2;
                body2.Sweep.A += body2.InvI * Vec2.Cross(mulR2, p2);

                body1.SynchronizeTransform();
                body2.SynchronizeTransform();
            }

            if (LimitState1 == LimitState.AtUpperLimit)
            {
                Vec2 mulR1       = Box2DXMath.Mul(body1.GetXForm().R, LocalAnchor1 - body1.GetLocalCenter());
                Vec2 body1SweepC = body1.Sweep.C + mulR1;

                U1 = body1SweepC - groundAnchor1;
                float length1 = U1.Length();

                if (length1 > Settings.LinearSlop)
                {
                    U1 *= 1.0f / length1;
                }
                else
                {
                    U1.SetZero();
                }

                float c = MaxLength1 - length1;
                linearError = Box2DXMath.Max(linearError, -c);
                c           = Box2DXMath.Clamp(c + Settings.LinearSlop, -Settings.MaxLinearCorrection, 0.0f);
                float impulse = -LimitMass1 * c;

                Vec2 p1 = -impulse * U1;
                body1.Sweep.C += body1.InvMass * p1;
                body1.Sweep.A += body1.InvI * Vec2.Cross(mulR1, p1);

                body1.SynchronizeTransform();
            }

            if (LimitState2 == LimitState.AtUpperLimit)
            {
                Vec2 mulR2       = Box2DXMath.Mul(body2.GetXForm().R, LocalAnchor2 - body2.GetLocalCenter());
                Vec2 body2SweepC = body2.Sweep.C + mulR2;

                U2 = body2SweepC - groundAnchor2;
                float length2 = U2.Length();

                if (length2 > Settings.LinearSlop)
                {
                    U2 *= 1.0f / length2;
                }
                else
                {
                    U2.SetZero();
                }

                float c = MaxLength2 - length2;
                linearError = Box2DXMath.Max(linearError, -c);
                c           = Box2DXMath.Clamp(c + Settings.LinearSlop, -Settings.MaxLinearCorrection, 0.0f);
                float impulse = -LimitMass2 * c;

                Vec2 p2 = -impulse * U2;
                body2.Sweep.C += body2.InvMass * p2;
                body2.Sweep.A += body2.InvI * Vec2.Cross(mulR2, p2);

                body2.SynchronizeTransform();
            }

            return(linearError < Settings.LinearSlop);
        }
コード例 #24
0
ファイル: Calculations.cs プロジェクト: UraharaGin/CMMPh
        public List <GraphPoint> NotImplicite()
        {
            var tempResult = new double[N + 1][];

            for (int i = 0; i <= N; i++)
            {
                tempResult[i] = new double[K + 1];
            }

            // initialize board conditions
            for (int i = 0; i <= N; i++)
            {
                tempResult[i][0] = U0.Value(XArg(i));
            }
            for (int n = 0; n <= K - 1; n++)
            {
                tempResult[0][n + 1] = U1.Value(TimeArg(n + 1));
                tempResult[N][n + 1] = U2.Value(TimeArg(n + 1));
            }


            var    A = new double[N - 2];
            var    B = new double[N - 2];
            var    C = new double[N - 2];
            var    D = new double[N - 2];
            double xi1, xi2, mu1, mu2;

            for (int i = 1; i <= N - 1 - 2; i++)
            {
                A[i] = Gamma;
                B[i] = Gamma;
                C[i] = (1 + 2 * Gamma);
            }

            for (int n = 0; n <= K - 1; n++)
            {
                for (int i = 2; i <= N - 1 - 1; i++)
                {
                    D[i - 1] = tempResult[i][n] + Tao * Fxt.Value(XArg(i), TimeArg(n));
                }
                xi1 = Gamma / (1 + 2 * Gamma);
                mu1 = (tempResult[1][n] + Tao * Fxt.Value(XArg(1), TimeArg(n)) + Gamma * tempResult[0][n]) / (1 + 2 * Gamma);
                xi2 = Gamma / (1 + 2 * Gamma);
                mu2 = (tempResult[N - 1][n] + Tao * Fxt.Value(XArg(N - 1), TimeArg(n)) + Gamma * tempResult[N][n]) / (1 + 2 * Gamma);

                var tempY = MetodProgonki(N - 2, A, B, C, D, xi1, mu1, xi2, mu2);

                for (int i = 1; i <= N - 1; i++)
                {
                    tempResult[i][n + 1] = tempY[i - 1];
                }
            }

            var result = new List <GraphPoint>();

            for (int i = 0; i <= N; i++)
            {
                result.Add(new GraphPoint
                {
                    X = XArg(i),
                    Y = tempResult[i][K]
                });
            }

            return(result);
        }