Skip to content

Commit

Permalink
Fix docs and printing
Browse files Browse the repository at this point in the history
  • Loading branch information
alesanter committed Mar 5, 2025
1 parent 7ed7609 commit dca9e34
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion symplyphysics/core/experimental/vectors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ def _sympystr(self, _p: Printer) -> str:
class VectorSymbol(DimensionSymbol, VectorExpr, Atom): # type: ignore[misc]
"""
Class representing a symbolic vector.
The ``display_symbol``, ``display_latex``, and ``dimension`` parameters are used to instantiate
the ``DimensionSymbol`` class.
The ``norm`` parameter represents the **norm**, in other words **length** or **magnitude**, of
the vector. It can be a number, an expression, a quantity, or a symbol, but its dimension must
match the ``dimension`` of the vector symbol. Note that only ``dimensionless`` vectors with
``norm=1`` can be considered as **unit vectors**. As a counterexample, a force vector of
magnitude `1 N` is not a unit vector since its norm contains a dimensionful quantity `N`.
"""

_norm: Optional[Expr]
Expand Down Expand Up @@ -280,9 +289,13 @@ def doit(self, **_hints: Any) -> VectorExpr:
return VectorScale(vector, scale, evaluate=False)

def _sympystr(self, p: Printer) -> str:
from symplyphysics.docs.printer_code import SymbolCodePrinter

vector, value = self.args

if isinstance(value, (Add, Mul)):
# NOTE: `p` is not needed for `_needs_mul_brackets`, we could refactor it out of the
# `SymbolCodePrinter` class.
if SymbolCodePrinter._needs_mul_brackets(p, value, last=True):
return f"{p.doprint(vector)}*({p.doprint(value)})"

return f"{p.doprint(vector)}*{p.doprint(value)}"
Expand Down

0 comments on commit dca9e34

Please sign in to comment.