# This file was generated during the PCRaster build.
# Do not edit!
import numbers
import sys
try:
    import pcraster._pcraster as _pcraster
    import pcraster as pcr
except Exception:
    # we rely on a correct PCRaster setup
    raise ImportError("Failed to import the module '_pcraster'")

from . import _operations as pmcop


def pcrmcAnd(self, field):
    return pmcop._and(self, field)


def pcrmcRAnd(self, number):
    return pmcop._and(number, self)


def pcrmcOr(self, field):
    return pmcop._or(self, field)


def pcrmcROr(self, number):
    return pmcop._or(number, self)


def pcrmcXOr(self, field):
    return pmcop._xor(self, field)


def pcrmcNot(self):
    return pmcop._not(self)


def pcrmcEQ(self, arg):
    if self.dataType() == _pcraster.Scalar and isinstance(arg, numbers.Integral):
        arg = pcr.scalar(arg)
    return pmcop.equal(self, arg)


def pcrmcNE(self, arg):
    if self.dataType() == _pcraster.Scalar and isinstance(arg, numbers.Integral):
        arg = pcr.scalar(arg)
    return pmcop.unequal(self, arg)


def pcrmcGT(self, arg):
    if self.dataType() == _pcraster.Scalar and isinstance(arg, numbers.Integral):
        arg = pcr.scalar(arg)
    return pmcop.greater(self, arg)


def pcrmcGE(self, arg):
    if self.dataType() == _pcraster.Scalar and isinstance(arg, numbers.Integral):
        arg = pcr.scalar(arg)
    return pmcop.greater_equal(self, arg)


def pcrmcLT(self, arg):
    if self.dataType() == _pcraster.Scalar and isinstance(arg, numbers.Integral):
        arg = pcr.scalar(arg)
    return pmcop.less(self, arg)


def pcrmcLE(self, arg):
    if self.dataType() == _pcraster.Scalar and isinstance(arg, numbers.Integral):
        arg = pcr.scalar(arg)
    return pmcop.less_equal(self, arg)


def pcrmcAdd(self, arg):
    if isinstance(arg, numbers.Integral):
        arg = float(arg)
    return pmcop.add(self, arg)


def pcrmcRAdd(self, number):
    if isinstance(number, numbers.Integral):
        number = float(number)
    return pmcop.add(number, self)


def pcrmcSub(self, arg):
    if isinstance(arg, numbers.Integral):
        arg = float(arg)
    return pmcop.sub(self, arg)


def pcrmcRSub(self, number):
    if isinstance(number, numbers.Integral):
        number = float(number)
    return pmcop.sub(number, self)


def pcrmcMul(self, arg):
    if isinstance(arg, numbers.Integral):
        arg = float(arg)
    return pmcop.mul(self, arg)


def pcrmcRMul(self, number):
    if isinstance(number, numbers.Integral):
        number = float(number)
    return pmcop.mul(number, self)


def pcrmcDiv(self, arg):
    if isinstance(arg, numbers.Integral):
        arg = float(arg)
    return pmcop.div(self, arg)


def pcrmcRDiv(self, number):
    if isinstance(number, numbers.Integral):
        number = float(number)
    return pmcop.div(number, self)


def pcrmcPow(self, arg):
    if isinstance(arg, numbers.Integral):
        arg = float(arg)
    return pmcop.power(self, arg)


def pcrmcRPow(self, number):
    if isinstance(number, numbers.Integral):
        number = float(number)
    return pmcop.power(number, self)


# Some syntactic sugar to still allow the use of operators on Field objects.
# These operators should overwrite the ones from the PCRaster module.
_pcraster.Field.__and__ = pcrmcAnd      # &
_pcraster.Field.__rand__ = pcrmcRAnd

_pcraster.Field.__or__ = pcrmcOr        # |
_pcraster.Field.__ror__ = pcrmcROr

_pcraster.Field.__invert__ = pcrmcNot   # ~
_pcraster.Field.__xor__ = pcrmcXOr      # ^

_pcraster.Field.__ne__ = pcrmcNE
_pcraster.Field.__eq__ = pcrmcEQ

_pcraster.Field.__gt__ = pcrmcGT
_pcraster.Field.__ge__ = pcrmcGE

_pcraster.Field.__lt__ = pcrmcLT
_pcraster.Field.__le__ = pcrmcLE

_pcraster.Field.__add__ = pcrmcAdd
_pcraster.Field.__radd__ = pcrmcRAdd

_pcraster.Field.__sub__ = pcrmcSub
_pcraster.Field.__rsub__ = pcrmcRSub

_pcraster.Field.__mul__ = pcrmcMul
_pcraster.Field.__rmul__ = pcrmcRMul

_pcraster.Field.__pow__ = pcrmcPow
_pcraster.Field.__rpow__ = pcrmcRPow

if sys.version_info[0] < 3:
    _pcraster.Field.__div__ = pcrmcDiv
    _pcraster.Field.__rdiv__ = pcrmcRDiv
else:
    _pcraster.Field.__truediv__ = pcrmcDiv
    _pcraster.Field.__rtruediv__ = pcrmcRDiv
