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.Windows;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Shapes;
- using System.Windows.Controls;
- using System.Windows.Media;
- using System.Windows.Input;
- namespace FiguresLib
- {
- #region Interfaces
- public struct MyPoint
- {
- public double X;
- public double Y;
- public MyPoint(double x, double y)
- {
- X = x; Y = y;
- }
- }
- interface IDeletable
- {
- bool Delete(MyPoint p);
- }
- interface ITriangle
- {
- bool CheckCrossPointWithTriangle(MyPoint p);
- }
- interface ISquare
- {
- bool CheckCrossPointWithSquare(MyPoint p);
- }
- interface ICircle
- {
- bool CheckCrossPointWithCircle(MyPoint p);
- }
- #endregion
- public abstract class BaseFigure: IDeletable
- {
- #region Поля
- private MyPoint _mousePos;
- public MyPoint mousePos
- {
- get { return _mousePos; }
- set { _mousePos = value; }
- }
- private Color _color;
- public Color color
- {
- get { return _color; }
- set { _color = value; }
- }
- public int size;
- #endregion
- public abstract bool Delete(MyPoint point);
- protected BaseFigure(MyPoint mousePos, Color color, int size)
- {
- this.mousePos = mousePos;
- this.color = color;
- this.size = size;
- }
- }
- public class Triangle : BaseFigure, ITriangle
- {
- #region Поля
- private MyPoint _point1, _point2, _point3;
- public MyPoint point1 { get { return _point1; } set { _point1 = value; } }
- public MyPoint point2 { get { return _point2; } set { _point2 = value; } }
- public MyPoint point3 { get { return _point3; } set { _point3 = value; } }
- #endregion
- public Triangle(MyPoint mousePos, Color color, int size) : base(mousePos, color, size)
- {
- this.mousePos = mousePos;
- this.color = color;
- this.size = size;
- double h = Math.Sqrt((size * size) / 12);
- point1 = new MyPoint(mousePos.X, (int)(mousePos.Y - ((size*Math.Sqrt(3))/3)));
- point2 = new MyPoint(mousePos.X - size / 2, (int)(mousePos.Y + h));
- point3 = new MyPoint(mousePos.X + size / 2, (int)(mousePos.Y + h));
- }
- public bool CheckCrossPointWithTriangle(MyPoint p)
- {
- double checkMult1 = (point1.X-p.X)*(point2.Y-point1.Y)-(point2.X-point1.X)*(point1.Y-p.Y);
- double checkMult2 = (point2.X - p.X) * (point3.Y - point2.Y) - (point3.X - point2.X) * (point2.Y - p.Y);
- double checkMult3 = (point3.X - p.X) * (point1.Y - point3.Y) - (point1.X - point3.X) * (point3.Y - p.Y);
- if ((checkMult1 < 0 && checkMult2 < 0 && checkMult3 < 0) ||
- (checkMult1 > 0 && checkMult2 > 0 && checkMult3 > 0) ||
- checkMult1 == 0 || checkMult2 == 0 || checkMult3 == 0)
- {
- return true;
- }
- else return false;
- }
- public override bool Delete(MyPoint point)
- {
- if (CheckCrossPointWithTriangle(point))
- {
- return true;
- }
- else return false;
- }
- }
- public class Square : BaseFigure, ISquare
- {
- #region Поля
- private MyPoint _point1, _point2, _point3, _point4;
- public MyPoint point1 { get { return _point1; } set { _point1 = value; } }
- public MyPoint point2 { get { return _point2; } set { _point2 = value; } }
- public MyPoint point3 { get { return _point3; } set { _point3 = value; } }
- public MyPoint point4 { get { return _point4; } set { _point4 = value; } }
- #endregion
- public Square(MyPoint mousePos, Color color, int size) : base(mousePos, color, size)
- {
- this.mousePos = mousePos;
- this.color = color;
- this.size = size;
- int halfSize = size/2;
- point1 = new MyPoint(mousePos.X - halfSize, mousePos.Y - halfSize);
- point2 = new MyPoint(mousePos.X + halfSize, mousePos.Y - halfSize);
- point3 = new MyPoint(mousePos.X + halfSize, mousePos.Y + halfSize);
- point4 = new MyPoint(mousePos.X - halfSize, mousePos.Y + halfSize);
- }
- public bool CheckCrossPointWithSquare(MyPoint p)
- {
- if(p.X >= point1.X && p.Y >= point1.Y && p.X <= point3.X && p.Y <= point3.Y)
- {
- return true;
- }
- else return false;
- }
- public override bool Delete(MyPoint point)
- {
- if(CheckCrossPointWithSquare(point))
- {
- return true;
- }
- else return false;
- }
- }
- public class Circle : BaseFigure, ICircle
- {
- public Circle(MyPoint mousePos, Color color, int size) : base(mousePos, color, size)
- {
- this.mousePos = mousePos;
- this.color = color;
- this.size = size;
- }
- public bool CheckCrossPointWithCircle(MyPoint p)
- {
- if(Math.Pow(p.X, 2) + Math.Pow(p.Y, 2) <= Math.Pow(size,2))
- {
- return true;
- }
- return false;
- }
- public override bool Delete(MyPoint point)
- {
- if (CheckCrossPointWithCircle(point))
- {
- return true;
- }
- else return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement