//copy assignment public StraightLineSegment1d <TPositiveInteger, TPositiveIntegerTrait> Copy(StraightLineSegment1d <TPositiveInteger, TPositiveIntegerTrait> that) { if (this != that) { a = that.a; b = that.b; } return(this); }
static void Main(string[] args) { { var ab = new StraightLineSegment1d <short, Int16Trait>(2, 4); //constructor var cd = new StraightLineSegment1d <short, Int16Trait>(); //default constructor var ef = new StraightLineSegment1d <short, Int16Trait>(); //default constructor and ef.Copy(new StraightLineSegment1d <short, Int16Trait>(1, 6)); //copy assignment var gh = new StraightLineSegment1d <short, Int16Trait>(new StraightLineSegment1d <short, Int16Trait>(2, 0)); //copy constructor Console.WriteLine("{0} == {1}? {2}", ab, gh, ab == gh); Console.WriteLine("{0} == {1}? {2}", cd, ef, cd == ef); Console.WriteLine("{0} != {1}? {2}", cd, ef, cd != ef); Console.WriteLine("{0} < {1}? {2}", ab, gh, ab < gh); Console.WriteLine("{0} <= {1}? {2}", ab, gh, ab <= gh); Console.WriteLine("{0} >= {1}? {2}", ab, gh, ab >= gh); Console.WriteLine("{0} > {1}? {2}", ab, gh, ab > gh); var xs = new StraightLineSegment1d <short, Int16Trait>[] { ab, cd, ef, gh }; Array.Sort(xs, Util.StraightLineSegment1dComparison); foreach (var x in xs) { Console.Write("[{0}] ", x); } Console.WriteLine(); } Console.WriteLine(new string('-', 40)); { var ab = new StraightLineSegment1d <int, Int32Trait>(42, 14); //constructor var cd = new StraightLineSegment1d <int, Int32Trait>(); //default constructor var ef = new StraightLineSegment1d <int, Int32Trait>(); //default constructor and ef.Copy(new StraightLineSegment1d <int, Int32Trait>(31, 16)); //copy assignment var gh = new StraightLineSegment1d <int, Int32Trait>(new StraightLineSegment1d <int, Int32Trait>(20, 0)); //copy constructor Console.WriteLine("{0} == {1}? {2}", ab, gh, ab == gh); Console.WriteLine("{0} == {1}? {2}", cd, ef, cd == ef); Console.WriteLine("{0} != {1}? {2}", cd, ef, cd != ef); Console.WriteLine("{0} < {1}? {2}", ab, gh, ab < gh); Console.WriteLine("{0} <= {1}? {2}", ab, gh, ab <= gh); Console.WriteLine("{0} >= {1}? {2}", ab, gh, ab >= gh); Console.WriteLine("{0} > {1}? {2}", ab, gh, ab > gh); var xs = new StraightLineSegment1d <int, Int32Trait>[] { ab, cd, ef, gh }; Array.Sort(xs, Util.StraightLineSegment1dComparison); foreach (var x in xs) { Console.Write("[{0}] ", x); } Console.WriteLine(); } }
public static int StraightLineSegment1dComparison <TPositiveInteger, TPositiveIntegerTrait> (StraightLineSegment1d <TPositiveInteger, TPositiveIntegerTrait> lhs, StraightLineSegment1d <TPositiveInteger, TPositiveIntegerTrait> rhs) where TPositiveInteger : struct /* PositiveInteger */ where TPositiveIntegerTrait : IPositiveIntegerTrait <TPositiveInteger>, new() { if (lhs == rhs) { return(0); } if (lhs > rhs) { return(1); } /*if (lhs > rhs)*/ return(-1); }
//copy constructor public StraightLineSegment1d(StraightLineSegment1d <TPositiveInteger, TPositiveIntegerTrait> that) { a = that.a; b = that.b; }