Skip to content

Commit

Permalink
Merge pull request #8 from mishaelnuh/dev
Browse files Browse the repository at this point in the history
Fix bugs and usability issues
  • Loading branch information
mishaelnuh authored Feb 4, 2020
2 parents 5c36c39 + 25f1c6f commit c7bd71b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
24 changes: 18 additions & 6 deletions RodSteward/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ protected override void RegisterInputParams(GH_InputParamManager pManager)
pManager.AddNumberParameter("Tolerance", "e", "Tolerance", GH_ParamAccess.item);

((Param_Number)pManager[2]).PersistentData.Append(new GH_Number(50));
((Param_Number)pManager[3]).PersistentData.Append(new GH_Number(6.35));
((Param_Number)pManager[4]).PersistentData.Append(new GH_Number(3));
((Param_Number)pManager[5]).PersistentData.Append(new GH_Number(38));
((Param_Number)pManager[6]).PersistentData.Append(new GH_Number(0.1));
((Param_Number)pManager[3]).PersistentData.Append(new GH_Number(0.00635));
((Param_Number)pManager[4]).PersistentData.Append(new GH_Number(0.003));
((Param_Number)pManager[5]).PersistentData.Append(new GH_Number(0.038));
((Param_Number)pManager[6]).PersistentData.Append(new GH_Number(0.0001));
}

protected override void RegisterOutputParams(GH_OutputParamManager pManager)
Expand Down Expand Up @@ -172,7 +172,11 @@ protected override void SolveInstance(IGH_DataAccess DA)
if (!DA.GetData(5, ref jointLength)) { return; }
if (!DA.GetData(6, ref tolerance)) { return; }

if (edges == null || vertices == null) { return; }
if (edges == null || vertices == null)
{
model.ClearModelGeometries();
return;
}
if (radius <= 0 || sides <= 2 || jointThickness < 0 || jointLength < 0 || tolerance < 0) { throw new Exception("Invalid input."); }

if (ForceRecalc || !(model.Edges.SequenceEqual(edges) &&
Expand All @@ -193,7 +197,15 @@ protected override void SolveInstance(IGH_DataAccess DA)
model.JointLength = jointLength;
model.Tolerance = tolerance;

model.Generate(PrintLabel);
try
{
model.Generate(PrintLabel);
}
catch (Exception ex)
{
model.ClearModelGeometries();
throw ex;
}
}

if (Collision)
Expand Down
11 changes: 10 additions & 1 deletion RodSteward/Lines2Graph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ protected override void SolveInstance(IGH_DataAccess DA)
var p1 = l.PointAt(0);
var p2 = l.PointAt(1);

if (p1.DistanceTo(p2) < tolerance)
continue;

int match1 = vertices.FindIndex(p => p.DistanceTo(p1) < tolerance);
int match2 = vertices.FindIndex(p => p.DistanceTo(p2) < tolerance);

Expand All @@ -61,7 +64,13 @@ protected override void SolveInstance(IGH_DataAccess DA)
match2 = vertices.Count() - 1;
}

edges.Add(Tuple.Create(match1, match2));
if (match1 != match2)
{
var t1 = Tuple.Create(match1, match2);
var t2 = Tuple.Create(match2, match1);
if (!edges.Contains(t1) && !edges.Contains(t2))
edges.Add(t1);
}
}

// Prune
Expand Down
7 changes: 7 additions & 0 deletions RodSteward/Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ public void Generate(bool label = true)
GenerateJointMeshes(label);
}

public void ClearModelGeometries()
{
RodMeshes.Clear();
RodCentrelines.Clear();
JointMeshes.Clear();
}

public Dictionary<Tuple<int, int>, double> CalculateRodOffsets()
{
Offsets.Clear();
Expand Down

0 comments on commit c7bd71b

Please sign in to comment.