示例#1
0
        public static void infinite_magnitude() {
            var line = new Line2(new Point2(1, 2), new Vector2(3, 4));

            var magnitude = line.GetMagnitude();

            magnitude.Should().Be(Double.PositiveInfinity);
        }
 public void Cancel()
 {
     mFace = null;
     Started = false;
     mLine = default( Line2 );
     mTexture = null;
 }
示例#3
0
        public static void direction_calculation_from_constructor() {
            var a = new Line2(new Point2(2, 1), new Point2(-1, 3));
            var b = new Line2(new Point2(5, -1), new Point2(10, 1));

            a.Direction.Should().Be(new Vector2(-3, 2));
            b.Direction.Should().Be(new Vector2(5, 2));
        }
        public void Collides_RectangleEnvelopsLineFromLeft_ReturnsTrue()
        {
            rectangle = new Rectangle2(0, -3, 8, 3);
            verticalLine = new Line2(10, -1, 10, 1);
            movement = new Vector2(4, 0);

            Assert.IsTrue(CollisionDetector.Collides(rectangle, movement, verticalLine));
        }
        public void Collides_RectangleMovesAcrossLineButUnderIt_ReturnsFalse()
        {
            rectangle = new Rectangle2(-20, 20, 20, -20);
            verticalLine = new Line2(50, -50, 50, 50);
            movement = new Vector2(50, -150);

            Assert.IsFalse(CollisionDetector.Collides(rectangle, movement, verticalLine));
        }
示例#6
0
        public static void interface_point_extraction() {
            var p = new Point2(1, 2);
            var line = new Line2(p, new Vector2(3, 4));

            var explicitP = ((ILine2<double>)line).P;

            explicitP.Should().Be(p);
        }
示例#7
0
        public static void can_copy_with_constructor() {
            var first = new Line2(new Point2(1, 2), new Point2(4, 5));

            var clone = new Line2(first);

            clone.P.Should().Be(first.P);
            clone.Direction.Should().Be(first.Direction);
        }
示例#8
0
        public static void construct_point_and_vector() {
            var a = new Point2(1, 2);
            var d = new Vector2(3, 4);

            var line = new Line2(a, d);

            line.P.Should().Be(a);
            line.Direction.Should().Be(d);
        }
示例#9
0
        public static void construct_point_to_point() {
            var a = new Point2(1, 2);
            var b = new Point2(3, 5);
            
            var line = new Line2(a, b);

            line.P.Should().Be(a);
            line.Direction.Should().Be(new Vector2(2, 3));
        }
        public OneWayPlatform( CubeGame game, World world, Body body, Line2 line )
            : base(game, world, body)
        {
            mLine = line - line.Center;

            mPlatform = Body.FindFixture( new SolidDescriptor( "platform" ) );
            mExclusionRec = Body.FindFixture( new SolidDescriptor( "exclusion" ) );

            Initialize();
        }
        public static void line_line_intersection_result()
        {
            var a = new Line2(A, B);
            var b = new Line2(C, D);

            var forward = a.Intersection(b);
            var reverse = b.Intersection(a);

            forward.Should().NotBeNull();
            forward.Should().Be(reverse);
        }
示例#12
0
        public static void basic_equality() {
            var a = new Line2(new Point2(1, 3), new Point2(2, 5));
            var b = new Line2(new Point2(1, 3), new Point2(2, 5));
            var c = new Line2(new Point2(0, 2), new Point2(5, 6));
            var d = new Line2(new Point2(2, 5), new Point2(1, 3));

            a.Should().Be(b);
            b.Should().Be(a);
            a.Should().NotBe(c);
            c.Should().NotBe(a);
            a.Should().NotBe(d);
            d.Should().NotBe(a);
        }
        public static void line_ray_intersection_result()
        {
            var a1 = new Line2(A, B);
            var a2 = new Line2(B, A);
            var b = new Ray2(C, D);

            var forward1 = a1.Intersection(b);
            var forward2 = a2.Intersection(b);
            var reverse1 = b.Intersection(a1);
            var reverse2 = b.Intersection(a2);

            forward1.Should().NotBeNull();
            forward1.Should().Be(forward2);
            forward1.Should().Be(reverse1);
            forward1.Should().Be(reverse2);
        }
        public static void line_segment_intersection_result()
        {
            var a1 = new Line2(A, B);
            var a2 = new Line2(B, A);
            var b1 = new Segment2(C, D);
            var b2 = new Segment2(D, C);

            var forward1 = a1.Intersection(b1);
            var forward2 = a2.Intersection(b2);
            var reverse1 = b1.Intersection(a1);
            var reverse2 = b2.Intersection(a2);

            forward1.Should().NotBeNull();
            forward1.Should().Be(forward2);
            forward1.Should().Be(reverse1);
            forward1.Should().Be(reverse2);
        }
示例#15
0
        public bool Intersect(Line2 b)
        {
            var n = (b.end - b.start).normalized;
            if (n == (end - b.start).normalized || n == (start - b.end).normalized)
                return true;

            var A1 = end.y - start.y;
            var B1 = start.x - end.x;
            var C1 = -A1 * start.x - B1 * start.y;

            var A2 = b.end.y - b.start.y;
            var B2 = b.start.x - b.end.x;
            var C2 = -A2 * b.start.x - B2 * b.start.y;

            var f1 = A1 * b.start.x + B1 * b.start.y + C1;
            var f2 = A1 * b.end.x + B1 * b.end.y + C1;
            var f3 = A2 * start.x + B2 * start.y + C2;
            var f4 = A2 * end.x + B2 * end.y + C2;

            return f1 * f2 < Mathf.Epsilon && f3 * f4 < Mathf.Epsilon; // строгое пересечение
        }
#pragma warning disable 108,114
        public virtual ToolBase.ToolErrors CheckBuildPosition(bool test, bool visualize, bool overlay, bool autofix,
#pragma warning restore 108,114
                                                              ref NetTool.ControlPoint startPoint, ref NetTool.ControlPoint middlePoint, ref NetTool.ControlPoint endPoint,
                                                              out BuildingInfo ownerBuilding, out Vector3 ownerPosition, out Vector3 ownerDirection,
                                                              out int productionRate)
        {
            ownerBuilding  = null;
            ownerPosition  = Vector3.zero;
            ownerDirection = Vector3.forward;
            productionRate = 0;
            ToolBase.ToolErrors toolErrors = ToolBase.ToolErrors.None;
            if (test)
            {
                ushort num = middlePoint.m_segment;
                if (startPoint.m_segment == num || endPoint.m_segment == num)
                {
                    num = 0;
                }
                if (num != 0 && Singleton <NetManager> .instance.m_segments.m_buffer[(int)num].Info == this.m_info)
                {
                    if (ZoneBlocksOffset.Mode == ZoneBlocksOffsetMode.Default)
                    {
                        toolErrors |= ToolBase.ToolErrors.CannotUpgrade;
                    }
                    else
                    {
                        // Do nothing
                    }
                }
            }
            if (autofix && this.m_info.m_enableBendingSegments)
            {
                Vector3 vector          = middlePoint.m_direction;
                Vector3 vector2         = -endPoint.m_direction;
                Vector3 vector3         = middlePoint.m_position;
                float   minNodeDistance = this.m_info.GetMinNodeDistance();
                for (int i = 0; i < 3; i++)
                {
                    bool flag  = false;
                    bool flag2 = false;
                    if (startPoint.m_node != 0)
                    {
                        if (ForceValidDirection(this.m_info, ref vector, startPoint.m_node,
                                                ref Singleton <NetManager> .instance.m_nodes.m_buffer[(int)startPoint.m_node]))
                        {
                            flag = true;
                        }
                    }
                    else if (startPoint.m_segment != 0 &&
                             ForceValidDirection(this.m_info, startPoint.m_position, ref vector,
                                                 startPoint.m_segment,
                                                 ref Singleton <NetManager> .instance.m_segments.m_buffer[(int)startPoint.m_segment]))
                    {
                        flag = true;
                    }
                    if (flag)
                    {
                        Line2 line  = Line2.XZ(startPoint.m_position, startPoint.m_position + vector);
                        Line2 line2 = Line2.XZ(endPoint.m_position, endPoint.m_position + vector2);
                        bool  flag3 = true;
                        float num2;
                        float num3;
                        if (line.Intersect(line2, out num2, out num3) && num2 >= minNodeDistance &&
                            num3 >= minNodeDistance)
                        {
                            vector3 = startPoint.m_position + vector * num2;
                            flag3   = false;
                        }
                        if (flag3)
                        {
                            Vector3 vector4 = endPoint.m_position - startPoint.m_position;
                            Vector3 vector5 = vector;
                            vector4.y = 0f;
                            vector5.y = 0f;
                            float num4 = Vector3.SqrMagnitude(vector4);
                            vector4 = Vector3.Normalize(vector4);
                            float num5 = Mathf.Min(1.17809725f, Mathf.Acos(Vector3.Dot(vector4, vector5)));
                            float d    = Mathf.Sqrt(0.5f * num4 / Mathf.Max(0.001f, 1f - Mathf.Cos(3.14159274f - 2f * num5)));
                            vector3   = startPoint.m_position + vector5 * d;
                            vector2   = vector3 - endPoint.m_position;
                            vector2.y = 0f;
                            vector2.Normalize();
                        }
                    }
                    if (endPoint.m_node != 0)
                    {
                        if (ForceValidDirection(this.m_info, ref vector2, endPoint.m_node,
                                                ref Singleton <NetManager> .instance.m_nodes.m_buffer[(int)endPoint.m_node]))
                        {
                            flag2 = true;
                        }
                    }
                    else if (endPoint.m_segment != 0 &&
                             ForceValidDirection(this.m_info, endPoint.m_position, ref vector2, endPoint.m_segment,
                                                 ref Singleton <NetManager> .instance.m_segments.m_buffer[(int)endPoint.m_segment]))
                    {
                        flag2 = true;
                    }
                    if (flag2)
                    {
                        Line2 line3 = Line2.XZ(startPoint.m_position, startPoint.m_position + vector);
                        Line2 line4 = Line2.XZ(endPoint.m_position, endPoint.m_position + vector2);
                        bool  flag4 = true;
                        float num6;
                        float num7;
                        if (line3.Intersect(line4, out num6, out num7) && num6 >= minNodeDistance &&
                            num7 >= minNodeDistance)
                        {
                            vector3 = endPoint.m_position + vector2 * num7;
                            flag4   = false;
                        }
                        if (flag4)
                        {
                            Vector3 vector6 = startPoint.m_position - endPoint.m_position;
                            Vector3 vector7 = vector2;
                            vector6.y = 0f;
                            vector7.y = 0f;
                            float num8 = Vector3.SqrMagnitude(vector6);
                            vector6 = Vector3.Normalize(vector6);
                            float num9 = Mathf.Min(1.17809725f, Mathf.Acos(Vector3.Dot(vector6, vector7)));
                            float d2   = Mathf.Sqrt(0.5f * num8 / Mathf.Max(0.001f, 1f - Mathf.Cos(3.14159274f - 2f * num9)));
                            vector3  = endPoint.m_position + vector7 * d2;
                            vector   = vector3 - startPoint.m_position;
                            vector.y = 0f;
                            vector.Normalize();
                        }
                    }
                    if (!flag && !flag2)
                    {
                        middlePoint.m_direction = vector;
                        endPoint.m_direction    = -vector2;
                        middlePoint.m_position  = vector3;
                        break;
                    }
                }
            }
            return(toolErrors);
        }
