Esempio n. 1
0
        public Octree(MeshToolkit mesh, bool cubic = true)
        {
            this._mesh  = mesh;
            this._cubic = cubic;
            //this.triangles = _mesh.Triangles();
            this.vertices         = _mesh.Vertices();
            this.vertexIndexByTri = Core.List.Chop <int>(_mesh.VertexIndicesByTri(), 3);
            BoundingBox bbox = Graphical.Geometry.MeshToolkit.BoundingBox(this._mesh);

            // Extending the BoundingBox to be cubical from the centre.
            // Done by getting the max component of the Bounding box and translating min and max points outwards.
            // https://github.com/diwi/Space_Partitioning_Octree_BVH/blob/b7f66fe04e4af3b98ab9404363ab33f5dc1628a9/SpacePartitioning/src/DwOctree/Octree.java#L83
            if (cubic)
            {
                using (Point center = Geometry.Point.MidPoint(bbox.MinPoint, bbox.MaxPoint))
                {
                    Vector   bboxSize       = Vector.ByTwoPoints(bbox.MinPoint, bbox.MaxPoint);
                    Vector   halfSize       = bboxSize.Scale(0.5);
                    double[] halfComponents = new double[3] {
                        halfSize.X, halfSize.Y, halfSize.Z
                    };
                    double maxComponent       = halfComponents[getSubdivisionPlane(bbox)];
                    Vector expansionDirection = Vector.ByCoordinates(maxComponent, maxComponent, maxComponent);
                    bbox = BoundingBox.ByCorners(
                        (Point)center.Translate(-maxComponent, -maxComponent, -maxComponent),
                        (Point)center.Translate(maxComponent, maxComponent, maxComponent)
                        );
                }
            }

            _root = new OctreeNode(0, bbox);
        }
Esempio n. 2
0
        internal bool AssureChildren(OctreeNode ot, int maxDepth)
        {
            if (ot.depth >= maxDepth)
            {
                return(false);
            }
            if (ot.isLeaf())
            {
                ot.children = new OctreeNode[8];
                // Half vector size, by scaling total diagonal or maybe faster creating the MidPoint?
                Vector halfSize   = Vector.ByTwoPoints(ot.bbox.MinPoint, ot.bbox.MaxPoint).Scale(0.5);
                int    childDepth = ot.depth + 1;
                for (int i = 0; i < ot.children.Count(); i++)
                {
                    Point min = Point.ByCoordinates(
                        ot.bbox.MinPoint.X + (((i & 4) > 0) ? halfSize.X : 0),
                        ot.bbox.MinPoint.Y + (((i & 2) > 0) ? halfSize.Y : 0),
                        ot.bbox.MinPoint.Z + (((i & 1) > 0) ? halfSize.Z : 0)
                        );
                    Point max = (Point)min.Translate(halfSize);

                    ot.children[i] = new OctreeNode(childDepth, BoundingBox.ByCorners(min, max));
                }
            }
            return(true);
        }
Esempio n. 3
0
        /// <summary>
        /// finds the common point of a triangle with angles bigger than 120
        /// </summary>
        /// <param name="points"></param>
        /// <returns>common point of a triangle with angles bigger than 120</returns>
        private static Point FermatPoint(List <Point> points)
        {
            List <Point> sortedPoints = points.OrderBy(pt => pt.Y).Reverse().ToList();

            Vector vectorAB = Vector.ByTwoPoints(sortedPoints[0], sortedPoints[1]).Rotate(Vector.ZAxis(), 90);
            Vector vectorAC = Vector.ByTwoPoints(sortedPoints[2], sortedPoints[0]).Rotate(Vector.ZAxis(), 90);

            Point midpointAB = Point.ByCoordinates((sortedPoints[0].X + sortedPoints[1].X) / 2, (sortedPoints[0].Y + sortedPoints[1].Y) / 2);
            Point midpointAC = Point.ByCoordinates((sortedPoints[0].X + sortedPoints[2].X) / 2, (sortedPoints[0].Y + sortedPoints[2].Y) / 2);

            double sideABLength = Math.Sqrt(Math.Pow((sortedPoints[0].X - sortedPoints[1].X), 2) + Math.Pow((sortedPoints[0].Y - sortedPoints[1].Y), 2));
            double sideACLength = Math.Sqrt(Math.Pow((sortedPoints[0].X - sortedPoints[2].X), 2) + Math.Pow((sortedPoints[0].Y - sortedPoints[2].Y), 2));

            double equilateralLengthAB = (sideABLength * Math.Sqrt(3)) / 2;
            double equilateralLengthAC = (sideACLength * Math.Sqrt(3)) / 2;

            Point equilateralTopPointAB = midpointAB.Translate(vectorAB, equilateralLengthAB) as Point;
            Point equilateralTopPointAC = midpointAC.Translate(vectorAC, equilateralLengthAC) as Point;

            Line lineABC = Line.ByStartPointEndPoint(equilateralTopPointAB, sortedPoints[2]);
            Line lineACB = Line.ByStartPointEndPoint(equilateralTopPointAC, sortedPoints[1]);

            Point fermatPt = lineABC.Intersect(lineACB)[0] as Point;

            return(fermatPt);
        }
        public override void DrawString(string text, MusicFontStyles fontStyle, Point location, Color color, Model.MusicalSymbol owner)
        {
            if (!TypedSettings.Fonts.ContainsKey(fontStyle))
            {
                return;                                                //Nie ma takiego fontu zdefiniowanego. Nie rysuj.
            }
            if (!EnsureProperPage(owner))
            {
                return;
            }
            if (Settings.RenderingMode != ScoreRenderingModes.Panorama && !TypedSettings.IgnorePageMargins)
            {
                location = location.Translate(CurrentScore.DefaultPageSettings);
            }

            location = TranslateTextLocation(location, fontStyle);

            var element = GetTextElement(text, fontStyle, location, color, owner);

            if (location.Y - 15 < ClippedAreaY)
            {
                ClippedAreaY = location.Y - 15;
            }
            if (location.X > ActualWidth)
            {
                ActualWidth = location.X;
            }
            if (location.Y > ActualHeight)
            {
                ActualHeight = location.Y;
            }

            Canvas.Add(element);
        }
