Feat(API): throw basis of api maht object (token)
This commit is contained in:
parent
5d2611260a
commit
5938cc7875
84
mapytex/calculus/API/tokens/number.py
Normal file
84
mapytex/calculus/API/tokens/number.py
Normal file
@ -0,0 +1,84 @@
|
||||
#! /usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim:fenc=utf-8
|
||||
#
|
||||
# Copyright © 2017 lafrite <lafrite@Poivre>
|
||||
#
|
||||
# Distributed under terms of the MIT license.
|
||||
|
||||
"""
|
||||
Tokens representing interger and decimal
|
||||
|
||||
"""
|
||||
from .token import Token
|
||||
from ...core.MO import MOnumber, MOFraction
|
||||
from decimal import Decimal as _Decimal
|
||||
|
||||
__all__ = ["Integer", "Decimal"]
|
||||
|
||||
class Integer(Token):
|
||||
|
||||
""" Token representing a integer """
|
||||
|
||||
def __init__(self, mo, name=""):
|
||||
if not isinstance(mo, MOnumber):
|
||||
raise TypeError
|
||||
if not isinstance(mo.value, int):
|
||||
raise TypeError
|
||||
|
||||
Token.__init__(self, mo, name)
|
||||
self._mathtype = 'entier'
|
||||
|
||||
@classmethod
|
||||
def random(cls):
|
||||
raise NotImplemented
|
||||
|
||||
class Decimal(Token):
|
||||
|
||||
""" Token representing a decimal """
|
||||
|
||||
def __init__(self, mo, name=""):
|
||||
if not isinstance(mo, MOnumber):
|
||||
raise TypeError
|
||||
if not isinstance(mo.value, _Decimal):
|
||||
raise TypeError
|
||||
|
||||
Token.__init__(self, mo, name)
|
||||
self._mathtype = 'décimal'
|
||||
|
||||
@classmethod
|
||||
def random(cls):
|
||||
raise NotImplemented
|
||||
|
||||
class Fraction(Token):
|
||||
|
||||
""" Token representing a fraction """
|
||||
|
||||
def __init__(self, mo, name=""):
|
||||
if not isinstance(mo, MOFraction):
|
||||
raise TypeError
|
||||
if not isinstance(mo._numerator, MOnumber):
|
||||
raise TypeError
|
||||
if not isinstance(mo._denominator, MOnumber):
|
||||
raise TypeError
|
||||
|
||||
Token.__init__(self, mo, name)
|
||||
self._mathtype = 'fraction'
|
||||
|
||||
@classmethod
|
||||
def random(cls):
|
||||
raise NotImplemented
|
||||
|
||||
@property
|
||||
def numerator(self):
|
||||
return self._mo.numerator
|
||||
|
||||
@property
|
||||
def denominator(self):
|
||||
return self._mo.denominator
|
||||
|
||||
|
||||
# -----------------------------
|
||||
# Reglages pour 'vim'
|
||||
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
|
||||
# cursor: 16 del
|
50
mapytex/calculus/API/tokens/polynomial.py
Normal file
50
mapytex/calculus/API/tokens/polynomial.py
Normal file
@ -0,0 +1,50 @@
|
||||
#! /usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim:fenc=utf-8
|
||||
#
|
||||
# Copyright © 2017 lafrite <lafrite@Poivre>
|
||||
#
|
||||
# Distributed under terms of the MIT license.
|
||||
|
||||
"""
|
||||
Tokens representing interger and decimal
|
||||
|
||||
"""
|
||||
from .token import Token
|
||||
|
||||
__all__ = ["Polynomial", "Quadratic", "Linear"]
|
||||
|
||||
class Polynomial(Token):
|
||||
|
||||
""" Token representing a polynomial """
|
||||
|
||||
def __init__(self, mo, name=""):
|
||||
if not isinstance(mo, MOpolynomial):
|
||||
raise TypeError
|
||||
if not isinstance(mo.value, int):
|
||||
raise TypeError
|
||||
|
||||
Token.__init__(self, mo, name)
|
||||
self._mathtype = 'polynome'
|
||||
|
||||
@classmethod
|
||||
def random(cls):
|
||||
raise NotImplemented
|
||||
|
||||
def __setitem__(self, key, item):
|
||||
""" Use Polynomial like if they were a dictionnary to set coefficients """
|
||||
pass
|
||||
|
||||
def __getitem__(self, key):
|
||||
""" Use Polynomial like if they were a dictionnary to get coefficients """
|
||||
pass
|
||||
|
||||
def __call__(self, value):
|
||||
""" Call a Polynomial to evaluate itself on value """
|
||||
pass
|
||||
|
||||
|
||||
# -----------------------------
|
||||
# Reglages pour 'vim'
|
||||
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
|
||||
# cursor: 16 del
|
32
mapytex/calculus/API/tokens/token.py
Normal file
32
mapytex/calculus/API/tokens/token.py
Normal file
@ -0,0 +1,32 @@
|
||||
#! /usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim:fenc=utf-8
|
||||
#
|
||||
# Copyright © 2017 lafrite <lafrite@Poivre>
|
||||
#
|
||||
# Distributed under terms of the MIT license.
|
||||
|
||||
"""
|
||||
Tokens: practical envelop of math object
|
||||
|
||||
"""
|
||||
|
||||
class Token(object):
|
||||
|
||||
""" Token: practical envelop of an math object """
|
||||
|
||||
def __init__(self, mo, name=""):
|
||||
self._mo = mo
|
||||
self.name = name
|
||||
self._mathtype = None
|
||||
|
||||
@classmethod
|
||||
def random(cls):
|
||||
raise NotImplemented
|
||||
|
||||
|
||||
|
||||
# -----------------------------
|
||||
# Reglages pour 'vim'
|
||||
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
|
||||
# cursor: 16 del
|
Loading…
Reference in New Issue
Block a user