コード例 #1
0
    private void add_collider(WireSegment ws)
    {
        if (tmp_obj == null || collider == null)
        {
            return;
        }

        GameObject tmp_coll = Instantiate(collider);

        tmp_coll.transform.parent = tmp_obj.transform;

        Quaternion q = new Quaternion();

        q.SetLookRotation(ws.diff.normalized, Vector3.up);
        // rotate it 90* on X
        Quaternion corrq = new Quaternion();
        float      theta = Mathf.PI * 0.5f;
        Vector3    axis  = Vector3.right;

        corrq.SetAxisAngle(axis, theta);

        tmp_coll.transform.rotation   = q * corrq;
        tmp_coll.transform.position   = tmp_obj.transform.position + ws.start + ws.diff * 0.5f;
        tmp_coll.transform.localScale = new Vector3(collider_radius, ws.diff.magnitude * 0.5f, collider_radius);

        if (tag != "")
        {
            tmp_coll.tag = tag;
        }
    }
コード例 #2
0
        public static MaterialComposition MaterialComposition(this WireSegment wire)
        {
            if (wire == null)
            {
                BH.Engine.Reflection.Compute.RecordError("Cannot query the material composition of a null wire segment.");
                return(null);
            }

            if (wire.SectionProperty == null)
            {
                Engine.Reflection.Compute.RecordError("The Duct MaterialComposition could not be calculated as no SectionProperty has been assigned.");
                return(null);
            }

            List <Material> materials = null;
            List <double>   ratios    = null;

            materials = new List <Material>()
            {
                wire.SectionProperty.ConductiveMaterial, wire.SectionProperty.InsulationMaterial
            };
            ratios = new List <double>()
            {
                wire.SectionProperty.ElementSolidArea, wire.SectionProperty.InsulationSolidArea
            };

            return(Matter.Create.MaterialComposition(materials, ratios));
        }
コード例 #3
0
    private Vector3 AdjustSegmentPosition(WireSegment segment, Vector3 newPosition)
    {
#if false
        Vector3 direction = segment.transform.position - newPosition;

        Ray ray    = new Ray(segment.transform.position, -direction.normalized);
        int result = Physics.RaycastNonAlloc(ray, hits, direction.magnitude);

        for (int i = 0; i < result; ++i)
        {
            RaycastHit hit = hits[i];

            if (hit.collider.GetComponent <Plug>())
            {
                continue;
            }

            if (hit.collider.gameObject.layer == 8)
            {
                newPosition = hit.point + (hit.normal * direction.magnitude);
                break;
            }
        }
#endif

        return(new Vector3(newPosition.x, newPosition.y, 0));
    }
コード例 #4
0
            public Wire(List <WireData> pieces)
            {
                Pieces = pieces;

                var position = new Point(0, 0);

                foreach (var piece in pieces)
                {
                    var start = new Point(position.X, position.Y);

                    switch (piece.Direction)
                    {
                    case "U":
                        position.Y += piece.Amount;
                        break;

                    case "D":
                        position.Y -= piece.Amount;
                        break;

                    case "R":
                        position.X += piece.Amount;
                        break;

                    case "L":
                        position.X -= piece.Amount;
                        break;
                    }

                    var segment = new WireSegment(start, position);
                    Segments.Add(segment);
                }
            }
コード例 #5
0
        public static void AddWireSegment(Point16 point, int color)
        {
            PointHighlight = point;

            WireSegment segment;

            if (!WireHighlight.TryGetValue(point, out segment))
            {
                if (WireHighlight.Count > maxWireVisual)
                {
                    return;
                }

                segment = new WireSegment();
                WireHighlight.Add(point, segment);
            }

            switch (color)
            {
            case 1: segment.red = true; break;

            case 2: segment.blue = true; break;

            case 3: segment.green = true; break;

            case 4: segment.yellow = true; break;
            }
        }
コード例 #6
0
    private void AdjustConstraint()
    {
        wireSegments[0].transform.position = plugs[0].transform.position;
        wireSegments[wireSegments.Count - 1].transform.position = plugs[1].transform.position;

        for (int i = 0; i < wireSegments.Count - 1; ++i)
        {
            WireSegment segment1 = wireSegments[i];
            WireSegment segment2 = wireSegments[i + 1];

            float distance   = (segment1.transform.position - segment2.transform.position).magnitude;
            float difference = Mathf.Abs(distance - SegmentLength);

            Vector2 direction = Vector2.zero;

            if (distance > SegmentLength)
            {
                direction = (segment1.transform.position - segment2.transform.position).normalized;
            }
            else if (distance < SegmentLength)
            {
                direction = (segment2.transform.position - segment1.transform.position).normalized;
            }

            Vector3 movement = direction * difference;
            segment1.transform.position = AdjustSegmentPosition(segment1, segment1.transform.position - (movement * 0.5f));
            segment2.transform.position = AdjustSegmentPosition(segment2, segment2.transform.position + (movement * 0.5f));
        }
    }
コード例 #7
0
            public bool IntersectsWith(WireSegment wire, out Point intersectionPoint)
            {
                int x = 0;
                int y = 0;

                if ((wire.From.X == wire.To.X) && (this.From.Y == this.To.Y))
                {
                    x = wire.From.X;
                    y = this.From.Y;
                }
                else if ((wire.From.Y == wire.To.Y) && (this.From.X == this.To.X))
                {
                    x = this.From.X;
                    y = wire.From.Y;
                }

                intersectionPoint = new Point(x, y);

                if (x == 0 && y == 0)
                {
                    return(false);
                }

                return(wire.IntersectsWith(intersectionPoint) &&
                       this.IntersectsWith(intersectionPoint));
            }
コード例 #8
0
        private static Segment CreateSegment(Point startingPoint, WireSegment wire, int steps)
        {
            var segment = new Segment
            {
                FirstPoint = startingPoint,
                Steps      = steps
            };

            var secondPoint = new Point(startingPoint.X, startingPoint.Y);

            switch (wire.MoveDirection)
            {
            case WireSegment.Direction.Up:
                secondPoint.Y += wire.Distance;
                break;

            case WireSegment.Direction.Down:
                secondPoint.Y -= wire.Distance;
                break;

            case WireSegment.Direction.Right:
                secondPoint.X += wire.Distance;
                break;

            case WireSegment.Direction.Left:
                secondPoint.X -= wire.Distance;
                break;
            }

            segment.SecondPoint = secondPoint;

            return(segment);
        }
コード例 #9
0
        public void OnSegmentHoriz()
        {
            var segment = new WireSegment(new Point(0, 0), new Point(5, 0));

            Assert.IsTrue(segment.ContainsPoint(segment.min), "Start point on segment");
            Assert.IsTrue(segment.ContainsPoint(new Point(3, 0)), "Mid point on segment");
            Assert.IsTrue(segment.ContainsPoint(segment.max), "End point on segment");
        }
コード例 #10
0
        public void CreateRelative()
        {
            var segment  = new WireSegment(new Point(0, 0), new Point(0, 5));
            var segment2 = segment.CreateRelative(new Point(5, 0));

            Assert.AreEqual(segment2.min, segment.max, "First Point");
            Assert.AreEqual(new Point(5, 5), segment2.max, "Second Point");
        }
コード例 #11
0
        public void Contains()
        {
            var segment  = new WireSegment(new Point(0, 0), new Point(0, 5));
            var segment2 = new WireSegment(new Point(0, 3), new Point(0, 5));

            Assert.IsTrue(segment.Contains(segment2));
            Assert.IsFalse(segment2.Contains(segment));
        }
コード例 #12
0
        public void Intersect()
        {
            var segment  = new WireSegment(new Point(0, 0), new Point(5, 0));
            var segment2 = new WireSegment(new Point(3, -2), new Point(3, 5));

            var i = segment.Intersect(segment2, out var intr);

            Assert.IsTrue(i, "Interescted");
            Assert.AreEqual(new Point(3, 0), intr, "Interesction Point");
        }
コード例 #13
0
        public void GetOverlapHoriz()
        {
            var segment  = new WireSegment(new Point(0, 0), new Point(5, 0));
            var segment2 = new WireSegment(new Point(3, 0), new Point(8, 0));
            var segment3 = new WireSegment(new Point(3, 0), new Point(5, 0));

            var overlap = segment.GetOverlap(segment2);

            Assert.AreEqual(segment2.min, overlap.min, "Start Point");
            Assert.AreEqual(segment.max, overlap.max, "End Point");
            overlap = segment.GetOverlap(segment3);
            Assert.AreEqual(segment3.min, overlap.min, "Contaiend Start");
            Assert.AreEqual(segment3.max, overlap.max, "Contaiend End");
        }
コード例 #14
0
        public void IntersectOverlappedVert()
        {
            var segment  = new WireSegment(new Point(0, 0), new Point(0, 5));
            var segment2 = new WireSegment(new Point(0, 3), new Point(0, 7));

            var i = segment.Intersect(segment2, out var intr);

            Assert.IsTrue(i, "Interescted");
            Assert.AreEqual(new Point(0, 3), intr, "Interesction Point");

            i = segment2.Intersect(segment, out intr);
            Assert.IsTrue(i, "Interescted 2");
            Assert.AreEqual(new Point(0, 3), intr, "Interesction Point 2");
        }
コード例 #15
0
ファイル: CrossedWires.cs プロジェクト: Amatsugu/AdventOfCode
 public WireSegment GetOverlap(WireSegment other)
 {
     if (Vertical)
     {
         if (other.Contains(this))
         {
             return(this);
         }
         else if (Contains(other))
         {
             return(other);
         }
         if (max.Y >= other.min.Y && min.Y <= other.min.Y && max.Y <= other.max.Y)
         {
             return(new WireSegment(other.min, max));
         }
         else if (max.Y >= other.max.Y && min.Y >= other.min.Y && min.Y <= other.max.Y)
         {
             return(new WireSegment(min, other.max));
         }
         else
         {
             throw new Exception("No Overlap");
         }
     }
     else
     {
         if (other.Contains(this))
         {
             return(this);
         }
         else if (Contains(other))
         {
             return(other);
         }
         if (max.X >= other.min.X && min.X <= other.min.X && max.X <= other.max.X)
         {
             return(new WireSegment(other.min, max));
         }
         else if (max.X >= other.max.X && min.X >= other.min.X && min.X <= other.max.X)
         {
             return(new WireSegment(min, other.max));
         }
         else
         {
             throw new Exception("No Overlap");
         }
     }
 }
コード例 #16
0
        private List <WireSegment> CreateWireSegments(string str)
        {
            var wireSegments  = new List <WireSegment>();
            var wireMovements = str.Split(',');
            var fromPoint     = new Point(0, 0);

            for (var i = 0; i < wireMovements.Length; i++)
            {
                var wireSegment = new WireSegment(fromPoint, wireMovements[i]);
                wireSegments.Add(wireSegment);
                fromPoint = wireSegment.To;
            }

            return(wireSegments);
        }
コード例 #17
0
ファイル: CrossedWires.cs プロジェクト: Amatsugu/AdventOfCode
 public bool Contains(WireSegment other)
 {
     if (Vertical != other.Vertical)
     {
         return(false);
     }
     if (Vertical)
     {
         return(min.Y <= other.min.Y && max.Y >= other.max.Y);
     }
     else
     {
         return(min.X <= other.min.X && max.X >= other.max.X);
     }
 }
コード例 #18
0
ファイル: SolidVolume.cs プロジェクト: BHoM/BHoM_Engine
        public static double SolidVolume(this WireSegment wireSegment)
        {
            double length              = wireSegment.Length();
            double elementSolidArea    = wireSegment.SectionProperty.ElementSolidArea;
            double insulationSolidArea = wireSegment.SectionProperty.InsulationSolidArea;
            double liningSolidArea     = wireSegment.SectionProperty.LiningSolidArea;

            if (length <= 0)
            {
                Engine.Reflection.Compute.RecordError("Cannot query SolidVolume from zero length members.");
                return(double.NaN);
            }

            if (wireSegment.SectionProperty.SectionProfile.ElementProfile == null)
            {
                Engine.Reflection.Compute.RecordWarning("No ElementProfile detected for object " + wireSegment.BHoM_Guid);
            }

            if (wireSegment.SectionProperty.SectionProfile.InsulationProfile == null)
            {
                Engine.Reflection.Compute.RecordWarning("No InsulationProfile detected for object " + wireSegment.BHoM_Guid);
            }

            if (wireSegment.SectionProperty.SectionProfile.LiningProfile == null)
            {
                Engine.Reflection.Compute.RecordWarning("No LiningProfile detected for object " + wireSegment.BHoM_Guid);
            }

            if (elementSolidArea <= 0)
            {
                Engine.Reflection.Compute.RecordNote("ElementSolidArea is 0. Returning 0 for ElementSolidVolume.");
            }

            if (insulationSolidArea <= 0)
            {
                Engine.Reflection.Compute.RecordNote("InsulationSolidArea is 0. Returning 0 for LiningSolidVolume.");
            }

            if (liningSolidArea <= 0)
            {
                Engine.Reflection.Compute.RecordNote("LiningSolidArea is 0. Returning 0 for InsulationSolidVolume.");
            }

            return((length * elementSolidArea) + (length * insulationSolidArea) + (length * liningSolidArea));
        }
コード例 #19
0
        public static Output <double, double, double> CompositeSolidVolumes(this WireSegment wire)
        {
            double length                = wire.Length();
            double elementSolidVolume    = wire.SectionProperty.ElementSolidArea * length;
            double insulationSolidVolume = wire.SectionProperty.InsulationSolidArea * length;
            double liningSolidVolume     = wire.SectionProperty.LiningSolidArea * length;

            if (wire.SectionProperty == null)
            {
                Engine.Reflection.Compute.RecordError("No section property defined.");
                return(null);
            }

            //Negative LiningThickness Warning
            if (wire.SectionProperty.LiningSolidArea < 0)
            {
                Engine.Reflection.Compute.RecordWarning("LiningSolidArea is a negative value, and will result in incorrect SolidVolume results. Try adjusting LiningThickness to produce a positive value for SolidArea.");
            }

            //SolidArea = 0 user feedback.
            if (wire.SectionProperty.ElementSolidArea <= 0)
            {
                Engine.Reflection.Compute.RecordNote("ElementSolidArea is 0. Returning 0 for ElementSolidVolume.");
            }

            if (wire.SectionProperty.LiningSolidArea <= 0)
            {
                Engine.Reflection.Compute.RecordNote("LiningSolidArea is 0. Returning 0 for LiningSolidVolume.");
            }

            if (wire.SectionProperty.InsulationSolidArea <= 0)
            {
                Engine.Reflection.Compute.RecordNote("InsulationSolidArea is 0. Returning 0 for InsulationSolidVolume.");
            }

            Output <double, double, double> output = new Output <double, double, double>
            {
                Item1 = elementSolidVolume,
                Item2 = insulationSolidVolume,
                Item3 = liningSolidVolume,
            };

            return(output);
        }
コード例 #20
0
        private void FindDistances2(List <WireSegment> wire1, List <WireSegment> wire2)
        {
            int distanceToIntersection = 0;

            foreach (var wireSegment1 in wire1)
            {
                foreach (var wireSegment2 in wire2)
                {
                    if (wireSegment1.IntersectsWith(wireSegment2, out var intersection))
                    {
                        var intersectionLength = new WireSegment(wireSegment1.From, intersection).Length;

                        DistancesByIntersections.TryGetValue(intersection, out int totalDistance);
                        DistancesByIntersections[intersection] = totalDistance + distanceToIntersection + intersectionLength;
                    }
                }
                distanceToIntersection += wireSegment1.Length;
            }
        }
コード例 #21
0
    void Awake()
    {
        Assert.IsNotNull(plugs[0]);
        Assert.IsNotNull(plugs[1]);

        plugs[0].wire = this;
        plugs[1].wire = this;

        Vector3 start     = plugs[0].transform.position;
        Vector3 end       = plugs[1].transform.position;
        Vector3 direction = end - start;

        int totalSegments = Mathf.CeilToInt((extraLength + direction.magnitude) / SegmentLength);

        float adjustedSegmentLength = direction.magnitude / totalSegments;

        direction = direction.normalized;

        for (int i = 0; i < totalSegments; ++i)
        {
            WireSegment node = (GameObject.Instantiate(Resources.Load("WireSegment") as GameObject)).GetComponent <WireSegment>();
            node.transform.position = start;
            node.previousPosition   = start;

            wireSegments.Add(node);

            start += direction * adjustedSegmentLength;
        }

        Material material = new Material(Shader.Find("Unlit/VertexColor"));

        lineRenderer            = gameObject.AddComponent(typeof(LineRenderer)) as LineRenderer;
        lineRenderer.startWidth = LineWidth;
        lineRenderer.endWidth   = LineWidth;
        lineRenderer.startColor = Color.white;
        lineRenderer.endColor   = Color.white;
        lineRenderer.material   = material;

        segmentPositions = new Vector3[totalSegments];
    }
コード例 #22
0
 public bool IsPointNearSegment(WireSegment segment, DiagramPoint p, float threshold)
 {
     return(false);
 }
コード例 #23
0
 public void AddWireEnding(WireSegment segment)
 {
     Extend(ref wiresEnding, segment);
 }
コード例 #24
0
 public void AddWireContaining(WireSegment segment)
 {
     Extend(ref wiresContaining, segment);
 }
コード例 #25
0
        public static void CheckForMerges(ILayoutAccess lo, LayoutWiringPoints wireData, IEnumerable <Location> toCheck)
        {
            HashSet <Location>    done    = new HashSet <Location>();
            HashSet <WireSegment> toMerge = new HashSet <WireSegment>();
            List <WireSegment>    w0s     = new List <WireSegment>();
            List <WireSegment>    w1s     = new List <WireSegment>();

            foreach (Location loc in toCheck)
            {
                if (!done.Contains(loc) && !wireData.IsPortAt(loc))
                {
                    done.Add(loc);
                    WireSegment w0        = null;
                    WireSegment w1        = null;
                    bool        moreFound = false;
                    foreach (WireSegment w in wireData.GetWiresEndingAt(loc))
                    {
                        if (w0 == null)
                        {
                            w0 = w;
                        }
                        else if (w1 == null)
                        {
                            w1 = w;
                        }
                        else
                        {
                            moreFound = true;
                            break;
                        }
                    }
                    if (!moreFound && w1 != null && w0.IsCollinear(w1, Constants.GRID_SIZE))
                    {
                        w0s.Add(w0);
                        w1s.Add(w1);
                        toMerge.Add(w0);
                        toMerge.Add(w1);
                    }
                }
            }

            UnionFind <WireSegment> uf = new UnionFind <WireSegment>(toMerge);

            for (int i = 0; i < w0s.Count; i++)
            {
                uf[w0s[i]].Unite(uf[w1s[i]]);
            }
            foreach (UnionFindNode <WireSegment> root in uf.Roots)
            {
                List <Location> locs = new List <Location>();
                foreach (UnionFindNode <WireSegment> member in root.GetSetMembers())
                {
                    WireSegment w = member.Value;
                    lo.RemoveWire(w);
                    locs.Add(w.End0);
                    locs.Add(w.End1);
                }
                locs.Sort(Location.XComparer);
                lo.AddWire(locs[0], locs[locs.Count - 1]);
            }
        }
コード例 #26
0
 /// <summary>
 /// Auto layout the branch of the given wire, of which the termianl is a part.
 /// </summary>
 /// <param name="segment">The segment.</param>
 /// <param name="wire">The wire.</param>
 public void CleanUpBranch(WireSegment segment, Wire wire)
 {
 }
コード例 #27
0
 public void VisitWireSegment(WireSegment wireSegment)
 {
 }
コード例 #28
0
 public DiagramPoint GetNearestPointOnSegment(WireSegment segment, DiagramPoint p)
 {
     return(new DiagramPoint());
 }
コード例 #29
0
        private static void AddWireSegment(ILayoutAccess lo, LayoutWiringPoints wiringData, WireSegment proposedSeg)
        {
            Location loc0 = proposedSeg.End0;
            Location loc1 = proposedSeg.End1;
            Dictionary <WireSegment, Location?> intersects = new Dictionary <WireSegment, Location?>();
            List <Location> breaks = new List <Location>();

            foreach (WireSegment w in wiringData.GetWiresContaining(loc0))
            {
                intersects[w] = intersects.ContainsKey(w) ? (Location?)null : loc0;
            }
            foreach (WireSegment w in wiringData.GetWiresContaining(loc1))
            {
                intersects[w] = intersects.ContainsKey(w) ? (Location?)null : loc1;
            }
            foreach (Location loc in proposedSeg.GetLocationsOnWire(Constants.GRID_SIZE, false))
            {
                foreach (WireSegment w in wiringData.GetWiresEndingAt(loc))
                {
                    intersects[w] = intersects.ContainsKey(w) ? (Location?)null : loc;
                }
                if (wiringData.IsPortAt(loc))
                {
                    breaks.Add(loc);
                }
            }

            List <WireSegment> toRemove  = new List <WireSegment>();
            List <WireSegment> toAdd     = new List <WireSegment>();
            List <Location>    endpoints = new List <Location>();

            endpoints.Add(loc0);
            endpoints.Add(loc1);
            foreach (WireSegment w in intersects.Keys)
            {
                Location?intersect = intersects[w];
                if (!intersect.HasValue)   // segment crosses both endpoints - delete subsegment
                {
                    toRemove.Add(w);
                }
                else if (w.IsCollinear(proposedSeg, Constants.GRID_SIZE))
                {
                    toRemove.Add(w);
                    endpoints.Add(w.End0);
                    endpoints.Add(w.End1);
                }
                else     // segment crosses over this one - maybe we should split it
                {
                    Location at = intersect.Value;
                    breaks.Add(at);
                    if (at != w.End0 && at != w.End1)
                    {
                        toRemove.Add(w);
                        toAdd.Add(new WireSegment(w.End0, at));
                        toAdd.Add(new WireSegment(at, w.End1));
                    }
                }
            }
            endpoints.Sort(Location.XComparer);
            breaks.Add(endpoints[0]);
            breaks.Add(endpoints[endpoints.Count - 1]);

            breaks.Sort(Location.XComparer);
            Location cur = breaks[0];

            foreach (Location loc in breaks)
            {
                if (cur != loc)
                {
                    toAdd.Add(new WireSegment(cur, loc));
                    cur = loc;
                }
            }

            foreach (WireSegment seg in toRemove)
            {
                lo.RemoveWire(seg);
            }
            foreach (WireSegment seg in toAdd)
            {
                lo.AddWire(seg.End0, seg.End1);
            }
        }
コード例 #30
0
ファイル: CrossedWires.cs プロジェクト: Amatsugu/AdventOfCode
 public bool Intersect(WireSegment other, out Point intersection)
 {
     if (Vertical)
     {
         if (!other.Vertical)                   //Other Horizontal
         {
             var potInt = new Point(min.X, other.min.Y);
             if (potInt == default)
             {
                 intersection = default;
                 return(false);
             }
             if (ContainsPoint(potInt) && other.ContainsPoint(potInt))
             {
                 intersection = potInt;
                 return(true);
             }
             else
             {
                 intersection = default;
                 return(false);
             }
         }
         else                      //Both
         {
             if (min.X != other.min.X)
             {
                 intersection = default;
                 return(false);
             }
             else
             {
                 var overlap = GetOverlap(other);
                 if (overlap.min.ManhattanMagnitude() < overlap.max.ManhattanMagnitude())
                 {
                     intersection = overlap.min == default ? overlap.max : overlap.min;
                 }
                 else
                 {
                     intersection = overlap.max == default ? overlap.min : overlap.max;
                 }
                 if (intersection == default)
                 {
                     return(false);
                 }
                 return(true);
             }
         }
     }
     else
     {
         if (!other.Vertical)                    //Other Horizontal
         {
             if (min.Y != other.min.Y)
             {
                 intersection = default;
                 return(false);
             }
             var overlap = GetOverlap(other);
             if (overlap.min.ManhattanMagnitude() < overlap.max.ManhattanMagnitude())
             {
                 intersection = overlap.min == default ? overlap.max : overlap.min;
             }
             else
             {
                 intersection = overlap.max == default ? overlap.min : overlap.max;
             }
             if (intersection == default)
             {
                 return(false);
             }
             return(true);
         }
         else
         {
             return(other.Intersect(this, out intersection));
         }
     }
 }