using ClipperLib;
using System.Collections.Generic;
using UnityEngine;

public class Vertex {
    protected readonly Vector3 vec; // in m
    protected readonly IntPoint pt;

    private List<Segment> segments;

    public Vertex(Vertex vertex) {
        vec = vertex.vec;
        pt = vertex.pt;
    }

    public Vertex(Vector3 point) {
        pt = Converter.vectorToIntPoint(point);
        vec = point;
    }

	public Vertex(double x, double y, double z) {
        vec = new Vector3((float)x, (float)y, (float)z);
        pt = Converter.vectorToIntPoint(vec);
    }

    public Vector3 getVector() {
        return vec;
    }

	public Vector3 getVector(float z) {
		return new Vector3(vec.x, vec.y, z);
	}

    public IntPoint getIntPoint() {
        return pt;
    }

    public float x() {
        return vec.x;
    }

    public float y() {
        return vec.y;
    }

	public float z() {
		return vec.z;
	}

    public float distance(Vertex other) {
        return (this - other).norm();
    }

    public static Vertex operator +(Vertex v1, Vector v2) {
        return new Vertex(v1.getVector() + v2.getValue());
    }

    public static Vertex operator -(Vertex v1, Vector v2) {
        return new Vertex(v1.getVector() - v2.getValue());
    }

    public static Vertex operator +(Vertex v1, Vertex v2) {
        return new Vertex(v1.getVector() + v2.getVector());
    }

    public static Vector operator -(Vertex v1, Vertex v2) {
        return new Vector(v1.getVector() - v2.getVector());
    }

    public static Vertex operator /(Vertex v1, float v2) {
        return new Vertex(v1.getVector() / v2);
    }

    public static bool operator ==(Vertex v1, Vertex v2) {
        if (ReferenceEquals(v1, v2)) {
            return true;
        }
        else if (ReferenceEquals(v1, null)) {
            return false;
        }
        else if (ReferenceEquals(v2, null)) {
            return false;
        }

        return v1.vec == v2.vec;
    }

    public static bool operator !=(Vertex v1, Vertex v2) {
        return ! (v1 == v2);
    }

    public override bool Equals(object obj) {
        Vertex other = obj as Vertex;

        if (other == null) {
            return false;
        }

        return other.vec == vec;
    }

    public override int GetHashCode() {
        return (int)(pt.X + pt.Y);
    }
}