Esempio n. 5
0
        public PointF Untransform(Point point)
        {
            Point  p       = point.Translate(-location.X, -location.Y);
            double unscale = 1.0 / scale;

            return(new PointF((float)(p.X * unscale), (float)(p.Y * unscale)));
        }
Esempio n. 6
0
        public void DrawCenterLines(TsPart tsPart, TsView tsView)
        {
            double scale = tsView.scale;
            double delta = 2 * scale;

            double[] start = tsPart.partStart;
            double[] end   = tsPart.partEnd;

            Point o = tsPart.origin;

            Point startPoint = new Point(start[0], start[1], start[2]);
            Point endPoint   = new Point(end[0], end[1], end[2]);

            LineSegment auxLS = new LineSegment(o, endPoint);

            Vector auxVec = auxLS.GetDirectionVector();

            Vector clVec  = Extensions.ExtendVector(auxVec, delta);
            Vector nclVec = (-1) * clVec;

            startPoint.Translate(nclVec.X, nclVec.Y, nclVec.Z);
            endPoint.Translate(clVec.X, clVec.Y, clVec.Z);

            Inserter.InsertLine(tsView._viewBase, startPoint, endPoint);
        }
Esempio n. 7
0
 public KeyframeLabel(Point _attachPoint, Color _color)
 {
     m_AttachLocation       = _attachPoint;
     m_Background.Rectangle = new Rectangle(_attachPoint.Translate(-20, -50), Size.Empty);
     m_StyleHelper.Font     = new Font("Arial", 8, FontStyle.Bold);
     m_StyleHelper.Bicolor  = new Bicolor(Color.FromArgb(160, _color));
 }
        private LineSegment GetBeamCenterLineSegmentExpanded(Part beam, double expandBy = 0)
        {
            var         partBox    = beam.GetCenterLine(false);
            LineSegment centerLine = null;

            try
            {
                Point p1 = (Point)partBox[0];
                Point p2 = (Point)partBox[1];
                if (expandBy > 1e-6)
                {
                    var v12 = new Vector(p2 - p1);
                    var v21 = new Vector(p1 - p2);
                    v12.Normalize(expandBy);
                    v21.Normalize(expandBy);
                    p1.Translate(v21.X, v21.Y, v21.Z);
                    p2.Translate(v12.X, v12.Y, v12.Z);
                }
                centerLine = new LineSegment(p1, p2);
            }
            catch
            {
                Tracer._trace($"Line Segment creation failed for profile: {beam?.Profile.ProfileString}");
            }
            return(centerLine);
        }
Esempio n. 9
0
        private static bool ModifyNeighbours(
            LevelComponent levelComponent, byte[] neighbours, Dictionary <int, byte> changes, Point point, bool add)
        {
            var changed = false;

            for (var directionIndex = 0; directionIndex < 8; directionIndex++)
            {
                var direction   = Vector.MovementDirections[directionIndex];
                var newLocation = point.Translate(direction);

                if (!levelComponent.IsValid(newLocation))
                {
                    continue;
                }

                var newLocationIndex = levelComponent.PointToIndex[newLocation.X, newLocation.Y];
                var neighbourBit     = (byte)(1 << Vector.OppositeDirectionIndexes[directionIndex]);
                var oldValue         = neighbours[newLocationIndex];
                var newValue         = add
                    ? (byte)(oldValue | neighbourBit)
                    : (byte)(oldValue & (byte)~neighbourBit);

                if (oldValue != newValue)
                {
                    changed = true;
                    neighbours[newLocationIndex] = newValue;
                    if (changes != null)
                    {
                        changes[newLocationIndex] = newValue;
                    }
                }
            }

            return(changed);
        }
