svg-ultralight 0.30.0__tar.gz → 0.31.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of svg-ultralight might be problematic. Click here for more details.

Files changed (49) hide show
  1. {svg_ultralight-0.30.0/src/svg_ultralight.egg-info → svg_ultralight-0.31.0}/PKG-INFO +1 -1
  2. {svg_ultralight-0.30.0 → svg_ultralight-0.31.0}/pyproject.toml +2 -2
  3. {svg_ultralight-0.30.0 → svg_ultralight-0.31.0}/src/svg_ultralight/__init__.py +9 -9
  4. {svg_ultralight-0.30.0 → svg_ultralight-0.31.0}/src/svg_ultralight/transformations.py +14 -0
  5. {svg_ultralight-0.30.0 → svg_ultralight-0.31.0/src/svg_ultralight.egg-info}/PKG-INFO +1 -1
  6. {svg_ultralight-0.30.0 → svg_ultralight-0.31.0}/src/svg_ultralight.egg-info/SOURCES.txt +1 -1
  7. {svg_ultralight-0.30.0 → svg_ultralight-0.31.0}/tests/test_bounding.py +0 -23
  8. svg_ultralight-0.31.0/tests/test_matrices.py +34 -0
  9. svg_ultralight-0.30.0/src/svg_ultralight/bounding_boxes/type_bound_confederation.py +0 -71
  10. {svg_ultralight-0.30.0 → svg_ultralight-0.31.0}/.gitignore +0 -0
  11. {svg_ultralight-0.30.0 → svg_ultralight-0.31.0}/.pre-commit-config.yaml +0 -0
  12. {svg_ultralight-0.30.0 → svg_ultralight-0.31.0}/README.md +0 -0
  13. {svg_ultralight-0.30.0 → svg_ultralight-0.31.0}/setup.cfg +0 -0
  14. {svg_ultralight-0.30.0 → svg_ultralight-0.31.0}/src/svg_ultralight/animate.py +0 -0
  15. {svg_ultralight-0.30.0 → svg_ultralight-0.31.0}/src/svg_ultralight/bounding_boxes/__init__.py +0 -0
  16. {svg_ultralight-0.30.0 → svg_ultralight-0.31.0}/src/svg_ultralight/bounding_boxes/bound_helpers.py +0 -0
  17. {svg_ultralight-0.30.0 → svg_ultralight-0.31.0}/src/svg_ultralight/bounding_boxes/supports_bounds.py +0 -0
  18. {svg_ultralight-0.30.0 → svg_ultralight-0.31.0}/src/svg_ultralight/bounding_boxes/type_bound_collection.py +0 -0
  19. {svg_ultralight-0.30.0 → svg_ultralight-0.31.0}/src/svg_ultralight/bounding_boxes/type_bound_element.py +0 -0
  20. {svg_ultralight-0.30.0 → svg_ultralight-0.31.0}/src/svg_ultralight/bounding_boxes/type_bounding_box.py +0 -0
  21. {svg_ultralight-0.30.0 → svg_ultralight-0.31.0}/src/svg_ultralight/bounding_boxes/type_padded_text.py +0 -0
  22. {svg_ultralight-0.30.0 → svg_ultralight-0.31.0}/src/svg_ultralight/constructors/__init__.py +0 -0
  23. {svg_ultralight-0.30.0 → svg_ultralight-0.31.0}/src/svg_ultralight/constructors/new_element.py +0 -0
  24. {svg_ultralight-0.30.0 → svg_ultralight-0.31.0}/src/svg_ultralight/inkscape.py +0 -0
  25. {svg_ultralight-0.30.0 → svg_ultralight-0.31.0}/src/svg_ultralight/layout.py +0 -0
  26. {svg_ultralight-0.30.0 → svg_ultralight-0.31.0}/src/svg_ultralight/main.py +0 -0
  27. {svg_ultralight-0.30.0 → svg_ultralight-0.31.0}/src/svg_ultralight/metadata.py +0 -0
  28. {svg_ultralight-0.30.0 → svg_ultralight-0.31.0}/src/svg_ultralight/nsmap.py +0 -0
  29. {svg_ultralight-0.30.0 → svg_ultralight-0.31.0}/src/svg_ultralight/py.typed +0 -0
  30. {svg_ultralight-0.30.0 → svg_ultralight-0.31.0}/src/svg_ultralight/query.py +0 -0
  31. {svg_ultralight-0.30.0 → svg_ultralight-0.31.0}/src/svg_ultralight/root_elements.py +0 -0
  32. {svg_ultralight-0.30.0 → svg_ultralight-0.31.0}/src/svg_ultralight/string_conversion.py +0 -0
  33. {svg_ultralight-0.30.0 → svg_ultralight-0.31.0}/src/svg_ultralight/strings/__init__.py +0 -0
  34. {svg_ultralight-0.30.0 → svg_ultralight-0.31.0}/src/svg_ultralight/strings/svg_strings.py +0 -0
  35. {svg_ultralight-0.30.0 → svg_ultralight-0.31.0}/src/svg_ultralight/unit_conversion.py +0 -0
  36. {svg_ultralight-0.30.0 → svg_ultralight-0.31.0}/src/svg_ultralight.egg-info/dependency_links.txt +0 -0
  37. {svg_ultralight-0.30.0 → svg_ultralight-0.31.0}/src/svg_ultralight.egg-info/requires.txt +0 -0
  38. {svg_ultralight-0.30.0 → svg_ultralight-0.31.0}/src/svg_ultralight.egg-info/top_level.txt +0 -0
  39. {svg_ultralight-0.30.0 → svg_ultralight-0.31.0}/tests/__init__.py +0 -0
  40. {svg_ultralight-0.30.0 → svg_ultralight-0.31.0}/tests/conftest.py +0 -0
  41. {svg_ultralight-0.30.0 → svg_ultralight-0.31.0}/tests/test_inkscape.py +0 -0
  42. {svg_ultralight-0.30.0 → svg_ultralight-0.31.0}/tests/test_layout.py +0 -0
  43. {svg_ultralight-0.30.0 → svg_ultralight-0.31.0}/tests/test_metadata.py +0 -0
  44. {svg_ultralight-0.30.0 → svg_ultralight-0.31.0}/tests/test_new_element.py +0 -0
  45. {svg_ultralight-0.30.0 → svg_ultralight-0.31.0}/tests/test_queries.py +0 -0
  46. {svg_ultralight-0.30.0 → svg_ultralight-0.31.0}/tests/test_root_elements.py +0 -0
  47. {svg_ultralight-0.30.0 → svg_ultralight-0.31.0}/tests/test_string_conversion.py +0 -0
  48. {svg_ultralight-0.30.0 → svg_ultralight-0.31.0}/tests/test_svg_ultralight.py +0 -0
  49. {svg_ultralight-0.30.0 → svg_ultralight-0.31.0}/tox.ini +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: svg-ultralight