示例#17
0
        public string ToHtmlString()
        {
            StringBuilder sb = new StringBuilder();

            if (NickName.Trim().Length > 0)
            {
                sb.Append("<em>" + NickName + "</em><br />");
            }
            if (LastName.Length > 0 || FirstName.Length > 0)
            {
                sb.Append(FirstName);
                if (MiddleInitial.Trim().Length > 0)
                {
                    sb.Append(" " + MiddleInitial);
                }
                sb.Append(" " + LastName + "<br />");
                if (Company.Trim().Length > 0)
                {
                    sb.Append(Company + "<br />");
                }
            }
            if (Line1.Length > 0)
            {
                sb.Append(Line1 + "<br />");
            }
            if (Line2.Trim().Length > 0)
            {
                sb.Append(Line2 + "<br />");
            }
            if (Line3.Trim().Length > 0)
            {
                sb.Append(Line3 + "<br />");
            }

            MerchantTribe.Web.Geography.Country c = MerchantTribe.Web.Geography.Country.FindByBvin(CountryBvin);
            MerchantTribe.Web.Geography.Region  r = c.Regions.Where(y => y.Abbreviation == RegionBvin).FirstOrDefault();

            if (r != null)
            {
                sb.Append(City + ", " + r.Abbreviation + " " + _PostalCode + "<br />");
            }
            else
            {
                if (RegionName.Trim().Length > 0)
                {
                    sb.Append(City + ", " + RegionName + " " + _PostalCode + "<br />");
                }
                else
                {
                    sb.Append(City + ", " + _PostalCode + "<br />");
                }
            }
            if (c != null)
            {
                sb.Append(c.DisplayName + "<br />");
            }

            if (Phone.Trim().Length > 0)
            {
                sb.Append(Phone + "<br />");
            }
            if (Fax.Trim().Length > 0)
            {
                sb.Append("Fax: " + Fax + "<br />");
            }
            if (WebSiteUrl.Trim().Length > 0)
            {
                sb.Append(WebSiteUrl + "<br />");
            }
            return(sb.ToString());
        }
示例#18
0
 private void IsTrue_Intersect(Line2 line, Segment2 segment, out IntersectionLineSegment2 intersection)
 {
     Assert.IsTrue(Geometry.IntersectLineSegment(line.origin, line.direction, segment.a, segment.b, out intersection),
                   line.ToString("F8") + "\n" + segment.ToString("F8"));
 }
示例#19
0
        private void AreEqual_Distance(Line2 line, Ray2D ray, float expected = 0)
        {
            string message = string.Format(format, line, ray.ToString("F8"));

            AreEqual(Distance.LineRay(line, ray), expected, message);
        }
        public void FindCollision_RectangleStartsInsideLineMovesRight_ReturnsMinus1()
        {
            rectangle = new Rectangle2(-2, -2, 2, 2);
            movement = new Vector2(-2, 0);
            verticalLine = new Line2(0, 5, 0, -5);

            Assert.AreEqual(-1, CollisionDetector.FindCollision(rectangle, movement, verticalLine).Value.Value);
        }
示例#21
0
文件: Address.cs 项目: wncoder/core
        /// <summary>
        ///     Allows you to compare another address object to determine if the two addresses are the same.
        /// </summary>
        /// <param name="a2">Another address object.</param>
        /// <returns>If true, the current address matches the address in the parameter.</returns>
        public bool IsEqualTo(Address a2)
        {
            if (a2 == null)
            {
                return(false);
            }

            var result = true;

            if (string.Compare(NickName.Trim(), a2.NickName.Trim(), true, CultureInfo.InvariantCulture) != 0)
            {
                result = false;
            }
            if (string.Compare(FirstName.Trim(), a2.FirstName.Trim(), true, CultureInfo.InvariantCulture) != 0)
            {
                result = false;
            }
            if (string.Compare(MiddleInitial.Trim(), a2.MiddleInitial.Trim(), true, CultureInfo.InvariantCulture) != 0)
            {
                result = false;
            }
            if (string.Compare(LastName.Trim(), a2.LastName.Trim(), true, CultureInfo.InvariantCulture) != 0)
            {
                result = false;
            }
            if (string.Compare(Company.Trim(), a2.Company.Trim(), true, CultureInfo.InvariantCulture) != 0)
            {
                result = false;
            }
            if (string.Compare(Line1.Trim(), a2.Line1.Trim(), true, CultureInfo.InvariantCulture) != 0)
            {
                result = false;
            }
            if (string.Compare(Line2.Trim(), a2.Line2.Trim(), true, CultureInfo.InvariantCulture) != 0)
            {
                result = false;
            }
            if (string.Compare(Line3.Trim(), a2.Line3.Trim(), true, CultureInfo.InvariantCulture) != 0)
            {
                result = false;
            }
            if (string.Compare(RegionBvin.Trim(), a2.RegionBvin.Trim(), true, CultureInfo.InvariantCulture) != 0)
            {
                result = false;
            }
            if (string.Compare(City.Trim(), a2.City.Trim(), true, CultureInfo.InvariantCulture) != 0)
            {
                result = false;
            }
            if (string.Compare(PostalCode.Trim(), a2.PostalCode.Trim(), true, CultureInfo.InvariantCulture) != 0)
            {
                result = false;
            }
            if (string.Compare(CountryBvin.Trim(), a2.CountryBvin.Trim(), true, CultureInfo.InvariantCulture) != 0)
            {
                result = false;
            }
            if (string.Compare(Phone.Trim(), a2.Phone.Trim(), true, CultureInfo.InvariantCulture) != 0)
            {
                result = false;
            }
            if (string.Compare(Fax.Trim(), a2.Fax.Trim(), true, CultureInfo.InvariantCulture) != 0)
            {
                result = false;
            }
            if (string.Compare(WebSiteUrl.Trim(), a2.WebSiteUrl.Trim(), true, CultureInfo.InvariantCulture) != 0)
            {
                result = false;
            }
            //if (this.Residential != a2.Residential) {
            //    result = false;
            //}

            return(result);
        }
示例#22
0
文件: Tle.cs 项目: rwright56/SGP.NET
        private void Initialize()
        {
            if (!IsValidLineLength(Line1))
            {
                throw new TleException("Invalid length for line one");
            }

            if (!IsValidLineLength(Line2))
            {
                throw new TleException("Invalid length for line two");
            }

            if (Line1[0] != '1')
            {
                throw new TleException("Invalid line beginning for line one");
            }

            if (Line2[0] != '2')
            {
                throw new TleException("Invalid line beginning for line two");
            }

            ExtractInteger(Line1.Substring(Tle1ColNoradnum,
                                           Tle1LenNoradnum), out var satNumber1);
            ExtractInteger(Line2.Substring(Tle2ColNoradnum,
                                           Tle2LenNoradnum), out var satNumber2);

            if (satNumber1 != satNumber2)
            {
                throw new TleException("Satellite numbers do not match");
            }

            NoradNumber = satNumber1;

            if (Name == "")
            {
                Name = Line1.Substring(Tle1ColNoradnum, Tle1LenNoradnum);
            }

            IntDesignator = Line1.Substring(Tle1ColIntldescA,
                                            Tle1LenIntldescA + Tle1LenIntldescB + Tle1LenIntldescC);

            ExtractInteger(Line1.Substring(Tle1ColEpochA,
                                           Tle1LenEpochA), out var year);
            ExtractDouble(Line1.Substring(Tle1ColEpochB,
                                          Tle1LenEpochB), 4, out var day);
            ExtractDouble(Line1.Substring(Tle1ColMeanmotiondt2,
                                          Tle1LenMeanmotiondt2), 2, out _meanMotionDt2);
            ExtractExponential(Line1.Substring(Tle1ColMeanmotionddt6,
                                               Tle1LenMeanmotionddt6), out _meanMotionDdt6);
            ExtractExponential(Line1.Substring(Tle1ColBstar,
                                               Tle1LenBstar), out _bstar);

            ExtractDouble(Line2.Substring(Tle2ColInclination,
                                          Tle2LenInclination), 4, out _inclination);
            ExtractDouble(Line2.Substring(Tle2ColRaascendnode,
                                          Tle2LenRaascendnode), 4, out _rightAscendingNode);
            ExtractDouble(Line2.Substring(Tle2ColEccentricity,
                                          Tle2LenEccentricity), -1, out _eccentricity);
            ExtractDouble(Line2.Substring(Tle2ColArgperigee,
                                          Tle2LenArgperigee), 4, out _argumentPerigee);
            ExtractDouble(Line2.Substring(Tle2ColMeananomaly,
                                          Tle2LenMeananomaly), 4, out _meanAnomaly);
            ExtractDouble(Line2.Substring(Tle2ColMeanmotion,
                                          Tle2LenMeanmotion), 3, out _meanMotion);
            ExtractInteger(Line2.Substring(Tle2ColRevatepoch,
                                           Tle2LenRevatepoch), out _orbitNumber);

            if (year < 57)
            {
                year += 2000;
            }
            else
            {
                year += 1900;
            }
            Epoch = new DateTime((int)year, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddDays(day - 1);
        }
示例#23
0
 public static void DrawLine( this SpriteBatch batch, Line2 line, Texture2D texture, Color color, float thickness = 1 )
 {
     batch.DrawLine( line.P0, line.P1, texture, color, thickness );
 }
示例#24
0
    //line->circle entry point
    public static bool LineCircleClosestIntersection(float cx, float cy, float radius, Line2 line, out Vector2 intersection)
    {
        int intersections = FindLineCircleIntersections(cx, cy, radius, line, out Vector2 intersection1, out Vector2 intersection2);

        if (intersections == 1)
        {
            intersection = intersection1;
            return(true);
        }

        if (intersections == 2)
        {
            float dist1 = (intersection1 - line.start).sqrMagnitude;
            float dist2 = (intersection2 - line.start).sqrMagnitude;
            intersection = dist1 < dist2 ? intersection1 : intersection2;
            return(true);
        }

        intersection = new Vector2(float.NaN, float.NaN);
        return(false);
    }
示例#25
0
 //is the point within rectangular bounding box area of a line
 public static bool PointWithinLineBox(Vector2 point, Line2 line)
 {
     return((Mathf.Min(line.start.x, line.end.x) <= point.x) && (point.x <= Mathf.Max(line.start.x, line.end.x)) &&
            (Mathf.Min(line.start.y, line.end.y) <= point.y) && (point.y <= Mathf.Max(line.start.y, line.end.y)));
 }
示例#26
0
        private void AreEqual_Distance(Line2 lineA, Line2 lineB, float expected = 0)
        {
            string message = string.Format(linesFormat, lineA, lineB);

            AreEqual(Distance.LineLine(lineA, lineB), expected, message);
        }
示例#27
0
 private void IsFalse_Intersect(Line2 lineA, Line2 lineB)
 {
     Assert.IsFalse(Intersect.LineLine(lineA, lineB, out _), linesFormat, lineA, lineB);
     Assert.IsFalse(Intersect.LineLine(lineB, lineA, out _), linesFormat, lineA, lineB);
 }
示例#28
0
 private void Intersect_LineSwap(Line2 lineA, Line2 lineB)
 {
     Intersect_Line(lineA, lineB);
     Intersect_Line(lineB, lineA);
 }
        public void FindCollision_RectangleCollidesWithSideOfLine_ReturnsNull()
        {
            rectangle = new Rectangle2(-50, 25, 0, -25);
            horizontalLine = new Line2(50, -50, 100, -50);
            movement = new Vector2(100, -100);

            Assert.IsNull(CollisionDetector.FindCollision(rectangle, movement, horizontalLine));
        }
 protected void DrawLine(ref Line2 line)
 {
     Gizmos.DrawLine(line.Center - line.Direction * _lineLength, line.Center + line.Direction * _lineLength);
 }
        public void FindCollision_RectangleMovesFullyAcrossLineFromRight_Returns0p4()
        {
            rectangle = new Rectangle2(9, -1, 11, 1);
            movement = new Vector2(-10, 0);
            verticalLine = new Line2(5, 5, 5, -5);

            Assert.AreEqual(0.4f, CollisionDetector.FindCollision(rectangle, movement, verticalLine).Value.Value);
        }
示例#32
0
        private static void CreateZoneBlocksTiny_Curve(NetInfo info, Randomizer randomizer, ref NetSegment segment)
        {
            var minHalfWidth = MIN_HALFWIDTH_TINY_CURVE;

            NetManager instance       = Singleton <NetManager> .instance;
            Vector3    startPosition  = instance.m_nodes.m_buffer[(int)segment.m_startNode].m_position;
            Vector3    endPosition    = instance.m_nodes.m_buffer[(int)segment.m_endNode].m_position;
            Vector3    startDirection = segment.m_startDirection;
            Vector3    endDirection   = segment.m_endDirection;
            float      num            = startDirection.x * endDirection.x + startDirection.z * endDirection.z;
            float      num2           = Mathf.Max(minHalfWidth, info.m_halfWidth);
            float      num3           = 32f;
            int        distance       = Mathf.RoundToInt(num2);
            float      num4           = VectorUtils.LengthXZ(endPosition - startPosition);
            bool       flag2          = startDirection.x * endDirection.z - startDirection.z * endDirection.x > 0f;
            bool       flag3          = num <-0.8f || num4> 50f;

            if (flag2)
            {
                num2 = -num2;
                num3 = -num3;
            }
            Vector3 vector  = startPosition - new Vector3(startDirection.z, 0f, -startDirection.x) * num2;
            Vector3 vector2 = endPosition + new Vector3(endDirection.z, 0f, -endDirection.x) * num2;
            Vector3 vector3;
            Vector3 vector4;

            NetSegment.CalculateMiddlePoints(vector, startDirection, vector2, endDirection, true, true, out vector3, out vector4);
            if (flag3)
            {
                float num5 = num * 0.025f + 0.04f;
                float num6 = num * 0.025f + 0.06f;
                if (num < -0.9f)
                {
                    num6 = num5;
                }
                Bezier3 bezier = new Bezier3(vector, vector3, vector4, vector2);
                vector  = bezier.Position(num5);
                vector3 = bezier.Position(0.5f - num6);
                vector4 = bezier.Position(0.5f + num6);
                vector2 = bezier.Position(1f - num5);
            }
            else
            {
                Bezier3 bezier2 = new Bezier3(vector, vector3, vector4, vector2);
                vector3 = bezier2.Position(0.86f);
                vector  = bezier2.Position(0.14f);
            }
            float   num7;
            Vector3 vector5 = VectorUtils.NormalizeXZ(vector3 - vector, out num7);
            int     num8    = Mathf.FloorToInt(num7 / 8f + 0.01f);
            float   num9    = num7 * 0.5f + (float)(num8 - 8) * ((!flag2) ? -4f : 4f);

            if (num8 != 0)
            {
                float   angle     = (!flag2) ? Mathf.Atan2(vector5.x, -vector5.z) : Mathf.Atan2(-vector5.x, vector5.z);
                Vector3 position3 = vector + new Vector3(vector5.x * num9 - vector5.z * num3, 0f, vector5.z * num9 + vector5.x * num3);
                if (flag2)
                {
                    Singleton <ZoneManager> .instance.CreateBlock(
                        out segment.m_blockStartRight,
                        ref randomizer,
                        position3,
                        angle,
                        num8,
                        distance,
                        segment.m_buildIndex);
                }
                else
                {
                    Singleton <ZoneManager> .instance.CreateBlock(
                        out segment.m_blockStartLeft,
                        ref randomizer,
                        position3,
                        angle,
                        num8,
                        distance,
                        segment.m_buildIndex);
                }
            }
            if (flag3)
            {
                vector5 = VectorUtils.NormalizeXZ(vector2 - vector4, out num7);
                num8    = Mathf.FloorToInt(num7 / 8f + 0.01f);
                num9    = num7 * 0.5f + (float)(num8 - 8) * ((!flag2) ? -4f : 4f);
                if (num8 != 0)
                {
                    float   angle2    = (!flag2) ? Mathf.Atan2(vector5.x, -vector5.z) : Mathf.Atan2(-vector5.x, vector5.z);
                    Vector3 position4 = vector4 + new Vector3(vector5.x * num9 - vector5.z * num3, 0f, vector5.z * num9 + vector5.x * num3);
                    if (flag2)
                    {
                        Singleton <ZoneManager> .instance.CreateBlock(
                            out segment.m_blockEndRight,
                            ref randomizer,
                            position4,
                            angle2,
                            num8,
                            distance,
                            segment.m_buildIndex + 1u);
                    }
                    else
                    {
                        Singleton <ZoneManager> .instance.CreateBlock(
                            out segment.m_blockEndLeft,
                            ref randomizer,
                            position4,
                            angle2,
                            num8,
                            distance,
                            segment.m_buildIndex + 1u);
                    }
                }
            }
            Vector3 vector6 = startPosition + new Vector3(startDirection.z, 0f, -startDirection.x) * num2;
            Vector3 vector7 = endPosition - new Vector3(endDirection.z, 0f, -endDirection.x) * num2;
            Vector3 b;
            Vector3 c;

            NetSegment.CalculateMiddlePoints(vector6, startDirection, vector7, endDirection, true, true, out b, out c);
            Bezier3 bezier3 = new Bezier3(vector6, b, c, vector7);
            Vector3 vector8 = bezier3.Position(0.5f);
            Vector3 vector9 = bezier3.Position(0.25f);

            vector9 = Line2.Offset(VectorUtils.XZ(vector6), VectorUtils.XZ(vector8), VectorUtils.XZ(vector9));
            Vector3 vector10 = bezier3.Position(0.75f);

            vector10 = Line2.Offset(VectorUtils.XZ(vector7), VectorUtils.XZ(vector8), VectorUtils.XZ(vector10));
            Vector3 vector11 = vector6;
            Vector3 a        = vector7;
            float   d;
            float   num10;

            if (Line2.Intersect(VectorUtils.XZ(startPosition), VectorUtils.XZ(vector6), VectorUtils.XZ(vector11 - vector9), VectorUtils.XZ(vector8 - vector9), out d, out num10))
            {
                vector6 = startPosition + (vector6 - startPosition) * d;
            }
            if (Line2.Intersect(VectorUtils.XZ(endPosition), VectorUtils.XZ(vector7), VectorUtils.XZ(a - vector10), VectorUtils.XZ(vector8 - vector10), out d, out num10))
            {
                vector7 = endPosition + (vector7 - endPosition) * d;
            }
            if (Line2.Intersect(VectorUtils.XZ(vector11 - vector9), VectorUtils.XZ(vector8 - vector9), VectorUtils.XZ(a - vector10), VectorUtils.XZ(vector8 - vector10), out d, out num10))
            {
                vector8 = vector11 - vector9 + (vector8 - vector11) * d;
            }
            float   num11;
            Vector3 vector12 = VectorUtils.NormalizeXZ(vector8 - vector6, out num11);
            int     num12    = Mathf.FloorToInt(num11 / 8f + 0.01f);
            float   num13    = num11 * 0.5f + (float)(num12 - 8) * ((!flag2) ? 4f : -4f);

            if (num12 != 0)
            {
                float   angle3    = (!flag2) ? Mathf.Atan2(-vector12.x, vector12.z) : Mathf.Atan2(vector12.x, -vector12.z);
                Vector3 position5 = vector6 + new Vector3(vector12.x * num13 + vector12.z * num3, 0f, vector12.z * num13 - vector12.x * num3);
                if (flag2)
                {
                    Singleton <ZoneManager> .instance.CreateBlock(
                        out segment.m_blockStartLeft,
                        ref randomizer,
                        position5,
                        angle3,
                        num12,
                        distance,
                        segment.m_buildIndex);
                }
                else
                {
                    Singleton <ZoneManager> .instance.CreateBlock(
                        out segment.m_blockStartRight,
                        ref randomizer,
                        position5,
                        angle3,
                        num12,
                        distance,
                        segment.m_buildIndex);
                }
            }
            vector12 = VectorUtils.NormalizeXZ(vector7 - vector8, out num11);
            num12    = Mathf.FloorToInt(num11 / 8f + 0.01f);
            num13    = num11 * 0.5f + (float)(num12 - 8) * ((!flag2) ? 4f : -4f);
            if (num12 != 0)
            {
                float   angle4    = (!flag2) ? Mathf.Atan2(-vector12.x, vector12.z) : Mathf.Atan2(vector12.x, -vector12.z);
                Vector3 position6 = vector8 + new Vector3(vector12.x * num13 + vector12.z * num3, 0f, vector12.z * num13 - vector12.x * num3);
                if (flag2)
                {
                    Singleton <ZoneManager> .instance.CreateBlock(
                        out segment.m_blockEndLeft,
                        ref randomizer,
                        position6,
                        angle4,
                        num12,
                        distance,
                        segment.m_buildIndex + 1u);
                }
                else
                {
                    Singleton <ZoneManager> .instance.CreateBlock(
                        out segment.m_blockEndRight,
                        ref randomizer,
                        position6,
                        angle4,
                        num12,
                        distance,
                        segment.m_buildIndex + 1u);
                }
            }
        }
示例#33
0
 public RelevantLine GetRelevantObjects(RelevantPoint point1, RelevantPoint point2)
 {
     return(new RelevantLine(Line2.FromPoints(point1.Child, point2.Child)));
 }
示例#34
0
 private void AreEqual_ClosestPoints(Line2 line, Segment2 segment, Vector2 expected)
 {
     AreEqual_ClosestPoints(line, segment, expected, expected);
 }
示例#35
0
        /// <summary>
        /// Intersection test on another line. (http://ideone.com/PnPJgb)
        /// </summary>
        /// <param name="other">The line to test against</param>
        /// <returns></returns>
        public bool Intersects(Line2 other) {
            //A = X1, Y1; B = X2, Y2; C = other.X1, other.Y1; D = other.X2, other.Y2;
            Vector2 A = new Vector2(X1, Y1);
            Vector2 B = new Vector2(X2, Y2);
            Vector2 C = new Vector2(other.X1, other.Y1);
            Vector2 D = new Vector2(other.X2, other.Y2);

            Vector2 CmP = new Vector2(C.X - A.X, C.Y - A.Y);
            Vector2 r = new Vector2(B.X - A.X, B.Y - A.Y);
            Vector2 s = new Vector2(D.X - C.X, D.Y - C.Y);

            float CmPxr = (float)CmP.X * (float)r.Y - (float)CmP.Y * (float)r.X;
            float CmPxs = (float)CmP.X * (float)s.Y - (float)CmP.Y * (float)s.X;
            float rxs = (float)r.X * (float)s.Y - (float)r.Y * (float)s.X;

            if (CmPxr == 0f) {
                // Lines are collinear, and so intersect if they have any overlap

                return ((C.X - A.X < 0f) != (C.X - B.X < 0f))
                        || ((C.Y - A.Y < 0f) != (C.Y - B.Y < 0f));
            }

            if (rxs == 0f)
                return false; // Lines are parallel.

            float rxsr = 1f / rxs;
            float t = CmPxs * rxsr;
            float u = CmPxr * rxsr;

            return (t >= 0f) && (t <= 1f) && (u >= 0f) && (u <= 1f);
        }
示例#36
0
 private void IsFalse_Intersect(Line2 line, Segment2 segment)
 {
     Assert.IsFalse(Intersect.LineSegment(line.origin, line.direction, segment.a, segment.b, out _), format, line, segment);
     Assert.IsFalse(Intersect.LineSegment(line.origin, line.direction, segment.b, segment.a, out _), format, line, segment);
 }
示例#37
0
 private void AreEqual_ClosestPoints(Line2 lineA, Line2 lineB, Vector2 expected)
 {
     AreEqual_ClosestPoints(lineA, lineB, expected, expected);
 }
示例#38
0
        public WpfArc(Point2 p1, Point2 p2, Point2 p3, Point2 p4)
        {
            var    rect    = Rect2.FromPoints(p1, p2);
            var    center  = new Point2(rect.X + (rect.Width / 2.0), rect.Y + (rect.Height / 2.0));
            double offsetX = center.X - rect.X;
            double offsetY = center.Y - rect.Y;

            double minLenght = (double)Math.Max(offsetX, offsetY);

            double length1 = center.DistanceTo(p3);
            double p3x     = p3.X + ((p3.X - center.X) / (length1 * minLenght));
            double p3y     = p3.Y + ((p3.Y - center.Y) / (length1 * minLenght));

            double length2 = center.DistanceTo(p4);
            double p4x     = p4.X + ((p4.X - center.X) / (length2 * minLenght));
            double p4y     = p4.Y + ((p4.Y - center.Y) / (length2 * minLenght));

            IList <Point2>?p3i;
            IList <Point2>?p4i;

            Line2.LineIntersectsWithEllipse(center, new Point2(p3x, p3y), rect, true, out p3i);
            Line2.LineIntersectsWithEllipse(center, new Point2(p4x, p4y), rect, true, out p4i);
            Point2 start;
            Point2 end;

            if (p3i != null && p3i.Count == 1)
            {
                start = p3i.FirstOrDefault();
            }
            else
            {
                start = new Point2(p3x, p3y);
            }

            if (p4i != null && p4i.Count == 1)
            {
                end = p4i.FirstOrDefault();
            }
            else
            {
                end = new Point2(p4x, p4y);
            }

            double angle      = Line2.AngleBetween(center, start, center, end);
            bool   isLargeArc = angle > 180.0;

            double helperLenght = 60.0;

            double lengthStart = center.DistanceTo(start);
            double p3hx        = start.X + ((start.X - center.X) / (lengthStart * helperLenght));
            double p3hy        = start.Y + ((start.Y - center.Y) / (lengthStart * helperLenght));

            double lengthEnd = center.DistanceTo(end);
            double p4hx      = end.X + ((end.X - center.X) / (lengthEnd * helperLenght));
            double p4hy      = end.Y + ((end.Y - center.Y) / (lengthEnd * helperLenght));

            P1         = p1;
            P2         = p2;
            P3         = new Point2(p3hx, p3hy);
            P4         = new Point2(p4hx, p4hy);
            Rect       = rect;
            Center     = center;
            Start      = start;
            End        = end;
            Radius     = new Size2(offsetX, offsetY);
            IsLargeArc = isLargeArc;
            Angle      = angle;
        }
示例#39
0
 private void AreEqual_ClosestPoints(Line2 line, Ray2D ray, Vector2 expected)
 {
     AreEqual_ClosestPoints(line, ray, expected, expected);
 }
 public void FindCollision_RectangleIsInsideHorizontalLine_ReturnsAVectorPushingItUp()
 {
     line = new Line2(-10, 0, 10, 0);
     Assert.AreEqual(new Vector2(0, 1), CollisionDetector.FindCollision(rectangle, line));
 }
示例#41
0
        public override void DrawOrMove(ChartPoint previousDrawn, ChartPoint current, int index, ChartCore chart)
        {
            var invertedMode = ((StepLineSeries)current.SeriesView).InvertedMode;

            if (IsNew)
            {
                if (invertedMode)
                {
                    Line1.X1 = current.ChartLocation.X;
                    Line1.X2 = current.ChartLocation.X - DeltaX;
                    Line1.Y1 = chart.DrawMargin.Height;
                    Line1.Y2 = chart.DrawMargin.Height;

                    Line2.X1 = current.ChartLocation.X - DeltaX;
                    Line2.X2 = current.ChartLocation.X - DeltaX;
                    Line2.Y1 = chart.DrawMargin.Height;
                    Line2.Y2 = chart.DrawMargin.Height;
                }
                else
                {
                    Line1.X1 = current.ChartLocation.X;
                    Line1.X2 = current.ChartLocation.X;
                    Line1.Y1 = chart.DrawMargin.Height;
                    Line1.Y2 = chart.DrawMargin.Height;

                    Line2.X1 = current.ChartLocation.X - DeltaX;
                    Line2.X2 = current.ChartLocation.X;
                    Line2.Y1 = chart.DrawMargin.Height;
                    Line2.Y2 = chart.DrawMargin.Height;
                }

                if (Shape != null)
                {
                    Canvas.SetLeft(Shape, current.ChartLocation.X - Shape.Width / 2);
                    Canvas.SetTop(Shape, chart.DrawMargin.Height);
                }
            }

            if (DataLabel != null && double.IsNaN(Canvas.GetLeft(DataLabel)))
            {
                Canvas.SetTop(DataLabel, chart.DrawMargin.Height);
                Canvas.SetLeft(DataLabel, current.ChartLocation.X);
            }

            if (HoverShape != null)
            {
                HoverShape.Width  = Shape != null ? (Shape.Width > 5 ? Shape.Width : 5) : 5;
                HoverShape.Height = Shape != null ? (Shape.Height > 5 ? Shape.Height : 5) : 5;
                Canvas.SetLeft(HoverShape, current.ChartLocation.X - HoverShape.Width / 2);
                Canvas.SetTop(HoverShape, current.ChartLocation.Y - HoverShape.Height / 2);
            }

            if (chart.View.DisableAnimations)
            {
                if (invertedMode)
                {
                    Line1.X1 = current.ChartLocation.X;
                    Line1.X2 = current.ChartLocation.X - DeltaX;
                    Line1.Y1 = current.ChartLocation.Y;
                    Line1.Y2 = current.ChartLocation.Y;

                    Line2.X1 = current.ChartLocation.X - DeltaX;
                    Line2.X2 = current.ChartLocation.X - DeltaX;
                    Line2.Y1 = current.ChartLocation.Y;
                    Line2.Y2 = current.ChartLocation.Y - DeltaY;
                }
                else
                {
                    Line1.X1 = current.ChartLocation.X;
                    Line1.X2 = current.ChartLocation.X;
                    Line1.Y1 = current.ChartLocation.Y;
                    Line1.Y2 = current.ChartLocation.Y - DeltaY;

                    Line2.X1 = current.ChartLocation.X - DeltaX;
                    Line2.X2 = current.ChartLocation.X;
                    Line2.Y1 = current.ChartLocation.Y - DeltaY;
                    Line2.Y2 = current.ChartLocation.Y - DeltaY;
                }

                if (Shape != null)
                {
                    Canvas.SetLeft(Shape, current.ChartLocation.X - Shape.Width / 2);
                    Canvas.SetTop(Shape, current.ChartLocation.Y - Shape.Height / 2);
                }

                if (DataLabel != null)
                {
                    DataLabel.UpdateLayout();
                    var xl = CorrectXLabel(current.ChartLocation.X - DataLabel.ActualWidth * .5, chart);
                    var yl = CorrectYLabel(current.ChartLocation.Y - DataLabel.ActualHeight * .5, chart);
                    Canvas.SetLeft(DataLabel, xl);
                    Canvas.SetTop(DataLabel, yl);
                }

                return;
            }

            var animSpeed = chart.View.AnimationsSpeed;

            if (invertedMode)
            {
                Line1.BeginAnimation(Line.X1Property,
                                     new DoubleAnimation(current.ChartLocation.X, animSpeed));
                Line1.BeginAnimation(Line.X2Property,
                                     new DoubleAnimation(current.ChartLocation.X - DeltaX, animSpeed));
                Line1.BeginAnimation(Line.Y1Property,
                                     new DoubleAnimation(current.ChartLocation.Y, animSpeed));
                Line1.BeginAnimation(Line.Y2Property,
                                     new DoubleAnimation(current.ChartLocation.Y, animSpeed));

                Line2.BeginAnimation(Line.X1Property,
                                     new DoubleAnimation(current.ChartLocation.X - DeltaX, animSpeed));
                Line2.BeginAnimation(Line.X2Property,
                                     new DoubleAnimation(current.ChartLocation.X - DeltaX, animSpeed));
                Line2.BeginAnimation(Line.Y1Property,
                                     new DoubleAnimation(current.ChartLocation.Y, animSpeed));
                Line2.BeginAnimation(Line.Y2Property,
                                     new DoubleAnimation(current.ChartLocation.Y - DeltaY, animSpeed));
            }
            else
            {
                Line1.BeginAnimation(Line.X1Property,
                                     new DoubleAnimation(current.ChartLocation.X, animSpeed));
                Line1.BeginAnimation(Line.X2Property,
                                     new DoubleAnimation(current.ChartLocation.X, animSpeed));
                Line1.BeginAnimation(Line.Y1Property,
                                     new DoubleAnimation(current.ChartLocation.Y, animSpeed));
                Line1.BeginAnimation(Line.Y2Property,
                                     new DoubleAnimation(current.ChartLocation.Y - DeltaY, animSpeed));

                Line2.BeginAnimation(Line.X1Property,
                                     new DoubleAnimation(current.ChartLocation.X - DeltaX, animSpeed));
                Line2.BeginAnimation(Line.X2Property,
                                     new DoubleAnimation(current.ChartLocation.X, animSpeed));
                Line2.BeginAnimation(Line.Y1Property,
                                     new DoubleAnimation(current.ChartLocation.Y - DeltaY, animSpeed));
                Line2.BeginAnimation(Line.Y2Property,
                                     new DoubleAnimation(current.ChartLocation.Y - DeltaY, animSpeed));
            }

            if (Shape != null)
            {
                Shape.BeginAnimation(Canvas.LeftProperty,
                                     new DoubleAnimation(current.ChartLocation.X - Shape.Width / 2, animSpeed));
                Shape.BeginAnimation(Canvas.TopProperty,
                                     new DoubleAnimation(current.ChartLocation.Y - Shape.Height / 2, animSpeed));
            }

            if (DataLabel != null)
            {
                DataLabel.UpdateLayout();
                var xl = CorrectXLabel(current.ChartLocation.X - DataLabel.ActualWidth * .5, chart);
                var yl = CorrectYLabel(current.ChartLocation.Y - DataLabel.ActualHeight * .5, chart);
                Canvas.SetLeft(DataLabel, xl);
                Canvas.SetTop(DataLabel, yl);
            }
        }
 public void FindCollision_RectangleIsOutsideLine_ReturnsNull()
 {
     line = new Line2(-10, -10, 10, -10);
     Assert.IsNull(CollisionDetector.FindCollision(rectangle, line));
 }
示例#43
0
 public bool CommonFaces(Line2 b)
     { return b.start == start || b.start == end || b.end == start || b.end == end; }
示例#44
0
    private void FillMeshVerticles(float a, Vector2 edgePoint1, Vector2 edgePoint2, List <Vector3> drawPoints)
    {
        List <Vector2> points = new List <Vector2>();

        for (int i = 0; i < drawPoints.Count; i++)
        {
            Vector3 t = drawPoints[i];
            points.Add(new Vector2(t.x, t.z));
        }
        var ps = GetArchimePoints(a, edgePoint1);

        Polygon2 polygon2 = new Polygon2(points.ToArray());
        Line2ConvexPolygon2Intr intr;

        _cutPoints = new List <Vector3>();
        for (int i = 0; i < ps.Count; i++)
        {
            _cutPoints.Add(new Vector3(ps[i].x, 0, ps[i].y));
        }

        int startIndex = 0;

        for (int i = 0; i < _cutPoints.Count; i++)
        {
            Vector2 center1 = new Vector2(_cutPoints[i].x, _cutPoints[i].z);
            Line2   line2   = new Line2(center1, edgePoint2 - edgePoint1);
            bool    b       = Intersection.FindLine2ConvexPolygon2(ref line2, polygon2, out intr);
            if (b)
            {
                switch (intr.IntersectionType)
                {
                case IntersectionTypes.Point:
                    _cutIntersectionCache.Add(i, new List <Vector2>()
                    {
                        intr.Point0
                    });
                    break;

                case IntersectionTypes.Segment:
                    float angle = Vector2.Angle(intr.Point1 - intr.Point0, edgePoint2 - edgePoint1);
                    _cutIntersectionCache.Add(i,
                                              Mathf.Abs(angle) < 10f
                                ? new List <Vector2>()
                    {
                        intr.Point0, intr.Point1
                    }
                                : new List <Vector2>()
                    {
                        intr.Point1, intr.Point0
                    });
                    break;
                }
            }

            if (i >= 1)
            {
                bool    isAdd     = false;
                Vector2 c1        = new Vector2(_cutPoints[i - 1].x, _cutPoints[i - 1].z);
                Vector2 c2        = new Vector2(_cutPoints[i].x, _cutPoints[i].z);
                float   maxlength = Vector3.Distance(c1, c2);

                _cutTopCache.Add(i - 1, new List <V3>());
                if (_cutIntersectionCache.ContainsKey(i - 1))
                {
                    for (int j = 0; j < _cutIntersectionCache[i - 1].Count; j++)
                    {
                        var     p    = _cutIntersectionCache[i - 1][j];
                        Vector3 temp = new Vector3(p.x, 0, p.y);
                        int     flag;
                        if (_cutIntersectionCache[i - 1].Count == 1)
                        {
                            flag = 0;
                        }
                        else
                        {
                            flag = j == 0 ? -1 : 1;
                        }
                        _cutTopCache[i - 1].Add(new V3(temp, true, i - 1, flag * i));
                    }
                }


                Line2 l1 = new Line2(c1, edgePoint2 - edgePoint1);
                for (int j = startIndex; j < drawPoints.Count; j++)
                {
                    Vector3 temp = drawPoints[j];
                    Vector2 p2   = new Vector2(temp.x, temp.z);
                    float   d    = Distance.Point2Line2(ref p2, ref l1);

                    if (d < maxlength && Mathf.Abs(d) > 0.05f && Mathf.Abs(d - maxlength) > 0.05f)
                    {
                        _cutTopCache[i - 1].Add(new V3(temp, false, -1, int.MaxValue));
                    }
                    else
                    {
                        if (!isAdd)
                        {
                            isAdd      = true;
                            startIndex = j;

                            if (_cutIntersectionCache.ContainsKey(i))
                            {
                                for (int k = _cutIntersectionCache[i].Count - 1; k >= 0; k--)
                                {
                                    var     p     = _cutIntersectionCache[i][k];
                                    Vector3 temp1 = new Vector3(p.x, 0, p.y);
                                    int     flag;
                                    if (_cutIntersectionCache[i].Count == 1)
                                    {
                                        flag = 0;
                                    }
                                    else
                                    {
                                        flag = k == 0 ? -1 : 1;
                                    }

                                    _cutTopCache[i - 1].Add(new V3(temp1, true, i, flag * (i + 1)));
                                }
                            }
                        }
                    }
                }
            }
        }
    }
        public void Collides_RectangleMovesIntoDiagonalLineAndOnlyOneCornerEndsUpOnTheOtherSideOfTheLine_ReturnsFalse()
        {
            rectangle = new Rectangle2(-2, 2, 2, -2);
            var diagonalLine = new Line2(5, -1, 8, 1);
            movement = new Vector2(5, 0);

            Assert.IsFalse(CollisionDetector.Collides(rectangle, movement, diagonalLine));
        }
示例#46
0
        public static Shape2 Mirror(this Shape2 shape, Line2 line)
        {
            var n = line.Normal;

            return(shape.Transform(p => p - 2 * line.Fn(p) * n / line.Normal.Len2).Reverse());
        }
        public void FindCollision_RectangleEnvelopsLineFromLeft2_Returns0p25()
        {
            rectangle = new Rectangle2(-50, 25, -25, -25);
            verticalLine = new Line2(0, -10, 0, 10);
            movement = new Vector2(100, 0);

            Assert.AreEqual(0.25f, CollisionDetector.FindCollision(rectangle, movement, verticalLine).Value.Value);
        }
示例#48
0
        public bool Slice(Node2 other)
        {
            Line2 line = Line2.MidLine(this.M, other);

            return(line != null && this.Slice(line));
        }
        public void FindCollision_RectangleStartsInsideLineItFullyEnvelopsMovesLeft_ReturnsMinus1()
        {
            rectangle = new Rectangle2(-2, -2, 2, 2);
            movement = new Vector2(2, 0);
            verticalLine = new Line2(0, -1, 0, 1);

            Assert.AreEqual(-1, CollisionDetector.FindCollision(rectangle, movement, verticalLine).Value.Value);
        }
示例#50
0
        /// <summary>
        /// Generic n-gon slicer. If the nodes in V do not represent a valid, convex NGon
        /// then the result will not be reliable.
        /// </summary>
        /// <param name="V">Corners of NGon</param>
        /// <param name="line">The line to slice with</param>
        /// <param name="side">Side of NGon to keep (with respect to line)</param>
        /// <returns>Result. List may share Node instances with V</returns>
        public static List <Node2> SliceConvexNGon(
            List <Node2> V,
            Line2 line,
            Side2 side,
            ref bool changed)
        {
            changed = false;
            List <Node2> node2List1;

            if (V.Count < 2)
            {
                node2List1 = V;
            }
            else
            {
                List <Node2> node2List2 = new List <Node2>(V.Count + 2);
                int          num1       = 0;
                Side2        side2      = Side2.Coincident;
                int          num2       = V.Count - 1;
                for (int index1 = 0; index1 <= num2; ++index1)
                {
                    if (side2 == Side2.Coincident)
                    {
                        side2 = Line2.Side(line, V[index1]);
                        if (side2 != side)
                        {
                            changed = true;
                        }
                    }
                    int index2 = index1 + 1;
                    if (index2 == V.Count)
                    {
                        index2 = 0;
                    }
                    Line2  A = new Line2(V[index1], V[index2]);
                    double t = 0.0;
                    switch (Line2.Intersect(A, line, ref t))
                    {
                    case LineX.None:
                        if (side2 == side)
                        {
                            node2List2.Add(V[index1]);
                            break;
                        }
                        break;

                    case LineX.Parallel:
                        if (side2 == side)
                        {
                            node2List2.Add(V[index1]);
                            break;
                        }
                        break;

                    case LineX.Coincident:
                        changed    = false;
                        node2List1 = V;
                        goto label_28;

                    case LineX.Point:
                        Node2 node2 = A.PointAt(t);
                        if (node2.IsCoincident(V[index1]))
                        {
                            node2List2.Add(V[index1]);
                            side2 = Side2.Coincident;
                            ++num1;
                            changed = true;
                            break;
                        }
                        if (node2.IsCoincident(V[index2]))
                        {
                            if (side2 == side)
                            {
                                node2List2.Add(V[index1]);
                                break;
                            }
                            break;
                        }
                        if (t < 0.0 || t > 1.0)
                        {
                            if (side2 == side)
                            {
                                node2List2.Add(V[index1]);
                                break;
                            }
                            break;
                        }
                        if (side2 == side)
                        {
                            node2List2.Add(V[index1]);
                        }
                        node2List2.Add(node2);
                        side2 = Side2.Coincident;
                        ++num1;
                        changed = true;
                        break;
                    }
                }
                node2List1 = node2List2;
            }
label_28:
            return(node2List1);
        }
 public void SetUp()
 {
     position = new Vector2(0, 0);
     rectangle = new Rectangle2(-1, 1, 1, -1);
     movement = new Vector2(10, 0);
     verticalLine = new Line2(5, -5, 5, 5);
     horizontalLine = new Line2(-5, 5, 5, 5);
 }
示例#52
0
        /// <summary>
        /// Draws the polygon boundary lines based on the height detail.
        /// </summary>
        private static void DrawPolyBoundaries(NavmeshTileHeader header
                                               , NavmeshPoly[] polys
                                               , UnityEngine.Vector3[] verts
                                               , NavmeshDetailMesh[] meshes
                                               , byte[] detailTris
                                               , UnityEngine.Vector3[] detailVerts
                                               , NavmeshLink[] links
                                               , Color color
                                               , bool inner)
        {
            const float thr = 0.01f * 0.01f;

            for (int i = 0; i < header.polyCount; i++)
            {
                NavmeshPoly poly = polys[i];

                if (poly.Type == NavmeshPolyType.OffMeshConnection)
                {
                    continue;
                }

                NavmeshDetailMesh     mesh = meshes[i];
                UnityEngine.Vector3[] tv   = new UnityEngine.Vector3[3];

                for (int j = 0, nj = ( int )poly.vertCount; j < nj; j++)
                {
                    Color c = color;                      // Color may change.
                    if (inner)
                    {
                        if (poly.neighborPolyRefs[j] == 0)
                        {
                            continue;
                        }
                        if ((poly.neighborPolyRefs[j]
                             & Navmesh.ExternalLink) != 0)
                        {
                            bool con = false;
                            for (uint k = poly.firstLink
                                 ; k != Navmesh.NullLink
                                 ; k = links[k].next)
                            {
                                if (links[k].edge == j)
                                {
                                    con = true;
                                    break;
                                }
                            }
                            if (con)
                            {
                                c = new Color(1, 1, 1, 0.2f);
                            }
                            else
                            {
                                c = new Color(0, 0, 0, 0.2f);
                            }
                        }
                        else
                        {
                            c = new Color(0, 0.2f, 0.25f, 0.13f);
                        }
                    }
                    else
                    {
                        if (poly.neighborPolyRefs[j] != 0)
                        {
                            continue;
                        }
                    }

                    GL.Color(c);

                    int pVertA = poly.indices[j];
                    int pVertB = poly.indices[(j + 1) % nj];

                    for (int k = 0; k < mesh.triCount; k++)
                    {
                        int pTri = ( int )((mesh.triBase + k) * 4);
                        for (int m = 0; m < 3; m++)
                        {
                            int iVert = detailTris[pTri + m];
                            if (iVert < poly.vertCount)
                            {
                                int pv = poly.indices[iVert];
                                tv[m] = verts[pv];
                            }
                            else
                            {
                                int pv = ( int )(mesh.vertBase
                                                 + (iVert - poly.vertCount));
                                tv[m] = detailVerts[pv];
                            }
                        }
                        for (int m = 0, n = 2; m < 3; n = m++)
                        {
                            if (((detailTris[pTri + 3] >> (n * 2)) & 0x3) == 0)
                            {
                                // Skip inner detail edges.
                                continue;
                            }

                            float distN = Line2.GetPointLineDistanceSq(
                                new Vector2(tv[n].x, tv[n].z)
                                , new Vector2(verts[pVertA].x, verts[pVertA].z)
                                , new Vector2(verts[pVertB].x, verts[pVertB].z));
                            float distM = Line2.GetPointLineDistanceSq(
                                new Vector2(tv[m].x, tv[m].z)
                                , new Vector2(verts[pVertA].x, verts[pVertA].z)
                                , new Vector2(verts[pVertB].x, verts[pVertB].z));

                            if (distN < thr && distM < thr)
                            {
                                GL.Vertex(tv[n]);
                                GL.Vertex(tv[m]);
                            }
                        }
                    }
                }
            }
        }
        public void Collides_RectangleMovesAboveLine_ReturnsFalse()
        {
            verticalLine = new Line2(5, -10, 5, -5);

            Assert.IsFalse(CollisionDetector.Collides(rectangle, movement, verticalLine));
        }
示例#54
0
        public void FromPointsTest1()
        {
            var line = Line2.FromPoints(new Vector2(1, 1), new Vector2(2, 2)); // y = x

            Assert.Equal(new Line2(-1, 1, 0), line);
        }
        public void Collides_RectangleMovesHalfwayAcrossHalfLineFromLeft_ReturnsTrue()
        {
            movement = new Vector2(5, 0);
            verticalLine = new Line2(5, 0, 5, 5);

            Assert.IsTrue(CollisionDetector.Collides(rectangle, movement, verticalLine));
        }
示例#56
0
        /// <summary>
        /// Draws the area between two curves using the provided color.
        /// </summary>
        /// <param name="curves">Curves to draw within the currently set range.</param>
        /// <param name="color">Color to draw the area with.</param>
        private void DrawCurveRange(EdAnimationCurve[] curves, Color color)
        {
            float range = GetRange();

            if (curves.Length != 2 || curves[0] == null || curves[1] == null)
            {
                return;
            }

            KeyFrame[][] keyframes = { curves[0].KeyFrames, curves[1].KeyFrames };
            if (keyframes[0].Length <= 0 || keyframes[1].Length <= 0)
            {
                return;
            }

            int   numSamples    = (drawableWidth + LINE_SPLIT_WIDTH - 1) / LINE_SPLIT_WIDTH;
            float timePerSample = range / numSamples;

            float time = rangeOffset;

            int[] keyframeIndices = { 0, 0 };

            // Find first valid keyframe indices
            for (int curveIdx = 0; curveIdx < 2; curveIdx++)
            {
                keyframeIndices[curveIdx] = keyframes[curveIdx].Length;

                for (int i = 0; i < keyframes[curveIdx].Length; i++)
                {
                    if (keyframes[curveIdx][i].time > time)
                    {
                        keyframeIndices[curveIdx] = i;
                    }
                }
            }

            List <float> times = new List <float>();

            List <float>[] points = { new List <float>(), new List <float>() };

            // Determine start points
            for (int curveIdx = 0; curveIdx < 2; curveIdx++)
            {
                float value = curves[curveIdx].Evaluate(time, false);
                points[curveIdx].Add(value);
            }

            times.Add(time);

            float rangeEnd = rangeOffset + range;

            while (time < rangeEnd)
            {
                float nextTime = time + timePerSample;
                bool  hasStep  = false;

                // Determine time to sample at. Use fixed increments unless there's a step keyframe within our increment in
                // which case we use its time so we can evaluate it directly
                for (int curveIdx = 0; curveIdx < 2; curveIdx++)
                {
                    int keyframeIdx = keyframeIndices[curveIdx];
                    if (keyframeIdx < keyframes[curveIdx].Length)
                    {
                        KeyFrame keyframe = keyframes[curveIdx][keyframeIdx];

                        bool isStep = keyframe.inTangent == float.PositiveInfinity ||
                                      keyframe.outTangent == float.PositiveInfinity;

                        if (isStep && keyframe.time <= nextTime)
                        {
                            nextTime = Math.Min(nextTime, keyframe.time);
                            hasStep  = true;
                        }
                    }
                }

                // Evaluate
                if (hasStep)
                {
                    for (int curveIdx = 0; curveIdx < 2; curveIdx++)
                    {
                        int keyframeIdx = keyframeIndices[curveIdx];
                        if (keyframeIdx < keyframes[curveIdx].Length)
                        {
                            KeyFrame keyframe = keyframes[curveIdx][keyframeIdx];

                            if (MathEx.ApproxEquals(keyframe.time, nextTime))
                            {
                                if (keyframeIdx > 0)
                                {
                                    KeyFrame prevKeyframe = keyframes[curveIdx][keyframeIdx - 1];
                                    points[curveIdx].Add(prevKeyframe.value);
                                }
                                else
                                {
                                    points[curveIdx].Add(keyframe.value);
                                }

                                points[curveIdx].Add(keyframe.value);
                            }
                            else
                            {
                                // The other curve has step but this one doesn't, we just insert the same value twice
                                float value = curves[curveIdx].Evaluate(nextTime, false);
                                points[curveIdx].Add(value);
                                points[curveIdx].Add(value);
                            }

                            times.Add(nextTime);
                            times.Add(nextTime);
                        }
                    }
                }
                else
                {
                    for (int curveIdx = 0; curveIdx < 2; curveIdx++)
                    {
                        points[curveIdx].Add(curves[curveIdx].Evaluate(nextTime, false));
                    }

                    times.Add(nextTime);
                }

                // Advance keyframe indices
                for (int curveIdx = 0; curveIdx < 2; curveIdx++)
                {
                    int keyframeIdx = keyframeIndices[curveIdx];
                    while (keyframeIdx < keyframes[curveIdx].Length)
                    {
                        KeyFrame keyframe = keyframes[curveIdx][keyframeIdx];
                        if (keyframe.time > nextTime)
                        {
                            break;
                        }

                        keyframeIdx = ++keyframeIndices[curveIdx];
                    }
                }

                time = nextTime;
            }

            // End points
            for (int curveIdx = 0; curveIdx < 2; curveIdx++)
            {
                float value = curves[curveIdx].Evaluate(rangeEnd, false);
                points[curveIdx].Add(value);
            }

            times.Add(rangeEnd);

            int             numQuads = times.Count - 1;
            List <Vector2I> vertices = new List <Vector2I>();

            for (int i = 0; i < numQuads; i++)
            {
                int idxLeft  = points[0][i] < points[1][i] ? 0 : 1;
                int idxRight = points[0][i + 1] < points[1][i + 1] ? 0 : 1;

                Vector2[] left =
                {
                    new Vector2(times[i], points[0][i]),
                    new Vector2(times[i], points[1][i])
                };

                Vector2[] right =
                {
                    new Vector2(times[i + 1], points[0][i + 1]),
                    new Vector2(times[i + 1], points[1][i + 1])
                };

                if (idxLeft == idxRight)
                {
                    int idxA = idxLeft;
                    int idxB = (idxLeft + 1) % 2;

                    vertices.Add(CurveToPixelSpace(left[idxB]));
                    vertices.Add(CurveToPixelSpace(right[idxB]));
                    vertices.Add(CurveToPixelSpace(left[idxA]));

                    vertices.Add(CurveToPixelSpace(right[idxB]));
                    vertices.Add(CurveToPixelSpace(right[idxA]));
                    vertices.Add(CurveToPixelSpace(left[idxA]));
                }
                // Lines intersects, can't represent them with a single quad
                else if (idxLeft != idxRight)
                {
                    int idxA = idxLeft;
                    int idxB = (idxLeft + 1) % 2;

                    Line2 lineA = new Line2(left[idxB], right[idxA] - left[idxB]);
                    Line2 lineB = new Line2(left[idxA], right[idxB] - left[idxA]);

                    if (lineA.Intersects(lineB, out var t))
                    {
                        Vector2 intersection = left[idxB] + t * (right[idxA] - left[idxB]);

                        vertices.Add(CurveToPixelSpace(left[idxB]));
                        vertices.Add(CurveToPixelSpace(intersection));
                        vertices.Add(CurveToPixelSpace(left[idxA]));

                        vertices.Add(CurveToPixelSpace(intersection));
                        vertices.Add(CurveToPixelSpace(right[idxB]));
                        vertices.Add(CurveToPixelSpace(right[idxA]));
                    }
                }
            }

            canvas.DrawTriangleList(vertices.ToArray(), color, 129);
        }
示例#57
0
 private void Intersect_Parallel(Line2 line, Vector2 a, Vector2 b)
 {
     IsFalse_Intersect(line, new Segment2(a, b));
     IsFalse_Intersect(line, new Segment2(b, a));
 }
        private void CreateZoneBlocks(ushort segment, ref NetSegment data)
        {
            NetManager instance       = Singleton <NetManager> .instance;
            Randomizer randomizer     = new Randomizer((int)segment);
            Vector3    position       = instance.m_nodes.m_buffer[(int)data.m_startNode].m_position;
            Vector3    position2      = instance.m_nodes.m_buffer[(int)data.m_endNode].m_position;
            Vector3    startDirection = data.m_startDirection;
            Vector3    endDirection   = data.m_endDirection;
            float      num            = startDirection.x * endDirection.x + startDirection.z * endDirection.z;
            bool       flag           = !NetSegment.IsStraight(position, startDirection, position2, endDirection);
            float      num2           = Mathf.Max(8f, this.m_info.m_halfWidth);
            float      num3           = 32f;

            if (flag)
            {
                float num4  = VectorUtils.LengthXZ(position2 - position);
                bool  flag2 = startDirection.x * endDirection.z - startDirection.z * endDirection.x > 0f;
                bool  flag3 = num <-0.8f || num4> 50f;
                if (flag2)
                {
                    num2 = -num2;
                    num3 = -num3;
                }
                Vector3 vector  = position - new Vector3(startDirection.z, 0f, -startDirection.x) * num2;
                Vector3 vector2 = position2 + new Vector3(endDirection.z, 0f, -endDirection.x) * num2;
                Vector3 vector3;
                Vector3 vector4;
                NetSegment.CalculateMiddlePoints(vector, startDirection, vector2, endDirection, true, true, out vector3, out vector4);
                if (flag3)
                {
                    float num5 = num * 0.025f + 0.04f;
                    float num6 = num * 0.025f + 0.06f;
                    if (num < -0.9f)
                    {
                        num6 = num5;
                    }
                    Bezier3 bezier = new Bezier3(vector, vector3, vector4, vector2);
                    vector  = bezier.Position(num5);
                    vector3 = bezier.Position(0.5f - num6);
                    vector4 = bezier.Position(0.5f + num6);
                    vector2 = bezier.Position(1f - num5);
                }
                else
                {
                    Bezier3 bezier2 = new Bezier3(vector, vector3, vector4, vector2);
                    vector3 = bezier2.Position(0.86f);
                    vector  = bezier2.Position(0.14f);
                }
                float   num7;
                Vector3 vector5 = VectorUtils.NormalizeXZ(vector3 - vector, out num7);
                int     num8    = Mathf.FloorToInt(num7 / 8f + 0.01f);
                float   num9    = num7 * 0.5f + (float)(num8 - 8) * ((!flag2) ? -4f : 4f);
                if (num8 != 0)
                {
                    float   angle     = (!flag2) ? Mathf.Atan2(vector5.x, -vector5.z) : Mathf.Atan2(-vector5.x, vector5.z);
                    Vector3 position3 = vector + new Vector3(vector5.x * num9 - vector5.z * num3, 0f, vector5.z * num9 + vector5.x * num3);
                    if (flag2)
                    {
                        Singleton <ZoneManager> .instance.CreateBlock(out data.m_blockStartRight, ref randomizer, position3, angle, num8, data.m_buildIndex);
                    }
                    else
                    {
                        Singleton <ZoneManager> .instance.CreateBlock(out data.m_blockStartLeft, ref randomizer, position3, angle, num8, data.m_buildIndex);
                    }
                }
                if (flag3)
                {
                    vector5 = VectorUtils.NormalizeXZ(vector2 - vector4, out num7);
                    num8    = Mathf.FloorToInt(num7 / 8f + 0.01f);
                    num9    = num7 * 0.5f + (float)(num8 - 8) * ((!flag2) ? -4f : 4f);
                    if (num8 != 0)
                    {
                        float   angle2    = (!flag2) ? Mathf.Atan2(vector5.x, -vector5.z) : Mathf.Atan2(-vector5.x, vector5.z);
                        Vector3 position4 = vector4 + new Vector3(vector5.x * num9 - vector5.z * num3, 0f, vector5.z * num9 + vector5.x * num3);
                        if (flag2)
                        {
                            Singleton <ZoneManager> .instance.CreateBlock(out data.m_blockEndRight, ref randomizer, position4, angle2, num8, data.m_buildIndex + 1u);
                        }
                        else
                        {
                            Singleton <ZoneManager> .instance.CreateBlock(out data.m_blockEndLeft, ref randomizer, position4, angle2, num8, data.m_buildIndex + 1u);
                        }
                    }
                }
                Vector3 vector6 = position + new Vector3(startDirection.z, 0f, -startDirection.x) * num2;
                Vector3 vector7 = position2 - new Vector3(endDirection.z, 0f, -endDirection.x) * num2;
                Vector3 b;
                Vector3 c;
                NetSegment.CalculateMiddlePoints(vector6, startDirection, vector7, endDirection, true, true, out b, out c);
                Bezier3 bezier3 = new Bezier3(vector6, b, c, vector7);
                Vector3 vector8 = bezier3.Position(0.5f);
                Vector3 vector9 = bezier3.Position(0.25f);
                vector9 = Line2.Offset(VectorUtils.XZ(vector6), VectorUtils.XZ(vector8), VectorUtils.XZ(vector9));
                Vector3 vector10 = bezier3.Position(0.75f);
                vector10 = Line2.Offset(VectorUtils.XZ(vector7), VectorUtils.XZ(vector8), VectorUtils.XZ(vector10));
                Vector3 vector11 = vector6;
                Vector3 a        = vector7;
                float   d;
                float   num10;
                if (Line2.Intersect(VectorUtils.XZ(position), VectorUtils.XZ(vector6), VectorUtils.XZ(vector11 - vector9), VectorUtils.XZ(vector8 - vector9), out d, out num10))
                {
                    vector6 = position + (vector6 - position) * d;
                }
                if (Line2.Intersect(VectorUtils.XZ(position2), VectorUtils.XZ(vector7), VectorUtils.XZ(a - vector10), VectorUtils.XZ(vector8 - vector10), out d, out num10))
                {
                    vector7 = position2 + (vector7 - position2) * d;
                }
                if (Line2.Intersect(VectorUtils.XZ(vector11 - vector9), VectorUtils.XZ(vector8 - vector9), VectorUtils.XZ(a - vector10), VectorUtils.XZ(vector8 - vector10), out d, out num10))
                {
                    vector8 = vector11 - vector9 + (vector8 - vector11) * d;
                }
                float   num11;
                Vector3 vector12 = VectorUtils.NormalizeXZ(vector8 - vector6, out num11);
                int     num12    = Mathf.FloorToInt(num11 / 8f + 0.01f);
                float   num13    = num11 * 0.5f + (float)(num12 - 8) * ((!flag2) ? 4f : -4f);
                if (num12 != 0)
                {
                    float   angle3    = (!flag2) ? Mathf.Atan2(-vector12.x, vector12.z) : Mathf.Atan2(vector12.x, -vector12.z);
                    Vector3 position5 = vector6 + new Vector3(vector12.x * num13 + vector12.z * num3, 0f, vector12.z * num13 - vector12.x * num3);
                    if (flag2)
                    {
                        Singleton <ZoneManager> .instance.CreateBlock(out data.m_blockStartLeft, ref randomizer, position5, angle3, num12, data.m_buildIndex);
                    }
                    else
                    {
                        Singleton <ZoneManager> .instance.CreateBlock(out data.m_blockStartRight, ref randomizer, position5, angle3, num12, data.m_buildIndex);
                    }
                }
                vector12 = VectorUtils.NormalizeXZ(vector7 - vector8, out num11);
                num12    = Mathf.FloorToInt(num11 / 8f + 0.01f);
                num13    = num11 * 0.5f + (float)(num12 - 8) * ((!flag2) ? 4f : -4f);
                if (num12 != 0)
                {
                    float   angle4    = (!flag2) ? Mathf.Atan2(-vector12.x, vector12.z) : Mathf.Atan2(vector12.x, -vector12.z);
                    Vector3 position6 = vector8 + new Vector3(vector12.x * num13 + vector12.z * num3, 0f, vector12.z * num13 - vector12.x * num3);
                    if (flag2)
                    {
                        Singleton <ZoneManager> .instance.CreateBlock(out data.m_blockEndLeft, ref randomizer, position6, angle4, num12, data.m_buildIndex + 1u);
                    }
                    else
                    {
                        Singleton <ZoneManager> .instance.CreateBlock(out data.m_blockEndRight, ref randomizer, position6, angle4, num12, data.m_buildIndex + 1u);
                    }
                }
            }
            else
            {
                num2 += num3;
                Vector2 vector13  = new Vector2(position2.x - position.x, position2.z - position.z);
                float   magnitude = vector13.magnitude;
                int     num14     = Mathf.FloorToInt(magnitude / 8f + 0.1f);
                int     num15     = (num14 <= 8) ? num14 : (num14 + 1 >> 1);
                int     num16     = (num14 <= 8) ? 0 : (num14 >> 1);
                if (num15 > 0)
                {
                    float   num17     = Mathf.Atan2(startDirection.x, -startDirection.z);
                    Vector3 position7 = position + new Vector3(startDirection.x * 32f - startDirection.z * num2, 0f, startDirection.z * 32f + startDirection.x * num2);
                    Singleton <ZoneManager> .instance.CreateBlock(out data.m_blockStartLeft, ref randomizer, position7, num17, num15, data.m_buildIndex);

                    position7 = position + new Vector3(startDirection.x * (float)(num15 - 4) * 8f + startDirection.z * num2, 0f, startDirection.z * (float)(num15 - 4) * 8f - startDirection.x * num2);
                    Singleton <ZoneManager> .instance.CreateBlock(out data.m_blockStartRight, ref randomizer, position7, num17 + 3.14159274f, num15, data.m_buildIndex);
                }
                if (num16 > 0)
                {
                    float   num18     = magnitude - (float)num14 * 8f;
                    float   num19     = Mathf.Atan2(endDirection.x, -endDirection.z);
                    Vector3 position8 = position2 + new Vector3(endDirection.x * (32f + num18) - endDirection.z * num2, 0f, endDirection.z * (32f + num18) + endDirection.x * num2);
                    Singleton <ZoneManager> .instance.CreateBlock(out data.m_blockEndLeft, ref randomizer, position8, num19, num16, data.m_buildIndex + 1u);

                    position8 = position2 + new Vector3(endDirection.x * ((float)(num16 - 4) * 8f + num18) + endDirection.z * num2, 0f, endDirection.z * ((float)(num16 - 4) * 8f + num18) - endDirection.x * num2);
                    Singleton <ZoneManager> .instance.CreateBlock(out data.m_blockEndRight, ref randomizer, position8, num19 + 3.14159274f, num16, data.m_buildIndex + 1u);
                }
            }
        }
 public void SetUp()
 {
     rectangle = new Rectangle2(-1, 1, 1, -1);
     line = new Line2(0, -10, 0, 10);
 }
示例#60
0
 /**
  * Move a triangle
  *
  * @param deltaX            The delta x-location by which the triangle should be moved -- must be a valid double
  * @param deltaY            The delta y-location by which the triangle should be moved -- must be a valid double
  * @throws ShapeException   Exception throw if any parameter is invalid
  * @throws ShapeException   When a triangle is moved to have a length of zero
  */
 public void Move(double deltaX, double deltaY)
 {
     Line1.Move(deltaX, deltaY);
     Line2.Move(deltaX, deltaY);
     Line3.Move(deltaX, deltaY);
 }