示例#1
0
            private void ReadHEAD()
            {
                Seek(TableName.HEAD, 0);

                /* var version = */
                ReadFixed();
                /* var fontRevision = */
                ReadFixed();
                /* var checksumAdjustment = */
                ReadUInt32();
                /* var magicNumber = */
                ReadUInt32();
                /* var flags = */
                ReadUInt16();
                _unitsPerEm = ReadUInt16();
                ReadDate();
                ReadDate();
                /* var xmin = */
                ReadInt16();
                /* var ymin = */
                ReadInt16();
                /* var xmax = */
                ReadInt16();
                /* var ymax = */
                ReadInt16();
                ReadUInt16();
                ReadUInt16();
                ReadInt16();

                _indexToLocFormat = ReadInt16();

                _scale   = Vector2Double.Zero;
                _scale.x = _requestedSize / _unitsPerEm;
                _scale.y = _requestedSize / _unitsPerEm;
            }
示例#2
0
        public override bool Contains(Vector2Double position)
        {
            if (Curve == null)
            {
                return(false);
            }

            if (leftComponent is SpecificationComponent && (Curve.GetPoint(leftComponent.Position) - position).Length < 15)
            {
                return(false);
            }
            if (rightComponent is SpecificationComponent && (Curve.GetPoint(rightComponent.Position) - position).Length < 15)
            {
                return(false);
            }

            foreach (double testedPosition in Scalars.GetIntermediateValuesSymmetric(leftComponent.Position, rightComponent.Position, SegmentSegmentCount + 1))
            {
                if ((Curve.GetPoint(testedPosition) - position).Length < 10)
                {
                    return(true);
                }
            }

            return(false);
        }
示例#3
0
    protected void OnButtonReleaseEvent(object o, ButtonReleaseEventArgs args)
    {
        Vector2Double position = new Vector2Double(args.Event.X, args.Event.Y);
        MouseButton   button   = (MouseButton)args.Event.Button;

        rootComponent.MouseUp(position, button);
    }
示例#4
0
		public DiscreteCurveItem(Vector2Double point, double speed, double direction, double curvature)
		{
			this.point = point;
			this.speed = speed;
			this.direction = direction;
			this.curvature = curvature;
		}
示例#5
0
 public virtual void MouseUp(Vector2Double mousePosition, MouseButton mouseButton)
 {
     foreach (Component component in SubComponents.ToArray())
     {
         component.MouseUp(mousePosition, mouseButton);
     }
 }
示例#6
0
 public virtual void MouseMove(Vector2Double mousePosition)
 {
     foreach (Component component in SubComponents.ToArray())
     {
         component.MouseMove(mousePosition);
     }
 }
        public override void MouseUp(Vector2Double mousePosition, MouseButton mouseButton)
        {
            if ((isLeftMouseDown || isRightMouseDown) && (mouseButton == MouseButton.Left || mouseButton == MouseButton.Right))
            {
                if ((mousePosition - mouseDownPosition).Length <= dragThreshold)
                {
                    isSelected = !isSelected;
                    OnSelectionChanged();
                }
                if (mouseButton == MouseButton.Left)
                {
                    isLeftMouseDown = false;
                }
                if (mouseButton == MouseButton.Right)
                {
                    isRightMouseDown = false;
                }
                isDragging = false;
                dragVector = Vector2Double.Origin;

                Changed();
            }

            base.MouseUp(mousePosition, mouseButton);
        }
