Skip to content

Commit

Permalink
Fix Slot deterministic state viewport rendering, Suggest Rule by lowe…
Browse files Browse the repository at this point in the history
…ring precision, null exception for Meshes with no naked edges

* Fix Slot deterministic state viewport rendering

* Fix Suggest Rule by lowering precision, fix null exception for Meshes with no naked edges
  • Loading branch information
janper authored Mar 19, 2021
1 parent 4c5b831 commit f48805d
Show file tree
Hide file tree
Showing 18 changed files with 58 additions and 45 deletions.
4 changes: 2 additions & 2 deletions Components/ModuleConstruct.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ namespace Monoceros {
public class ComponentConstructModule : GH_Component {
public ComponentConstructModule( ) : base("Construct Module",
"ConstModule",
"Construct a Monoceros Module from slot centers. " +
"Construct a Monoceros Module from Slot centers. " +
"The specified production geometry will be " +
"used in Monoceros solver result.",
"used in Monoceros Solver result.",
"Monoceros", "Module") {
}

Expand Down
2 changes: 1 addition & 1 deletion Components/ModuleDeconstruct.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ComponentModuleDeconstruct : GH_Component {
public ComponentModuleDeconstruct( ) : base("Deconstruct Module",
"DeconModule",
"Deconstruct Monoceros Module into name, base " +
"plane, connector planes, connector numbers " +
"plane, Connector planes, Connector numbers " +
"and properties.",
"Monoceros",
"Module") {
Expand Down
2 changes: 1 addition & 1 deletion Components/RuleAtBoundaryFromPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Monoceros {
public class ComponentRuleOuterFromPoint : GH_Component {
public ComponentRuleOuterFromPoint( )
: base("Rule At Boundary From Point",
: base("Rule at Boundary from Point",
"RuleBoundPt",
"Rule allowing the Monoceros Module to touch the boundary of the Envelope with " +
"a Connector marked with a Point. All connectors with an Indifferent Rule can " +
Expand Down
2 changes: 1 addition & 1 deletion Components/RuleExplicit2Lists.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Monoceros {

public class ComponentRuleExplicitBetweenTwoSets : GH_Component {
public ComponentRuleExplicitBetweenTwoSets( )
: base("Construct Explicit Rule Between 2 Lists",
: base("Construct Explicit Rule between 2 Lists",
"RuleExp2Lists",
"Construct a Monoceros Explicit Rule (connector-to-connector) between " +
"all listed Connectors of all listed Modules of two lists. The existence " +
Expand Down
2 changes: 1 addition & 1 deletion Components/RuleExplicitFromCurve.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Monoceros {

public class ComponentRuleExplicitFromCurve : GH_Component {
public ComponentRuleExplicitFromCurve( )
: base("Explicit Rule From Curve",
: base("Explicit Rule from Curve",
"RuleExpCrv",
"Create an Monoceros Explicit Rule (connector-to-connector) " +
"from a curve connecting two opposite connectors.",
Expand Down
2 changes: 1 addition & 1 deletion Components/RuleIndifferentFromPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Monoceros {
public class ComponentRuleIndifferentFromPoint : GH_Component {
public ComponentRuleIndifferentFromPoint( )
: base("Indifferent Rule From Point",
: base("Indifferent Rule from Point",
"RuleIndiffPt",
"Connectors of a Monoceros Module marked with a Point connect to any opposite " +
"indifferent connector of any Monoceros Module.",
Expand Down
2 changes: 1 addition & 1 deletion Components/RuleIndifferentUnused.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Monoceros {
// TODO: Consider doing this entirely in Grasshopper as a user object / cluster
public class ComponentRuleIndifferentUnused : GH_Component {
public ComponentRuleIndifferentUnused( )
: base("Indifferent Rules For Unused Connectors",
: base("Indifferent Rules for unused Connectors",
"RuleIndiffUnused",
"Unused connectors of Monoceros Modules connect to any opposite " +
"indifferent connector of any Monoceros Module.",
Expand Down
2 changes: 1 addition & 1 deletion Components/RulePreview.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ComponentPreviewRules : GH_Component, IGH_PreviewObject, IGH_BakeAw
public ComponentPreviewRules( )
: base("Preview Rules",
"RulePreview",
"Preview Monoceros Rules as lines connecting individual connectors of Monoceros Modules.",
"Preview Monoceros Rules as lines connecting individual Connectors of Monoceros Modules.",
"Monoceros",
"Postprocess") {
_explicitLines = new List<ExplicitLine>();
Expand Down
49 changes: 28 additions & 21 deletions Components/RuleSuggest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected override void SolveInstance(IGH_DataAccess DA) {
.Select(curve => curve.ToPolyline(0, 0, 0.05, 0.1, 0, precision, precision * 2, 0, true).ToPolyline());
var nakedPolylinesMesh = allGeometry
.Where(geo => geo.ObjectType == ObjectType.Mesh)
.SelectMany(geo => ((Mesh)geo).GetNakedEdges());
.SelectMany(geo => ((Mesh)geo).GetNakedEdges() ?? new Polyline[0]);
var curveEndPoints = allGeometry
.Where(geo => geo.ObjectType == ObjectType.Curve)
.Select(geo => (Curve)geo)
Expand All @@ -96,36 +96,43 @@ protected override void SolveInstance(IGH_DataAccess DA) {
connectorGeometry.MeshNakedEdgePoints = new List<Point3d>();
connectorGeometry.CurveEndPoints = new List<Point3d>();

connectorGeometry.BrepNakedEdgePoints = nakedPolylinesBrep
connectorGeometry.BrepNakedEdgePoints = nakedPolylinesBrep
.Where(polyline => polyline.All(point => connector.ContainsPoint(point)))
.SelectMany(polyline => polyline.Distinct().ToArray())
.Select(point => {
var transformedPoint = point;
transformedPoint.Transform(transform);
var roundedPoint = new Point3d(Math.Round(transformedPoint.X, Config.DECIMAL_PRECISION),
Math.Round(transformedPoint.Y, Config.DECIMAL_PRECISION),
Math.Round(transformedPoint.Z, Config.DECIMAL_PRECISION));
return roundedPoint;
}).ToList();
connectorGeometry.BrepNakedEdgePoints.Sort();

connectorGeometry.MeshNakedEdgePoints = nakedPolylinesMesh
.Where(polyline => polyline.All(point => connector.ContainsPoint(point)))
.SelectMany(polyline => polyline.Distinct().ToArray())
.SelectMany(polyline => polyline.Distinct())
.Select(point => {
var transformedPoint = point;
transformedPoint.Transform(transform);
return transformedPoint;
var roundedPoint = new Point3d(Math.Round(transformedPoint.X, Config.DECIMAL_PRECISION),
Math.Round(transformedPoint.Y, Config.DECIMAL_PRECISION),
Math.Round(transformedPoint.Z, Config.DECIMAL_PRECISION));
return roundedPoint;
}).ToList();
connectorGeometry.BrepNakedEdgePoints.Sort();
connectorGeometry.MeshNakedEdgePoints.Sort();

connectorGeometry.MeshNakedEdgePoints = nakedPolylinesMesh
.Where(polyline => polyline.All(point => connector.ContainsPoint(point)))
.SelectMany(polyline => polyline.Distinct().ToArray())
.Select(point => {
var transformedPoint = point;
transformedPoint.Transform(transform);
return transformedPoint;
}).ToList();
connectorGeometry.MeshNakedEdgePoints.Sort();


connectorGeometry.CurveEndPoints = curveEndPoints
connectorGeometry.CurveEndPoints = curveEndPoints
.Where(point => connector.ContainsPoint(point))
.Select(point => {
var transformedPoint = point;
transformedPoint.Transform(transform);
return transformedPoint;
var roundedPoint = new Point3d(Math.Round(transformedPoint.X, Config.DECIMAL_PRECISION),
Math.Round(transformedPoint.Y, Config.DECIMAL_PRECISION),
Math.Round(transformedPoint.Z, Config.DECIMAL_PRECISION));
return roundedPoint;
}).ToList();

connectorGeometry.CurveEndPoints.Sort();
connectorGeometry.CurveEndPoints.Sort();

if (connectorGeometry.BrepNakedEdgePoints.Any()
|| connectorGeometry.MeshNakedEdgePoints.Any()
Expand Down Expand Up @@ -179,7 +186,7 @@ private static bool ArePointListsEpsilonEqual(List<Point3d> a, List<Point3d> b)
for (var i = 0; i < a.Count; i++) {
var pointCurrent = a[i];
var pointOther = b[i];
if (!pointCurrent.EpsilonEquals(pointOther, RhinoMath.SqrtEpsilon)) {
if (!pointCurrent.EpsilonEquals(pointOther, Config.EPSILON)) {
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Components/RuleTypedFromPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Monoceros {

public class ComponentRuleTypedFromPoint : GH_Component {
public ComponentRuleTypedFromPoint( )
: base("Typed Rule From Point",
: base("Typed Rule from Point",
"RuleTypPt",
"Create a Monoceros Typed Rule (connector-to-all-same-type-connectors) from " +
"a Point tag. The connector Type will be converted to lowercase.",
Expand Down
2 changes: 1 addition & 1 deletion Components/SlotConstructWithAll.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Monoceros {
public class ComponentConstructSlotWithAll : GH_Component {
public ComponentConstructSlotWithAll( )
: base("Construct Slot With All Modules Allowed",
: base("Construct Slot with All Modules Allowed",
"SlotAll",
"Construct a Monoceros Slot with all Monoceros Modules allowed.",
"Monoceros",
Expand Down
2 changes: 1 addition & 1 deletion Components/SlotConstructWithModules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Monoceros {

public class ComponentConstructSlotWithModules : GH_Component {
public ComponentConstructSlotWithModules( )
: base("Construct Slot With Listed Modules Allowed",
: base("Construct Slot with Listed Modules Allowed",
"SlotModules",
"Construct a Monoceros Slot with allowed Monoceros Module names.",
"Monoceros",
Expand Down
2 changes: 1 addition & 1 deletion Components/SlotsFromGeometry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Monoceros {
public class ComponentSlotsFromgeometry : GH_Component {
public ComponentSlotsFromgeometry( ) : base("Slots From Geometry",
public ComponentSlotsFromgeometry( ) : base("Slots from Geometry",
"SlotsFromGeometry",
"Identify Module geometry and construct Slots containing it. Ignores connection to boundary.",
"Monoceros", "Slot") {
Expand Down
5 changes: 5 additions & 0 deletions Config.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using Rhino;

namespace Monoceros {
/// <summary>
Expand Down Expand Up @@ -36,6 +37,10 @@ public class Config {
public static string RESERVED_TO_STRING => RESERVED_NAMES
.Aggregate("", (accum, name) => accum + ", " + name);

public static int DECIMAL_PRECISION = 10;

public static double EPSILON = RhinoMath.SqrtEpsilon;

/// <summary>
/// Maximum number of parts supported by the current solver.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.3.2")]
[assembly: AssemblyFileVersion("1.2.3.2")]
[assembly: AssemblyVersion("1.2.3.3")]
[assembly: AssemblyFileVersion("1.2.3.3")]
5 changes: 3 additions & 2 deletions Types/Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1107,8 +1107,9 @@ public ModuleConnector(string moduleName,
/// <param name="point">The point.</param>
/// <returns>True if contains.</returns>
public bool ContainsPoint(Point3d point) {
return Math.Abs(AnchorPlane.DistanceTo(point)) < RhinoMath.SqrtEpsilon &&
Face.Contains(point) == PointContainment.Inside;
return Math.Abs(AnchorPlane.DistanceTo(point)) <= Config.EPSILON &&
(Face.Contains(point) == PointContainment.Inside
|| Face.Contains(point) == PointContainment.Coincident);
}

/// <summary>
Expand Down
14 changes: 7 additions & 7 deletions Types/Slot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ public void DrawViewportWires(GH_PreviewWireArgs args) {

var partsCount = AllowedPartNames.Count;

if (partsCount == 1 && AllPartsCount != 0) {
if (IsDeterministic) {
color = Config.CAGE_ONE_COLOR;
}

Expand All @@ -446,7 +446,6 @@ public void DrawViewportWires(GH_PreviewWireArgs args) {
color = InterpolateColor(Config.CAGE_TWO_COLOR, Config.CAGE_EVERYTHING_COLOR, t);
}


var cage = Cage;
var minDimension = Math.Min(cage.X.Length, Math.Min(cage.Y.Length, cage.Z.Length));
var shrinkSize = minDimension * Config.SLOT_SHRINK_FACTOR;
Expand Down Expand Up @@ -479,11 +478,12 @@ public void DrawViewportWires(GH_PreviewWireArgs args) {
// Only Grasshopper can instantiate an invalid slot and in such case
// the fields are set to their defaults. It is sufficient to null-check
// just one of them.
public bool IsValid => BasePlane != null &&
Diagonal != null &&
AllowedModuleNames != null &&
AllowedPartNames != null &&
(AllowsAnyModule || AllowedModuleNames.Count > 0);
public bool IsValid => BasePlane != null
&& Diagonal != null
&& AllowedModuleNames != null
&& AllowedPartNames != null
&& (AllowsAnyModule || AllowedModuleNames.Any())
&& (!AllowedPartNames.Any() || AllowedModuleNames.Any());

/// <summary>
/// Explains the invalidity of the <see cref="Slot"/>. Required by
Expand Down
Binary file modified bin/Monoceros.pdb
Binary file not shown.

0 comments on commit f48805d

Please sign in to comment.