Skip to content
Projects

tikzfigure.core.rectangle

Classes

NameDescription
RectangleA TikZ rectangle drawn with \draw rectangle or \filldraw rectangle.

Rectangleclass#

class Rectangle(corner1: PositionInput, corner2: PositionInput, label: str = '', comment: str | None = None, layer: int = 0, options: OptionInput | None = None, tikz_command: str = 'draw', **kwargs: Any)

Bases: TikzObject

A TikZ rectangle drawn with \draw rectangle or \filldraw rectangle.

Attributes

NameTypeDescription
corner1TikzCoordinateFirst corner coordinate.
corner2TikzCoordinateSecond corner coordinate (opposite corner).
tikz_commandstrThe TikZ drawing command (“draw” or “filldraw”).

corner1property#

corner1: TikzCoordinate

First corner coordinate of the rectangle.

corner2property#

corner2: TikzCoordinate

Second (opposite) corner coordinate of the rectangle.

tikz_commandproperty#

tikz_command: str

The TikZ drawing command (“draw” or “filldraw”).

from_dictmethodclassmethod#

def from_dict(d: dict[str, Any]) -> Rectangle

Reconstruct a Rectangle from a dictionary.

Parameters

NameTypeDescription
ddict[str, Any]Dictionary as produced by to_dict().

Returns

Rectangle
A new Rectangle instance.

to_dictmethod#

def to_dict() -> dict[str, Any]

Serialize this rectangle to a plain dictionary.

Returns

dict[str, Any]
A dictionary with type, corners, tikz_command, and all base-class keys.

to_tikzmethod#

def to_tikz(output_unit: str | None = None) -> str

Generate the TikZ rectangle command for this rectangle.

Returns

str
A \draw or \filldraw command string ending with a newline,
str
optionally preceded by a comment line.
Inherited from tikzfigure.core.base.TikzObject

commentproperty#

comment: str | None

Comment prepended to the generated TikZ code, or None.

kwargsproperty#

kwargs: dict

Keyword-style TikZ options as a plain dict.

labelproperty#

label: str | None

Unique identifier for this object within the figure.

layerproperty#

layer: int | None

Layer index this object belongs to.

optionsproperty#

options: list[OptionValue]

Flag-style TikZ options without values.

add_commentmethod#

def add_comment(string_in: str) -> str

Prepend a TikZ comment line to a string if a comment is set.

Parameters

NameTypeDescription
string_instrThe TikZ code string to annotate.

Returns

str
The original string prefixed with % <comment>\n when a
str
comment is set, otherwise the string unchanged.

copymethod#

def copy(**overrides: Any) -> TikzObject

Return a copy of this object with optional constructor-style overrides.

tikz_optionsmethod#

def tikz_options(output_unit: str | None = None) -> str

Render all options as a single TikZ option string.

Combines flag-style options and keyword options into the format expected inside TikZ square brackets, e.g. "thick, color=red, line width=1pt".

Parameters

NameTypeDefaultDescription
output_unitstr | NoneNoneIf provided, any :class:~tikzfigure.units.TikzDimension values are converted to this unit before rendering.

Returns

str
A comma-separated string of TikZ options.