Ejemplo n.º 1
0
        public bool Join(SlicePart other)
        {
            if (Closed)
            {
                return(false);
            }

            if (LastPoint.Near(other.FirstPoint))
            {
                bool closing = FirstPoint.Near(other.LastPoint);
                int  start   = 1;
                int  count   = closing ? other.Points.Count - 1 : other.Points.Count;
                Normals[Normals.Count - 1] = other.Normals[0];
                for (int i = start; i < count; i++)
                {
                    Append(other.Points[i], other.Normals[i]);
                }
                Closed = closing;
                return(true);
            }

            if (LastPoint.Near(other.LastPoint))
            {
                bool closing = FirstPoint.Near(other.FirstPoint);
                int  end     = closing ? 1 : 0;
                Normals[Normals.Count - 1] = other.Normals[other.Normals.Count - 1];
                for (int i = other.Points.Count - 2; i >= end; i--)
                {
                    Append(other.Points[i], other.Normals[i]);
                }
                Closed = closing;
                return(true);
            }

            if (FirstPoint.Near(other.LastPoint))
            {
                bool closing = LastPoint.Near(other.FirstPoint);
                int  end     = closing ? 1 : 0;
                for (int i = other.Points.Count - 2; i >= end; i--)
                {
                    Insert(0, other.Points[i], other.Normals[i]);
                }
                Closed = closing;
                return(true);
            }

            if (FirstPoint.Near(other.FirstPoint))
            {
                bool closing = LastPoint.Near(other.LastPoint);
                int  start   = 1;
                int  count   = closing ? other.Points.Count - 1 : other.Points.Count;
                for (int i = start; i < count; i++)
                {
                    Insert(0, other.Points[i], other.Normals[i]);
                }
                Closed = closing;
                return(true);
            }
            return(false);
        }
Ejemplo n.º 2
0
        public void Reset()
        {
            FirstPoint.SetPosition(new Vector2(0, 0));
            SecondPoint.SetPosition(new Vector2(200, 0));

            CalculateSplineCenter(new Transform[] { FirstPoint, SecondPoint });
        }
Ejemplo n.º 3
0
 public override int GetHashCode()
 {
     return
         (FirstPoint.GetHashCode() +
          SecondPoint.GetHashCode() +
          ThirdPoint.GetHashCode());
 }
Ejemplo n.º 4
0
 private bool Equals(Segment2D other)
 {
     return(FirstPoint.Equals(other.FirstPoint) &&
            SecondPoint.Equals(other.SecondPoint) ||
            FirstPoint.Equals(other.SecondPoint) &&
            SecondPoint.Equals(other.FirstPoint));
 }
Ejemplo n.º 5
0
 public override string ToString()
 {
     return
         ("x=" +
          FirstPoint.ToString() +
          "+a*" + SecondPoint.ToString() +
          "+b*" + ThirdPoint.ToString());
 }
Ejemplo n.º 6
0
 public List <string> ToStringList()
 {
     return(new List <string>
     {
         FirstPoint.ToString(),
         SecondPoint.ToString()
     });
 }
Ejemplo n.º 7
0
        public TagCompound Save() =>
        new TagCompound()
        {
            { nameof(UUID), UUID.ToString() },

            { nameof(FirstPoint), FirstPoint.ToVector2() },
            { nameof(SecondPoint), SecondPoint.ToVector2() }
        };
Ejemplo n.º 8
0
        public void CheckTriangle()
        {
            if (FirstPoint == null || SecondPoint == null || ThirdPoint == null)
            {
                Console.WriteLine("Не все точки введены!");
                Thread.Sleep(1000);
                return;
            }

            _ABLength = FirstPoint.Distance(SecondPoint);
            _BCLength = SecondPoint.Distance(ThirdPoint);
            _ACLength = ThirdPoint.Distance(FirstPoint);

            if ((_ABLength + _BCLength) < _ACLength && (_BCLength + _ACLength) < _ABLength && (_ACLength + _ABLength) < _BCLength)
            {
                Console.WriteLine("Треугольник не существует!");
                Thread.Sleep(1000);
                return;
            }

            if (_ABLength == _BCLength && _BCLength == _ACLength)
            {
                Console.WriteLine("Треугольник равносторонний.");
                Thread.Sleep(1000);
                return;
            }

            if (_ABLength == _BCLength || _BCLength == _ACLength || _ACLength == _ABLength)
            {
                if ((Math.Round(Math.Pow(_ABLength, 2)) + Math.Round(Math.Pow(_BCLength, 2)) == Math.Round(Math.Pow(_ACLength, 2))) ||
                    (Math.Round(Math.Pow(_ABLength, 2)) + Math.Round(Math.Pow(_ACLength, 2)) == Math.Round(Math.Pow(_BCLength, 2))) ||
                    (Math.Round(Math.Pow(_ACLength, 2)) + Math.Round(Math.Pow(_BCLength, 2)) == Math.Round(Math.Pow(_ABLength, 2))))
                {
                    Console.WriteLine("Треугольник прямоугольный.");
                    Thread.Sleep(1000);
                    return;
                }

                Console.WriteLine("Треугольник равнобедренный.");
                Thread.Sleep(1000);
                return;
            }

            if ((Math.Round(Math.Pow(_ABLength, 2)) + Math.Round(Math.Pow(_BCLength, 2)) == Math.Round(Math.Pow(_ACLength, 2))) ||
                (Math.Round(Math.Pow(_ABLength, 2)) + Math.Round(Math.Pow(_ACLength, 2)) == Math.Round(Math.Pow(_BCLength, 2))) ||
                (Math.Round(Math.Pow(_ACLength, 2)) + Math.Round(Math.Pow(_BCLength, 2)) == Math.Round(Math.Pow(_ABLength, 2))))
            {
                Console.WriteLine("Треугольник прямоугольный.");
                Thread.Sleep(1000);
                return;
            }

            Console.WriteLine("Треугольник разносторонний.");
            Thread.Sleep(1000);
        }
