Example #1
0
    public static void Main()
    {
        Console.WriteLine("First Example");
        //first example
        Point p1 = new Point();

        p1.store      = new SomeClass();
        p1.store.Name = "Jenish";
        p1.Name       = "firstPoint";
        p1.X          = 10;
        p1.Y          = 20;

        Point p2 = p1;

        p2.Name       = "secondPoint";
        p2.store      = new SomeClass();
        p2.store.Name = "Jenish2";
        p2.X          = 40;
        p2.Y          = 50;

        p1.Print();     //Prints - Name: firstPoint, X:10, Y:20
        p2.Print();     //Prints - Name: secondPoint, X:40, Y:50

        Console.ReadLine();
    }
Example #2
0
 public static void Main()
 {
     Point p = new Point(7, 3);
     p.Print();
     Console.WriteLine(p.ToString()); // Redefinido em Point
     Console.WriteLine(p.GetType()); // box + call
     Console.WriteLine(p.GetHashCode()); // Herdado de Object
 }
Example #3
0
    public static void Main()
    {
        Point p = new Point(3, 9);

        p.Print();
        Console.WriteLine("Modulo = " + p.GetModule());
        Console.WriteLine("y = {0}", p.y);
    }
Example #4
0
    public static void Main(String [] args)
    {
        // Point p = new Point();    // => initobj
        Point   p   = new Point(5, 7);
        Student std = new Student(74517, "Ze Manel", 17, "ze"); // => newobj

        std.Print();                                            // ldloc.1 + callvirt Student::Print()
        p.Print();
    }
Example #5
0
    public static void Main()
    {
        Point p = new Point(7, 3);

        p.Print();
        Console.WriteLine(p.ToString());    // Redefinido em Point
        Console.WriteLine(p.GetType());     // box + call
        Console.WriteLine(p.GetHashCode()); // Herdado de Object
    }
class App {   // <=> private
    static void Main()
    {
        Point p = new Point(3, 7);

        p.Print();
        Console.WriteLine("x: " + p.x);
        Console.WriteLine("y: " + p.y);
        Console.WriteLine("z: " + p.y);
    }
Example #7
0
        static void Main(string[] args)
        {
            // 0. point class examples
            // point1 is an instance of class Point
            Point point1 = new Point(2, 3);

            point1.Print();

            // point2 is an instance of class Point
            Point point2 = new Point(5, 10);

            point2.Print();

            //Point.Print(); - nu merge, pt ca metoda print trebuie accesata prin instanta

            point1.Print();

            Point point3 = new Point(1);

            point3.Print();

            //Point point4 = new Point(); - nu va merge


            // 1. properties in point
            Point p = new Point(10, 20);

            p.Print();
            System.Console.WriteLine($"X = {p.X}");
            p.X = -5;
            p.Print();


            // 2. examples with properties

            Student s = new Student();

            s.Name = "Andrei";
            s.Cnp  = "123";

            System.Console.WriteLine(s.FullDescription);

            //s.FullDescription = "21";
        }
Example #8
0
        public static void Main(string[] args)
        {
            Point point  = new Point(37, 77);
            Point point2 = point.Clone() as Point;

            point.Move(100, 100);

            point.Print();
            point2.Print();
        }
Example #9
0
    static void Main()
    {
        Point p1 = new Point(5, 7);
        p1.Print();

        Printer pr = p1; // box;
        pr.Print();

        Point p2 = new Point(5, 7);
        Console.WriteLine(p1.Equals(p2));
    }
Example #10
0
    static void Main()
    {
        System.Int32 n1; // Utilização do tipo System.Int32
        int n2; // Utilização da designação primitiva

        System.String s1 = "ISEL";
        string s2 = "super"; // Utilização da designação primitiva

        A a = new A(); // uma instância alocada em Heap => IL newobj
        Point p = new Point(); // uma instância em Stack => IL initobj
        a.Print();
        p.Print();
    }
    static void testBoxUnbox()
    {
        Point   p1  = new Point(6, 7);
        Student std = new Student();

        Console.WriteLine(p1.GetType());  // => Point
        Console.WriteLine(std.GetType()); // => Student
        Object o = p1;                    // ldloc.0 + box Point + stloc.1

        Point p2 = (Point)o;              // ldloc.1 + unbox + stloc.2

        o.GetType();                      // ldloc.1 + callvirt Object::GetType
        p1.GetType();                     // ldloc.0 + box Point + callvirt Object::GetType
        p1.Print();                       // NÂO existe BOX
    }
Example #12
0
    public static void Main(String[] args)
    {
        Student s  = new Student();   // instanciar  => newobj
        Point   p1 = new Point();     // inicializar => initobj
        Point   p2 = new Point(5, 7); // call

        Object   o = p1;              // box
        IPrinter i = p1;              // box

        // ((Point) o).x = 11; // ERRO de compilação
        Point p3 = (Point)o;

        p3.x = 11;
        ((IPrinter)o).Print();         // castclass + callvirt Print => 0, 0
        o = SetPointX(o, 17);
        ((IPrinter)o).Print();         // castclass + callvirt Print => 17, 0
        p3 = (Point)SetPointX(p3, 23); // box: p3 -> object + unbox
        p3.Print();
    }
Example #13
0
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());

        var points = new List <Point>();

        for (int i = 0; i < n; i++)
        {
            var currentPoint = ReadPoint();
            points.Add(currentPoint);
        }

        var   minimumDistance   = double.MaxValue;
        Point firstPointResult  = null;
        Point secondPointResult = null;

        for (int first = 0; first < points.Count; first++)
        {
            for (int second = first + 1; second < points.Count; second++)
            {
                var firstPont   = points[first];
                var secondPoint = points[second];

                var distance = Distance(firstPont, secondPoint);

                if (distance < minimumDistance)
                {
                    minimumDistance = distance;

                    firstPointResult  = firstPont;
                    secondPointResult = secondPoint;
                }
            }
        }

        Console.WriteLine("{0:F3}", minimumDistance);
        Console.WriteLine(firstPointResult.Print());
        Console.WriteLine(secondPointResult.Print());
    }
Example #14
0
        protected override ITrimmedCurve GetTransformedProfileCurve(ITrimmedCurve iTrimmedCurve, double param)
        {
            int numPoints = 10000;

            Point[] points = new Point[numPoints + 1];

            double paramZ       = StartZ + (EndZ - StartZ) * param;
            Frame  profileFrame = Frame.Create(StartPoint + (EndPoint - StartPoint) * param, StartFrame.DirX, StartFrame.DirY);
            Cone   profileCone  = GetConeAtParameter(paramZ);
            double radius       = profileCone.Radius;
            ICollection <IntPoint <SurfaceEvaluation, CurveEvaluation> > intersections = profileCone.IntersectCurve(TangentLine);
            Matrix trans = Matrix.CreateRotation(Axis, intersections.OrderBy(i => Math.Abs(i.Point.Z)).First().EvaluationA.Param.U);

            //		profileCone.Print(Part);

            //		double scale = (radius / A) / Math.Sin(profileCone.HalfAngle);

            for (int j = 0; j <= numPoints; j++)
            {
                double t           = iTrimmedCurve.Bounds.Start + iTrimmedCurve.Bounds.Span * (double)j / numPoints;
                Vector pointVector = iTrimmedCurve.Geometry.Evaluate(t).Point.Vector;
                double angle       = -Circle.Create(Frame.Create(Point.Origin, Direction.DirX, Direction.DirY), GearData.PitchRadius).ProjectPoint(pointVector.GetPoint()).Param;
                double distance    = (pointVector.Magnitude - A) * radius / A;             // *Math.Sin(profileCone.HalfAngle);

                //		points[j] = profileCone.WrapPoint(angle, (distance - A) / Math.Sin(profileCone.HalfAngle));
                points[j] = profileCone.WrapPoint(angle, distance);
            }
            try {
                return(CurveSegment.Create(NurbsCurve.CreateThroughPoints(false, points, Accuracy.LinearResolution)).CreateTransformedCopy(trans));
            }
            catch {
                points.Print();
            }

            return(null);
        }