Esempio n. 10
0
        public void TestTranslate()
        {
            Point expected = new Point(10, 10);

            TestPointA.Translate(8, 6);

            Assert.AreEqual(expected.X(), TestPointA.X());
            Assert.AreEqual(expected.Y(), TestPointA.Y());
        }
Esempio n. 11
0
        public void DiagonalTranslate()
        {
            Point p     = new Point(1, 2);
            Point trans = new Point(3, 4);

            p = p.Translate(trans);

            Assert.AreEqual(4, p.X);
            Assert.AreEqual(6, p.Y);
        }
Esempio n. 12
0
        public void TestTranslate()
        {
            // arrange
            var point = new Point(1, 2, 3);

            // act
            var pointTranslated = point.Translate(10, 20, 30);

            // assert
            Assert.IsTrue(pointTranslated.Equals(new Point(11, 22, 33)));
        }
        public override void DrawLine(Point startPoint, Point endPoint, Pen pen, Model.MusicalSymbol owner)
        {
            if (!EnsureProperPage(owner))
            {
                return;
            }
            if (Settings.RenderingMode != ScoreRenderingModes.Panorama && !TypedSettings.IgnorePageMargins)
            {
                startPoint = startPoint.Translate(CurrentScore.DefaultPageSettings);
                endPoint   = endPoint.Translate(CurrentScore.DefaultPageSettings);
            }

            var element = new XElement("line",
                                       new XAttribute("x1", startPoint.X.ToStringInvariant()),
                                       new XAttribute("y1", startPoint.Y.ToStringInvariant()),
                                       new XAttribute("x2", endPoint.X.ToStringInvariant()),
                                       new XAttribute("y2", endPoint.Y.ToStringInvariant()),
                                       new XAttribute("style", pen.ToCss()),
                                       new XAttribute("id", BuildElementId(owner)));

            var playbackAttributes = BuildPlaybackAttributes(owner);

            foreach (var playbackAttr in playbackAttributes)
            {
                element.Add(new XAttribute(playbackAttr.Key, playbackAttr.Value));
            }

            if (startPoint.Y < ClippedAreaY)
            {
                ClippedAreaY = startPoint.Y;
            }
            if (endPoint.Y < ClippedAreaY)
            {
                ClippedAreaY = endPoint.Y;
            }
            if (startPoint.X > ActualWidth)
            {
                ActualWidth = startPoint.X;
            }
            if (endPoint.X > ActualWidth)
            {
                ActualWidth = endPoint.X;
            }
            if (startPoint.Y > ActualHeight)
            {
                ActualHeight = startPoint.Y;
            }
            if (endPoint.Y > ActualHeight)
            {
                ActualHeight = endPoint.Y;
            }

            Canvas.Add(element);
        }
Esempio n. 14
0
        public void Translatae_WithCoordinates_ExpectedBehavior()
        {
            //----------- Arrange -----------------------------
            Point p = new Point(0, 0);

            //----------- Act ---------------------------------
            Point p2 = p.Translate(1, 1);

            //----------- Assert-------------------------------
            Assert.True(p.X == 0 && p.Y == 0); // yes, should be *exactly* 0.
            Assert.True(p2.X.Is(1) && p2.Y.Is(1));
        }
