Upload New File

parent cdcbee3b
using System;
using System.Collections.Generic;
using System.Text;
/*
copyright s-hull.org 2011
released under the contributors beerware license
S-hull is free software and may be obtained from www.s-hull.org. It may be freely copied, modified, and redistributed under the following conditions which might loosely be termed a contribtors beerware license:
1. All copyright notices must remain intact in all files.
2. A copy of this text file must be distributed along with any copies of S-hull that you redistribute; this includes copies that you have modified, or copies of programs or other software products that include S-hull where distributed as source.
3. If you modify S-hull, you must include a notice giving the name of the person performing the modification, the date of modification, and the reason for such modification.
4. If you are distributing a binary or compiled version of s-hull it is not necessary to include any acknowledgement or reference to s-hull.
5. There is no warranty or other guarantee of fitness for S-hull, it is provided solely "as is". Bug reports or fixes may be sent to bugs@s-hull.org; the authors may or may not act on them as they desire.
6. By copying or compliing the code for S-hull you explicitly indemnify the copyright holder against any liability he may incur as a result of you copying the code.
7. If you meet any of the contributors to the code you used from s-hull.org in a pub or a bar, and you think the source code they contributed to is worth it, you can buy them a beer. If your principles run against beer a bacon-double-cheeseburger would do just as nicely or you could email david@s-hull.org and arrange to make a donation of 10 of your local currancy units to support s-hull.org.
contributors: Phil Atkin, Dr Sinclair.
*/
namespace DelaunayTriangulator
{
/// <summary>
/// Vertices belonging to the convex hull need to maintain a point and triad index
/// </summary>
internal class HullVertex : Vertex
{
public int pointsIndex;
public int triadIndex;
public HullVertex(List<Vertex> points, int pointIndex)
{
x = points[pointIndex].x;
y = points[pointIndex].y;
pointsIndex = pointIndex;
triadIndex = 0;
}
}
/// <summary>
/// Hull represents a list of vertices in the convex hull, and keeps track of
/// their indices (into the associated points list) and triads
/// </summary>
class Hull : List<HullVertex>
{
private int NextIndex(int index)
{
if (index == Count - 1)
return 0;
else
return index + 1;
}
/// <summary>
/// Return vector from the hull point at index to next point
/// </summary>
public void VectorToNext(int index, out float dx, out float dy)
{
Vertex et = this[index], en = this[NextIndex(index)];
dx = en.x - et.x;
dy = en.y - et.y;
}
/// <summary>
/// Return whether the hull vertex at index is visible from the supplied coordinates
/// </summary>
public bool EdgeVisibleFrom(int index, float dx, float dy)
{
float idx, idy;
VectorToNext(index, out idx, out idy);
float crossProduct = -dy * idx + dx * idy;
return crossProduct < 0;
}
/// <summary>
/// Return whether the hull vertex at index is visible from the point
/// </summary>
public bool EdgeVisibleFrom(int index, Vertex point)
{
float idx, idy;
VectorToNext(index, out idx, out idy);
float dx = point.x - this[index].x;
float dy = point.y - this[index].y;
float crossProduct = -dy * idx + dx * idy;
return crossProduct < 0;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment