Exemplo n.º 1
0
 /// <summary>
 /// Construct a new array placement rule from scratch.
 /// </summary>
 /// <param name="definition">The element to array.</param>
 /// <param name="arrayPath">The path along which to array.</param>
 /// <param name="spacingRule">The configuration for the spacing.</param>
 /// <param name="anchorIndices">For each vertex, the index of the corresponding anchor.</param>
 /// <param name="anchorDisplacements">For each vertex, the displacement from its anchor.</param>
 /// <param name="name">The name.</param>
 public ArrayPlacementRule(GeometricElement definition, Polyline arrayPath, SpacingConfiguration spacingRule, IList <int> anchorIndices, IList <Vector3> anchorDisplacements, string name)
 {
     Curve               = arrayPath;
     AnchorIndices       = anchorIndices;
     AnchorDisplacements = anchorDisplacements;
     Name              = name;
     IsClosed          = arrayPath is Polygon;
     SpacingRule       = spacingRule;
     ElementDefinition = definition;
 }
Exemplo n.º 2
0
        /// <summary>
        /// Construct an ArrayPlacementRule from closest points using a set of reference anchors. Each polyline vertex will be associated with its closest anchor.
        /// </summary>
        /// <param name="element">The element to array.</param>
        /// <param name="polyline">The array path.</param>
        /// <param name="spacingRule">The spacing configuration.</param>
        /// <param name="Anchors">The reference anchors from which to calculate the associations.</param>
        /// <param name="name">The rule name.</param>
        public static ArrayPlacementRule FromClosestPoints(GeometricElement element, Polyline polyline, SpacingConfiguration spacingRule, IList <Vector3> Anchors, string name)
        {
            var anchorIndices       = new List <int>();
            var anchorDisplacements = new List <Vector3>();

            foreach (var v in polyline.Vertices)
            {
                var closestAnchorIndex = Enumerable.Range(0, Anchors.Count).OrderBy(a => Anchors[a].DistanceTo(v)).First();
                anchorIndices.Add(closestAnchorIndex);
                var closestAnchor = Anchors[closestAnchorIndex];
                anchorDisplacements.Add(v - closestAnchor);
            }
            return(new ArrayPlacementRule(element, polyline, spacingRule, anchorIndices, anchorDisplacements, name));
        }