コード例 #1
0
        //bool hitTestInit = false;

        //void InitHitTest(RenderContext renderContext)
        //{
        //    Vector2d center = new Vector2d();
        //    double radius = 0;
        //    Vector2d[] screenPoints = new Vector2d[points.Count];
        //    int index = 0;
        //    foreach (Vector3d pnt in points)
        //    {
        //        Vector3d screenSpacePnt = renderContext.ViewMatrix.Transform(pnt);
        //        if (screenSpacePnt.Z < 0)
        //        {
        //            return;
        //        }
        //        if (Vector3d.Dot(renderContext.ViewPoint, pnt) < .55)
        //        {
        //            return;
        //        }
        //        screenPoints[index] = new Vector2d(screenSpacePnt.X, screenSpacePnt.Y);
        //        index++;
        //    }

        //    ConvexHull.FindEnclosingCircle(screenPoints, out center, out radius);
        //}

        public override void Draw(RenderContext renderContext)
        {
            if (renderContext.gl != null)
            {
                //todo draw in WebGL
            }
            else
            {
                CanvasContext2D ctx = renderContext.Device;
                ctx.Save();
                ctx.Alpha = Opacity;

                ctx.BeginPath();

                bool first = true;
                foreach (Vector3d pnt in points)
                {
                    Vector3d screenSpacePnt = renderContext.WVP.Transform(pnt);
                    if (screenSpacePnt.Z < 0)
                    {
                        ctx.Restore();

                        return;
                    }

                    if (Vector3d.Dot(renderContext.ViewPoint, pnt) < .75)
                    {
                        ctx.Restore();
                        return;
                    }

                    if (first)
                    {
                        first = false;
                        ctx.MoveTo(screenSpacePnt.X, screenSpacePnt.Y);
                    }
                    else
                    {
                        ctx.LineTo(screenSpacePnt.X, screenSpacePnt.Y);
                    }
                }
                ctx.ClosePath();

                ctx.LineWidth = strokeWidth;
                if (fill)
                {
                    ctx.FillStyle = fillColor.ToString();
                    ctx.Fill();
                }

                ctx.StrokeStyle = lineColor.ToString();
                ctx.Alpha       = 1;
                ctx.Stroke();

                ctx.Restore();
            }
        }
コード例 #2
0
        public void DrawLines(RenderContext renderContext, float opacity, Color color)
        {
            if (linePoints.Count < 2)
            {
                return;
            }

            InitLineBuffer(renderContext);

            int count = linePoints.Count;

            if (renderContext.gl == null)
            {
                Vector3d viewPoint = Vector3d.TransformCoordinate(renderContext.ViewPoint, ViewTransform);



                CanvasContext2D ctx = renderContext.Device;
                ctx.Save();

                ctx.StrokeStyle = color.ToString();
                ctx.LineWidth   = 2;
                ctx.Alpha       = .25;
                Vector3d firstPoint  = new Vector3d();
                Vector3d secondPoint = new Vector3d();
                for (int i = 0; i < count; i += 2)
                {
                    firstPoint  = renderContext.WVP.Transform(linePoints[i]);
                    secondPoint = renderContext.WVP.Transform(linePoints[i + 1]);
                    if (Vector3d.Dot(linePoints[i], viewPoint) > .60)
                    {
                        ctx.BeginPath();
                        ctx.MoveTo(firstPoint.X, firstPoint.Y);
                        ctx.LineTo(secondPoint.X, secondPoint.Y);


                        ctx.Stroke();
                    }
                }
                ctx.Restore();
            }
            else
            {
                foreach (PositionVertexBuffer lineBuffer in lineBuffers)
                {
                    if (Pure2D)
                    {
                        SimpleLineShader2D.Use(renderContext, lineBuffer.VertexBuffer, color, zBuffer);
                    }
                    else
                    {
                        SimpleLineShader.Use(renderContext, lineBuffer.VertexBuffer, color, zBuffer);
                    }
                    renderContext.gl.drawArrays(GL.LINES, 0, lineBuffer.Count);
                }
            }
        }