示例#8
0
    public PolygonData(int n, double vectorScaling)
    {
        name          = n.ToString() + "-gon";
        this.n        = n;
        diagonalCount = Mathf.CeilToInt((n - 3.0f) / 2.0f);
        diagonals     = new List <double>(diagonalCount);
        exteriorAngle = PolygonDiagonal.GetExteriorAngle(n);

//		verts = new List<Vector2Double>(n);
        verts = new List <Vector2Double>(diagonalCount + 2);
        verts.Add(new Vector2Double(0.0, vectorScaling));
        for (int vIndex = 1; vIndex < verts.Capacity; vIndex++)
        {
            Vector2Double newVector = verts[vIndex - 1].Rotate(exteriorAngle);
            verts.Add(newVector);
            if (vIndex == 1)
            {
                sideLength = Vector2Double.Distance(verts[0], newVector);
            }
            else if (vIndex > 1)
            {
                double dist = Vector2Double.Distance(verts[0], newVector) / sideLength / vectorScaling;
//				double dist = diagonals.Count + 1.0 + sideLength / Vector2Double.Distance(verts[0], newVector);
                diagonals.Add(dist);
            }
        }
    }
    public static double Distance(Vector2Double a, Vector2Double b)
    {
        double x = (b.x - a.x);
        double y = (b.y - a.y);

        return(Math.Sqrt(x * x + y * y));
    }
        internal static bool LineSegmentIntersection(Vector2Double p1, Vector2Double p2, Vector2Double p3, Vector2Double p4, ref Vector2Double result)
        {
            double num1 = p2.x - p1.x;
            double num2 = p2.y - p1.y;
            double num3 = p4.x - p3.x;
            double num4 = p4.y - p3.y;
            double num5 = (num1 * num4 - num2 * num3);

            if (Math.Abs(num5) < Epsilon)
            {
                return(false);
            }

            double num6 = p3.x - p1.x;
            double num7 = p3.y - p1.y;
            double num8 = (num6 * num4 - num7 * num3) / num5;

            if (num8 < 0.0d || num8 > 1.0d)
            {
                return(false);
            }

            double num9 = (num6 * num2 - num7 * num1) / num5;

            if (num9 < 0.0d || num9 > 1.0d)
            {
                return(false);
            }

            result = new Vector2Double(p1.x + num8 * num1, p1.y + num8 * num2);

            return(true);
        }
示例#11
0
 public override Vector2Double GetPoint(double mix)
 {
     return(Vector2Double.Mix(
                Vector2Double.Mix(p0, p1, mix),
                Vector2Double.Mix(p1, p2, mix),
                mix));
 }
        public override void MouseMove(Vector2Double mousePosition)
        {
            if (IsDragging)
            {
                if (IsShiftDown)
                {
                    double closestPosition =
                        (
                            from position in Scalars.GetIntermediateValuesSymmetric(0, 1, SegmentCount + 1)
                            let distance = (Curve.GetPoint(position) - mousePosition).Length
                                           orderby distance ascending
                                           select position
                        )
                        .First();

                    CurrentPosition = closestPosition;
                    point           = Curve.GetPoint(closestPosition);
                }
                else
                {
                    Point += DragVector * SlowDownFactor;
                }

                OnSpecificationChanged();
                Changed();
            }

            base.MouseMove(mousePosition);
        }
示例#13
0
        public IEnumerable <XElement> GetSvgPaths()
        {
            Kurve.Curves.Curve curve = optimizer.GetCurve(specification);

            IEnumerable <string> curveCommands = Enumerables.Concatenate
                                                 (
                Enumerables.Create(Svg.MoveTo(curve.GetPoint(0))),
                from positions in Scalars.GetIntermediateValuesSymmetric(0, 1, SegmentCount + 1).GetRanges()
                let controlPoint1 = curve.GetPoint(positions.Item1) + (1.0 / (3 * SegmentCount)) * curve.GetVelocity(positions.Item1)
                                    let controlPoint2 = curve.GetPoint(positions.Item2) - (1.0 / (3 * SegmentCount)) * curve.GetVelocity(positions.Item2)
                                                        let point2 = curve.GetPoint(positions.Item2)
                                                                     select Svg.CurveTo(controlPoint1, controlPoint2, point2)
                                                 );

            yield return(Svg.PathShape(curveCommands, null, Colors.Black, 2));

            IEnumerable <string> curvatureMarkersCommands =
                (
                    from positions in Scalars.GetIntermediateValuesSymmetric(0, 1, SegmentCount + 1).GetRanges()
                    let position = Enumerables.Average(positions.Item1, positions.Item2)
                                   let curvatureVector = CurvatureMarkersFactor * curve.GetCurvature(position) * curve.GetNormalVector(position)
                                                         select Svg.Line(curve.GetPoint(position), curve.GetPoint(position) + curvatureVector)
                );

            yield return(Svg.PathShape(curvatureMarkersCommands, null, Colors.Blue, 0.5));

            foreach (PointCurveSpecification pointCurveSpecification in specification.BasicSpecification.CurveSpecifications.OfType <PointCurveSpecification>())
            {
                Vector2Double point = curve.GetPoint(pointCurveSpecification.Position);

                yield return(Svg.CircleShape(point, 10, Colors.Red, null, 0));
            }
            foreach (DirectionCurveSpecification directionCurveSpecification in specification.BasicSpecification.CurveSpecifications.OfType <DirectionCurveSpecification>())
            {
                Vector2Double directionVector = curve.GetDirectionVector(directionCurveSpecification.Position);
                Vector2Double start           = curve.GetPoint(directionCurveSpecification.Position) - 1000 * directionVector;
                Vector2Double end             = curve.GetPoint(directionCurveSpecification.Position) + 1000 * directionVector;

                yield return(Svg.LineShape(start, end, null, Colors.Green, 2));
            }
            foreach (CurvatureCurveSpecification curvatureCurveSpecification in specification.BasicSpecification.CurveSpecifications.OfType <CurvatureCurveSpecification>())
            {
                if (curvatureCurveSpecification.Curvature == 0)
                {
                    Vector2Double directionVector = curve.GetDirectionVector(curvatureCurveSpecification.Position);
                    Vector2Double start           = curve.GetPoint(curvatureCurveSpecification.Position) - 1000 * directionVector;
                    Vector2Double end             = curve.GetPoint(curvatureCurveSpecification.Position) + 1000 * directionVector;

                    yield return(Svg.LineShape(start, end, null, Colors.Blue, 2));
                }
                else
                {
                    Vector2Double center = curve.GetPoint(curvatureCurveSpecification.Position) - (1.0 / curvatureCurveSpecification.Curvature) * curve.GetNormalVector(curvatureCurveSpecification.Position);
                    double        radius = 1.0 / curvatureCurveSpecification.Curvature.Absolute();

                    yield return(Svg.CircleShape(center, radius, null, Colors.Blue, 2));
                }
            }
        }
