-
Notifications
You must be signed in to change notification settings - Fork 654
Add tolerance based equals node #10004
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 10 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
8c431ac
add tolerance based equals node
aparajit-pratap 9800429
remove test entry from layoutspec
aparajit-pratap 89374ba
added lacing, supported disabling default value
aparajit-pratap 8cd225f
fix lacing in If UI node
aparajit-pratap 63b8a6d
fixes
aparajit-pratap deb69c8
add tests, string resources, review comments
aparajit-pratap 5f22a81
fix tests
aparajit-pratap bd0c71b
fix resource string
aparajit-pratap be85036
add test for default arg attribute with rep guides
aparajit-pratap c9af362
remove If node changes
aparajit-pratap 21c2f40
add icons for new equals node
aparajit-pratap e53abed
remove unused usings
aparajit-pratap 968f729
fix resx file
aparajit-pratap 7ddbd8a
update small icon
aparajit-pratap File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,93 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using CoreNodeModels.Properties; | ||
using Dynamo.Graph.Nodes; | ||
using Newtonsoft.Json; | ||
using ProtoCore.AST.AssociativeAST; | ||
using ProtoCore.DSASM; | ||
using ProtoCore.Utils; | ||
|
||
namespace CoreNodeModels | ||
{ | ||
[NodeName("==")] | ||
[NodeDescription("EqualsWithToleranceDescription", typeof(Resources))] | ||
[NodeCategory("Core.Math")] | ||
[NodeSearchTags("EqualsWithToleranceSearchTags", typeof(Resources))] | ||
[InPortTypes("double", "double", "double")] | ||
[OutPortTypes("bool")] | ||
[IsDesignScriptCompatible] | ||
public class Equals : NodeModel | ||
{ | ||
private static readonly DoubleNode tolerancePortDefaultValue = new DoubleNode(MathUtils.Tolerance); | ||
|
||
[JsonConstructor] | ||
private Equals(IEnumerable<PortModel> inPorts, IEnumerable<PortModel> outPorts) : base(inPorts, outPorts) | ||
{ | ||
ArgumentLacing = LacingStrategy.Auto; | ||
inPorts.ElementAt(2).DefaultValue = tolerancePortDefaultValue; | ||
} | ||
|
||
public Equals() | ||
{ | ||
ArgumentLacing = LacingStrategy.Auto; | ||
|
||
InPorts.Add(new PortModel(PortType.Input, this, new PortData("x", Resources.EqualsWithToleranceLhsRhsTooltip))); | ||
InPorts.Add(new PortModel(PortType.Input, this, new PortData("y", Resources.EqualsWithToleranceLhsRhsTooltip))); | ||
InPorts.Add(new PortModel(PortType.Input, this, | ||
new PortData("tolerance", string.Format(Resources.EqualsWithToleranceTooltip, MathUtils.Tolerance), tolerancePortDefaultValue))); | ||
OutPorts.Add(new PortModel(PortType.Output, this, new PortData("bool", Resources.EqualsWithToleranceOutportTooltip))); | ||
RegisterAllPorts(); | ||
} | ||
|
||
public override IEnumerable<AssociativeNode> BuildOutputAst(List<AssociativeNode> inputAstNodes) | ||
{ | ||
if (!InPorts[0].IsConnected && !InPorts[1].IsConnected && !InPorts[2].IsConnected) | ||
{ | ||
return new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), AstFactory.BuildNullNode()) }; | ||
} | ||
|
||
AssociativeNode rhs; | ||
if (IsPartiallyApplied) | ||
{ | ||
var connectedInputs = Enumerable.Range(0, InPorts.Count) | ||
.Where(index => InPorts[index].IsConnected) | ||
.Select(x => new IntNode(x) as AssociativeNode) | ||
.ToList(); | ||
var arguments = AstFactory.BuildExprList(inputAstNodes); | ||
|
||
|
||
var functionNode = new IdentifierListNode | ||
{ | ||
LeftNode = new IdentifierNode("DSCore.Math"), | ||
RightNode = new IdentifierNode("Equals") | ||
}; | ||
IntNode paramNumNode = new IntNode(3); | ||
var positionNode = AstFactory.BuildExprList(connectedInputs); | ||
|
||
var inputParams = new List<AssociativeNode> | ||
{ | ||
functionNode, | ||
paramNumNode, | ||
positionNode, | ||
arguments, | ||
AstFactory.BuildBooleanNode(true) | ||
}; | ||
|
||
rhs = AstFactory.BuildFunctionCall("__CreateFunctionObject", inputParams); | ||
} | ||
else | ||
{ | ||
UseLevelAndReplicationGuide(inputAstNodes); | ||
|
||
rhs = AstFactory.BuildFunctionCall(new Func<double, double, double, bool>(DSCore.Math.Equals), | ||
inputAstNodes); | ||
} | ||
|
||
return new[] | ||
{ | ||
AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), rhs) | ||
}; | ||
} | ||
} | ||
} |
54 changes: 50 additions & 4 deletions
54
src/Libraries/CoreNodeModels/Properties/Resources.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
---|---|---|
|
@@ -687,6 +687,9 @@ | |
{ | ||
"path": "Operators.==" | ||
}, | ||
{ | ||
"path": "Core.Math.==" | ||
}, | ||
{ | ||
"path": "Operators.>=" | ||
}, | ||
|
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.