Ejemplo n.º 9
0
    //保存修改
    protected void save_btn_Click(object sender, EventArgs e)
    {
        int res = 0;

        for (int i = 0; i < Repeater1.Items.Count; i++)
        {
            int    firstId         = int.Parse(((Label)Repeater1.Items[i].FindControl("idLabel")).Text.ToString());
            string firstPointName  = ((TextBox)Repeater1.Items[i].FindControl("FirstPointName_td")).Text.ToString();
            string firstPointOrder = ((TextBox)Repeater1.Items[i].FindControl("FirstPointOrder_td")).Text.ToString();

            if (!Public.isNumberic(firstPointOrder))
            {
                alert("请输入合法的排序号");
                return;
            }

            if (firstPointName != "" && firstPointOrder.ToString() != "")
            {
                FirstPoint point = new FirstPoint()
                {
                    FirstPointId    = firstId,
                    FirstPointName  = firstPointName,
                    FirstPointOrder = int.Parse(firstPointOrder)
                };
                if (pointService.isHaveFist(point.FirstPointName) && firstId == 0)
                {
                    alert(point.FirstPointName + "已存在, 请务重复添加");
                    return;
                }

                res = pointService.SaveFirstPoint(point);
            }

            else
            {
                alert("知识点信息不能为空");
                return;
            }


            if (res == 0)
            {
                alert("保存失败");
            }
        }
        if (res == 1)
        {
            alert("保存成功");
            BindFirstPoint();
        }
    }
Ejemplo n.º 10
0
        public override bool Equals(object obj)
        {
            if (ReferenceEquals(this, obj))
            {
                return(true);
            }

            if (ReferenceEquals(obj, null) || obj.GetType() != this.GetType())
            {
                return(false);
            }

            var triangle = (Triangle)obj;

            return(FirstPoint.Equals(triangle.FirstPoint) && SecondPoint.Equals(triangle.SecondPoint) && ThirdPoint.Equals(triangle.ThirdPoint));
        }
Ejemplo n.º 11
0
        public Transform TryGetTransformFromPosition(Vector2 position)
        {
            if (FirstPoint != null && FirstPoint.TryGetPosition(position))
            {
                return(FirstPoint);
            }
            else if (SecondPoint != null && SecondPoint.TryGetPosition(position))
            {
                return(SecondPoint);
            }

            else
            {
                return(null);
            }
        }
Ejemplo n.º 12
0
    //保存一级知识点
    public int SaveFirstPoint(FirstPoint point)
    {
        var count = db.FirstPoint.Count(t => t.FirstPointId == point.FirstPointId);
        int res   = 0;

        //该知识点已存在
        if (count == 1)
        {
            string updateSql = "update FirstPoint set FirstPointName={0}, FirstPointOrder={1} where FirstPointId={2}";
            res = db.ExecuteCommand(updateSql, new Object[] { point.FirstPointName, point.FirstPointOrder, point.FirstPointId });
        }
        else //插入
        {
            string insertSql = "insert into FirstPoint values({0}, {1})";
            res = db.ExecuteCommand(insertSql, new Object[] { point.FirstPointName, point.FirstPointOrder });
        }
        return(res);
    }
