Skip to content

Commit

Permalink
Workaround to avoid to have to set the locale (hence use locale_patch…
Browse files Browse the repository at this point in the history
…) before using a mathmakerlib Number.
  • Loading branch information
nicolashainaux committed Jun 21, 2018
1 parent 4ddbf08 commit 940f857
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions mathmakerlib/geometry/angle.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# along with Mathmaker Lib; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

import locale
from math import atan2, degrees

from mathmakerlib import required, config
Expand All @@ -35,7 +36,6 @@
from mathmakerlib.geometry.vector import Vector
from mathmakerlib.geometry.bipoint import Bipoint
from mathmakerlib.calculus.number import Number, is_number
from mathmakerlib.constants import LOCALE_US

AVAILABLE_NAMING_MODES = ['from_endpoints', 'from_armspoints', 'from_vertex']

Expand Down Expand Up @@ -619,11 +619,17 @@ def tikz_rightangle_mark(self, winding='anticlockwise'):
if self.decoration is None or not self.mark_right:
return ''
check_winding(winding)
# Decimal numbers in TikZ must be written with a dot as decimal point.
# As of now, there is no reliable way to temporarily change the
# locale to 'C' (or 'en_US'), so here's a little patch that will
# replace possibly other decimal points by a '.'.
theta = str(Bipoint(self.vertex, self.points[0])
.slope.rounded(Number('0.01')).printed)
if (locale.localeconv()['decimal_point'] != '.'
and locale.localeconv()['decimal_point'] in theta):
theta = theta.replace(locale.localeconv()['decimal_point'], '.')
rt = 'cm={{cos({θ}), sin({θ}), -sin({θ}), cos({θ}), ({v})}}' \
.format(θ=Bipoint(self.vertex, self.points[0])
.slope.rounded(Number('0.01'))
.imprint(mod_locale=LOCALE_US),
v=self.vertex.name)
.format(θ=theta, v=self.vertex.name)
draw_options = tikz_options_list([self.decoration.thickness,
self.decoration.color,
rt])
Expand Down

0 comments on commit 940f857

Please sign in to comment.