Exemple #1
0
 public Struct12(Point2L start, Point2L end, Vector2L delta)
 {
     this.point2L_0  = start;
     this.point2L_1  = end;
     this.vector2L_0 = delta;
     this.long_0     = this.vector2L_0.GetLengthSquared();
 }
Exemple #2
0
        public bool Contains(Point2L point)
        {
            if (point.X > System.Math.Max(this.start.X, this.end.X) || point.X < System.Math.Min(this.start.X, this.end.X) || (point.Y > System.Math.Max(this.start.Y, this.end.Y) || point.Y < System.Math.Min(this.start.Y, this.end.Y)))
            {
                return(false);
            }
            if (this.start == this.end)
            {
                return(true);
            }
            Vector2L delta = this.GetDelta();
            Vector2L u     = point - this.start;
            Vector2L v     = new Vector2L(-delta.Y, delta.X);

            if (Vector2L.DotProduct(u, v) != 0L)
            {
                return(false);
            }
            long num = Vector2L.DotProduct(u, delta);

            if (num < 0L)
            {
                return(false);
            }
            long lengthSquared = delta.GetLengthSquared();

            return(num <= lengthSquared);
        }
Exemple #3
0
 void pictureBox1_MouseDown(object sender, MouseEventArgs e)
 {
     if ((e.Button & MouseButtons.Left) != 0)
     {
         _start = new Point2L(e.X, e.Y);
     }
 }
Exemple #4
0
            public bool method_1(Point2L point)
            {
                long num = Vector2L.DotProduct(point - this.point2L_0, this.vector2L_0);

                if (num >= 0L)
                {
                    return(num <= this.long_0);
                }
                return(false);
            }
Exemple #5
0
        public LongRational?GetNormalizedProjection(Point2L point)
        {
            if (this.start == this.end)
            {
                return(new LongRational?());
            }
            Vector2L delta = this.GetDelta();

            return(new LongRational?(new LongRational(Vector2L.DotProduct(point - this.start, delta), delta.GetLengthSquared())));
        }
Exemple #6
0
        public bool ContainsProjection(Point2L point)
        {
            Vector2L delta = this.GetDelta();
            long     num   = Vector2L.DotProduct(point - this.start, delta);

            if (num < 0L)
            {
                return(false);
            }
            long lengthSquared = delta.GetLengthSquared();

            return(num * num <= lengthSquared);
        }
Exemple #7
0
        /// <summary>
        /// Draws the image on SurfaceImageSource.
        /// </summary>
        void UpdateImageSource(ImageEffect imageEffect)
        {
            int     w             = _bitmap.PixelWidth + _marginLT + _marginRB;
            int     h             = _bitmap.PixelHeight + _marginLT + _marginRB;
            Point2L surfaceOffset = Point2L.Empty;

            DXGI.Surface dxgiSurface = null;
            var          hr          = HResult.Ok;

            // receive the target DXGI.Surface and offset for drawing
            for (int i = 0; i <= 1; i++)
            {
                hr = _sisNative.BeginDraw(new RectL(w, h), out surfaceOffset, out dxgiSurface);
                if ((hr != DXGI.ResultCode.DeviceRemoved && hr != DXGI.ResultCode.DeviceReset) || i > 0)
                {
                    break;
                }

                // try to recreate the device resources if the old GPU device was removed
                DiscardDeviceResources();
                CreateDeviceResources();
                _sisNative.SetDevice(_dxgiDevice);
            }
            hr.CheckError();

            // the render target object
            var rt = _d2dContext;

            // create the target Direct2D bitmap for the given DXGI.Surface
            var bpTarget = new D2D.BitmapProperties1(
                new D2D.PixelFormat(DXGI.Format.B8G8R8A8_UNorm, D2D.AlphaMode.Premultiplied),
                (float)_bitmap.DpiX, (float)_bitmap.DpiY, D2D.BitmapOptions.Target | D2D.BitmapOptions.CannotDraw);

            var targetBmp = D2D.Bitmap1.Create(rt, dxgiSurface, bpTarget);

            dxgiSurface.Dispose();

            // associate the target bitmap with render target
            rt.SetTarget(targetBmp);
            targetBmp.Dispose();

            // start drawing
            rt.BeginDraw();

            // clear the target bitmap
            rt.Clear(null);

            // convert C1Bitmap image to Direct2D image
            var d2dBitmap = _bitmap.ToD2DBitmap1(rt, D2D.BitmapOptions.None);

            // apply the effect or just draw the original image
            surfaceOffset.X += _marginLT;
            surfaceOffset.Y += _marginLT;
            var targetOffset = surfaceOffset.ToPoint2F();

            switch (imageEffect)
            {
            case ImageEffect.Original:
                rt.DrawImage(d2dBitmap, targetOffset);
                break;

            case ImageEffect.GaussianBlur:
                rt.DrawImage(ApplyGaussianBlur(d2dBitmap), targetOffset);
                break;

            case ImageEffect.Sharpen:
                rt.DrawImage(ApplySharpen(d2dBitmap), targetOffset);
                break;

            case ImageEffect.HorizontalSmear:
                rt.DrawImage(ApplyHorizontalSmear(d2dBitmap), targetOffset);
                break;

            case ImageEffect.Shadow:
                rt.DrawImage(ApplyShadow(d2dBitmap), targetOffset);
                break;

            case ImageEffect.DisplacementMap:
                rt.DrawImage(ApplyDisplacementMap(d2dBitmap), targetOffset);
                break;

            case ImageEffect.Emboss:
                rt.DrawImage(ApplyEmboss(d2dBitmap), targetOffset);
                break;

            case ImageEffect.EdgeDetect:
                rt.DrawImage(ApplyEdgeDetect(d2dBitmap), targetOffset);
                break;

            case ImageEffect.Sepia:
                rt.DrawImage(ApplySepia(d2dBitmap), targetOffset);
                break;
            }
            d2dBitmap.Dispose();

            // draw the additional text label in case of the Shadow effect
            if (imageEffect == ImageEffect.Shadow)
            {
                var mr = Matrix3x2.Rotation(-90f);
                var mt = Matrix3x2.Translation(targetOffset.X + 6f, targetOffset.Y + 344f);
                rt.Transform = mr * mt;
                _brush.SetColor(ColorF.White);
                rt.DrawTextLayout(new Point2F(-1f, -1f), _textLayout, _brush);
                _brush.SetColor(ColorF.DimGray);
                rt.DrawTextLayout(Point2F.Empty, _textLayout, _brush);
                rt.Transform = Matrix3x2.Identity;
            }

            // finish drawing (all drawing commands are executed at that moment)
            rt.EndDraw();

            // detach and actually dispose the target bitmap
            rt.SetTarget(null);

            // complete drawing on SurfaceImageSource
            _sisNative.EndDraw();
        }
