sketchkit.core package¶
Submodules¶
sketchkit.core.camera module¶
- class sketchkit.core.camera.Camera(xyz: tuple[float, float, float] | ndarray = array([0, 0, 0]), wxyz: tuple[float, float, float, float] | ndarray = array([1, 0, 0, 0]), fov_x: float = 40, fov_y: float = 40, z_far: float = 1000, z_near: float = 0.1, coordinate_type='RDF')[source]¶
Bases:
Object3D- property extrinsics¶
- property intrinsics¶
- class sketchkit.core.camera.Object3D(xyz: tuple[float, float, float] | ndarray = array([0., 0., 0.]), wxyz: tuple[float, float, float, float] | ndarray = array([1., 0., 0., 0.]))[source]¶
Bases:
object- property pitch¶
- property roll¶
- property rotation_matrix¶
- property transform_matrix¶
- property translation_matrix¶
- property yaw¶
sketchkit.core.schema module¶
- class sketchkit.core.schema.Curve3DSchema(*, p_start: ~sketchkit.core.schema.Point3DSchema, p_ctrl1: ~sketchkit.core.schema.Point3DSchema, p_ctrl2: ~sketchkit.core.schema.Point3DSchema, p_end: ~sketchkit.core.schema.Point3DSchema, widths: ~typing.List[float] | None = None, attributes: ~typing.Dict[str, ~typing.Any] = <factory>)[source]¶
Bases:
BaseModel- _abc_impl = <_abc._abc_data object>¶
- attributes: Dict[str, Any]¶
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- p_ctrl1: Point3DSchema¶
- p_ctrl2: Point3DSchema¶
- p_end: Point3DSchema¶
- p_start: Point3DSchema¶
- widths: List[float] | None¶
- class sketchkit.core.schema.CurveSchema(*, p_start: ~sketchkit.core.schema.PointSchema, p_crtl1: ~sketchkit.core.schema.PointSchema, p_crtl2: ~sketchkit.core.schema.PointSchema, p_end: ~sketchkit.core.schema.PointSchema, attributes: ~typing.Dict[str, ~typing.Any] = <factory>)[source]¶
Bases:
BaseModel- _abc_impl = <_abc._abc_data object>¶
- attributes: Dict[str, Any]¶
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- p_crtl1: PointSchema¶
- p_crtl2: PointSchema¶
- p_end: PointSchema¶
- p_start: PointSchema¶
- class sketchkit.core.schema.Path3DSchema(*, curves: ~typing.List[~sketchkit.core.schema.Curve3DSchema], label: str | None = None, attributes: ~typing.Dict[str, ~typing.Any] = <factory>)[source]¶
Bases:
BaseModel- _abc_impl = <_abc._abc_data object>¶
- attributes: Dict[str, Any]¶
- curves: List[Curve3DSchema]¶
- label: str | None¶
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class sketchkit.core.schema.PathSchema(*, curves: ~typing.List[~sketchkit.core.schema.CurveSchema], label: str | None = None, attributes: ~typing.Dict[str, ~typing.Any] = <factory>)[source]¶
Bases:
BaseModel- _abc_impl = <_abc._abc_data object>¶
- attributes: Dict[str, Any]¶
- curves: List[CurveSchema]¶
- label: str | None¶
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class sketchkit.core.schema.Point3DSchema(*, x: float, y: float, z: float, thickness: float | None = None, color: ~typing.Tuple[float, float, float] | None = None, opacity: float | None = None, attributes: ~typing.Dict[str, ~typing.Any] = <factory>)[source]¶
Bases:
BaseModel- _abc_impl = <_abc._abc_data object>¶
- attributes: Dict[str, Any]¶
- color: Tuple[float, float, float] | None¶
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- opacity: float | None¶
- thickness: float | None¶
- x: float¶
- y: float¶
- z: float¶
- class sketchkit.core.schema.PointSchema(*, x: float, y: float, pressure: float | None = None, thickness: float | None = None, color: ~typing.Tuple[float, float, float] | None = None, opacity: float | None = None, attributes: ~typing.Dict[str, ~typing.Any] = <factory>)[source]¶
Bases:
BaseModel- _abc_impl = <_abc._abc_data object>¶
- attributes: Dict[str, Any]¶
- color: Tuple[float, float, float] | None¶
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- opacity: float | None¶
- pressure: float | None¶
- thickness: float | None¶
- x: float¶
- y: float¶
- class sketchkit.core.schema.Sketch3DSchema(*, paths: ~typing.List[~sketchkit.core.schema.Path3DSchema], attributes: ~typing.Dict[str, ~typing.Any] = <factory>)[source]¶
Bases:
BaseModel- _abc_impl = <_abc._abc_data object>¶
- attributes: Dict[str, Any]¶
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- paths: List[Path3DSchema]¶
- class sketchkit.core.schema.SketchSchema(*, height: float, width: float, paths: ~typing.List[~sketchkit.core.schema.PathSchema], attributes: ~typing.Dict[str, ~typing.Any] = <factory>)[source]¶
Bases:
BaseModel- _abc_impl = <_abc._abc_data object>¶
- attributes: Dict[str, Any]¶
- height: float¶
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- paths: List[PathSchema]¶
- width: float¶
sketchkit.core.sketch module¶
- class sketchkit.core.sketch.Curve(p_start: Point, p_end: Point, p_crtl1: Point, p_crtl2: Point, attributes: dict | None = None)[source]¶
Bases:
objectCurve defined by two endpoint points and two control points.
Connects two endpoint points (start and end) with optional control points for a curved path. Visual properties (color, pressure, thickness, opacity) are applied to both endpoints together.
- attributes¶
Custom user metadata for the curve.
- Type:
dict
Notes
When setting properties, the same value is applied to both endpoints. Numeric properties are converted to np.float32 automatically.
- property color¶
Colors of the start and end endpoints.
- Returns:
A two-element list of RGB colors for the start and end endpoints (each as float32 arrays) or None.
- Return type:
list[np.ndarray | None]
- classmethod from_line(line, attribute_list=None) Curve[source]¶
- Parameters:
line – In shape (2, 2), including two points.
attribute_list – A list of attributes (dict) for the two endpoints.
- Returns:
Curve object.
- Return type:
cubic
- get_division_points(ts: ndarray) ndarray[source]¶
Get points on the curve at specified parameter values.
- Parameters:
ts (np.ndarray) – Array of parameter values between 0 and 1.
- Returns:
Array of points on the curve at the specified parameter values.
- Return type:
np.ndarray
- is_line() bool[source]¶
Check if the curve is a line.
- Returns:
True if the curve is a line, False otherwise.
- Return type:
bool
- is_zero_length() bool[source]¶
Check if the curve is zero length.
- Returns:
True if the curve is zero length, False otherwise.
- Return type:
bool
- property length: float¶
Calculate the length of the curve.
- Returns:
Length of the curve.
- Return type:
float
- property np_points: ndarray¶
Get the points of the curve.
- Returns:
Array of points (shape: [4, 2]).
- Return type:
np.ndarray
- property opacity¶
Opacities of the start and end endpoints.
- Returns:
Two-element list of opacities or None.
- Return type:
list[np.float32 | None]
- property pressure¶
Pressures of the start and end endpoints.
- Returns:
Two-element list of pressures or None.
- Return type:
list[np.float32 | None]
- svg_length() float[source]¶
Calculate the length of the curve in SVG path units.
- Returns:
Length of the curve in SVG path units.
- Return type:
float
- property thickness¶
Thicknesses of the start and end endpoints.
- Returns:
Two-element list of thicknesses or None.
- Return type:
list[np.float32 | None]
- class sketchkit.core.sketch.Path(curves: list[Curve] | None = None, label: str | None = None, attributes: dict | None = None)[source]¶
Bases:
objectCollection of curves.
Manages multiple curves and applies common operations to all of them.
- attributes¶
Custom user metadata for the path.
- Type:
dict
Examples
>>> path = Path([curve1, curve2, curve3]) >>> path.color = (1.0, 0.0, 0.0) # Set all curves to red >>> path.thickness = 2.5 # Set all curves to thickness 2.5 >>> path.curve_num 3
- property color¶
Colors for each curve.
- Returns:
For each curve, a two-element list of endpoint colors (RGB arrays) or None.
- Return type:
list[list[np.ndarray | None]]
- curve_lengths()[source]¶
Calculate the length of each curve in the path.
- Returns:
Total length of the path.
- Return type:
float
- property curve_num¶
Number of curves in the path.
- Returns:
Count of curves.
- Return type:
int
- get_division_points(ts: ndarray) ndarray[source]¶
Get points on the path at parameters ts.
- Parameters:
ts (np.ndarray) – Array of parameter values between 0 and 1.
- Returns:
Array of points on the path at parameters ts.
- Return type:
np.ndarray
- property length¶
Calculate the total length of all curves in the path.
- Returns:
Total length of the path.
- Return type:
float
- property opacity¶
Opacities for each curve.
- Returns:
For each curve, a two-element list of endpoint opacities or None.
- Return type:
list[list[np.float32 | None]]
- property pressure¶
Pressures for each curve.
- Returns:
For each curve, a two-element list of endpoint pressures or None.
- Return type:
list[list[np.float32 | None]]
- svg_curve_lengths() list[float][source]¶
Calculate the lengths of each curve in SVG path units.
- Returns:
Array of lengths for each curve in SVG path units.
- Return type:
np.ndarray
- svg_length() float[source]¶
Calculate the total length of all curves in the path in SVG path units.
- Returns:
Total length of the path in SVG path units.
- Return type:
float
- property thickness¶
Thicknesses for each curve.
- Returns:
For each curve, a two-element list of endpoint thicknesses or None.
- Return type:
list[list[np.float32 | None]]
- class sketchkit.core.sketch.Point(x: float | float32, y: float | float32, pressure: None | float | float32 = None, thickness: None | float | float32 = None, color: None | tuple[float, float, float] | ndarray = None, opacity: None | float | float32 = None, attributes: dict | None = None)[source]¶
Bases:
object2D point with optional drawing attributes.
Point is now the single 2D point type used across the library. It can represent both geometric control points and styled stroke endpoints. Custom user metadata can be stored in attributes.
- class sketchkit.core.sketch.Sketch(height: float, width: float, paths: list[Path] | None = None, attributes: dict | None = None)[source]¶
Bases:
objectSketch composed of multiple paths.
A Sketch collects Path objects to form a complete drawing and exposes convenient accessors for color, pressure, thickness, and opacity.
- attributes¶
Custom user metadata for the sketch.
- Type:
dict
Examples
>>> sketch = Sketch([path1, path2, path3]) >>> sketch.color = (1.0, 0.0, 0.0) # Set all paths to red >>> sketch.thickness = 2.5 # Set all paths to thickness 2.5
- property color¶
Colors per path.
- Returns:
For each path, a list of curve colors where each curve has a two-element list of endpoint colors.
- Return type:
list[list[list[np.ndarray | None]]]
- property curve_num¶
Total number of curves across all paths.
- Returns:
Sum of curves in all paths.
- Return type:
int
- classmethod from_json(file_path: str) Sketch[source]¶
Load a sketch from a JSON file (Compact Format).
- Parameters:
json_path (str) – Path to the JSON file.
- Returns:
Loaded sketch object.
- Return type:
- classmethod from_svg(svg_file: str, *, default_thickness: float = 1.0, default_pressure: float | None = None, cast_canvas_to_int: bool = True) Sketch[source]¶
- property opacity¶
Opacities per path.
- Returns:
For each path, a list of curve opacities where each curve has a two-element list of endpoint values.
- Return type:
list[list[list[np.float32 | None]]]
- property path_num¶
Number of paths in the sketch.
- Returns:
Count of paths.
- Return type:
int
- property pressure¶
Pressures per path.
- Returns:
For each path, a list of curve pressures where each curve has a two-element list of endpoint pressures.
- Return type:
list[list[list[np.float32 | None]]]
- resize(height: float, width: float)[source]¶
Resize the sketch canvas and scale all strokes accordingly.
This rescales all curve points (including Bezier control points) from the current canvas size to the new canvas size.
Notes
X coordinates are scaled by
width / old_width.Y coordinates are scaled by
height / old_height.Stroke thickness (if present) is scaled by the average of the two scale factors.
- Parameters:
height (int) – New height.
width (int) – New width.
- resize_canvas(height: float, width: float)[source]¶
Resize the sketch canvas without scaling strokes.
This changes the canvas size but leaves all curve points and stroke properties unchanged.
- Parameters:
height (float) – New height.
width (float) – New width.
- property thickness¶
Thicknesses per path.
- Returns:
For each path, a list of curve thicknesses where each curve has a two-element list of endpoint values.
- Return type:
list[list[list[np.float32 | None]]]
- to_json(file_path: str)[source]¶
Save the sketch to a JSON file (Compact Format).
- Parameters:
file_path (str) – Path to the output JSON file.
- to_svg(height: int | None = None, width: int | None = None, fit_size: bool = False, is_polyline: bool = False, filename: str | None = None) str[source]¶
Convert the sketch to an SVG string.
- Parameters:
size – Size of the SVG canvas (width and height in pixels).
filename – Optional filename to save the SVG.
fit_size – If True, scale and center the sketch while preserving aspect ratio.
- Returns:
SVG representation of the sketch.
- Return type:
str
- sketchkit.core.sketch._deserialize_point(point_data: PointSchema) Point[source]¶
- sketchkit.core.sketch._serialize_point(point: Point) PointSchema[source]¶
sketchkit.core.sketch3d module¶
- class sketchkit.core.sketch3d.Curve3D(p_start: Point3D, p_end: Point3D, p_ctrl1: Point3D, p_ctrl2: Point3D, attributes: dict | None = None)[source]¶
Bases:
objectCubic Bézier curve in 3D defined by two endpoints and two control points.
- property widths: ndarray | None¶
- class sketchkit.core.sketch3d.Path3D(curves: list[Curve3D] | None = None, label: str | None = None, attributes: dict | None = None)[source]¶
Bases:
object- property curve_num¶
- class sketchkit.core.sketch3d.Point3D(x: float, y: float, z: float, thickness: float | None = None, color: tuple[float, float, float] | ndarray | None = None, opacity: float | None = None, attributes: dict | None = None)[source]¶
Bases:
object3D point with optional drawing attributes.
- class sketchkit.core.sketch3d.Sketch3D(paths: list[Path3D] | None = None, attributes: dict | None = None)[source]¶
Bases:
object- property curve_num¶
- classmethod from_json(json_path: str) Sketch3D[source]¶
Load a 3D sketch from a JSON file (Compact Format).
- Parameters:
json_path (str) – Path to the JSON file.
- Returns:
Loaded sketch object.
- Return type:
- property path_num¶
- sketchkit.core.sketch3d._deserialize_point3d(point_data: Point3DSchema) Point3D[source]¶
- sketchkit.core.sketch3d._serialize_point3d(point: Point3D) Point3DSchema[source]¶
Module contents¶
- class sketchkit.core.Curve(p_start: Point, p_end: Point, p_crtl1: Point, p_crtl2: Point, attributes: dict | None = None)[source]¶
Bases:
objectCurve defined by two endpoint points and two control points.
Connects two endpoint points (start and end) with optional control points for a curved path. Visual properties (color, pressure, thickness, opacity) are applied to both endpoints together.
- attributes¶
Custom user metadata for the curve.
- Type:
dict
Notes
When setting properties, the same value is applied to both endpoints. Numeric properties are converted to np.float32 automatically.
- property color¶
Colors of the start and end endpoints.
- Returns:
A two-element list of RGB colors for the start and end endpoints (each as float32 arrays) or None.
- Return type:
list[np.ndarray | None]
- classmethod from_line(line, attribute_list=None) Curve[source]¶
- Parameters:
line – In shape (2, 2), including two points.
attribute_list – A list of attributes (dict) for the two endpoints.
- Returns:
Curve object.
- Return type:
cubic
- get_division_points(ts: ndarray) ndarray[source]¶
Get points on the curve at specified parameter values.
- Parameters:
ts (np.ndarray) – Array of parameter values between 0 and 1.
- Returns:
Array of points on the curve at the specified parameter values.
- Return type:
np.ndarray
- is_line() bool[source]¶
Check if the curve is a line.
- Returns:
True if the curve is a line, False otherwise.
- Return type:
bool
- is_zero_length() bool[source]¶
Check if the curve is zero length.
- Returns:
True if the curve is zero length, False otherwise.
- Return type:
bool
- property length: float¶
Calculate the length of the curve.
- Returns:
Length of the curve.
- Return type:
float
- property np_points: ndarray¶
Get the points of the curve.
- Returns:
Array of points (shape: [4, 2]).
- Return type:
np.ndarray
- property opacity¶
Opacities of the start and end endpoints.
- Returns:
Two-element list of opacities or None.
- Return type:
list[np.float32 | None]
- property pressure¶
Pressures of the start and end endpoints.
- Returns:
Two-element list of pressures or None.
- Return type:
list[np.float32 | None]
- svg_length() float[source]¶
Calculate the length of the curve in SVG path units.
- Returns:
Length of the curve in SVG path units.
- Return type:
float
- property thickness¶
Thicknesses of the start and end endpoints.
- Returns:
Two-element list of thicknesses or None.
- Return type:
list[np.float32 | None]
- class sketchkit.core.Path(curves: list[Curve] | None = None, label: str | None = None, attributes: dict | None = None)[source]¶
Bases:
objectCollection of curves.
Manages multiple curves and applies common operations to all of them.
- attributes¶
Custom user metadata for the path.
- Type:
dict
Examples
>>> path = Path([curve1, curve2, curve3]) >>> path.color = (1.0, 0.0, 0.0) # Set all curves to red >>> path.thickness = 2.5 # Set all curves to thickness 2.5 >>> path.curve_num 3
- property color¶
Colors for each curve.
- Returns:
For each curve, a two-element list of endpoint colors (RGB arrays) or None.
- Return type:
list[list[np.ndarray | None]]
- curve_lengths()[source]¶
Calculate the length of each curve in the path.
- Returns:
Total length of the path.
- Return type:
float
- property curve_num¶
Number of curves in the path.
- Returns:
Count of curves.
- Return type:
int
- get_division_points(ts: ndarray) ndarray[source]¶
Get points on the path at parameters ts.
- Parameters:
ts (np.ndarray) – Array of parameter values between 0 and 1.
- Returns:
Array of points on the path at parameters ts.
- Return type:
np.ndarray
- property length¶
Calculate the total length of all curves in the path.
- Returns:
Total length of the path.
- Return type:
float
- property opacity¶
Opacities for each curve.
- Returns:
For each curve, a two-element list of endpoint opacities or None.
- Return type:
list[list[np.float32 | None]]
- property pressure¶
Pressures for each curve.
- Returns:
For each curve, a two-element list of endpoint pressures or None.
- Return type:
list[list[np.float32 | None]]
- svg_curve_lengths() list[float][source]¶
Calculate the lengths of each curve in SVG path units.
- Returns:
Array of lengths for each curve in SVG path units.
- Return type:
np.ndarray
- svg_length() float[source]¶
Calculate the total length of all curves in the path in SVG path units.
- Returns:
Total length of the path in SVG path units.
- Return type:
float
- property thickness¶
Thicknesses for each curve.
- Returns:
For each curve, a two-element list of endpoint thicknesses or None.
- Return type:
list[list[np.float32 | None]]
- class sketchkit.core.Point(x: float | float32, y: float | float32, pressure: None | float | float32 = None, thickness: None | float | float32 = None, color: None | tuple[float, float, float] | ndarray = None, opacity: None | float | float32 = None, attributes: dict | None = None)[source]¶
Bases:
object2D point with optional drawing attributes.
Point is now the single 2D point type used across the library. It can represent both geometric control points and styled stroke endpoints. Custom user metadata can be stored in attributes.
- class sketchkit.core.Sketch(height: float, width: float, paths: list[Path] | None = None, attributes: dict | None = None)[source]¶
Bases:
objectSketch composed of multiple paths.
A Sketch collects Path objects to form a complete drawing and exposes convenient accessors for color, pressure, thickness, and opacity.
- attributes¶
Custom user metadata for the sketch.
- Type:
dict
Examples
>>> sketch = Sketch([path1, path2, path3]) >>> sketch.color = (1.0, 0.0, 0.0) # Set all paths to red >>> sketch.thickness = 2.5 # Set all paths to thickness 2.5
- property color¶
Colors per path.
- Returns:
For each path, a list of curve colors where each curve has a two-element list of endpoint colors.
- Return type:
list[list[list[np.ndarray | None]]]
- property curve_num¶
Total number of curves across all paths.
- Returns:
Sum of curves in all paths.
- Return type:
int
- classmethod from_json(file_path: str) Sketch[source]¶
Load a sketch from a JSON file (Compact Format).
- Parameters:
json_path (str) – Path to the JSON file.
- Returns:
Loaded sketch object.
- Return type:
- classmethod from_svg(svg_file: str, *, default_thickness: float = 1.0, default_pressure: float | None = None, cast_canvas_to_int: bool = True) Sketch[source]¶
- property opacity¶
Opacities per path.
- Returns:
For each path, a list of curve opacities where each curve has a two-element list of endpoint values.
- Return type:
list[list[list[np.float32 | None]]]
- property path_num¶
Number of paths in the sketch.
- Returns:
Count of paths.
- Return type:
int
- property pressure¶
Pressures per path.
- Returns:
For each path, a list of curve pressures where each curve has a two-element list of endpoint pressures.
- Return type:
list[list[list[np.float32 | None]]]
- resize(height: float, width: float)[source]¶
Resize the sketch canvas and scale all strokes accordingly.
This rescales all curve points (including Bezier control points) from the current canvas size to the new canvas size.
Notes
X coordinates are scaled by
width / old_width.Y coordinates are scaled by
height / old_height.Stroke thickness (if present) is scaled by the average of the two scale factors.
- Parameters:
height (int) – New height.
width (int) – New width.
- resize_canvas(height: float, width: float)[source]¶
Resize the sketch canvas without scaling strokes.
This changes the canvas size but leaves all curve points and stroke properties unchanged.
- Parameters:
height (float) – New height.
width (float) – New width.
- property thickness¶
Thicknesses per path.
- Returns:
For each path, a list of curve thicknesses where each curve has a two-element list of endpoint values.
- Return type:
list[list[list[np.float32 | None]]]
- to_json(file_path: str)[source]¶
Save the sketch to a JSON file (Compact Format).
- Parameters:
file_path (str) – Path to the output JSON file.
- to_svg(height: int | None = None, width: int | None = None, fit_size: bool = False, is_polyline: bool = False, filename: str | None = None) str[source]¶
Convert the sketch to an SVG string.
- Parameters:
size – Size of the SVG canvas (width and height in pixels).
filename – Optional filename to save the SVG.
fit_size – If True, scale and center the sketch while preserving aspect ratio.
- Returns:
SVG representation of the sketch.
- Return type:
str