コード例 #3
0
ファイル: Overlay.cs プロジェクト: itguy327/wwt-web-client
        private void CreateStarGeometry(RenderContext renderContext)
        {
            CanvasContext2D ctx = renderContext.Device;

            ctx.Save();
            ctx.Translate(X, Y);
            ctx.Rotate(RotationAngle * RC);
            ctx.BeginPath();

            double centerX = 0;
            double centerY = 0;
            double radius  = Width / 2;

            double radiansPerSegment = ((double)Math.PI * 2) / 5;

            bool first = true;

            for (int i = 0; i < 5; i++)
            {
                double rads = i * radiansPerSegment - (Math.PI / 2);
                if (first)
                {
                    first = false;
                    ctx.MoveTo(centerX + Math.Cos(rads) * (Width / 2), centerY + Math.Sin(rads) * (Height / 2));
                }
                else
                {
                    ctx.LineTo(centerX + Math.Cos(rads) * (Width / 2), centerY + Math.Sin(rads) * (Height / 2));
                }

                double rads2 = i * radiansPerSegment + (radiansPerSegment / 2) - (Math.PI / 2);
                ctx.LineTo(centerX + Math.Cos(rads2) * (Width / 5.3), centerY + Math.Sin(rads2) * (Height / 5.3));
            }

            ctx.ClosePath();
            ctx.LineWidth = 0;
            ctx.FillStyle = Color.ToString();


            ctx.Alpha = Opacity;
            ctx.Fill();
            ctx.Restore();
        }
コード例 #4
0
ファイル: Overlay.cs プロジェクト: itguy327/wwt-web-client
        private void CreateRectGeometry(RenderContext renderContext)
        {
            CanvasContext2D ctx = renderContext.Device;

            ctx.Save();
            ctx.Translate(X, Y);
            ctx.Rotate(RotationAngle * RC);

            ctx.BeginPath();
            ctx.MoveTo(-Width / 2, -Height / 2);
            ctx.LineTo(Width / 2, -Height / 2);
            ctx.LineTo(Width / 2, +Height / 2);
            ctx.LineTo(-Width / 2, +Height / 2);
            ctx.ClosePath();
            ctx.LineWidth = 0;
            ctx.FillStyle = Color.ToString();

            ctx.Alpha = Opacity;
            ctx.Fill();
            ctx.Restore();
        }
コード例 #5
0
        public void DrawHistogram(CanvasContext2D ctx)
        {
            ctx.ClearRect(0, 0, 255, 150);
            ctx.BeginPath();
            ctx.StrokeStyle = "rgba(255,255,255,255)";
            double logMax = Math.Log(HistogramMaxCount);

            for (int i = 0; i < Histogram.Length; i++)
            {
                double height = Math.Log(Histogram[i]) / logMax;
                if (height < 0)
                {
                    height = 0;
                }

                ctx.MoveTo(i, 150);
                ctx.LineTo(i, 150 - (height * 150));
                ctx.Stroke();
            }
        }
コード例 #6
0
ファイル: Overlay.cs プロジェクト: itguy327/wwt-web-client
        private void CreateLineGeometry(RenderContext renderContext)
        {
            //todo this needs to be Dashed rounded lines..

            CanvasContext2D ctx = renderContext.Device;

            ctx.Save();
            double radius = Width / 2;

            ctx.Translate(X, Y);
            ctx.Rotate(RotationAngle * RC);

            ctx.MoveTo(-radius, 0);
            ctx.LineTo(radius, 0);
            ctx.LineWidth   = 9;
            ctx.StrokeStyle = Color.ToString();
            ctx.Alpha       = Opacity;
            ctx.Stroke();
            ctx.Restore();
        }
コード例 #7
0
        //protected Vector3d RaDecTo3d(double lat, double lng)
        //{
        //    return Vector3d.Create((Math.Cos(lng * RC) * Math.Cos(lat * RC) * radius), (Math.Sin(lat * RC) * radius), (Math.Sin(lng * RC) * Math.Cos(lat * RC) * radius));

        //}
        private void DrawSingleConstellationOld(RenderContext renderContext, Lineset ls)
        {
            bool reverse = false;
            // todo get this working
            Place centroid = ConstellationCentroids[ls.Name];

            if (centroid != null)
            {
                Vector3d pos = Coordinates.RADecTo3d(reverse ? -centroid.RA - 6 : centroid.RA, reverse ? centroid.Dec : centroid.Dec);

                if (Vector3d.Dot(renderContext.ViewPoint, pos) < maxSeperation)
                {
                    return;
                }
            }

            drawCount++;
            string col;

            if (boundry)
            {
                if (constToDraw != ls.Name)
                {
                    col = Settings.GlobalSettings.ConstellationBoundryColor;
                }
                else
                {
                    col = Settings.GlobalSettings.ConstellationSelectionColor;
                }
            }
            else
            {
                col = Settings.GlobalSettings.ConstellationFigureColor;
            }

            if (renderContext.gl == null)
            {
                CanvasContext2D ctx = renderContext.Device;

                int count = ls.Points.Count;

                Vector3d lastPoint = new Vector3d();
                ctx.Save();
                bool linePending = false;
                ctx.BeginPath();
                ctx.StrokeStyle = col;
                ctx.LineWidth   = 2;
                ctx.Alpha       = .25;
                for (int i = 0; i < count; i++)
                {
                    if (ls.Points[i].PointType == PointType.Move || i == 0)
                    {
                        if (linePending)
                        {
                            ctx.Stroke();
                        }
                        lastPoint = renderContext.WVP.Transform(Coordinates.RADecTo3d(ls.Points[i].RA, ls.Points[i].Dec));

                        ctx.MoveTo(lastPoint.X, lastPoint.Y);
                    }
                    else
                    {
                        Vector3d newPoint = renderContext.WVP.Transform(Coordinates.RADecTo3d(ls.Points[i].RA, ls.Points[i].Dec));

                        //            if (lastPoint.Z > 0 && newPoint.Z > 0)
                        {
                            ctx.LineTo(newPoint.X, newPoint.Y);
                            linePending = true;
                        }
                    }
                }

                if (boundry)
                {
                    ctx.ClosePath();
                }

                ctx.Stroke();
                ctx.Restore();
            }
            else
            {
                //todo add webgl method of drawing
            }
        }
コード例 #8
0
        public override void Draw(RenderContext renderContext)
        {
            if (renderContext.gl != null)
            {
                if (Annotation.BatchDirty || AnnotationDirty)
                {
                    //todo can we save this work for later?
                    List <Vector3d> vertexList = points;


                    if (strokeWidth > 0)
                    {
                        for (int i = 0; i < (points.Count - 1); i++)
                        {
                            LineList.AddLine(vertexList[i], vertexList[i + 1], lineColor, new Dates(0, 1));
                        }
                    }

                    AnnotationDirty = false;
                }
            }
            else
            {
                CanvasContext2D ctx = renderContext.Device;
                ctx.Save();
                ctx.Alpha = Opacity;

                bool first = true;
                foreach (Vector3d pnt in points)
                {
                    Vector3d screenSpacePnt = renderContext.WVP.Transform(pnt);
                    if (screenSpacePnt.Z < 0)
                    {
                        ctx.Restore();
                        return;
                    }
                    if (Vector3d.Dot(renderContext.ViewPoint, pnt) < .75)
                    {
                        ctx.Restore();
                        return;
                    }
                    if (first)
                    {
                        first = false;
                        ctx.BeginPath();
                        ctx.MoveTo(screenSpacePnt.X, screenSpacePnt.Y);
                    }
                    else
                    {
                        ctx.LineTo(screenSpacePnt.X, screenSpacePnt.Y);
                    }
                }

                ctx.LineWidth = strokeWidth;

                ctx.StrokeStyle = lineColor.ToString();

                ctx.Stroke();

                ctx.Restore();
            }
        }
コード例 #9
0
        //bool hitTestInit = false;

        //void InitHitTest(RenderContext renderContext)
        //{
        //    Vector2d center = new Vector2d();
        //    double radius = 0;
        //    Vector2d[] screenPoints = new Vector2d[points.Count];
        //    int index = 0;
        //    foreach (Vector3d pnt in points)
        //    {
        //        Vector3d screenSpacePnt = renderContext.ViewMatrix.Transform(pnt);
        //        if (screenSpacePnt.Z < 0)
        //        {
        //            return;
        //        }
        //        if (Vector3d.Dot(renderContext.ViewPoint, pnt) < .55)
        //        {
        //            return;
        //        }
        //        screenPoints[index] = new Vector2d(screenSpacePnt.X, screenSpacePnt.Y);
        //        index++;
        //    }

        //    ConvexHull.FindEnclosingCircle(screenPoints, out center, out radius);
        //}

        public override void Draw(RenderContext renderContext)
        {
            if (renderContext.gl != null)
            {
                if (Annotation.BatchDirty || AnnotationDirty)
                {
                    //todo can we save this work for later?
                    List <Vector3d> vertexList = points;


                    if (strokeWidth > 0 && points.Count > 1)
                    {
                        for (int i = 0; i < (points.Count - 1); i++)
                        {
                            LineList.AddLine(vertexList[i], vertexList[i + 1], lineColor, new Dates(0, 1));
                        }
                        LineList.AddLine(vertexList[points.Count - 1], vertexList[0], lineColor, new Dates(0, 1));
                    }
                    if (fill)
                    {
                        List <int> indexes = Tessellator.TesselateSimplePoly(vertexList);

                        for (int i = 0; i < indexes.Count; i += 3)
                        {
                            TriangleList.AddSubdividedTriangles(vertexList[indexes[i]], vertexList[indexes[i + 1]], vertexList[indexes[i + 2]], fillColor, new Dates(0, 1), 2);
                        }
                    }
                    AnnotationDirty = false;
                }
            }
            else
            {
                CanvasContext2D ctx = renderContext.Device;
                ctx.Save();
                ctx.Alpha = Opacity;

                ctx.BeginPath();

                bool first = true;
                foreach (Vector3d pnt in points)
                {
                    Vector3d screenSpacePnt = renderContext.WVP.Transform(pnt);
                    if (screenSpacePnt.Z < 0)
                    {
                        ctx.Restore();

                        return;
                    }

                    if (Vector3d.Dot(renderContext.ViewPoint, pnt) < .75)
                    {
                        ctx.Restore();
                        return;
                    }

                    if (first)
                    {
                        first = false;
                        ctx.MoveTo(screenSpacePnt.X, screenSpacePnt.Y);
                    }
                    else
                    {
                        ctx.LineTo(screenSpacePnt.X, screenSpacePnt.Y);
                    }
                }
                ctx.ClosePath();

                ctx.LineWidth = strokeWidth;
                if (fill)
                {
                    ctx.FillStyle = fillColor.ToString();
                    ctx.Fill();
                }

                ctx.StrokeStyle = lineColor.ToString();
                ctx.Alpha       = 1;
                ctx.Stroke();

                ctx.Restore();
            }
        }