Example #15
0
 public static void PrintPoints(double smallestDistance, Point firstPointResult, Point secondPointResult)
 {
     Console.WriteLine($"{smallestDistance:f3}");
     Console.WriteLine(firstPointResult.Print());
     Console.WriteLine(secondPointResult.Print());
 }
    static void Main(string[] args)
    {
        string[] inputs;
        int      N = int.Parse(Console.ReadLine());
        int      M = int.Parse(Console.ReadLine());
        int      L = int.Parse(Console.ReadLine());

        List <Point <int> > Spots = new List <Point <int> >();
        List <Point <int> > Orcs  = new List <Point <int> >();
        Dictionary <int, Tuple <int, int> > PathPointsIndices = new Dictionary <int, Tuple <int, int> >();
        int StartPointIndice;
        int StopPointIndice;

        for (int i = 0; i < N; i++)
        {
            inputs = Console.ReadLine().Split(' ');
            int XS = int.Parse(inputs[0]);
            int YS = int.Parse(inputs[1]);
            Spots.Add(new Point <int> {
                X = XS, Y = YS
            });
        }
        for (int i = 0; i < M; i++)
        {
            inputs = Console.ReadLine().Split(' ');
            int XO = int.Parse(inputs[0]);
            int YO = int.Parse(inputs[1]);
            Orcs.Add(new Point <int> {
                X = XO, Y = YO
            });
        }
        for (int i = 0; i < L; i++)
        {
            inputs = Console.ReadLine().Split(' ');
            int N1 = int.Parse(inputs[0]);
            int N2 = int.Parse(inputs[1]);
            PathPointsIndices.Add(i, new Tuple <int, int>(N1, N2));
        }
        StartPointIndice = int.Parse(Console.ReadLine());
        StopPointIndice  = int.Parse(Console.ReadLine());

        Console.Error.WriteLine("Starting Point: ");
        Point <int> .Print(Spots[StartPointIndice]);

        Console.Error.WriteLine("Spots Points: ");
        Spots.ForEach(Point <int> .Print);
        PathPointsIndices.ToList().ForEach(a => Console.Error.WriteLine(a.Value));
        Orcs.ForEach(Point <int> .Print);
        Console.Error.WriteLine("Start: {0}.", StartPointIndice);
        Console.Error.WriteLine("Stop: {0}.", StopPointIndice);

        //routes.Keys.ToList().ForEach(r => PathPointsIndices.Remove(r));
        HashSet <string> result = FindPaths(routes: PathPointsIndices, pathPointsIndices: PathPointsIndices,
                                            orcs: Orcs, spots: Spots, startPointIndice: StartPointIndice, stopPointIndice: StopPointIndice, indices: StartPointIndice.ToString());

        Console.Error.WriteLine("Result:");
        if (result.Count != 0)
        {
            result.ToList().ForEach(Console.Error.WriteLine);

            var paths    = result.ToList().Select(a => a.Split(' ').ToArray()).ToList();
            var pathsInt = new List <int[]>();
            foreach (var r in paths)
            {
                pathsInt.Add(
                    Array.ConvertAll(r, e => Int32.Parse(e)));
            }

            var distance = pathsInt.Select(r => r.Aggregate((_e, e) => _e + e)).ToArray();

            for (int i = 0; i < paths.Count; i++)
            {
                Console.Error.WriteLine("Dostance for path: {0} = {1}.", paths[i].Aggregate((_e, e) => _e + " " + e), distance[i]);
            }
            var ans = result.OrderBy(o => o.Length).ToList();

            Console.Error.WriteLine("Answer:");
            Console.WriteLine(ans.First());
        }
        else
        {
            Console.WriteLine("IMPOSSIBLE");
        }

        //Tests
        Console.Error.WriteLine("Tests:");
        Console.Error.WriteLine(CalcDistance <int>(new Point <int> {
            X = 0, Y = 0
        }, new Point <int> {
            X = 1, Y = 1
        }));
        Console.Error.WriteLine(Math.Pow(2, 2));
        //var res = calcDistance<string> (new Point<string>{X="asd",Y="ds"}, new Point<string>{X="asd",Y="ds"});
        Console.ReadKey();
    }
Example #17
0
        static void Main(string[] args)
        {
            Point point = new Point();

            point.Print();
        }
Example #18
0
    static void conv6()
    {
        Point p1 = new Point(5, 7);
           Object r1 = p1; // box;

           int n2 = 789;
           Object r2 = n2; // box;

           p1 = (Point)r1; // unbox
           // p1 = (Point)n1; // unbox => CastClassException

           Printer pr = p1; // Box
           p1 = (Point) pr; // unbox

           pr.Print();

           /*
        * O CLR não permite alterar o estado de uma instância (de tipo valor)
        * que esteja boxed.
        */
           // ((Point) pr).x = 78; // Erro de compilação
           pr.SetX(78);

           pr.Print();

           /*
        *  !!!!! CUIDADO
        *
        */
           p1.Print();
           p1.x = 8;
           p1.Print();
           ((Printer) p1).SetX(9); // Erro pq o metodo SetX so é acessivel com uma referncia do tipo Printer
           p1.Print();
    }