Darthbhyrava has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/275112

Change subject: Change: Implement Coordinate.precisionToDim
......................................................................

Change: Implement Coordinate.precisionToDim

Allow for precision to dimension conversion by implementing 
Coordinate.precisionToDim

Bug: T89670
Change-Id: I2f1432603218f0ede2b0f703ef3c5046928440b3
---
M pywikibot/__init__.py
1 file changed, 21 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/12/275112/1

diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index 4fe6801..efe5903 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -364,9 +364,28 @@
     def precision(self, value):
         self._precision = value
 
+    @property
     def precisionToDim(self):
-        """Convert precision from Wikibase to GeoData's dim."""
-        raise NotImplementedError
+        u"""Converts precision from Wikibase to GeoData's dim and returns the 
latter.
+
+        The dimension is calculated if the Coordinate doesn't have a 
dimension, and self._precision is set.
+        When neither dim nor precision are set, None is returned. 
+
+        Carrying on from the earlier derivation of precision, since 
+            precision = 
math.degrees(self._dim/(radius*math.cos(math.radians(self.lat)))), we get
+            self._dim = 
math.radians(precision)*radius*math.cos(math.radians(self.lat))
+        But this is not valid, since it returns a float value for self._dim 
which is an integer. We must round it off
+        to the nearest integer.
+
+        Therefore::
+            self._dim = 
int(round(math.radians(precision)*radius*math.cos(math.radians(self.lat))))
+
+        @rtype: int or None
+        """
+        if self._dim is None and self._precision is not None:
+            radius = 6378137
+            self._dim = 
int(round(math.radians(self._precision)*radius*math.cos(math.radians(self.lat))))
+        return self._dim
 
 
 class WbTime(_WbRepresentation):

-- 
To view, visit https://gerrit.wikimedia.org/r/275112
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2f1432603218f0ede2b0f703ef3c5046928440b3
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Darthbhyrava <hbhyr...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to