Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace dz
- {
- class Segment
- {
- private float _x1;
- private float _x2;
- public float X1
- {
- get { return _x1; }
- set
- {
- _x1 = value;
- }
- }
- public float X2
- {
- get { return _x2; }
- set
- {
- _x2 = value;
- }
- }
- public Segment()
- { }
- public Segment(float x1, float x2)
- {
- X1 = x1;
- X2 = x2;
- }
- public override string ToString()
- {
- var str = string.Format("X1: {0}, X2: {1}", X1, X2);
- return str;
- }
- public Segment Intersection(Segment Otr)
- {
- var otrezok = new Segment();
- float[] A = new float[] { X1, X2, Otr.X1, Otr.X2 };
- for (int i = 0; i < A.Length; i++)
- {
- for (int j = i + 1; j < A.Length; j++)
- {
- if (A[j] < A[i])
- {
- var temp = A[i];
- A[i] = A[j];
- A[j] = temp;
- }
- }
- }
- if (A[0] == X1)
- {
- if (A[1] == X2)
- {
- return null;
- }
- if (A[1] == Otr.X1)
- {
- if (A[2] == X2)
- {
- otrezok.X1 = Otr.X1;
- otrezok.X2 = X2;
- }
- if (A[2] == Otr.X2)
- {
- otrezok.X1 = Otr.X1;
- otrezok.X2 = Otr.X2;
- }
- return otrezok;
- }
- return null;
- }
- if (A[0] == Otr.X1)
- {
- if (A[1] == Otr.X2)
- {
- return null;
- }
- if (A[1] == X1)
- {
- if (A[2] == X2)
- {
- otrezok.X1 = X1;
- otrezok.X2 = X2;
- }
- if (A[2] == Otr.X2)
- {
- otrezok.X1 = X1;
- otrezok.X2 = Otr.X2;
- }
- return otrezok;
- }
- return null;
- }
- return null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement