示例#1
0
        public static bool CalculateSolidPart(LineBorders borders, ITrajectory trajectory, float offset, float width, Color32 color, out MarkupStylePart part)
        {
            part = CalculateSolidPart(trajectory, offset, width, color);

            if (borders.IsEmpty)
            {
                return(true);
            }

            var vertex = borders.GetVertex(part);

            var from = 0f;
            var to   = 1f;

            foreach (var border in borders)
            {
                for (var i = 0; i < vertex.Length; i += 2)
                {
                    var start = Intersection.CalculateSingle(border, vertex[i]);
                    var end   = Intersection.CalculateSingle(border, vertex[i + 1]);

                    if (start.IsIntersect && end.IsIntersect)
                    {
                        return(false);
                    }

                    if (!start.IsIntersect && !end.IsIntersect)
                    {
                        continue;
                    }

                    var intersect = Intersection.CalculateSingle(border, new StraightTrajectory(vertex[i].EndPosition, vertex[i + 1].EndPosition));
                    if (intersect.IsIntersect)
                    {
                        if (start.IsIntersect)
                        {
                            from = Mathf.Max(from, intersect.SecondT);
                        }
                        else if (end.IsIntersect)
                        {
                            to = Mathf.Min(to, intersect.SecondT);
                        }
                    }
                }
            }

            if (from != 0f || to != 1f)
            {
                var dir  = part.Angle.Direction();
                var line = new StraightTrajectory(part.Position + dir * (part.Length / 2), part.Position - dir * (part.Length / 2)).Cut(from, to);
                part = new MarkupStylePart(line.StartPosition, line.EndPosition, line.Direction, part.Width, part.Color);
            }
            return(true);
        }
示例#2
0
        public static bool CalculateDashedParts(LineBorders borders, ITrajectory trajectory, float startT, float endT, float dashLength, float offset, float width, Color32 color, out MarkupStylePart part)
        {
            part = CalculateDashedPart(trajectory, startT, endT, dashLength, offset, width, color);

            if (borders.IsEmpty)
            {
                return(true);
            }

            var vertex = borders.GetVertex(part);

            return(!borders.Any(c => vertex.Any(v => Intersection.CalculateSingle(c, v).IsIntersect)));
        }