Skip to content

Commit

Permalink
Merge pull request #209 from xyz2tex/208-exported-arcs-are-often-back…
Browse files Browse the repository at this point in the history
…wards

FIX: arc direction
  • Loading branch information
ldevillez authored Aug 30, 2024
2 parents 9cd3a2a + 8d1483a commit 6687ad1
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

### Added
- Adding info about the dependencies and how to contribute in the README
- Adding test for the arc direction
### Changed
### Deprecated
### Removed
### Fixed
- Fixing the latex build of the docs
- Fixing some arc were not rendered correctly by tikz
### Security

## v3.1.0 - 19/05/2024
Expand Down
28 changes: 19 additions & 9 deletions svg2tikz/tikz_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,23 @@ def _add_booloption(self, parser, *args, **kwargs):
kwargs["action"] = "store_true"
parser.add_argument(*args, **kwargs)

def sanitize_angles(self, start_raw: float, end_raw: float):
"""
Sanitizes angles from arc to put them in [-360, 360] range
start_raw: start angle of the arc
end_raw: end angle of the arc
"""

start_ang = self.round_value(start_raw % 360)
end_ang = self.round_value(end_raw % 360)
# # Does not to seem a problem anymore
if start_raw < end_raw and not start_ang < end_ang:
start_ang -= 360
elif start_raw > end_raw and not start_ang > end_ang:
end_ang -= 360
return start_ang, end_ang

def convert_unit(self, value: float) -> float:
"""Convert value from the user unit to the output unit which is an option"""
ret = self.svg.unit_to_viewport(value, self.options.output_unit)
Expand Down Expand Up @@ -1152,15 +1169,8 @@ def convert_path_to_tikz(self, path):
if not self.options.noreversey:
r.y *= -1

# pgf 2.0 does not like angles larger than 360
# make sure it is in the +- 360 range
start_ang = self.round_value(start_ang_o % 360)
end_ang = self.round_value(end_ang_o % 360)
# # Does not to seem a problem anymore
# if start_ang_o < end_ang_o and not start_ang < end_ang:
# start_ang -= 360
# elif start_ang_o > end_ang_o and not start_ang > end_ang:
# end_ang -= 360
# For Pgf 2.0
start_ang, end_ang = self.sanitize_angles(start_ang_o, end_ang_o)

if not self.options.noreversey:
command.x_axis_rotation *= -1
Expand Down
6 changes: 6 additions & 0 deletions tests/test_complete_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ def test_attribute_texmode(self):
filename, self, texmode="attribute", texmode_attribute="data-texmode"
)

def test_arc_direction(self):
"""Test per SVG object texmode with attribute"""
# Exemple taken from svg of the flag of the state of California
filename = "R_letter_with_arc"
create_test_from_filename(filename, self)


if __name__ == "__main__":
unittest.main()
47 changes: 47 additions & 0 deletions tests/testfiles/R_letter_with_arc.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions tests/testfiles/R_letter_with_arc.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}

\begin{document}
\definecolor{c584528}{RGB}{88,69,40}


\def \globalscale {1.000000}
\begin{tikzpicture}[y=1cm, x=1cm, yscale=\globalscale,xscale=\globalscale, every node/.append style={scale=\globalscale}, inner sep=0pt, outer sep=0pt]
\path[fill=c584528,line width=0.0265cm] (1.139, 27.7421) -- (0.8996, 27.7421) -- (0.8996, 29.065) -- (1.412, 29.065)arc(269.0684:315.4369:0.1347 and -0.1347)arc(-46.43000000000001:0.8173:0.1311 and -0.1311) -- (1.5509, 28.4461)arc(-1.6533999999999764:58.4445:0.1287 and -0.1287)arc(-58.43090000000001:1.6398:0.1288 and -0.1288) -- (1.5509, 27.8781)arc(182.0888:115.7033:0.127 and -0.127) .. controls (1.6278, 27.7559) and (1.6304, 27.7528) .. (1.6304, 27.7497)arc(-8.094499999999982:98.4931:0.0067 and -0.0067) -- (1.459, 27.7421)arc(88.9159:135.3056:0.1339 and -0.1339)arc(133.7122:180.9811:0.1302 and -0.1302) -- (1.3211, 28.2335) -- (1.1391, 28.2335) -- cycle(1.139, 28.4413) -- (1.321, 28.4413) -- (1.321, 28.8288) -- (1.139, 28.8288) -- cycle;




\end{tikzpicture}
\end{document}

0 comments on commit 6687ad1

Please sign in to comment.