public bool Select(Shape parentShape, Shape componentShape, SemanticSelector selector) { var componentShapeType = componentShape.GetType(); if (componentShapeType != typeof(Quad)) { throw new ArgumentException($"'{nameof(Box)}' cannot have a '{componentShapeType.Name}' as a component"); } var cN = componentShape.Transform.GetZAxis(); switch (selector) { case SemanticSelector.BOTTOM: { var pY = parentShape.Transform.GetYAxis(); var dot = Vector3.Dot(pY, cN); return(dot <= -_DotThreshold); /* Y and N are almost parallel and point to same direction */ } case SemanticSelector.TOP: { var pY = parentShape.Transform.GetYAxis(); var dot = Vector3.Dot(pY, cN); return(dot >= _DotThreshold); /* Y and N are almost parallel and point to opposite directions */ } case SemanticSelector.BACK: { var pZ = parentShape.Transform.GetZAxis(); var dot = Vector3.Dot(pZ, cN); return(dot <= -_DotThreshold); /* Z and N are almost parallel and point to same direction */ } case SemanticSelector.FRONT: { var pZ = parentShape.Transform.GetZAxis(); var dot = Vector3.Dot(pZ, cN); return(dot >= _DotThreshold); /* Z and N are almost parallel and point to opposite directions */ } case SemanticSelector.RIGHT: { var pX = parentShape.Transform.GetXAxis(); var dot = Vector3.Dot(pX, cN); return(dot >= _DotThreshold); /* X and N are almost parallel and point to same direction */ } case SemanticSelector.LEFT: { var pX = parentShape.Transform.GetXAxis(); var dot = Vector3.Dot(pX, cN); return(dot <= -_DotThreshold); /* X and N are almost parallel and point to opposite directions */ } case SemanticSelector.HORIZONTAL: { var pY = parentShape.Transform.GetYAxis(); var absDot = Math.Abs(Vector3.Dot(pY, cN)); return(absDot >= _DotThreshold); /* Y and N are almost parallel */ } case SemanticSelector.VERTICAL: case SemanticSelector.SIDE: { var pY = parentShape.Transform.GetYAxis(); var absDot = Math.Abs(Vector3.Dot(pY, cN)); return(absDot <= _Epsilon); /* Y and N are almost perpendicular */ } case SemanticSelector.ALL: return(true); /* permissive */ default: throw new Exception($"Unknown {nameof(SemanticSelector)}: '{selector.ToString()}'"); } }
public ComponentSplitArg(SemanticSelector selector, ISymbol successor) { Selector = selector; Successor = successor ?? throw new ArgumentNullException(nameof(successor)); }