Skip to content

Commit

Permalink
map range functions moved to common
Browse files Browse the repository at this point in the history
  • Loading branch information
IlgarLunin committed Sep 16, 2019
1 parent 64c9f63 commit 32f6091
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
12 changes: 12 additions & 0 deletions PyFlow/Core/Common.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ def GetRangePct(MinValue, MaxValue, Value):
"""
return (Value - MinValue) / (MaxValue - MinValue)

def mapRangeClamped(Value, InRangeA, InRangeB, OutRangeA, OutRangeB):
"""Returns Value mapped from one range into another where the Value is clamped to the Input Range.
(e.g. 0.5 normalized from the range 0->1 to 0->50 would result in 25)
"""

ClampedPct = clamp(GetRangePct(InRangeA, InRangeB, Value), 0.0, 1.0)
return lerp(OutRangeA, OutRangeB, ClampedPct)

def mapRangeUnclamped(Value, InRangeA, InRangeB, OutRangeA, OutRangeB):
"""Returns Value mapped from one range into another where the Value is clamped to the Input Range.
(e.g. 0.5 normalized from the range 0->1 to 0->50 would result in 25)"""
return lerp(OutRangeA, OutRangeB, GetRangePct(InRangeA, InRangeB, Value))

def sign(x):
"""Returns sign of x. -1 if x is negative, 1 if positive and zero if 0.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ def mapRangeClamped(Value=("FloatPin", 0.0),
OutRangeB=("FloatPin", 0.0)):
"""Returns Value mapped from one range into another where the Value is clamped to the Input Range.\
(e.g. 0.5 normalized from the range 0->1 to 0->50 would result in 25)"""
ClampedPct = clamp(GetRangePct(InRangeA, InRangeB, Value), 0.0, 1.0)
return lerp(OutRangeA, OutRangeB, ClampedPct)
return mapRangeClamped(Value, InRangeA, InRangeB, OutRangeA, OutRangeB)

@staticmethod
@IMPLEMENT_NODE(returns=('FloatPin', 0.0), meta={NodeMeta.CATEGORY: 'Math|Basic', NodeMeta.KEYWORDS: []})
Expand All @@ -119,7 +118,7 @@ def mapRangeUnclamped(Value=("FloatPin", 0.0),
OutRangeB=("FloatPin", 0.0)):
"""Returns Value mapped from one range into another where the Value is clamped to the Input Range.\
(e.g. 0.5 normalized from the range 0->1 to 0->50 would result in 25)"""
return lerp(OutRangeA, OutRangeB, GetRangePct(InRangeA, InRangeB, Value))
return mapRangeUnclamped(Value, InRangeA, InRangeB, OutRangeA, OutRangeB)

@staticmethod
@IMPLEMENT_NODE(returns=("FloatPin", 0.0), meta={NodeMeta.CATEGORY: 'Math|Basic', NodeMeta.KEYWORDS: ['clamp']})
Expand Down

0 comments on commit 32f6091

Please sign in to comment.