Exemple #8
0
 public bool method_0(Point2L p)
 {
     return(Vector2L.DotProduct(p - this.point2L_0, new Vector2L(-this.vector2L_0.Y, this.vector2L_0.X)) == 0L);
 }
Exemple #9
0
        public static int GetIntersections20Bits(
            Segment2L a,
            Segment2L b,
            out Point2L intersection1,
            out Point2L intersection2)
        {
            Vector2L delta1 = a.GetDelta();
            Vector2L delta2 = b.GetDelta();
            long     num1   = delta1.X * delta2.Y - delta1.Y * delta2.X;

            if (num1 == 0L)
            {
                Segment2L.Struct12 struct12_1 = new Segment2L.Struct12(a.start, a.end, delta1);
                Segment2L.Struct12 struct12_2 = new Segment2L.Struct12(b.start, b.end, delta2);
                if ((struct12_1.long_0 > struct12_2.long_0 ? (!struct12_1.method_0(b.start) ? 0 : (struct12_1.method_0(b.End) ? 1 : 0)) : (struct12_2.long_0 == 0L || !struct12_2.method_0(a.start) ? 0 : (struct12_2.method_0(a.end) ? 1 : 0))) != 0)
                {
                    if (struct12_1.method_1(b.start))
                    {
                        if (struct12_1.method_1(b.end))
                        {
                            intersection1 = b.start;
                            intersection2 = b.end;
                            return(2);
                        }
                        if (struct12_2.method_1(a.start))
                        {
                            intersection1 = a.start;
                            intersection2 = b.start;
                            return(2);
                        }
                        if (struct12_2.method_1(a.End))
                        {
                            intersection1 = b.start;
                            intersection2 = a.end;
                            return(2);
                        }
                    }
                    else if (struct12_1.method_1(b.end))
                    {
                        if (struct12_2.method_1(a.start))
                        {
                            if (struct12_2.method_1(a.End))
                            {
                                intersection1 = a.start;
                                intersection2 = a.end;
                            }
                            else
                            {
                                intersection1 = a.start;
                                intersection2 = b.end;
                            }
                            return(2);
                        }
                        if (struct12_2.method_1(a.End))
                        {
                            intersection1 = a.end;
                            intersection2 = b.end;
                            return(2);
                        }
                    }
                    else if (struct12_2.method_1(a.start))
                    {
                        intersection1 = a.start;
                        intersection2 = a.end;
                        return(2);
                    }
                }
                intersection1 = Point2L.Zero;
                intersection2 = Point2L.Zero;
                return(0);
            }
            long num2 = (b.Start.X - a.Start.X) * delta2.Y - (b.Start.Y - a.Start.Y) * delta2.X;

            if (num1 > 0L)
            {
                if (num2 < 0L || num2 > num1)
                {
                    intersection1 = Point2L.Zero;
                    intersection2 = Point2L.Zero;
                    return(0);
                }
            }
            else if (num2 > 0L || num2 < num1)
            {
                intersection1 = Point2L.Zero;
                intersection2 = Point2L.Zero;
                return(0);
            }
            long num3 = (b.Start.X - a.Start.X) * delta1.Y - (b.Start.Y - a.Start.Y) * delta1.X;

            if (num1 > 0L)
            {
                if (num3 < 0L || num3 > num1)
                {
                    intersection1 = Point2L.Zero;
                    intersection2 = Point2L.Zero;
                    return(0);
                }
            }
            else if (num3 > 0L || num3 < num1)
            {
                intersection1 = Point2L.Zero;
                intersection2 = Point2L.Zero;
                return(0);
            }
            long num4 = num2 * delta1.X;
            long num5 = num2 * delta1.Y;

            intersection1 = new Point2L(a.start.X + num4 / num1 << 43, a.start.Y + num5 / num1 << 43);
            long   num6 = num4 % num1;
            long   num7 = num5 % num1;
            double a1   = (double)num6 * 8796093022208.0 / (double)num1;
            double a2   = (double)num7 * 8796093022208.0 / (double)num1;

            intersection1.X += (long)System.Math.Round(a1);
            intersection1.Y += (long)System.Math.Round(a2);
            intersection2    = Point2L.Zero;
            return(1);
        }
Exemple #10
0
 public Segment2L(long startx, long starty, long endx, long endy)
 {
     this.start = new Point2L(startx, starty);
     this.end   = new Point2L(endx, endy);
 }
Exemple #11
0
 public Segment2L(Point2L start, Point2L end)
 {
     this.start = start;
     this.end   = end;
 }