Exemple #1
0
        public static IGaSymMultivector Compactify(this IGaSymMultivector mv, bool returnZeroMvAsNull = false)
        {
            if (DisableCompactifyMultivectors)
            {
                return(mv);
            }

            if (ReferenceEquals(mv, null))
            {
                return(null);
            }

            //Make sure this is not a temp multivector
            if (mv.IsTemp)
            {
                mv = mv.ToMultivector();
            }

            //If it's zero return null or a zero term depending on returnZeroMvAsNull
            if (mv.IsZero())
            {
                return(returnZeroMvAsNull
                    ? null
                    : GaSymMultivectorTerm.CreateZero(mv.GaSpaceDimension));
            }

            //If it's a non-zero term return it as is
            var termMv = mv as GaSymMultivectorTerm;

            if (!ReferenceEquals(termMv, null))
            {
                return(termMv);
            }

            //It's a full multivector
            var fullMv = (GaSymMultivector)mv;

            //If it's not a term return it after simplification
            if (!mv.IsTerm())
            {
                fullMv.Simplify();
                return(fullMv);
            }

            //It's a full multivector containing a single term
            var term = mv.NonZeroExprTerms.FirstOrDefault();

            return(GaSymMultivectorTerm.CreateTerm(mv.GaSpaceDimension, term.Key, term.Value));
        }
Exemple #2
0
 public static bool IsNullOrZero(this IGaSymMultivector mv)
 {
     return(ReferenceEquals(mv, null) || mv.IsZero());
 }