Warn about deprecated SCALING_FACTOR.

This commit is contained in:
Michael Schwarz 2015-11-02 22:44:56 +01:00
parent ef61a542b3
commit 6efebc1592

View file

@ -9,11 +9,8 @@ This wrapper was written by Maxime Chalton, Lukas Treyer and Gregor Ratajc.
SILENT = True
"""
Clipper library operates with integer coordinates. To preserve the degree of
floating point precision use the SCALING_FACTOR with which all the coordinates and
relevant properties will be multiplied before used with the Clipper library.
More info: http://www.angusj.com/delphi/clipper/documentation/Docs/Units/ClipperLib/Classes/ClipperOffset/Properties/ArcTolerance.htm"""
SCALING_FACTOR has been deprecated. See https://github.com/greginvm/pyclipper/wiki/Deprecating-SCALING_FACTOR for an explanation.
"""
SCALING_FACTOR = 1
@ -28,6 +25,7 @@ import struct
import copy as _copy
import unicodedata as _unicodedata
import time as _time
import warnings as _warnings
from cython.operator cimport dereference as deref
@ -590,6 +588,8 @@ cdef class Pyclipper:
Returns:
PyIntRect with left, right, bottom, top vertices that define the axis-aligned bounding rectangle.
"""
_check_scaling_factor()
cdef IntRect rr = <IntRect> self.thisptr.GetBounds()
return PyIntRect(left=_from_clipper_value(rr.left), top=_from_clipper_value(rr.top),
right=_from_clipper_value(rr.right), bottom=_from_clipper_value(rr.bottom))
@ -772,9 +772,13 @@ cdef class PyclipperOffset:
More info: http://www.angusj.com/delphi/clipper/documentation/Docs/Units/ClipperLib/Classes/ClipperOffset/Properties/ArcTolerance.htm
"""
def __get__(self):
_check_scaling_factor()
return _from_clipper_value(<double> self.thisptr.ArcTolerance)
def __set__(self, value):
_check_scaling_factor()
self.thisptr.ArcTolerance = _to_clipper_double(<double> value)
@ -834,6 +838,8 @@ cdef Paths _to_clipper_paths(object polygons):
cdef Path _to_clipper_path(object polygon):
_check_scaling_factor()
cdef Path path = Path()
cdef IntPoint p
for v in polygon:
@ -858,6 +864,8 @@ cdef object _from_clipper_paths(Paths paths):
cdef object _from_clipper_path(Path path):
_check_scaling_factor()
poly = []
cdef IntPoint point
for i in xrange(path.size()):
@ -869,6 +877,15 @@ cdef object _from_clipper_path(Path path):
return poly
def _check_scaling_factor():
"""
Check whether SCALING_FACTOR has been set by the code using this library and warn the user that it has been deprecated and it's value is ignored.
"""
if SCALING_FACTOR != 1:
_warnings.warn('SCALING_FACTOR is deprecated and it\'s value is ignored. See https://github.com/greginvm/pyclipper/wiki/Deprecating-SCALING_FACTOR for more information.', DeprecationWarning)
cdef cInt _to_clipper_int(val):
return val * SCALING_FACTOR