def RelativeHeading(X, Y=None): X = toHeading(X, '"relative heading of X from Y" with X not a heading') if Y is None: Y = ego().heading else: Y = toHeading(Y, '"relative heading of X from Y" with Y not a heading') return normalizeAngle(X - Y)
def RelativeHeading(X, Y=None): """The 'relative heading of <heading> [from <heading>]' operator. If the 'from <heading>' is omitted, the heading of ego is used. """ X = toHeading(X, '"relative heading of X from Y" with X not a heading') if Y is None: Y = ego().heading else: Y = toHeading(Y, '"relative heading of X from Y" with Y not a heading') return normalizeAngle(X - Y)
def ApparentlyFacing(heading, fromPt=None): heading = toHeading(heading, 'specifier "apparently facing X" with X not a heading') if fromPt is None: fromPt = ego() fromPt = toVector(fromPt, 'specifier "apparently facing X from Y" with Y not a vector') value = lambda self: fromPt.angleTo(self.position) + heading return Specifier('heading', DelayedArgument({'position'}, value))
def Facing(heading): if isinstance(heading, VectorField): return Specifier('heading', DelayedArgument({'position'}, lambda self: heading[self.position])) else: heading = toHeading(heading, 'specifier "facing X" with X not a heading or vector field') return Specifier('heading', heading)
def OffsetAlong(X, H, Y): X = toVector(X, '"X offset along H by Y" with X not a vector') Y = toVector(Y, '"X offset along H by Y" with Y not a vector') if isinstance(H, VectorField): H = H[X] H = toHeading(H, '"X offset along H by Y" with H not a heading or vector field') return X.offsetRotated(H, Y)
def _specify(self, prop, value): assert prop not in self.properties # Normalize types of some built-in properties if prop == 'position': value = toVector(value, f'"position" of {self} not a vector') elif prop == 'heading': value = toHeading(value, f'"heading" of {self} not a heading') self.properties.add(prop) object.__setattr__(self, prop, value)
def ApparentlyFacing(heading, fromPt=None): """The 'apparently facing <heading> [from <vector>]' specifier. Specifies 'heading', depending on 'position'. If the 'from <vector>' is omitted, the position of ego is used. """ heading = toHeading(heading, 'specifier "apparently facing X" with X not a heading') if fromPt is None: fromPt = ego() fromPt = toVector(fromPt, 'specifier "apparently facing X from Y" with Y not a vector') value = lambda self: fromPt.angleTo(self.position) + heading return Specifier('heading', DelayedArgument({'position'}, value))
def Facing(heading): """The 'facing X' polymorphic specifier. Specifies 'heading', with dependencies depending on the form: facing <number> -- no dependencies; facing <field> -- depends on 'position'. """ if isinstance(heading, VectorField): return Specifier('heading', DelayedArgument({'position'}, lambda self: heading[self.position])) else: heading = toHeading(heading, 'specifier "facing X" with X not a heading or vector field') return Specifier('heading', heading)
def OffsetAlong(X, H, Y): """The 'X offset along H by Y' polymorphic operator. Allowed forms: <vector> offset along <heading> by <vector> <vector> offset along <field> by <vector> """ X = toVector(X, '"X offset along H by Y" with X not a vector') Y = toVector(Y, '"X offset along H by Y" with Y not a vector') if isinstance(H, VectorField): H = H[X] H = toHeading(H, '"X offset along H by Y" with H not a heading or vector field') return X.offsetRotated(H, Y)