-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ibrahim Saad
committed
Mar 26, 2023
1 parent
fc8c679
commit 687f842
Showing
15 changed files
with
521 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
############################################################################### | ||
# Set default behavior to automatically normalize line endings. | ||
############################################################################### | ||
* text=auto | ||
|
||
############################################################################### | ||
# Set default behavior for command prompt diff. | ||
# | ||
# This is need for earlier builds of msysgit that does not have it on by | ||
# default for csharp files. | ||
# Note: This is only used by command line | ||
############################################################################### | ||
#*.cs diff=csharp | ||
|
||
############################################################################### | ||
# Set the merge driver for project and solution files | ||
# | ||
# Merging from the command prompt will add diff markers to the files if there | ||
# are conflicts (Merging from VS is not affected by the settings below, in VS | ||
# the diff markers are never inserted). Diff markers may cause the following | ||
# file extensions to fail to load in VS. An alternative would be to treat | ||
# these files as binary and thus will always conflict and require user | ||
# intervention with every merge. To do so, just uncomment the entries below | ||
############################################################################### | ||
#*.sln merge=binary | ||
#*.csproj merge=binary | ||
#*.vbproj merge=binary | ||
#*.vcxproj merge=binary | ||
#*.vcproj merge=binary | ||
#*.dbproj merge=binary | ||
#*.fsproj merge=binary | ||
#*.lsproj merge=binary | ||
#*.wixproj merge=binary | ||
#*.modelproj merge=binary | ||
#*.sqlproj merge=binary | ||
#*.wwaproj merge=binary | ||
|
||
############################################################################### | ||
# behavior for image files | ||
# | ||
# image files are treated as binary by default. | ||
############################################################################### | ||
#*.jpg binary | ||
#*.png binary | ||
#*.gif binary | ||
|
||
############################################################################### | ||
# diff behavior for common document formats | ||
# | ||
# Convert binary document formats to text before diffing them. This feature | ||
# is only available from the command line. Turn it on by uncommenting the | ||
# entries below. | ||
############################################################################### | ||
#*.doc diff=astextplain | ||
#*.DOC diff=astextplain | ||
#*.docx diff=astextplain | ||
#*.DOCX diff=astextplain | ||
#*.dot diff=astextplain | ||
#*.DOT diff=astextplain | ||
#*.pdf diff=astextplain | ||
#*.PDF diff=astextplain | ||
#*.rtf diff=astextplain | ||
#*.RTF diff=astextplain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Application x:Class="CGAA.Visualizer.App" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="clr-namespace:CGAA.Visualizer" | ||
StartupUri="MainWindow.xaml"> | ||
<Application.Resources> | ||
|
||
</Application.Resources> | ||
</Application> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Configuration; | ||
using System.Data; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
|
||
namespace CGAA.Visualizer | ||
{ | ||
/// <summary> | ||
/// Interaction logic for App.xaml | ||
/// </summary> | ||
public partial class App : Application | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System.Windows; | ||
|
||
[assembly: ThemeInfo( | ||
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located | ||
//(used if a resource is not found in the page, | ||
// or application resource dictionaries) | ||
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located | ||
//(used if a resource is not found in the page, | ||
// app, or any theme specific resource dictionaries) | ||
)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>WinExe</OutputType> | ||
<TargetFramework>net6.0-windows</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<UseWPF>true</UseWPF> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<Window | ||
x:Class="CGAA.Visualizer.CGAAVisualizer" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:local="clr-namespace:CGAA.Visualizer" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
Title="MainWindow" | ||
Width="1000" | ||
Height="800" | ||
Closed="Window_Closed" | ||
mc:Ignorable="d"> | ||
<Grid Margin="40"> | ||
<Canvas x:Name="canvas" Background="#00FFFFFF" /> | ||
</Grid> | ||
</Window> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Windows; | ||
using System.Windows.Media; | ||
using System.Windows.Shapes; | ||
using Pnt = System.Drawing.Point; | ||
|
||
|
||
namespace CGAA.Visualizer | ||
{ | ||
/// <summary> | ||
/// Interaction logic for CGAAVisualizer.xaml | ||
/// </summary> | ||
public partial class CGAAVisualizer : Window | ||
{ | ||
|
||
public CGAAVisualizer() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
public static void DrawConvexHull(IEnumerable<Pnt> points, IEnumerable<Pnt> convexHull, Color color = default, double thickness = 3) | ||
{ | ||
if (color == default) | ||
color = Colors.DarkGreen; | ||
|
||
CGAAVisualizer visualizer = new(); | ||
|
||
Polyline polyline = new() | ||
{ | ||
Stroke = new SolidColorBrush(color), | ||
StrokeThickness = thickness, | ||
Points = new PointCollection(convexHull.Select(p => new Point(p.X, p.Y))) | ||
}; | ||
|
||
if (convexHull.First() != convexHull.Last()) | ||
polyline.Points.Add(new Point(convexHull.First().X, convexHull.First().Y)); | ||
|
||
visualizer.canvas.Children.Add(polyline); | ||
|
||
foreach (var point in points) | ||
{ | ||
visualizer.canvas.Children.Add(CreateEllipse(3, 3, point.X, point.Y)); | ||
} | ||
|
||
visualizer.ShowDialog(); | ||
} | ||
|
||
|
||
static Ellipse CreateEllipse(double width, double height, double desiredCenterX, double desiredCenterY) | ||
{ | ||
double left = desiredCenterX - (width / 2); | ||
double top = desiredCenterY - (height / 2); | ||
Ellipse ellipse = new() | ||
{ | ||
Width = width, | ||
Height = height, | ||
Stroke = new SolidColorBrush(Colors.Red), | ||
Margin = new Thickness(left, top, 0, 0) | ||
}; | ||
return ellipse; | ||
} | ||
|
||
private void Window_Closed(object sender, System.EventArgs e) | ||
{ | ||
// OnClosed logic | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.4.33205.214 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CGAA", "CGAA\CGAA.csproj", "{C7917907-526B-4F4A-ACB9-2037576CF639}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Misc", "Misc", "{58A92EE2-FCD1-47B1-A52D-640347ED09FC}" | ||
ProjectSection(SolutionItems) = preProject | ||
C:\Users\Ibrahim Saad\Desktop\content.png = C:\Users\Ibrahim Saad\Desktop\content.png | ||
EndProjectSection | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CGAA.Visualizer", "CGAA.Visualizer\CGAA.Visualizer.csproj", "{71B8C473-49CE-468B-B1F7-58901C626C99}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{C7917907-526B-4F4A-ACB9-2037576CF639}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{C7917907-526B-4F4A-ACB9-2037576CF639}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{C7917907-526B-4F4A-ACB9-2037576CF639}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{C7917907-526B-4F4A-ACB9-2037576CF639}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{71B8C473-49CE-468B-B1F7-58901C626C99}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{71B8C473-49CE-468B-B1F7-58901C626C99}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{71B8C473-49CE-468B-B1F7-58901C626C99}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{71B8C473-49CE-468B-B1F7-58901C626C99}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {F92A82BF-8FA8-4661-AEA5-D8C8D7E0F397} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using CGAA.Extensions; | ||
using System.Drawing; | ||
|
||
namespace CGAA | ||
{ | ||
public class ConvexHull | ||
{ | ||
|
||
public static IEnumerable<Point> Make(IEnumerable<Point> points) | ||
{ | ||
return UpperHull(points).Union(LowerHull(points)); | ||
} | ||
|
||
public static IEnumerable<Point> UpperHull(IEnumerable<Point> points) | ||
{ | ||
|
||
if (points.Count() < 3) | ||
return points; | ||
|
||
var sortedPoints = points.OrderBy(p => p.X).ThenBy(p => p.Y).ToList(); | ||
var upperHull = new List<Point>(); | ||
|
||
for (int i = 0; i < sortedPoints.Count; i++) | ||
{ | ||
var point = sortedPoints[i]; | ||
upperHull.Add(point); | ||
|
||
while (upperHull.Count > 2 && !IsLastThreePointsMakingRightTurn(upperHull)) | ||
{ | ||
upperHull.Remove(upperHull[upperHull.Count - 2]); | ||
} | ||
} | ||
|
||
return upperHull; | ||
} | ||
|
||
|
||
public static IEnumerable<Point> LowerHull(IEnumerable<Point> points) | ||
{ | ||
if (points.Count() < 3) | ||
return points; | ||
|
||
var sortedPoints = points.OrderBy(p => p.X).ThenBy(p => p.Y).ToList(); | ||
var lowerHull = new List<Point>(); | ||
|
||
for (int i = sortedPoints.Count - 1; i > -1; i--) | ||
{ | ||
var point = sortedPoints[i]; | ||
lowerHull.Add(point); | ||
|
||
while (lowerHull.Count > 2 && !IsLastThreePointsMakingRightTurn(lowerHull)) | ||
{ | ||
lowerHull.Remove(lowerHull[lowerHull.Count - 2]); | ||
} | ||
} | ||
return lowerHull; | ||
} | ||
|
||
|
||
private static bool IsLastThreePointsMakingRightTurn(List<Point> points) | ||
{ | ||
return points.Last().IsPointsLiesToTheRightOfLine(points[points.Count - 2], points[points.Count - 3]); | ||
} | ||
} | ||
} |
Oops, something went wrong.