3
- Version: 0.30.0
3
+ Version: 0.31.0
4
4
  Summary: a sensible way to create svg files with Python
5
5
  Author-email: Shay Hill <shay_public@hotmail.com>
6
6
  License: MIT
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "svg-ultralight"
3
- version = "0.30.0"
3
+ version = "0.31.0"
4
4
  description = "a sensible way to create svg files with Python"
5
5
  authors = [{ name = "Shay Hill", email = "shay_public@hotmail.com" }]
6
6
  license = { text = "MIT" }
@@ -37,7 +37,7 @@ legacy_tox_ini = """
37
37
 
38
38
  [tool.commitizen]
39
39
  name = "cz_conventional_commits"
40
- version = "0.30.0"
40
+ version = "0.31.0"
41
41
  tag_format = "$version"
42
42
  version_files = ["pyproject.toml:^version"]
43
43
  annotated_tag = true
@@ -10,11 +10,7 @@ from svg_ultralight.bounding_boxes.bound_helpers import (
10
10
  new_element_union,
11
11
  )
12
12
  from svg_ultralight.bounding_boxes.supports_bounds import SupportsBounds
13
- <<<<<<< HEAD
14
- from svg_ultralight.bounding_boxes.type_bound_confederation import BoundConfederation
15
- =======
16
13
  from svg_ultralight.bounding_boxes.type_bound_collection import BoundCollection
17
- >>>>>>> dev
18
14
  from svg_ultralight.bounding_boxes.type_bound_element import BoundElement
19
15
  from svg_ultralight.bounding_boxes.type_bounding_box import BoundingBox
20
16
  from svg_ultralight.bounding_boxes.type_padded_text import PaddedText
@@ -42,14 +38,15 @@ from svg_ultralight.string_conversion import (
42
38
  format_numbers,
43
39
  format_numbers_in_string,
44
40
  )
45
- from svg_ultralight.transformations import transform_element
41
+ from svg_ultralight.transformations import (
42
+ mat_apply,
43
+ mat_dot,
44
+ mat_invert,
45
+ transform_element,
46
+ )
46
47
 
47
48
  __all__ = [
48
- <<<<<<< HEAD
49
- "BoundConfederation",
50
- =======
51
49
  "BoundCollection",
52
- >>>>>>> dev
53
50
  "BoundElement",
54
51
  "BoundingBox",
55
52
  "NSMAP",
@@ -60,6 +57,9 @@ __all__ = [
60
57
  "format_number",
61
58
  "format_numbers",
62
59
  "format_numbers_in_string",
60
+ "mat_apply",
61
+ "mat_dot",
62
+ "mat_invert",
63
63
  "new_bbox_union",
64
64
  "new_bound_union",
65
65
  "new_element",
@@ -59,6 +59,20 @@ def mat_apply(mat1: _Matrix, mat2: tuple[float, float]) -> tuple[float, float]:
59
59
  return mat1[0] * mat2[0] + mat1[4], mat1[3] * mat2[1] + mat1[5]
60
60
 
61
61
 
62
+ def mat_invert(tmat: _Matrix) -> _Matrix:
63
+ """Invert a 2D transformation matrix in svg format."""
64
+ a, b, c, d, e, f = tmat
65
+ det = a * d - b * c
66
+ return (
67
+ d / det,
68
+ -b / det,
69
+ -c / det,
70
+ a / det,
71
+ (c * f - d * e) / det,
72
+ (b * e - a * f) / det,
73
+ )
74
+
75
+
62
76
  def get_transform_matrix(elem: EtreeElement) -> _Matrix:
63
77
  """Get the transformation matrix from an svg element.