示例#14
0
        public static void DrawText(Context context, string text, Vector2Double position, Krach.Graphics.Color color)
        {
            //context.SelectFontFace("Helvetica", FontSlant.Normal, FontWeight.Bold);
            context.SetFontSize(13);
            context.Color = Drawing.ToCairoColor(color);

            context.MoveTo(position.X, position.Y);
            context.ShowText(text);
        }
        public PointCurveSpecification(XElement source)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            this.position = (double)source.Element("position");
            this.point    = new Vector2Double(source.Element("point").Elements().Single());
        }
示例#16
0
        public static void DrawLine(Context context, Vector2Double startPoint, Vector2Double endPoint, double lineWidth, Krach.Graphics.Color color)
        {
            context.MoveTo(startPoint.X, startPoint.Y);
            context.LineTo(endPoint.X, endPoint.Y);

            context.LineWidth = lineWidth;
            context.LineCap   = LineCap.Butt;
            context.Color     = ToCairoColor(color);
            context.Stroke();
        }
        public PointCurveSpecification(double position, Vector2Double point)
        {
            if (position < 0 || position > 1)
            {
                throw new ArgumentOutOfRangeException("position");
            }

            this.position = position;
            this.point    = point;
        }
    public static Vector2Double Rotate(this Vector2Double v, double angle)
    {
        double        sin  = Math.Sin(angle);
        double        cos  = Math.Cos(angle);
        Vector2Double temp = new Vector2Double(v.x, v.y);

        temp.x = cos * v.x - sin * v.y;
        temp.y = sin * v.x + cos * v.y;
        return(temp);
    }
示例#19
0
            public override bool Equals(object other)
            {
                if (!(other is Vector2Double))
                {
                    return(false);
                }
                Vector2Double vector2D = (Vector2Double)other;

                return(this.x.Equals(vector2D.x) && this.y.Equals(vector2D.y));
            }
示例#20
0
 public static Vector2Double ClampMagnitude(Vector2Double vector, double maxLength)
 {
     if (vector.sqrMagnitude > maxLength * maxLength)
     {
         return(vector.normalized * maxLength);
     }
     else
     {
         return(vector);
     }
 }
示例#21
0
            public QuadraticEdge(Vector2Double p0, Vector2Double p1, Vector2Double p2, EdgeColor color) : base(color)
            {
                if (p1 == p0 || p1 == p2)
                {
                    p1 = 0.5 * (p0 + p2);
                }

                this.p0 = p0;
                this.p1 = p1;
                this.p2 = p2;
            }
