/*
* GNU AFFERO GENERAL PUBLIC LICENSE
* Version 3, 19 November 2007
* Copyright (C) 2007 Free Software Foundation, Inc.
* Everyone is permitted to copy and distribute verbatim copies
* of this license document, but changing it is not allowed.
*/
using System;
using System.Drawing;
using System.Text.Json.Serialization;
using System.Xml.Serialization;
using UVtools.Core.Extensions;
namespace UVtools.Core.Layers;
//[JsonDerivedType(typeof(Issue))]
//[JsonDerivedType(typeof(IssueOfPoints))]
//[JsonDerivedType(typeof(IssueOfContours))]
public class Issue
{
///
/// Gets the issue type associated
///
[JsonIgnore]
[XmlIgnore]
public MainIssue? Parent { get; internal set; }
public MainIssue.IssueType? Type => Parent?.Type;
///
/// Gets the layer where this issue is present
///
[JsonIgnore]
[XmlIgnore]
public Layer Layer { get; init; }
///
/// Gets the layer index
///
public uint LayerIndex => Layer.Index;
///
/// Gets the bounding rectangle of the area
///
public Rectangle BoundingRectangle { get; init; }
///
/// Gets the number of pixels
///
public uint PixelsCount { get; init; }
///
/// Gets the area of the issue
///
public double Area { get; init; }
public Point FirstPoint { get; init; } = new(-1,-1);
public Issue() { }
public Issue(Layer layer, Rectangle boundingRectangle, double area)
{
Layer = layer;
BoundingRectangle = boundingRectangle;
Area = area;
}
public Issue(Layer layer, Rectangle boundingRectangle = default) : this(layer, boundingRectangle, boundingRectangle.Area())
{ }
public virtual void Sort(){ }
protected bool Equals(Issue other)
{
return Type == other.Type && LayerIndex == other.LayerIndex && BoundingRectangle.Equals(other.BoundingRectangle) && PixelsCount == other.PixelsCount && Area.Equals(other.Area);
}
public override bool Equals(object? obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((Issue)obj);
}
public override int GetHashCode()
{
return HashCode.Combine(Layer, BoundingRectangle, PixelsCount, Area);
}
}