Example #1
0
        public static IGaNumMultivector Compactify(this IGaNumMultivector 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
                    : GaNumMultivectorTerm.CreateZero(mv.GaSpaceDimension));
            }

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

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

            //It's a full multivector
            var fullMv = (GaNumMultivector)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.NonZeroTerms.FirstOrDefault();

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