Ejemplo n.º 13
0
    //添加知识点
    public int AddPoint(Point point)
    {
        int a = 0, b = 0;

        if (IsHasFist(point.FirstPointName) == 0)
        {
            FirstPoint firstPoint = new FirstPoint()
            {
                FirstPointName  = point.FirstPointName,
                FirstPointOrder = MaxFirstOrder()
            };
            db.FirstPoint.InsertOnSubmit(firstPoint);
            db.SubmitChanges();
            if (firstPoint.FirstPointId > 0)
            {
                a = 1;
            }
        }

        if (IsHasSecond(point.SecondPointName) == 0)
        {
            decimal     firstPointId = GetFirstPoint(point.FirstPointName).FirstPointId;
            SecondPoint secondPoint  = new SecondPoint()
            {
                FIrstPointId     = firstPointId,
                SecondPointName  = point.SecondPointName,
                SecondPointOrder = MaxSecondOrder(point.FirstPointName)
            };
            db.SecondPoint.InsertOnSubmit(secondPoint);
            db.SubmitChanges();
            if (secondPoint.SecondPointId > 0)
            {
                b = 1;
            }
        }
        if (a == 1 && b == 1)
        {
            return(1);
        }
        else
        {
            return(0);
        }
    }
Ejemplo n.º 14
0
 public bool IsComplete()
 {
     return(FirstPoint.Equals(LastPoint));
 }
Ejemplo n.º 15
0
        //--------------------------------------------------------------------------------------------------

        public bool ComputeParameters(out Parameters parameters)
        {
            if (FirstPoint.IsEqual(SecondPoint, 0.01))
            {
                parameters = new();
                return(false);
            }

            double scale = 1.0;

            // Dimension line direction
            var dimDir   = new Vec2d(_FirstPoint, _SecondPoint).ToDir();
            var dimMid   = _FirstPoint.Lerped(_SecondPoint, 0.5);
            var dimWidth = _FirstPoint.Distance(_SecondPoint);

            scale = Math.Min(scale, dimWidth / (DrawingRenderHelper.GetArrowSize().Length * 3));
            if (_AutoText)
            {
                Text = dimWidth.ToInvariantString("F1");
            }

            var  rotation       = dimDir.Angle(Dir2d.DX);
            bool dimRightToLeft = false;

            if (rotation < -Maths.HalfPI)
            {
                rotation      += Maths.PI;
                dimRightToLeft = true;
            }
            else if (rotation > Maths.HalfPI)
            {
                rotation      -= Maths.PI;
                dimRightToLeft = true;
            }

            // Extension line
            var extDir = new Dir2d(dimDir.Y, -dimDir.X);

            if (dimDir.Angle(new Vec2d(dimMid, Position).ToDir()) > 0)
            {
                extDir.Reverse();
            }

            var dimToPos  = new gp_Lin2d(_FirstPoint, dimDir).Distance(Position);
            var extVector = extDir.ToVec(dimToPos + _ExtensionOverlength);
            var dimOffset = extDir.ToVec(dimToPos);

            // Text
            var textOrigin = _FirstPoint.Lerped(_SecondPoint, 0.5)
                             .Translated(dimOffset);
            var textWidth  = 1.0;
            var textHeight = 1.0;
            var textScale  = scale;

            if (!Text.IsNullOrWhiteSpace())
            {
                var fontStyle = DrawingRenderHelper.GetDefaultFontStyle();
                var textSize  = DrawingRenderHelper.MeasureText(Text, fontStyle);
                textScale = Math.Min(1.0, dimWidth * 0.90 / textSize.X);
                scale     = Math.Min(scale, textScale);

                // Exact positioning on above dim line
                var textOffset = dimDir.Angle(extDir) > 0 ? 1.0 : -1.0;
                if (dimRightToLeft)
                {
                    textOffset *= -1;
                }
                textOrigin.Translate(extDir.ToVec(textOffset));

                // Center
                textOrigin.Translate(dimDir.ToVec((dimRightToLeft ? 1.0 : -1.0) * textSize.X / 2 * textScale));

                textWidth  = textSize.X * textScale;
                textHeight = textSize.Y * textScale;
            }

            parameters = new Parameters()
            {
                ExtensionVector    = extVector,
                DimensionDirection = dimDir,
                DimensionOffset    = dimOffset,
                DimensionRotation  = rotation,
                TextOrigin         = textOrigin,
                TextWidth          = textWidth,
                TextHeight         = textHeight,
                Scale     = scale,
                TextScale = textScale
            };

            return(true);
        }