64
78
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: svg-ultralight
3
- Version: 0.30.0
3
+ Version: 0.31.0
4
4
  Summary: a sensible way to create svg files with Python
5
5
  Author-email: Shay Hill <shay_public@hotmail.com>
6
6
  License: MIT
@@ -25,7 +25,6 @@ src/svg_ultralight/bounding_boxes/__init__.py
25
25
  src/svg_ultralight/bounding_boxes/bound_helpers.py
26
26
  src/svg_ultralight/bounding_boxes/supports_bounds.py
27
27
  src/svg_ultralight/bounding_boxes/type_bound_collection.py
28
- src/svg_ultralight/bounding_boxes/type_bound_confederation.py
29
28
  src/svg_ultralight/bounding_boxes/type_bound_element.py
30
29
  src/svg_ultralight/bounding_boxes/type_bounding_box.py
31
30
  src/svg_ultralight/bounding_boxes/type_padded_text.py
@@ -38,6 +37,7 @@ tests/conftest.py
38
37
  tests/test_bounding.py
39
38
  tests/test_inkscape.py
40
39
  tests/test_layout.py
40
+ tests/test_matrices.py
41
41
  tests/test_metadata.py
42
42
  tests/test_new_element.py
43
43
  tests/test_queries.py
@@ -9,11 +9,7 @@ import math
9
9
  from svg_ultralight.bounding_boxes.type_bound_element import BoundElement
10
10
  from svg_ultralight.bounding_boxes.type_padded_text import PaddedText
11
11
  from svg_ultralight.bounding_boxes.type_bounding_box import BoundingBox
12
- <<<<<<< HEAD
13
- from svg_ultralight.bounding_boxes.type_bound_confederation import BoundConfederation
14
- =======
15
12
  from svg_ultralight.bounding_boxes.type_bound_collection import BoundCollection
16
- >>>>>>> dev
17
13
  import copy
18
14
  from svg_ultralight.constructors import new_element
19
15
 
@@ -159,16 +155,6 @@ class TestPaddedText:
159
155
  assert math.isclose(bound_element.height, 252.76)
160
156
  assert bound_element.y2 == 203.0
161
157
 
162
- <<<<<<< HEAD
163
- class TestBoundConfederation:
164
-
165
- @pytest.fixture
166
- def bound_confederation(self) -> BoundConfederation:
167
- elem = new_element("rect", x=0, y=0, width=100, height=200)
168
- bbox = BoundingBox(0, 0, 100, 200)
169
- blem = PaddedText(elem, bbox, 1, 2, 3, 4)
170
- return BoundConfederation(blem, copy.deepcopy(elem))
171
- =======
172
158
  class TestBoundCollection:
173
159
 
174
160
  @pytest.fixture
@@ -177,7 +163,6 @@ class TestBoundCollection:
177
163
  bbox = BoundingBox(0, 0, 100, 200)
178
164
  blem = PaddedText(elem, bbox, 1, 2, 3, 4)
179
165
  return BoundCollection(blem, copy.deepcopy(elem))
180
- >>>>>>> dev
181
166
 
182
167
  def test_blem_and_elem(self):
183
168
  """Test that bound element and unbound element transforms are the same."""
@@ -185,19 +170,11 @@ class TestBoundCollection:
185
170
  bbox = BoundingBox(0, 0, 100, 200)
186
171
  blem = BoundElement(rect, bbox)
187
172
  elem = copy.deepcopy(rect)
