Расширить общие API графиков и GAS обмена
This commit is contained in:
@@ -37,7 +37,7 @@ class PlotMath:
|
||||
self.library = library
|
||||
library.set_plot_abi_version.restype = ctypes.c_uint32
|
||||
library.set_plot_abi_version.argtypes = []
|
||||
if library.set_plot_abi_version() != 1:
|
||||
if library.set_plot_abi_version() != 2:
|
||||
raise RuntimeError("Unsupported plot ABI")
|
||||
library.set_plot_eval.argtypes = [ctypes.c_uint32, ctypes.POINTER(ctypes.c_double),
|
||||
ctypes.c_size_t, ctypes.POINTER(ctypes.c_double), ctypes.c_size_t]
|
||||
@@ -67,6 +67,10 @@ class PlotMath:
|
||||
except ValueError:
|
||||
return None
|
||||
|
||||
def limits(self, left: float, right: float, bottom: float, top: float) -> "Bounds":
|
||||
"""Validate absolute axis limits in the shared core."""
|
||||
return Bounds(*self.call(8, left, right, bottom, top))
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Viewport:
|
||||
@@ -92,6 +96,9 @@ class Bounds:
|
||||
bottom: float
|
||||
top: float
|
||||
|
||||
def validated(self, core: PlotMath) -> "Bounds":
|
||||
return core.limits(self.left, self.right, self.bottom, self.top)
|
||||
|
||||
def fraction(self, core: PlotMath, value: float, horizontal: bool) -> float:
|
||||
return core.call(2, value, self.bottom if horizontal else self.left,
|
||||
self.top if horizontal else self.right, int(horizontal))[0]
|
||||
|
||||
Reference in New Issue
Block a user