Ejemplo n.º 16
0
        //--------------------------------------------------------------------------------------------------

        public bool ComputeParameters(out Parameters parameters)
        {
            if (FirstPoint.IsEqual(SecondPoint, 0.01))
            {
                parameters = new();
                return(false);
            }

            var    arrowSize = DrawingRenderHelper.GetArrowSize();
            double scale     = 1.0;

            // Dimension line
            var radius = _CenterPoint.Distance(Position);

            // Extension line
            var extDir1    = new Vec2d(_CenterPoint, _FirstPoint).ToDir();
            var angle1     = -extDir1.Angle(Dir2d.DX);
            var extVector1 = extDir1.ToVec(radius - _CenterPoint.Distance(_FirstPoint) + _ExtensionOverlength);

            var extDir2    = new Vec2d(_CenterPoint, _SecondPoint).ToDir();
            var angle2     = -extDir2.Angle(Dir2d.DX);
            var extVector2 = extDir2.ToVec(radius - _CenterPoint.Distance(_SecondPoint) + _ExtensionOverlength);

            var angle = (angle1 - angle2).Abs();

            if (_AutoText)
            {
                Text = (angle1 - angle2).Abs().ToDeg().ToInvariantString("F0") + "°";
            }

            Geom2d_Circle circle   = new(new Ax2d(_CenterPoint, Dir2d.DX), radius);
            var           dimWidth = circle.Circ2d().Length() / circle.Period() * angle;

            scale = Math.Min(scale, dimWidth / (arrowSize.Length * 3));

            // Text
            Pnt2d textOrigin  = new();
            Vec2d textTangent = new();

            circle.D1(angle1.Lerp(angle2, 0.5), ref textOrigin, ref textTangent);
            if (textTangent.X < 0.0)
            {
                textTangent.Reverse();
            }
            var textDirection = textTangent.ToDir();
            var textNormal    = new Vec2d(_CenterPoint, textOrigin).ToDir();
            var textWidth     = 1.0;
            var textHeight    = 1.0;
            var textRotation  = textDirection.Angle(Dir2d.DX);
            var textScale     = scale;

            if (!Text.IsNullOrWhiteSpace())
            {
                var fontStyle = DrawingRenderHelper.GetDefaultFontStyle();
                var textSize  = DrawingRenderHelper.MeasureText(Text, fontStyle);
                textScale = Math.Min(1.0, dimWidth * 0.90 / textSize.X);
                scale     = Math.Min(scale, textScale);
                var textOffset = textNormal.Y < 0 ? -1.0 : 1.0; // Exact positioning on above dim line
                textOrigin.Translate(textNormal.ToVec(textOffset));
                textOrigin.Translate(textDirection.ToVec(-textSize.X / 2 * textScale));
                textWidth  = textSize.X * textScale;
                textHeight = textSize.Y * textScale;
            }

            // Arrows
            bool   reverse    = angle1 < angle2;
            double arrowAngle = circle.Period() / circle.Circ2d().Length() * arrowSize.Length * scale * (reverse ? 0.5 : -0.5);

            angle1 += arrowAngle;
            angle2 -= arrowAngle;

            Pnt2d arrowP1 = new(), arrowP2 = new();
            Vec2d arrowT1 = new(), arrowT2 = new();

            circle.D1(angle1, ref arrowP1, ref arrowT1);
            circle.D1(angle2, ref arrowP2, ref arrowT2);
            if (reverse)
            {
                arrowT1.Reverse();
            }
            else
            {
                arrowT2.Reverse();
            }

            arrowP1.Translate(arrowT1.ToDir().ToVec(arrowSize.Length * scale * 0.5));
            arrowP2.Translate(arrowT2.ToDir().ToVec(arrowSize.Length * scale * 0.5));

            // Move arrows slightly towards center, to compensate that the tangent is taken from the middle of the arrow
            double arrowOffset = _CenterPoint.Distance(circle.Value(angle1)) - _CenterPoint.Distance(arrowP1);

            arrowP1.Translate(extDir1.ToVec(arrowOffset));
            arrowP2.Translate(extDir2.ToVec(arrowOffset));

            parameters = new ()
            {
                FirstExtensionVector  = extVector1,
                FirstArrowPoint       = arrowP1,
                FirstArrowTangent     = arrowT1.ToDir(),
                SecondExtensionVector = extVector2,
                SecondArrowPoint      = arrowP2,
                SecondArrowTangent    = arrowT2.ToDir(),
                Radius       = radius,
                StartAngle   = angle1 + arrowAngle,
                EndAngle     = angle2 - arrowAngle,
                TextOrigin   = textOrigin,
                TextRotation = textRotation,
                TextWidth    = textWidth,
                TextHeight   = textHeight,
                Scale        = scale,
                TextScale    = textScale
            };

            return(true);
        }

        //--------------------------------------------------------------------------------------------------

        #endregion
    }
Ejemplo n.º 17
0
 private double DistanceBetweenFirstAndSecondPoint()
 {
     return(FirstPoint.GiveDistanceBetween(SecondPoint));
 }