188
- <<<<<<< HEAD
189
- bound_confederation = BoundConfederation(blem, elem)
190
- bound_confederation.x = -4
191
- bound_confederation.scale = 10
192
- bound_confederation.width = 60
193
- bound_confederation.cy = -40
194
- =======
195
173
  bound_collection = BoundCollection(blem, elem)
196
174
  bound_collection.x = -4
197
175
  bound_collection.scale = 10
198
176
  bound_collection.width = 60
199
177
  bound_collection.cy = -40
200
- >>>>>>> dev
201
178
  blem_trans = blem.elem.attrib["transform"]
202
179
  elem_trans = elem.attrib["transform"]
203
180
  assert blem_trans == elem_trans
@@ -0,0 +1,34 @@
1
+ """Test transformations of matrices.
2
+
3
+ :author: Shay Hill
4
+ :created: 2024-05-05
5
+ """
6
+
7
+ from svg_ultralight.transformations import mat_dot, mat_apply, mat_invert
8
+ import random
9
+ import math
10
+
11
+
12
+ class TestMat:
13
+ def test_explicit(self):
14
+ expect = (31, 46, 12, 22, 10, 14)
15
+ assert mat_dot((1, 2, 3, 4, 5, 6), (7, 8, 9, 1, 2, 1)) == expect
16
+
17
+ def test_apply(self):
18
+ expect = (12, 38)
19
+ assert mat_apply((1, 2, 3, 4, 5, 6), (7, 8)) == expect
20
+
21
+ def test_invert(self):
22
+ identity = (1, 0, 0, 1, 0, 0)
23
+ for _ in range(10):
24
+ tmat = (
25
+ random.randint(-10, 10),
26
+ random.randint(-10, 10),
27
+ random.randint(-10, 10),
28
+ random.randint(-10, 10),
29
+ random.randint(-10, 10),
30
+ random.randint(-10, 10),
31
+ )
32
+ result = mat_dot(tmat, mat_invert(tmat))
33
+ for x, y in zip(result, identity):
34
+ assert math.isclose(x, y, abs_tol=0.0001)
@@ -1,71 +0,0 @@
1
- """A class to hold a list of bound elements and transform them together.
2
-
3
- :author: Shay Hill
4
- :created: 2024-05-05
5
- """
6
-
7
- from __future__ import annotations
8
-
9
- import dataclasses
10
- from typing import TYPE_CHECKING
11
-
12
- from lxml.etree import _Element as EtreeElement # type: ignore
13
-
14
- from svg_ultralight.bounding_boxes.bound_helpers import new_bbox_union
15
- from svg_ultralight.bounding_boxes.supports_bounds import SupportsBounds
16
- from svg_ultralight.bounding_boxes.type_bounding_box import HasBoundingBox
17
- from svg_ultralight.transformations import new_transformation_matrix, transform_element
18
-
19
- if TYPE_CHECKING:
20
- from svg_ultralight.bounding_boxes.type_bounding_box import BoundingBox
21
-
22
- _Matrix = tuple[float, float, float, float, float, float]
23
-
24
-
25
- @dataclasses.dataclass
26
- class BoundConfederation(HasBoundingBox):
27
- """A class to hold a list of bound elements and transform them together.
28
-
29
- This will transform the individual elements in place.
30
- """
31
-
32
- blems: list[SupportsBounds | EtreeElement] = dataclasses.field(init=False)
33
- bbox: BoundingBox = dataclasses.field(init=False)
34
-
35
- def __init__(self, *blems: SupportsBounds | EtreeElement) -> None:
36
- """Initialize the bound confederation.
37
-
38
- :param blems: bound elements to be transformed together
39
- """
40
- self.blems = list(blems)
41
- self.bbox = new_bbox_union(*self.blems)
42
-
43
- def transform(
44
- self,
45
- transformation: _Matrix | None = None,
46
- *,
47
- scale: float | None = None,
48
- dx: float | None = None,
49
- dy: float | None = None,
50
- ):
51
- """Transform each bound element in self.blems.
52
-
53
- :param transformation: 2D transformation matrix
54
- :param scale: optional scale factor
55
- :param dx: optional x translation
56
- :param dy: optional y translation
57
-
58
- Keep track of all compounding transformations in order to have a value for
59
- self.scale (required for membersh and to provide access to cumulative
60
- transforms should this be useful for any reason. This means all
61
- transformations must be applied to two bounding boxes: a persistant bbox to
62
- keep track of the scale property and a temporary bbox to isolate each
63
- transformation.
64
- """
65
- tmat = new_transformation_matrix(transformation, scale=scale, dx=dx, dy=dy)
66
- self.bbox.transform(tmat)
67
- for blem in self.blems:
68
- if isinstance(blem, EtreeElement):
69
- _ = transform_element(blem, tmat)
70
- else:
71
- blem.transform(tmat)
File without changes