-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added diff/dist separation in condition number comparator
- Loading branch information
Showing
2 changed files
with
151 additions
and
145 deletions.
There are no files selected for viewing
204 changes: 104 additions & 100 deletions
204
...ction/Condition/conditions/StandardCondition/Comparator/comparators/NumberComparators.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,101 +1,105 @@ | ||
/* | ||
============================================================================== | ||
NumberComparators.cpp | ||
Created: 2 Nov 2016 8:57:34pm | ||
Author: bkupe | ||
============================================================================== | ||
*/ | ||
|
||
NumberComparator::NumberComparator(Parameter* sourceParam, Multiplex* multiplex) : | ||
BaseComparator(multiplex), | ||
isFloat(dynamic_cast<FloatParameter*>(sourceParam) != nullptr) | ||
{ | ||
|
||
sourceRange.append(sourceParam->minimumValue); | ||
sourceRange.append(sourceParam->maximumValue); | ||
|
||
setupReferenceParam(); | ||
reference->setValue(sourceParam->floatValue(), false, true, true); | ||
if (isFloat)((FloatParameter*)reference)->defaultUI = ((FloatParameter*)sourceParam)->defaultUI; | ||
|
||
addCompareOption("=", equalsId); | ||
addCompareOption("!=", differentId); | ||
addCompareOption(">", greaterId); | ||
addCompareOption("<", lessId); | ||
addCompareOption(">=", greaterOrEqualId); | ||
addCompareOption("<=", lessOrEqualId); | ||
addCompareOption("Modulo =", moduloEqualId); | ||
addCompareOption("Modulo >", moduloGreaterId); | ||
addCompareOption("Modulo <", moduloLessId); | ||
addCompareOption("Floor =", floorEqualId); | ||
addCompareOption("Floor >", floorGreaterId); | ||
addCompareOption("Floor <", floorLessId); | ||
addCompareOption("Diff >", diffGreaterId); | ||
addCompareOption("Diff <", diffLessId); | ||
addCompareOption("Range", inRangeId); | ||
addCompareOption("Change", changeId); | ||
} | ||
|
||
NumberComparator::~NumberComparator() | ||
{ | ||
} | ||
|
||
void NumberComparator::compareFunctionChanged() | ||
{ | ||
setupReferenceParam(); | ||
} | ||
|
||
void NumberComparator::setupReferenceParam() | ||
{ | ||
if (currentFunctionId == inRangeId || currentFunctionId.toString().contains("%") || currentFunctionId.toString().contains("f")) | ||
{ | ||
Point2DParameter* p2d = new Point2DParameter("Reference", "Comparison Reference to check against source value"); | ||
p2d->setBounds(sourceRange[0], sourceRange[0], sourceRange[1], sourceRange[1]); | ||
if (currentFunctionId != inRangeId) p2d->setPoint(2, 0); | ||
setReferenceParam(p2d); | ||
} | ||
else | ||
{ | ||
if (isFloat) | ||
{ | ||
if (reference == nullptr || reference->type != Parameter::FLOAT) | ||
{ | ||
setReferenceParam(new FloatParameter("Reference", "Comparison Reference to check against source value", 0, sourceRange[0], sourceRange[1])); | ||
} | ||
} | ||
else if (reference == nullptr || reference->type != Parameter::INT) | ||
{ | ||
setReferenceParam(new IntParameter("Reference", "Comparison Reference to check against source value", 0, sourceRange[0], sourceRange[1])); | ||
} | ||
} | ||
} | ||
|
||
bool NumberComparator::compareInternal(Parameter* sourceParam, int multiplexIndex) | ||
{ | ||
var value = isMultiplexed() ? refLink->getLinkedValue(multiplexIndex) : reference->getValue(); | ||
|
||
if (currentFunctionId == equalsId) return sourceParam->floatValue() == (float)value; | ||
else if (currentFunctionId == differentId) return sourceParam->floatValue() != (float)value; | ||
else if (currentFunctionId == greaterId) return sourceParam->floatValue() > (float)value; | ||
else if (currentFunctionId == lessId) return sourceParam->floatValue() < (float)value; | ||
else if (currentFunctionId == greaterOrEqualId) return sourceParam->floatValue() >= (float)value; | ||
else if (currentFunctionId == lessOrEqualId) return sourceParam->floatValue() <= (float)value; | ||
else if (currentFunctionId == moduloEqualId) return (float)value[0] == 0 ? false : fmodf(sourceParam->floatValue(), (float)value[0]) == (float)value[1]; | ||
else if (currentFunctionId == moduloGreaterId) return (float)value[0] == 0 ? false : fmodf(sourceParam->floatValue(), (float)value[0]) > (float)value[1]; | ||
else if (currentFunctionId == moduloLessId) return (float)value[0] == 0 ? false : fmodf(sourceParam->floatValue(), (float)value[0]) < (float)value[1]; | ||
else if (currentFunctionId == floorEqualId) return (float)value[0] == 0 ? false : floorf(sourceParam->floatValue() / (float)value[0]) == (float)value[1]; | ||
else if (currentFunctionId == floorGreaterId) return (float)value[0] == 0 ? false : floorf(sourceParam->floatValue() / (float)value[0]) >(float)value[1]; | ||
else if (currentFunctionId == floorLessId) return (float)value[0] == 0 ? false : floorf(sourceParam->floatValue() / (float)value[0]) < (float)value[1]; | ||
else if (currentFunctionId == inRangeId) return sourceParam->floatValue() >= (float)value[0] && sourceParam->floatValue() <= (float)value[1]; | ||
else if (currentFunctionId == diffGreaterId || currentFunctionId == diffLessId) | ||
{ | ||
prevValues.ensureStorageAllocated(multiplexIndex + 1); | ||
float diff = fabsf(sourceParam->floatValue() - prevValues[multiplexIndex]); | ||
bool result = currentFunctionId == diffGreaterId ? diff > (float)value : diff < (float)value; | ||
prevValues.set(multiplexIndex, sourceParam->floatValue()); | ||
return result; | ||
} | ||
return false; | ||
/* | ||
============================================================================== | ||
NumberComparators.cpp | ||
Created: 2 Nov 2016 8:57:34pm | ||
Author: bkupe | ||
============================================================================== | ||
*/ | ||
|
||
NumberComparator::NumberComparator(Parameter* sourceParam, Multiplex* multiplex) : | ||
BaseComparator(multiplex), | ||
isFloat(dynamic_cast<FloatParameter*>(sourceParam) != nullptr) | ||
{ | ||
|
||
sourceRange.append(sourceParam->minimumValue); | ||
sourceRange.append(sourceParam->maximumValue); | ||
|
||
setupReferenceParam(); | ||
reference->setValue(sourceParam->floatValue(), false, true, true); | ||
if (isFloat)((FloatParameter*)reference)->defaultUI = ((FloatParameter*)sourceParam)->defaultUI; | ||
|
||
addCompareOption("=", equalsId); | ||
addCompareOption("!=", differentId); | ||
addCompareOption(">", greaterId); | ||
addCompareOption("<", lessId); | ||
addCompareOption(">=", greaterOrEqualId); | ||
addCompareOption("<=", lessOrEqualId); | ||
addCompareOption("Modulo =", moduloEqualId); | ||
addCompareOption("Modulo >", moduloGreaterId); | ||
addCompareOption("Modulo <", moduloLessId); | ||
addCompareOption("Floor =", floorEqualId); | ||
addCompareOption("Floor >", floorGreaterId); | ||
addCompareOption("Floor <", floorLessId); | ||
addCompareOption("Diff >", diffGreaterId); | ||
addCompareOption("Diff <", diffLessId); | ||
addCompareOption("Dist >", distGreaterId); | ||
addCompareOption("Dist <", distLessId); | ||
addCompareOption("Range", inRangeId); | ||
addCompareOption("Change", changeId); | ||
} | ||
|
||
NumberComparator::~NumberComparator() | ||
{ | ||
} | ||
|
||
void NumberComparator::compareFunctionChanged() | ||
{ | ||
setupReferenceParam(); | ||
} | ||
|
||
void NumberComparator::setupReferenceParam() | ||
{ | ||
if (currentFunctionId == inRangeId || currentFunctionId.toString().contains("%") || currentFunctionId.toString().contains("f")) | ||
{ | ||
Point2DParameter* p2d = new Point2DParameter("Reference", "Comparison Reference to check against source value"); | ||
p2d->setBounds(sourceRange[0], sourceRange[0], sourceRange[1], sourceRange[1]); | ||
if (currentFunctionId != inRangeId) p2d->setPoint(2, 0); | ||
setReferenceParam(p2d); | ||
} | ||
else | ||
{ | ||
if (isFloat) | ||
{ | ||
if (reference == nullptr || reference->type != Parameter::FLOAT) | ||
{ | ||
setReferenceParam(new FloatParameter("Reference", "Comparison Reference to check against source value", 0, sourceRange[0], sourceRange[1])); | ||
} | ||
} | ||
else if (reference == nullptr || reference->type != Parameter::INT) | ||
{ | ||
setReferenceParam(new IntParameter("Reference", "Comparison Reference to check against source value", 0, sourceRange[0], sourceRange[1])); | ||
} | ||
} | ||
} | ||
|
||
bool NumberComparator::compareInternal(Parameter* sourceParam, int multiplexIndex) | ||
{ | ||
var value = isMultiplexed() ? refLink->getLinkedValue(multiplexIndex) : reference->getValue(); | ||
|
||
if (currentFunctionId == equalsId) return sourceParam->floatValue() == (float)value; | ||
else if (currentFunctionId == differentId) return sourceParam->floatValue() != (float)value; | ||
else if (currentFunctionId == greaterId) return sourceParam->floatValue() > (float)value; | ||
else if (currentFunctionId == lessId) return sourceParam->floatValue() < (float)value; | ||
else if (currentFunctionId == greaterOrEqualId) return sourceParam->floatValue() >= (float)value; | ||
else if (currentFunctionId == lessOrEqualId) return sourceParam->floatValue() <= (float)value; | ||
else if (currentFunctionId == moduloEqualId) return (float)value[0] == 0 ? false : fmodf(sourceParam->floatValue(), (float)value[0]) == (float)value[1]; | ||
else if (currentFunctionId == moduloGreaterId) return (float)value[0] == 0 ? false : fmodf(sourceParam->floatValue(), (float)value[0]) > (float)value[1]; | ||
else if (currentFunctionId == moduloLessId) return (float)value[0] == 0 ? false : fmodf(sourceParam->floatValue(), (float)value[0]) < (float)value[1]; | ||
else if (currentFunctionId == floorEqualId) return (float)value[0] == 0 ? false : floorf(sourceParam->floatValue() / (float)value[0]) == (float)value[1]; | ||
else if (currentFunctionId == floorGreaterId) return (float)value[0] == 0 ? false : floorf(sourceParam->floatValue() / (float)value[0]) >(float)value[1]; | ||
else if (currentFunctionId == floorLessId) return (float)value[0] == 0 ? false : floorf(sourceParam->floatValue() / (float)value[0]) < (float)value[1]; | ||
else if (currentFunctionId == inRangeId) return sourceParam->floatValue() >= (float)value[0] && sourceParam->floatValue() <= (float)value[1]; | ||
else if (currentFunctionId == distGreaterId || currentFunctionId == distLessId | ||
|| currentFunctionId == diffGreaterId || currentFunctionId == diffLessId) | ||
{ | ||
prevValues.ensureStorageAllocated(multiplexIndex + 1); | ||
float diff = sourceParam->floatValue() - prevValues[multiplexIndex]; | ||
if (currentFunctionId == distGreaterId || currentFunctionId == distLessId) diff = fabsf(diff); | ||
bool result = (currentFunctionId == distGreaterId || currentFunctionId == diffGreaterId) ? diff > (float)value : diff < (float)value; | ||
prevValues.set(multiplexIndex, sourceParam->floatValue()); | ||
return result; | ||
} | ||
return false; | ||
} |
92 changes: 47 additions & 45 deletions
92
.../Action/Condition/conditions/StandardCondition/Comparator/comparators/NumberComparators.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,48 @@ | ||
/* | ||
============================================================================== | ||
NumberComparators.h | ||
Created: 2 Nov 2016 8:57:34pm | ||
Author: bkupe | ||
============================================================================== | ||
*/ | ||
|
||
#pragma once | ||
|
||
class NumberComparator : | ||
public BaseComparator | ||
{ | ||
public: | ||
NumberComparator(Parameter * sourceParam, Multiplex* multiplex); | ||
virtual ~NumberComparator(); | ||
|
||
const Identifier equalsId = "="; | ||
const Identifier differentId = "!="; | ||
const Identifier greaterId = ">"; | ||
const Identifier lessId = "<"; | ||
const Identifier greaterOrEqualId = ">="; | ||
const Identifier lessOrEqualId = "<="; | ||
const Identifier moduloEqualId = "%="; | ||
const Identifier moduloGreaterId = "%>"; | ||
const Identifier moduloLessId = "%<"; | ||
const Identifier floorEqualId = "f="; | ||
const Identifier floorGreaterId = "f>"; | ||
const Identifier floorLessId = "f<"; | ||
const Identifier diffGreaterId = "d>"; | ||
const Identifier diffLessId = "d<"; | ||
const Identifier inRangeId = "r"; | ||
const Identifier changeId = "ch"; | ||
|
||
bool isFloat; | ||
Parameter * refParam; | ||
var sourceRange; | ||
Array<float> prevValues; | ||
|
||
virtual void compareFunctionChanged() override; | ||
virtual void setupReferenceParam(); | ||
|
||
virtual bool compareInternal(Parameter* sourceParam, int multiplexIndex = 0) override; | ||
/* | ||
============================================================================== | ||
NumberComparators.h | ||
Created: 2 Nov 2016 8:57:34pm | ||
Author: bkupe | ||
============================================================================== | ||
*/ | ||
|
||
#pragma once | ||
|
||
class NumberComparator : | ||
public BaseComparator | ||
{ | ||
public: | ||
NumberComparator(Parameter * sourceParam, Multiplex* multiplex); | ||
virtual ~NumberComparator(); | ||
|
||
const Identifier equalsId = "="; | ||
const Identifier differentId = "!="; | ||
const Identifier greaterId = ">"; | ||
const Identifier lessId = "<"; | ||
const Identifier greaterOrEqualId = ">="; | ||
const Identifier lessOrEqualId = "<="; | ||
const Identifier moduloEqualId = "%="; | ||
const Identifier moduloGreaterId = "%>"; | ||
const Identifier moduloLessId = "%<"; | ||
const Identifier floorEqualId = "f="; | ||
const Identifier floorGreaterId = "f>"; | ||
const Identifier floorLessId = "f<"; | ||
const Identifier diffGreaterId = "d>"; | ||
const Identifier diffLessId = "d<"; | ||
const Identifier distGreaterId = "ds>"; | ||
const Identifier distLessId = "ds<"; | ||
const Identifier inRangeId = "r"; | ||
const Identifier changeId = "ch"; | ||
|
||
bool isFloat; | ||
Parameter * refParam; | ||
var sourceRange; | ||
Array<float> prevValues; | ||
|
||
virtual void compareFunctionChanged() override; | ||
virtual void setupReferenceParam(); | ||
|
||
virtual bool compareInternal(Parameter* sourceParam, int multiplexIndex = 0) override; | ||
}; |