Esempio n. 15
0
        public static bool NormalAwayFromSpace(this Polyline polyline, List <Panel> panelsAsSpace, double tolerance = BH.oM.Geometry.Tolerance.Distance)
        {
            List <Point> centrePtList = new List <Point>();
            Point        centrePt     = polyline.PointInRegion(false, tolerance); //Modifed to Centroid to fix special cases Point centrePt = polyline.Centre();

            centrePtList.Add(centrePt);

            if (!polyline.IsClosed())
            {
                return(false);                      //Prevent failures of the clockwise check
            }
            List <Point> pts = polyline.DiscontinuityPoints(tolerance);

            if (pts.Count < 3)
            {
                return(false);               //Protection in case there aren't enough points to make a plane
            }
            Plane plane = BH.Engine.Geometry.Create.Plane(pts[0], pts[1], pts[2]);

            //The polyline can be locally concave. Check if the polyline is clockwise.
            if (!BH.Engine.Geometry.Query.IsClockwise(polyline, plane.Normal, tolerance))
            {
                plane.Normal = -plane.Normal;
            }

            if (!BH.Engine.Geometry.Query.IsContaining(polyline, centrePtList, false, tolerance))
            {
                Point  pointOnLine = polyline.ClosestPoint(centrePt);
                Vector vector      = new Vector();
                if (BH.Engine.Geometry.Query.Distance(pointOnLine, centrePt) > BH.oM.Geometry.Tolerance.MicroDistance)
                {
                    vector = pointOnLine - centrePt;
                }
                else
                {
                    Line line = BH.Engine.Geometry.Query.GetLineSegment(polyline, pointOnLine);
                    vector = ((line.Start - line.End).Normalise()).CrossProduct(plane.Normal);
                }

                centrePt = BH.Engine.Geometry.Modify.Translate(pointOnLine, BH.Engine.Geometry.Modify.Normalise(vector) * 0.001);
            }

            //Move centrepoint along the normal.
            if (panelsAsSpace.IsContaining(centrePt.Translate(plane.Normal * 0.01)))
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Esempio n. 16
0
        public void Point_TranslateTest()
        {
            Point pointToTranslate = Point.MakePointWithInches(1, 2, 3);
            //Direction directionToTranslate = new Direction(Point.MakePointWithInches(-1, 5, 4));
            //Distance displacementOfPoint = 12.9614814 * Unit.Inches;
            var testDisplacement = FreeVector.MakeWithInches(-2, 10, 8);

            Point actualResult = pointToTranslate.Translate(testDisplacement);

            Point expectedResult = Point.MakePointWithInches(-1, 12, 11);

            actualResult.Should().Be(expectedResult);
        }
Esempio n. 17
0
        public void CheckIfViewsToOutsideDetectsObstaclesInLayout()
        {
            Polygon internalPoly = Rectangle.ByWidthLength(5, 5) as Polygon;
            Point   newOrigin    = origin.Translate(10) as Point;
            // Result of ViewsToOutside.ByLineSegments
            var result = ViewsToOutside.ByLineSegments(lines, newOrigin, boundaryPoly, new List <Polygon> {
                internalPoly
            });

            var viewScore = (double)result["score"];

            Assert.AreNotEqual(1.0, viewScore);
        }
Esempio n. 18
0
        public void ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
        {
            ((UIElement)e.OriginalSource).CancelDirectManipulations();
            e.Handled = true;
            var newScale = Math.Min(8, Math.Max(0.25, Scale.Value * e.Delta.Scale));
            var step     = newScale / Scale.Value;
            var center   = _manipulationPoint.Translate(ViewportOffsetX.Value, ViewportOffsetY.Value);

            ViewportOffsetX.Value += center.X * step - center.X;
            ViewportOffsetY.Value += center.Y * step - center.Y;
            Scale.Value            = newScale;
            Messenger.Default.Send <InvalidateRequestedMessage>();
        }
Esempio n. 19
0
        /***************************************************/
        /**** Private methods                           ****/
        /***************************************************/

        private static bool SimpleIsContaining(PolyCurve crv, Plane plane, Point pt)
        {
            Point end = pt.Translate(Engine.Geometry.Create.RandomVectorInPlane(plane, true));
            Line  ray = new Line {
                Start = pt, End = end
            };

            ray.Infinite = true;

            List <Point> interPts = crv.Curves.SelectMany(x => x.ILineIntersections(ray, true)).ToList();

            return(interPts.Count % 2 != 0);
        }
 public virtual TextRectangle GetTextRectangle(SvgDrawContext context, Point basePoint)
 {
     if (this.attributesAndStyles != null)
     {
         ResolveFontSize();
         ResolveFont(context);
         double x = 0;
         double y = 0;
         if (GetAbsolutePositionChanges()[0] != null)
         {
             x = GetAbsolutePositionChanges()[0][0];
         }
         else
         {
             if (basePoint != null)
             {
                 x = basePoint.GetX();
             }
         }
         if (GetAbsolutePositionChanges()[1] != null)
         {
             y = GetAbsolutePositionChanges()[1][0];
         }
         else
         {
             if (basePoint != null)
             {
                 y = basePoint.GetY();
             }
         }
         basePoint = new Point(x, y);
         basePoint.Translate(GetRelativeTranslation()[0], GetRelativeTranslation()[1]);
         Rectangle commonRect = null;
         foreach (ISvgTextNodeRenderer child in GetChildren())
         {
             if (child is ISvgTextNodeHelper)
             {
                 TextRectangle rectangle = ((ISvgTextNodeHelper)child).GetTextRectangle(context, basePoint);
                 basePoint  = rectangle.GetTextBaseLineRightPoint();
                 commonRect = Rectangle.GetCommonRectangle(commonRect, rectangle);
             }
         }
         if (commonRect != null)
         {
             return(new TextRectangle(commonRect.GetX(), commonRect.GetY(), commonRect.GetWidth(), commonRect.GetHeight
                                          (), (float)basePoint.GetY()));
         }
     }
     return(null);
 }
Esempio n. 21
0
        public void Point_TranslateTest_OneComponent()
        {
            Point pointToTranslate = Point.MakePointWithInches(1, 1, 1);

            //Direction directionToTranslate = new Direction(Point.MakePointWithInches(1, 0, 0));
            //Distance displacementOfPoint = 4 * Unit.Inches;
            var testDisplacement = FreeVector.MakeWithInches(4, 0, 0);

            Point actualResult = pointToTranslate.Translate(testDisplacement);

            Point expectedResult = Point.MakePointWithInches(5, 1, 1);

            actualResult.Should().Be(expectedResult);
        }
 public static Triangle FromCenterAndLenghts(Point center, double l1, double l2, double l3)
 {
     Point p1 = new Point(0, 0);
     Point p2 = new Point(0, l1);
     double area = AreaByLenghts(l1, l2, l3);
     double height = area * 2 / l1;
     double l1bis = Math.Sqrt(Math.Pow(l3, 2) - Math.Pow(height, 2));
     Point p3 = new Point(height, l1bis);
     Point g = new Triangle(p1, p2, p3).Center();
     Vector translation = new Vector(center.X - g.X, center.Y - g.Y);
     return new Triangle(
         p1.Translate(translation),
         p2.Translate(translation),
         p3.Translate(translation));
 }
Esempio n. 23
0
        public void DrawCenterLines(TsPart tsPart, TsView tsView)
        {
            double scale = tsView.scale;
            double delta = 2 * scale;

            Point o = tsPart.origin;

            CoordinateSystem partCS = tsPart.partCS;

            double width  = tsPart.width;
            double height = tsPart.height;
            double length = tsPart.length;

            var x = new Point(o);
            var y = new Point(o);
            var z = new Point(o);

            var nx = new Point(o);
            var ny = new Point(o);
            var nz = new Point(o);

            Vector rX = Extensions.RoundVector(partCS.AxisX.GetNormal()) * length * 0.5;
            Vector rY = Extensions.RoundVector(partCS.AxisY.GetNormal()) * height * 0.5;
            Vector rZ =
                Extensions.RoundVector(Vector.Cross(partCS.AxisX, partCS.AxisY).GetNormal()) * width * 0.5;

            rX = Extensions.ExtendVector(rX, delta);
            rY = Extensions.ExtendVector(rY, delta);
            rZ = Extensions.ExtendVector(rZ, delta);

            Vector nrX = (-1) * rX;
            Vector nrY = (-1) * rY;
            Vector nrZ = (-1) * rZ;

            x.Translate(rX.X, rX.Y, rX.Z);
            y.Translate(rY.X, rY.Y, rY.Z);
            z.Translate(rZ.X, rZ.Y, rZ.Z);

            nx.Translate(nrX.X, nrX.Y, nrX.Z);
            ny.Translate(nrY.X, nrY.Y, nrY.Z);
            nz.Translate(nrZ.X, nrZ.Y, nrZ.Z);

            ViewBase view = tsView._viewBase;

            Inserter.InsertLine(view, nx, x);
            Inserter.InsertLine(view, ny, y);
            Inserter.InsertLine(view, nz, z);
        }
Esempio n. 24
0
        public static Triangle FromCenterAndLenghts(Point center, double l1, double l2, double l3)
        {
            Point  p1          = new Point(0, 0);
            Point  p2          = new Point(0, l1);
            double area        = AreaByLenghts(l1, l2, l3);
            double height      = area * 2 / l1;
            double l1bis       = Math.Sqrt(Math.Pow(l3, 2) - Math.Pow(height, 2));
            Point  p3          = new Point(height, l1bis);
            Point  g           = new Triangle(p1, p2, p3).Center();
            Vector translation = new Vector(center.X - g.X, center.Y - g.Y);

            return(new Triangle(
                       p1.Translate(translation),
                       p2.Translate(translation),
                       p3.Translate(translation)));
        }
Esempio n. 25
0
        public static Rectangle Grow(this Rectangle source, KnownPoint draggedPoint, int dw, int dh)
        {
            Size  size = source.Size;
            Point loc  = source.Location;

            switch (draggedPoint)
            {
            case KnownPoint.TopLeft:
                loc  = loc.Translate(dw, dh);
                size = size.Grow(-dw, -dh);
                break;

            case KnownPoint.TopMiddle:
                loc  = loc.Translate(0, dh);
                size = size.Grow(0, -dh);
                break;

            case KnownPoint.TopRight:
                loc  = loc.Translate(0, dh);
                size = size.Grow(dw, -dh);
                break;

            case KnownPoint.MiddleRight:
                // no need to change location => loc = loc.Translate(0, 0);
                size = size.Grow(dw, 0);
                break;

            case KnownPoint.BottomRight:
                // no need to change location => loc = loc.Translate(0, 0);
                size = size.Grow(dw, dh);
                break;

            case KnownPoint.BottomMiddle:
                // no need to change location => loc = loc.Translate(0, 0);
                size = size.Grow(0, dh);
                break;

            case KnownPoint.BottomLeft:
                loc  = loc.Translate(dw, 0);
                size = size.Grow(-dw, dh);
                break;

            case KnownPoint.MiddleLeft:
                loc  = loc.Translate(dw, 0);
                size = size.Grow(-dw, 0);
                break;

            case KnownPoint.Center:
                loc  = loc.Translate(dw / 2, dh / 2);
                size = size.Grow(dw, dh);
                break;
            }
            return(new Rectangle(loc, size));
        }
Esempio n. 26
0
        public Circle(Point center, Distance radius, Direction normalDirection = null)    
        {
            if (normalDirection == null)
            {
                normalDirection = Direction.Out;
            }
            var vector1 = new Vector(Point.MakePointWithInches(1, 0, 0)).CrossProduct(normalDirection * new Distance(1, Inches));
            var vector2 = new Vector(Point.MakePointWithInches(0, 1, 0)).CrossProduct(normalDirection * new Distance(1, Inches));
            var vector3 = new Vector(Point.MakePointWithInches(0, 0, 1)).CrossProduct(normalDirection * new Distance(1, Inches));
            var chosen = new List<Vector>() { vector1, vector2, vector3 }.MaxBy(v => v.Magnitude);

            var basePoint = center.Translate(chosen.Direction * radius);
            var arc = new Arc(basePoint, basePoint, new Line(center, normalDirection));

            this._Edges = new List<IEdge>() { arc };
            this.NormalLine = new Line(arc.CenterPoint, arc.NormalDirection);
        }
Esempio n. 27
0
        public static IEnumerable <Point> GetAdjacentPoints(
            LevelComponent level, Point point, Direction startingDirection, bool includeInitial = false)
        {
            if (includeInitial)
            {
                yield return(point);
            }

            for (var i = 0; i < 8; i++)
            {
                var newPoint = point.Translate(startingDirection.Rotate(i).AsVector());
                if (newPoint.X < level.Width &&
                    newPoint.Y < level.Height)
                {
                    yield return(newPoint);
                }
            }
        }
Esempio n. 28
0
        //TODO: Simplify method to translate point without using point geometries.
        public static SphereNode BoundingSphereNode(SphereNode sphere1, SphereNode sphere2)
        {
            SphereNode minSp           = (sphere1.radius < sphere2.radius) ? sphere1 : sphere2;
            SphereNode maxSp           = (sphere1.radius < sphere2.radius) ? sphere2 : sphere1;
            double     centersDistance = DistanceBetweenCenters(minSp, maxSp);

            double[] vectorCoord = minSp.center.Zip(maxSp.center, (sp1, sp2) => sp2 - sp1).ToArray();
            using (Point minCenter = SphereNode.Center(minSp))
                using (Point maxCenter = SphereNode.Center(maxSp))
                {
                    Vector v = Vector.ByTwoPoints(minCenter, maxCenter);
                    double translationDist = (centersDistance + (maxSp.radius - minSp.radius)) * 0.5;

                    Point  center = (Point)minCenter.Translate(v, translationDist);
                    double radius = (centersDistance + minSp.radius + maxSp.radius) * 0.5;
                    return(new SphereNode(new double[3] {
                        center.X, center.Y, center.Z
                    }, radius));
                }
        }
Esempio n. 29
0
        static void Exo02_14()
        {
            Point po = new Point(3, 3);

            WriteLine($"{po.X} {po.Y}");
            HelpProgram.Exo02_14BadFonc(po);
            po.Translate(2, 2);          //**
            WriteLine($"{po.X} {po.Y}"); //1. 'Point' class is not immutable because the method 'Exo02_14BadFonc()' that itself calls the method 'Translate()'can change the axis values of a Point, which makes this class mutable.
            Circle ce = new Circle(2, po);

            WriteLine($"{ce.Centre.X} {ce.Centre.Y}");
            HelpProgram.Exo02_14BadFonc2(ce);
            ce.Centre.Translate(1, 1);
            WriteLine($"{ce.Centre.X} {ce.Centre.Y}"); //2. As the circle includes a Point object as one of its members, that makes this class mutable too, even if it is a structure.
            ReadKey(true);

            //3. If we change the class Point for a Structure, it will make this object immutable before methods but it's still mutable.
            //Exo02_15 This is because of the "Translate" member function, which uses the same instance of the object changing it's values, as we can see in ** comment.
            //To make this an immutable structure, we have to make the "Translate" function create and return a new instance of the object.
        }
Esempio n. 30
0
        private static Point dlugosc(Point x, Point y, double l, double kat, Point prz)
        {
            double x1 = x.X;
            double y1 = x.Y;
            double z1 = x.Z;
            double x2 = y.X;
            double y2 = y.Y;
            double z2 = y.Z;
            double dl = l / kat;

            Vector v         = new Vector((x2 - x1) / 10000, (y2 - y1) / 10000, (z2 - z1) / 10000);
            double d         = v.GetLength();
            double skrocenie = dl;
            double ile       = skrocenie / d;
            Vector v2        = ile * v;
            Point  p4        = new Point(prz);

            p4.Translate(v2.X, v2.Y, v2.Z);

            return(p4);
        }
Esempio n. 31
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="solid"></param>
        /// <param name="plane"></param>
        /// <returns></returns>
        List <List <Point> > IntersectSolid(Solid solid, GeometricPlane plane)
        {
            Point p1, p2, p3 = null;

            p1 = new Point(plane.Origin);
            p2 = new Point(p1);
            p2.Translate(100, 100, 100);
            p2 = Projection.PointToPlane(p2, plane);
            Vector x = new Vector(p2 - p1);

            x.Normalize(1000);
            Vector y = Vector.Cross(plane.Normal, x);

            y.Normalize(1000);
            p3 = new Point(p1 + y);
            p3 = Projection.PointToPlane(p3, plane);

            IEnumerator          faceEnumerator = solid.IntersectAllFaces(p1, p2, p3);
            List <List <Point> > polygons       = new List <List <Point> >();

            while (faceEnumerator.MoveNext())
            {
                ArrayList   points    = faceEnumerator.Current as ArrayList;
                IEnumerator LoopsEnum = points.GetEnumerator();
                while (LoopsEnum.MoveNext())
                {
                    ArrayList    ps      = LoopsEnum.Current as ArrayList;
                    List <Point> polygon = new List <Point>();
                    foreach (object o in ps)
                    {
                        Point p = o as Point;
                        polygon.Add(p);
                    }
                    polygons.Add(polygon);
                }
            }
            return(polygons);
        }
        public override void DrawCharacterInBounds(char character, MusicFontStyles fontStyle, Point location, Size size, Color color, Model.MusicalSymbol owner)
        {
            if (!EnsureProperPage(owner))
            {
                return;
            }
            if (Settings.RenderingMode != ScoreRenderingModes.Panorama && !TypedSettings.IgnorePageMargins)
            {
                location = location.Translate(CurrentScore.DefaultPageSettings);
            }

            var element = GetTextElement(character.ToString(), fontStyle, new Point(0, 0), color, owner);
            var svg     = new XElement("svg",
                                       new XAttribute("x", location.X.ToStringInvariant()),
                                       new XAttribute("y", location.Y.ToStringInvariant()),
                                       new XAttribute("width", size.Width.ToStringInvariant()),
                                       new XAttribute("height", size.Height.ToStringInvariant()),
                                       new XAttribute("viewBox", $"0 0 {size.Width.ToStringInvariant()} {size.Height.ToStringInvariant()}"));

            svg.Add(element);

            //element.SetAttributeValue(XName.Get("viewBox"), $"0 0 {size.Width.ToStringInvariant()} {size.Height.ToStringInvariant()}");

            if (location.Y < ClippedAreaY)
            {
                ClippedAreaY = location.Y;
            }
            if (location.X > ActualWidth)
            {
                ActualWidth = location.X;
            }
            if (location.Y > ActualHeight)
            {
                ActualHeight = location.Y;
            }

            Canvas.Add(svg);
        }
Esempio n. 33
0
        public void StrokeLine(
			float lineStartX, float lineStartY, float lineEndX, float lineEndY)
        {
            Contract.Requires(Thread.CurrentThread == BoundThread);
            Contract.Requires(ActiveTarget != null);
            Contract.Requires(Check.IsFinite(lineStartX));
            Contract.Requires(Check.IsFinite(lineStartY));
            Contract.Requires(Check.IsFinite(lineEndX));
            Contract.Requires(Check.IsFinite(lineEndY));

            if(!_IsTargetEmpty)
            {
                Point start = new Point(lineStartX, lineStartY);
                Point end = new Point(lineEndX, lineEndY);

                // translate to 2D surface coordinate space
                start = start.Translate(_TargetDelta);
                end = end.Translate(_TargetDelta);

                OnStrokeLine(ref start, ref end);
            }
        }
Esempio n. 34
0
        public void SetBrush(
			float radialGradientCenterX,
			float radialGradientCenterY,
			float radialGradientOffsetWidth,
			float radialGradientOffsetHeight,
			float radialGradientRadiusWidth,
			float radialGradientRadiusHeight,
			Gradient gradient)
        {
            Contract.Requires(Thread.CurrentThread == BoundThread);
            Contract.Requires(ActiveTarget != null);
            Contract.Requires(Check.IsFinite(radialGradientCenterX));
            Contract.Requires(Check.IsFinite(radialGradientCenterY));
            Contract.Requires(Check.IsFinite(radialGradientOffsetWidth));
            Contract.Requires(Check.IsFinite(radialGradientOffsetHeight));
            Contract.Requires(Check.IsPositive(radialGradientRadiusWidth));
            Contract.Requires(Check.IsPositive(radialGradientRadiusHeight));
            Contract.Requires(gradient != null);

            if(!_IsTargetEmpty)
            {
                Point radialGradientCenter = new Point(
                    radialGradientCenterX, radialGradientCenterY);

                // translate to 2D surface coordinate space
                radialGradientCenter = radialGradientCenter.Translate(_TargetDelta);

                Size radialGradientOffset = new Size(
                    radialGradientOffsetWidth, radialGradientOffsetHeight);
                Size radialGradientRadius = new Size(
                    radialGradientRadiusWidth, radialGradientRadiusHeight);

                OnSetBrush(
                    ref radialGradientCenter,
                    ref radialGradientOffset,
                    ref radialGradientRadius,
                    gradient);
            }
        }
Esempio n. 35
0
        public void SetBrush(
			float linearGradientStartX,
			float linearGradientStartY,
			float linearGradientEndX,
			float linearGradientEndY,
			Gradient gradient)
        {
            Contract.Requires(Thread.CurrentThread == BoundThread);
            Contract.Requires(ActiveTarget != null);
            Contract.Requires(Check.IsFinite(linearGradientStartX));
            Contract.Requires(Check.IsFinite(linearGradientStartY));
            Contract.Requires(Check.IsFinite(linearGradientEndX));
            Contract.Requires(Check.IsFinite(linearGradientEndY));
            Contract.Requires(gradient != null);

            if(!_IsTargetEmpty)
            {
                Point linearGradientStart = new Point(
                    linearGradientStartX, linearGradientStartY);
                Point linearGradientEnd = new Point(
                    linearGradientEndX, linearGradientEndY);

                linearGradientStart = linearGradientStart.Translate(_TargetDelta);
                linearGradientEnd = linearGradientEnd.Translate(_TargetDelta);

                OnSetBrush(ref linearGradientStart, ref linearGradientEnd, gradient);
            }
        }
Esempio n. 36
0
        public void SetBrush(
			Point radialGradientCenter,
			Size radialGradientOffset,
			Size radialGradientRadius,
			Gradient gradient)
        {
            Contract.Requires(Thread.CurrentThread == BoundThread);
            Contract.Requires(ActiveTarget != null);
            Contract.Requires(Check.IsPositive(radialGradientRadius.Width));
            Contract.Requires(Check.IsPositive(radialGradientRadius.Height));
            Contract.Requires(gradient != null);

            if(!_IsTargetEmpty)
            {
                // translate to 2D surface coordinate space
                radialGradientCenter = radialGradientCenter.Translate(_TargetDelta);

                OnSetBrush(
                    ref radialGradientCenter,
                    ref radialGradientOffset,
                    ref radialGradientRadius,
                    gradient);
            }
        }
Esempio n. 37
0
 public void Translate(Point t)
 {
     Point point = new Point(X, Y, Z);
     point.Translate(t);
     X = (int)point.X;
     Y = (int)point.Y;
     Z = (int)point.Z;
 }
Esempio n. 38
0
 public void Translate(double x, double y, double z)
 {
     Point point = new Point(X, Y, Z);
     point.Translate(x, y, z);
     X = (int)point.X;
     Y = (int)point.Y;
     Z = (int)point.Z;
 }
Esempio n. 39
0
        public void SetBrush(
			Point linearGradientStart, Point linearGradientEnd, Gradient gradient)
        {
            Contract.Requires(Thread.CurrentThread == BoundThread);
            Contract.Requires(ActiveTarget != null);
            Contract.Requires(gradient != null);

            if(!_IsTargetEmpty)
            {
                // translate to 2D surface coordinate space
                linearGradientStart = linearGradientStart.Translate(_TargetDelta);
                linearGradientEnd = linearGradientEnd.Translate(_TargetDelta);

                OnSetBrush(ref linearGradientStart, ref linearGradientEnd, gradient);
            }
        }
Esempio n. 40
0
        public void StrokeLine(Point lineStart, Point lineEnd)
        {
            Contract.Requires(Thread.CurrentThread == BoundThread);
            Contract.Requires(ActiveTarget != null);

            if(!_IsTargetEmpty)
            {
                // translate to 2D surface coordinate space
                lineStart = lineStart.Translate(_TargetDelta);
                lineEnd = lineEnd.Translate(_TargetDelta);

                OnStrokeLine(ref lineStart, ref lineEnd);
            }
        }