using System;
using System.Collections.Generic;
using System.Drawing;
using System.Numerics;
using System.Text;
using static CommonUsage.Geometries.CircularArc;

namespace CommonUsage.Geometries
{
	/// <summary>
	/// 便于直接创建几何形状并求几何形状的切点、切线等。
	/// </summary>
	public abstract class AbstractGeometry
	{
		protected AbstractGeometry()
		{
			PaddingType = Padding.StartExtendEndExtend;
			VisualizeOption = new VisualizeOption(Color.Red, Color.Gray);
		}

		public Padding PaddingType;

		public abstract (Vector2 Pt, float Angle, float Bias, float Position) QueryTangentPoint(Vector2 point);

		public abstract void Visualize(Action<VisDot> processDot, Action<VisLine> processLine,
			bool visExtendedPart = false);

		public VisualizeOption VisualizeOption;

		/// <summary>
		/// 查询指定位置的曲率。
		/// </summary>
		/// <param name="position">从起点到查询位置的距离。</param>
		/// <returns></returns>
		public abstract float QueryCurvature(float position);

		public abstract float Length();
	}

	public class VisualizeOption
	{
		public VisualizeOption(Color mainColor, Color auxiliaryColor)
		{
			MainColor = mainColor;
			AuxiliaryColor = auxiliaryColor;
		}

		public Color MainColor;
		public Color AuxiliaryColor;
		public bool DrawAuxiliary = true;
		public bool VisualizeDirection = true;
	}

	public enum Padding
	{
		StartLineEndLine = 0b_0001_0001,
		StartLineEndExtend = 0b_0001_0010,
		StartExtendEndLine = 0b_0010_0001,
		StartExtendEndExtend = 0b_0010_0010,
	}

	public class VisDot
	{
		public VisDot(Vector2 point, Color color)
		{
			Point = point;
			Color = color;
		}

		public Vector2 Point;
		public Color Color;
	}

	public class VisLine
	{
		public VisLine(Vector2 start, Vector2 end, bool startArrow, bool endArrow, Color color, float width = 1)
		{
			Start = start;
			End = end;
			StartArrow = startArrow;
			EndArrow = endArrow;
			Color = color;
			Width = width;
		}

		public Vector2 Start;
		public Vector2 End;
		public bool StartArrow = false;
		public bool EndArrow = false;
		public Color Color;
		public float Width;
	}
}