コード例 #10
0
        private bool DrawTriangle(CanvasContext2D ctx, ImageElement im, double x0, double y0, double x1, double y1, double x2, double y2,
                                  double sx0, double sy0, double sx1, double sy1, double sx2, double sy2)
        {
            if (!Intersects(0, Width, 0, Height, x0, y0, x1, y1, x2, y2))
            {
                return(false);
            }

            //double edgeOffset = isOutlined ? ContractionInPixels : ExpansionInPixels;
            //Vector2d expandedS0 = GetMiterPoint(Vector2d.Create(x0, y0), Vector2d.Create(x1, y1), Vector2d.Create(x2, y2), ExpansionInPixels);
            //Vector2d expandedS1 = GetMiterPoint(Vector2d.Create(x1, y1), Vector2d.Create(x0, y0), Vector2d.Create(x2, y2), ExpansionInPixels);
            //Vector2d expandedS2 = GetMiterPoint(Vector2d.Create(x2, y2), Vector2d.Create(x1, y1), Vector2d.Create(x0, y0), ExpansionInPixels);

            //Vector2d expandedS0 = MiterPoint(x0, y0, x1, y1, x2, y2);
            //Vector2d expandedS1 = MiterPoint(x1, y1, x0, y0, x2, y2);
            //Vector2d expandedS2 = MiterPoint(x2, y2, x1, y1, x0, y0);
            MiterPointOut(expandedS0, x0, y0, x1, y1, x2, y2, ExpansionInPixels);
            MiterPointOut(expandedS1, x1, y1, x0, y0, x2, y2, ExpansionInPixels);
            MiterPointOut(expandedS2, x2, y2, x1, y1, x0, y0, ExpansionInPixels);

            x0 = expandedS0.X;
            y0 = expandedS0.Y;
            x1 = expandedS1.X;
            y1 = expandedS1.Y;
            x2 = expandedS2.X;
            y2 = expandedS2.Y;


            ctx.Save();
            if (RenderingOn)
            {
                ctx.BeginPath();
                ctx.MoveTo(x0, y0);
                ctx.LineTo(x1, y1);
                ctx.LineTo(x2, y2);
                ctx.ClosePath();
                ctx.Clip();
            }
            double denom = sx0 * (sy2 - sy1) - sx1 * sy2 + sx2 * sy1 + (sx1 - sx2) * sy0;
            //if (denom == 0)
            //{
            //    ctx.Restore();
            //    return false;
            //}
            double m11 = -(sy0 * (x2 - x1) - sy1 * x2 + sy2 * x1 + (sy1 - sy2) * x0) / denom;
            double m12 = (sy1 * y2 + sy0 * (y1 - y2) - sy2 * y1 + (sy2 - sy1) * y0) / denom;
            double m21 = (sx0 * (x2 - x1) - sx1 * x2 + sx2 * x1 + (sx1 - sx2) * x0) / denom;
            double m22 = -(sx1 * y2 + sx0 * (y1 - y2) - sx2 * y1 + (sx2 - sx1) * y0) / denom;
            double dx  = (sx0 * (sy2 * x1 - sy1 * x2) + sy0 * (sx1 * x2 - sx2 * x1) + (sx2 * sy1 - sx1 * sy2) * x0) / denom;
            double dy  = (sx0 * (sy2 * y1 - sy1 * y2) + sy0 * (sx1 * y2 - sx2 * y1) + (sx2 * sy1 - sx1 * sy2) * y0) / denom;


            ctx.Transform(m11, m12, m21, m22, dx, dy);

            if (RenderingOn)
            {
                ctx.Alpha = Opacity;

                if (lighting < 1.0)
                {
                    ctx.Alpha     = 1;
                    ctx.FillStyle = "Black";
                    ctx.FillRect(0, 0, Width, Height);
                    ctx.Alpha = lighting * Opacity;
                }

                ctx.DrawImage(im, 0, 0);
            }



            ctx.Restore();
            return(true);
        }
コード例 #11
0
ファイル: RaceLevel.cs プロジェクト: Ventajou/Space-Dinosaurs
        protected override void Update(CanvasContext2D context)
        {
            if (Status != RaceStatus.Fail && Status != RaceStatus.Win)
            {
                context.DrawImage(_timeLeftFrame, 308, 10);

                Type.SetField(context, "textAlign", "right");
                context.FillStyle = "#00AD11";

                if (TimeLeft > 10000 || Math.Floor((TimeLeft / 300) % 2) != 0)
                {
                    if (TimeLeft < 0)
                    {
                        TimeLeft = 0;
                    }
                    context.Font = "110px Digital";
                    context.FillText(Math.Floor(TimeLeft / 1000).ToString(), 475, 105);
                }

                if (Speed > 0)
                {
                    context.Save();
                    context.Scale(-1, 1);
                    long width = Math.Floor((10 * Speed) / MaxSpeed) * 22;
                    if (width > 0)
                    {
                        context.DrawImage(_meterImage, 220 - width, 0, width, 102, -561 - width, 20, width, 102);
                    }
                    context.Restore();
                }

                context.Font = "30px Digital";
                context.FillText(Math.Floor(Speed * 5) + " Km/h", 780, 120);

                int rpmWidth = Math.Floor(_rpm / 500) * 22 + 22;

                context.DrawImage(_meterImage, 220 - rpmWidth, 0, rpmWidth, 102, 240 - rpmWidth, 20, rpmWidth, 102);
                context.FillText(Math.Floor(_rpm) + " RPM", 130, 120);

                context.BeginPath();
                context.LineWidth   = 3;
                context.StrokeStyle = "#00AD11";
                context.MoveTo(5, 150);
                float x = 5 + Math.Min(Position * 735 / RoadLength, 735);
                context.LineTo(x, 150);
                context.Stroke();
                context.ClosePath();

                context.BeginPath();
                context.StrokeStyle = "#006808";
                context.MoveTo(x, 150);
                context.LineTo(790, 150);
                context.Stroke();
                context.ClosePath();
                context.DrawImage(_markerImage, x, 142);
            }

            if (Status == RaceStatus.Running)
            {
                TimeLeft -= DeltaTime;

                if (TimeLeft < 0)
                {
                    _music.Pause();
                    CarSystem.CarObject.CurrentAnimation = "Forward";
                    Status = RaceStatus.Fail;
                    ShowMessage(_failMessage);
                    RemoveSystem(_engineSoundSystem);
                    RemoveSystem(_npcSystem);
                    pendingTimers.Add(Window.SetTimeout(delegate()
                    {
                        UpdateMessage("<p>Press a key to continue.</p>");
                    }, 3000));
                }
            }
        }
コード例 #12
0
        public void Draw()
        {
            CanvasElement   canvas = Document.GetElementById <CanvasElement>("graph");
            CanvasContext2D ctx    = (CanvasContext2D)canvas.GetContext(Rendering.Render2D);

            if (image != null)
            {
                image.DrawHistogram(ctx);
            }

            string red   = "rgba(255,0,0,255)";
            string green = "rgba(0,255,0,255)";
            string blue  = "rgba(0,0,255,255)";

            ctx.StrokeStyle = red;
            ctx.BeginPath();
            ctx.MoveTo(lowPosition, 0);
            ctx.LineTo(lowPosition, 150);

            ctx.Stroke();

            ctx.StrokeStyle = green;
            ctx.BeginPath();
            ctx.MoveTo(highPosition, 0);
            ctx.LineTo(highPosition, 150);
            ctx.Stroke();

            ctx.StrokeStyle = blue;
            ctx.BeginPath();
            ctx.Arc(center, 75, 10, 0, Math.PI * 2, false);
            ctx.ClosePath();
            ctx.Stroke();


            List <Vector2d> Curve = new List <Vector2d>();

            //todo get from combo box

            switch (SelectedCurveStyle)
            {
            case 0:     // Linear
            {
                Curve.Clear();
                Curve.Add(Vector2d.Create(lowPosition, 150));
                Curve.Add(Vector2d.Create(highPosition, 0));
                break;
            }

            case 1:     // Log
            {
                Curve.Clear();
                double factor = 150 / Math.Log(255);
                double diff   = (highPosition - lowPosition);
                int    jump   = diff < 0 ? -1 : 1;
                double step   = Math.Abs(256.0 / (diff == 0 ? .000001 : diff));
                double val    = .000001;
                for (int i = lowPosition; i != highPosition; i += jump)
                {
                    Curve.Add(Vector2d.Create((float)i, (float)(150 - (Math.Log(val) * factor))));
                    val += step;
                }
            }
            break;

            case 2:     // Power 2
            {
                Curve.Clear();
                double factor = 150 / Math.Pow(255, 2);
                double diff   = (highPosition - lowPosition);
                int    jump   = diff < 0 ? -1 : 1;
                double step   = Math.Abs(256.0 / (diff == 0 ? .000001 : diff));
                double val    = .000001;
                for (int i = lowPosition; i != highPosition; i += jump)
                {
                    Curve.Add(Vector2d.Create((float)i, (float)(150 - (Math.Pow(val, 2) * factor))));
                    val += step;
                }
            }

            break;

            case 3:     // Square Root
            {
                Curve.Clear();
                double factor = 150 / Math.Sqrt(255);
                double diff   = (highPosition - lowPosition);
                int    jump   = diff < 0 ? -1 : 1;
                double step   = Math.Abs(256.0 / (diff == 0 ? .000001 : diff));
                double val    = .000001;
                for (int i = lowPosition; i != highPosition; i += jump)
                {
                    Curve.Add(Vector2d.Create((float)i, (float)(150 - (Math.Sqrt(val) * factor))));
                    val += step;
                }
            }

            break;
            }

            if (Curve.Count > 1)
            {
                ctx.BeginPath();
                ctx.StrokeStyle = blue;
                ctx.MoveTo(Curve[0].X, Curve[0].Y);

                for (int i = 1; i < Curve.Count; i++)
                {
                    ctx.LineTo(Curve[i].X, Curve[i].Y);
                }
                ctx.Stroke();
            }
        }
        private bool DrawTriangle(CanvasContext2D ctx, ImageElement im, double x0, double y0, double x1, double y1, double x2, double y2,
                                  double sx0, double sy0, double sx1, double sy1, double sx2, double sy2)
        {
            bool inside;

            if (factor == 1.0)
            {
                inside = Intersects(0, Width, 0, Height, x0, y0, x1, y1, x2, y2);
            }
            else
            {
                hw     = Width / 2;
                qw     = hw * factor;
                hh     = Height / 2;
                qh     = hh * factor;
                inside = Intersects(hw - qw, hw + qw, hh - qh, hh + qh, x0, y0, x1, y1, x2, y2);
            }

            if (!inside)
            {
                return(false);
            }

            double   edgeOffset = isOutlined ? ContractionInPixels : ExpansionInPixels;
            Vector2d expandedS0 = GetMiterPoint(Vector2d.Create(x0, y0), Vector2d.Create(x1, y1), Vector2d.Create(x2, y2), edgeOffset);
            Vector2d expandedS1 = GetMiterPoint(Vector2d.Create(x1, y1), Vector2d.Create(x0, y0), Vector2d.Create(x2, y2), edgeOffset);
            Vector2d expandedS2 = GetMiterPoint(Vector2d.Create(x2, y2), Vector2d.Create(x1, y1), Vector2d.Create(x0, y0), edgeOffset);

            x0 = expandedS0.X;
            y0 = expandedS0.Y;
            x1 = expandedS1.X;
            y1 = expandedS1.Y;
            x2 = expandedS2.X;
            y2 = expandedS2.Y;


            ctx.Save();
            ctx.BeginPath();
            ctx.MoveTo(x0, y0);
            ctx.LineTo(x1, y1);
            ctx.LineTo(x2, y2);
            ctx.ClosePath();
            ctx.Clip();

            double denom = sx0 * (sy2 - sy1) - sx1 * sy2 + sx2 * sy1 + (sx1 - sx2) * sy0;

            if (denom == 0)
            {
                ctx.Restore();
                return(false);
            }
            double m11 = -(sy0 * (x2 - x1) - sy1 * x2 + sy2 * x1 + (sy1 - sy2) * x0) / denom;
            double m12 = (sy1 * y2 + sy0 * (y1 - y2) - sy2 * y1 + (sy2 - sy1) * y0) / denom;
            double m21 = (sx0 * (x2 - x1) - sx1 * x2 + sx2 * x1 + (sx1 - sx2) * x0) / denom;
            double m22 = -(sx1 * y2 + sx0 * (y1 - y2) - sx2 * y1 + (sx2 - sx1) * y0) / denom;
            double dx  = (sx0 * (sy2 * x1 - sy1 * x2) + sy0 * (sx1 * x2 - sx2 * x1) + (sx2 * sy1 - sx1 * sy2) * x0) / denom;
            double dy  = (sx0 * (sy2 * y1 - sy1 * y2) + sy0 * (sx1 * y2 - sx2 * y1) + (sx2 * sy1 - sx1 * sy2) * y0) / denom;


            ctx.Transform(m11, m12, m21, m22, dx, dy);

            ctx.DrawImage(im, 0, 0);

            ctx.Restore();

            if (factor != 1.0)
            {
                ctx.BeginPath();
                ctx.MoveTo(hw - qw, hh - qh);
                ctx.LineTo(hw + qw, hh - qh);
                ctx.LineTo(hw + qw, hh + qh);
                ctx.LineTo(hw - qw, hh + qh);
                ctx.ClosePath();
                ctx.StrokeStyle = "yellow";
                ctx.Stroke();
            }

            return(true);
        }