示例#22
0
            public static Vector2Double MoveTowards(Vector2Double current, Vector2Double target, double maxDistanceDelta)
            {
                Vector2Double vector2   = target - current;
                double        magnitude = vector2.magnitude;

                if (magnitude <= maxDistanceDelta || magnitude == 0.0d)
                {
                    return(target);
                }

                return(current + vector2 / magnitude * maxDistanceDelta);
            }
示例#23
0
 public static XElement CircleShape(Vector2Double center, double radius, Color?fill, Color?stroke, double strokeWidth)
 {
     return(new XElement
            (
                Namespace + "circle",
                new XAttribute("cx", center.X),
                new XAttribute("cy", center.Y),
                new XAttribute("r", radius),
                FillStyle(fill),
                StrokeStyle(stroke),
                StrokeWidthStyle(strokeWidth)
            ));
 }
        public override void MouseMove(Vector2Double mousePosition)
        {
            if (isLeftMouseDown)
            {
                isDragging = true;
                dragVector = mousePosition - lastMousePosition;

                Changed();
            }

            lastMousePosition = mousePosition;

            base.MouseMove(mousePosition);
        }
示例#25
0
 // shapes
 public static XElement LineShape(Vector2Double point1, Vector2Double point2, Color?fill, Color?stroke, double strokeWidth)
 {
     return(new XElement
            (
                Namespace + "line",
                new XAttribute("x1", point1.X),
                new XAttribute("y1", point1.Y),
                new XAttribute("x2", point2.X),
                new XAttribute("y2", point2.Y),
                FillStyle(fill),
                StrokeStyle(stroke),
                StrokeWidthStyle(strokeWidth)
            ));
 }
示例#26
0
        public override void MouseMove(Vector2Double mousePosition)
        {
            base.MouseMove(mousePosition);

            if (IsDragging)
            {
                foreach (SpecificationComponent component in Enumerables.Create(leftComponent, rightComponent).OfType <SpecificationComponent>())
                {
                    component.Point += DragVector * SlowDownFactor;
                }

                OnSpecificationChanged();
            }
        }
示例#27
0
        public override void MouseUp(Vector2Double mousePosition, MouseButton mouseButton)
        {
            if (IsRightMouseDown)
            {
                double closestPosition =
                    (
                        from position in Scalars.GetIntermediateValuesSymmetric(leftComponent.Position, rightComponent.Position, SegmentSegmentCount + 1)
                        let distance = (Curve.GetPoint(position) - mousePosition).Length
                                       orderby distance ascending
                                       select position
                    )
                    .First();

                OnAddSpecification(closestPosition);
            }

            base.MouseUp(mousePosition, mouseButton);
        }
示例#28
0
 protected static void Bounds(Vector2Double p, ref double l, ref double b, ref double r, ref double t)
 {
     if (p.x < l)
     {
         l = p.x;
     }
     if (p.y < b)
     {
         b = p.y;
     }
     if (p.x > r)
     {
         r = p.x;
     }
     if (p.y > t)
     {
         t = p.y;
     }
 }
示例#29
0
        public override void Draw(Context context)
        {
            if (curve != null)
            {
                foreach (Tuple <double, double> positions in Scalars.GetIntermediateValuesSymmetric(0, 1, SegmentCount + 1).GetRanges())
                {
                    double position = Enumerables.Average(positions.Item1, positions.Item2);

                    Vector2Double curvatureVector = CurveOptimizer.CurvatureMarkersFactor * curve.GetCurvature(position) * curve.GetNormalVector(position);

                    Krach.Graphics.Color lineColor = StretchColor(curve.GetSpeed(position) / basicSpecification.CurveLength);

                    Drawing.DrawLine(context, curve.GetPoint(position), curve.GetPoint(position) + curvatureVector, 0.5, Colors.Blue);
                    Drawing.DrawLine(context, curve.GetPoint(positions.Item1), curve.GetPoint(positions.Item2), 2, lineColor);
                }
            }

            base.Draw(context);
        }
        public override void MouseDown(Vector2Double mousePosition, MouseButton mouseButton)
        {
            if (Contains(mousePosition) && (mouseButton == MouseButton.Left || mouseButton == MouseButton.Right))
            {
                if (mouseButton == MouseButton.Left)
                {
                    isLeftMouseDown = true;
                }
                if (mouseButton == MouseButton.Right)
                {
                    isRightMouseDown = true;
                }

                mouseDownPosition = mousePosition;

                Changed();
            }

            base.MouseDown(mousePosition, mouseButton);
        }