├── .gitignore
├── LICENSE
├── MathHelper
├── MathHelper.csproj
├── Properties
│ └── AssemblyInfo.cs
└── Vector.cs
├── PuzzleGraph
├── Decorator.cs
├── Decorators
│ ├── AbstractTetrisDecorator.cs
│ ├── ArrowDecorator.cs
│ ├── BoxDecorator.cs
│ ├── BrokenDecorator.cs
│ ├── CircleDecorator.cs
│ ├── CombinedDecorator.cs
│ ├── EliminatorDecorator.cs
│ ├── EndDecorator.cs
│ ├── HollowTetrisDecorator.cs
│ ├── ParallelPuzzleDecorator.cs
│ ├── PointDecorator.cs
│ ├── RingDecorator.cs
│ ├── SelfIntersectionDecorator.cs
│ ├── SquareDecorator.cs
│ ├── StarDecorator.cs
│ ├── StartDecorator.cs
│ ├── SymmetryPuzzleDecorator.cs
│ ├── TetrisDecorator.cs
│ ├── TextDecorator.cs
│ ├── ThreeWayPuzzleDecorator.cs
│ └── TriangleDecorator.cs
├── Edge.cs
├── Face.cs
├── Graph.cs
├── GraphElement.cs
├── IEdgeDecorable.cs
├── IFaceDecorable.cs
├── INodeDecorable.cs
├── IUnifiedScaleDecorator.cs
├── LocalizedDisplayNameAttribute.cs
├── MetaData.cs
├── Node.cs
├── ObsolateFormatFixer.cs
├── Properties
│ └── AssemblyInfo.cs
├── PuzzleGraph.csproj
├── Resources
│ ├── Lang.Designer.cs
│ ├── Lang.resx
│ └── Lang.zh-CN.resx
├── SaveState.cs
├── SerializableFont.cs
├── TetrisTemplate.cs
├── TransformableDecorator.cs
├── XmlColor.cs
└── XmlFont.cs
├── README.md
├── Screenshots
├── 1.png
└── 2.jpg
├── TemplateGenerator
├── App.config
├── HexagonTemplateGenerator.cs
├── Program.cs
├── Properties
│ └── AssemblyInfo.cs
├── PyramidHexagonTemplateGenerator.cs
├── RightTriangleTemplateGenerator.cs
├── SquareTemplateGenerator.cs
└── TemplateGenerator.csproj
├── WitnessVisualizer.sln
└── WitnessVisualizer
├── App.config
├── EditManager.cs
├── EditView.cs
├── FormHelper.cs
├── GraphManipulation.cs
├── Icons
├── ColorPicker.png
├── Cursor.png
└── Paint.png
├── InputDialog.cs
├── MainForm.Designer.cs
├── MainForm.cs
├── MainForm.resx
├── MainForm.zh-CN.resx
├── PaintingModeControl.cs
├── Program.cs
├── Prompt.cs
├── Properties
├── AssemblyInfo.cs
├── Resources.Designer.cs
├── Resources.resx
├── Settings.Designer.cs
└── Settings.settings
├── PuzzleGraphRenderer.cs
├── PuzzleSettings.cs
├── PuzzleToolkit.cs
├── PuzzleToolkitDecoratorItem.cs
├── PuzzleToolkitItem.cs
├── PuzzleToolkitMiscItem.cs
├── Puzzles
└── README.txt
├── Resources
├── Lang.Designer.cs
├── Lang.resx
└── Lang.zh-CN.resx
├── Templates
└── README.txt
├── TetrisTemplateRenderer.cs
├── TetrisTransferHelper.cs
├── Toolkit
└── README.txt
├── WitnessVisualizer.csproj
├── designer.ico
├── designer2.ico
└── packages.config
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | bld/
21 | [Bb]in/
22 | [Oo]bj/
23 | [Ll]og/
24 |
25 | # Visual Studio 2015 cache/options directory
26 | .vs/
27 | # Uncomment if you have tasks that create the project's static files in wwwroot
28 | #wwwroot/
29 |
30 | # MSTest test Results
31 | [Tt]est[Rr]esult*/
32 | [Bb]uild[Ll]og.*
33 |
34 | # NUNIT
35 | *.VisualState.xml
36 | TestResult.xml
37 |
38 | # Build Results of an ATL Project
39 | [Dd]ebugPS/
40 | [Rr]eleasePS/
41 | dlldata.c
42 |
43 | # DNX
44 | project.lock.json
45 | artifacts/
46 |
47 | *_i.c
48 | *_p.c
49 | *_i.h
50 | *.ilk
51 | *.meta
52 | *.obj
53 | *.pch
54 | *.pdb
55 | *.pgc
56 | *.pgd
57 | *.rsp
58 | *.sbr
59 | *.tlb
60 | *.tli
61 | *.tlh
62 | *.tmp
63 | *.tmp_proj
64 | *.log
65 | *.vspscc
66 | *.vssscc
67 | .builds
68 | *.pidb
69 | *.svclog
70 | *.scc
71 |
72 | # Chutzpah Test files
73 | _Chutzpah*
74 |
75 | # Visual C++ cache files
76 | ipch/
77 | *.aps
78 | *.ncb
79 | *.opendb
80 | *.opensdf
81 | *.sdf
82 | *.cachefile
83 | *.VC.db
84 | *.VC.VC.opendb
85 |
86 | # Visual Studio profiler
87 | *.psess
88 | *.vsp
89 | *.vspx
90 | *.sap
91 |
92 | # TFS 2012 Local Workspace
93 | $tf/
94 |
95 | # Guidance Automation Toolkit
96 | *.gpState
97 |
98 | # ReSharper is a .NET coding add-in
99 | _ReSharper*/
100 | *.[Rr]e[Ss]harper
101 | *.DotSettings.user
102 |
103 | # JustCode is a .NET coding add-in
104 | .JustCode
105 |
106 | # TeamCity is a build add-in
107 | _TeamCity*
108 |
109 | # DotCover is a Code Coverage Tool
110 | *.dotCover
111 |
112 | # NCrunch
113 | _NCrunch_*
114 | .*crunch*.local.xml
115 | nCrunchTemp_*
116 |
117 | # MightyMoose
118 | *.mm.*
119 | AutoTest.Net/
120 |
121 | # Web workbench (sass)
122 | .sass-cache/
123 |
124 | # Installshield output folder
125 | [Ee]xpress/
126 |
127 | # DocProject is a documentation generator add-in
128 | DocProject/buildhelp/
129 | DocProject/Help/*.HxT
130 | DocProject/Help/*.HxC
131 | DocProject/Help/*.hhc
132 | DocProject/Help/*.hhk
133 | DocProject/Help/*.hhp
134 | DocProject/Help/Html2
135 | DocProject/Help/html
136 |
137 | # Click-Once directory
138 | publish/
139 |
140 | # Publish Web Output
141 | *.[Pp]ublish.xml
142 | *.azurePubxml
143 | # TODO: Comment the next line if you want to checkin your web deploy settings
144 | # but database connection strings (with potential passwords) will be unencrypted
145 | *.pubxml
146 | *.publishproj
147 |
148 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
149 | # checkin your Azure Web App publish settings, but sensitive information contained
150 | # in these scripts will be unencrypted
151 | PublishScripts/
152 |
153 | # NuGet Packages
154 | *.nupkg
155 | # The packages folder can be ignored because of Package Restore
156 | **/packages/*
157 | # except build/, which is used as an MSBuild target.
158 | !**/packages/build/
159 | # Uncomment if necessary however generally it will be regenerated when needed
160 | #!**/packages/repositories.config
161 | # NuGet v3's project.json files produces more ignoreable files
162 | *.nuget.props
163 | *.nuget.targets
164 |
165 | # Microsoft Azure Build Output
166 | csx/
167 | *.build.csdef
168 |
169 | # Microsoft Azure Emulator
170 | ecf/
171 | rcf/
172 |
173 | # Windows Store app package directories and files
174 | AppPackages/
175 | BundleArtifacts/
176 | Package.StoreAssociation.xml
177 | _pkginfo.txt
178 |
179 | # Visual Studio cache files
180 | # files ending in .cache can be ignored
181 | *.[Cc]ache
182 | # but keep track of directories ending in .cache
183 | !*.[Cc]ache/
184 |
185 | # Others
186 | ClientBin/
187 | ~$*
188 | *~
189 | *.dbmdl
190 | *.dbproj.schemaview
191 | *.pfx
192 | *.publishsettings
193 | node_modules/
194 | orleans.codegen.cs
195 |
196 | # Since there are multiple workflows, uncomment next line to ignore bower_components
197 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
198 | #bower_components/
199 |
200 | # RIA/Silverlight projects
201 | Generated_Code/
202 |
203 | # Backup & report files from converting an old project file
204 | # to a newer Visual Studio version. Backup files are not needed,
205 | # because we have git ;-)
206 | _UpgradeReport_Files/
207 | Backup*/
208 | UpgradeLog*.XML
209 | UpgradeLog*.htm
210 |
211 | # SQL Server files
212 | *.mdf
213 | *.ldf
214 |
215 | # Business Intelligence projects
216 | *.rdl.data
217 | *.bim.layout
218 | *.bim_*.settings
219 |
220 | # Microsoft Fakes
221 | FakesAssemblies/
222 |
223 | # GhostDoc plugin setting file
224 | *.GhostDoc.xml
225 |
226 | # Node.js Tools for Visual Studio
227 | .ntvs_analysis.dat
228 |
229 | # Visual Studio 6 build log
230 | *.plg
231 |
232 | # Visual Studio 6 workspace options file
233 | *.opt
234 |
235 | # Visual Studio LightSwitch build output
236 | **/*.HTMLClient/GeneratedArtifacts
237 | **/*.DesktopClient/GeneratedArtifacts
238 | **/*.DesktopClient/ModelManifest.xml
239 | **/*.Server/GeneratedArtifacts
240 | **/*.Server/ModelManifest.xml
241 | _Pvt_Extensions
242 |
243 | # Paket dependency manager
244 | .paket/paket.exe
245 | paket-files/
246 |
247 | # FAKE - F# Make
248 | .fake/
249 |
250 | # JetBrains Rider
251 | .idea/
252 | *.sln.iml
253 |
254 | # Others
255 |
256 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Junyan Jiang
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/MathHelper/MathHelper.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {4ED83A7C-9E43-4E5E-95EF-F724F5664730}
8 | Library
9 | Properties
10 | MathHelper
11 | MathHelper
12 | v4.7.2
13 | 512
14 | true
15 |
16 |
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | pdbonly
27 | true
28 | bin\Release\
29 | TRACE
30 | prompt
31 | 4
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/MathHelper/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // 有关程序集的一般信息由以下
6 | // 控制。更改这些特性值可修改
7 | // 与程序集关联的信息。
8 | [assembly: AssemblyTitle("MathHelper")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("MathHelper")]
13 | [assembly: AssemblyCopyright("Copyright © 2019")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // 将 ComVisible 设置为 false 会使此程序集中的类型
18 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
19 | //请将此类型的 ComVisible 特性设置为 true。
20 | [assembly: ComVisible(false)]
21 |
22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23 | [assembly: Guid("4ed83a7c-9e43-4e5e-95ef-f724f5664730")]
24 |
25 | // 程序集的版本信息由下列四个值组成:
26 | //
27 | // 主版本
28 | // 次版本
29 | // 生成号
30 | // 修订号
31 | //
32 | //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
33 | //通过使用 "*",如下所示:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/MathHelper/Vector.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Drawing;
3 |
4 | namespace MathHelper
5 | {
6 | public class Vector
7 | {
8 | public double X { get; private set; }
9 | public double Y { get; private set; }
10 | public Vector(double inputX,double inputY)
11 | {
12 | X = inputX;
13 | Y = inputY;
14 | }
15 | public static Vector Zero = new Vector(0.0, 0.0);
16 | public static Vector UnitX = new Vector(1.0, 0.0);
17 | public static Vector UnitY = new Vector(0.0, 1.0);
18 | public PointF ToPoint()
19 | {
20 | return new PointF((float)X, (float)Y);
21 | }
22 | public RectangleF ToCircleBoundingBox(double radius)
23 | {
24 | float diameter = (float)(radius*2);
25 | return new RectangleF((float)(X - radius), (float)(Y - radius), diameter, diameter);
26 | }
27 | public static RectangleF ToRectangleF(Vector a, Vector b)
28 | {
29 | double x1 = Math.Min(a.X, b.X);
30 | double y1 = Math.Min(a.Y, b.Y);
31 | double width = Math.Max(a.X, b.X) - x1;
32 | double height = Math.Max(a.Y, b.Y) - y1;
33 | return new RectangleF((float)x1, (float)y1, (float)width, (float)height);
34 | }
35 |
36 | #region operations
37 | public static Vector operator +(Vector a) => a;
38 | public static Vector operator -(Vector a) => new Vector(-a.X,-a.Y);
39 | public static Vector operator +(Vector a, Vector b) => new Vector(a.X + b.X, a.Y + b.Y);
40 | public static Vector operator -(Vector a, Vector b) => new Vector(a.X - b.X, a.Y - b.Y);
41 | public static Vector operator *(Vector a, double b) => new Vector(a.X * b, a.Y * b);
42 | public static Vector operator *(double b, Vector a) => new Vector(a.X * b, a.Y * b);
43 | public static Vector operator /(Vector a, double b) => new Vector(a.X / b, a.Y / b);
44 | public static Vector operator /(double b, Vector a) => new Vector(a.X / b, a.Y / b);
45 | public static double operator ^(Vector a, Vector b) => a.X * b.X + a.Y * b.Y;
46 | public static double operator *(Vector a, Vector b) => a.X * b.Y - b.X * a.Y;
47 | #endregion
48 |
49 | #region helper functions
50 | public Vector MapToScreen(double scale,Vector origin) => this * scale + origin;
51 | public Vector MapFromScreen(double scale, Vector origin) => (this - origin) / scale;
52 | public double Length() => Math.Sqrt(X * X + Y * Y);
53 | public static double PointDistance(Vector query, Vector point) => (query - point).Length();
54 | public static double SegmentDistance(Vector query, Vector start, Vector end)
55 | {
56 | // from https://stackoverflow.com/questions/849211/shortest-distance-between-a-point-and-a-line-segment by Joshua
57 | double x = query.X, y = query.Y;
58 | double x1 = start.X, y1 = start.Y;
59 | double x2 = end.X, y2 = end.Y;
60 | double A = x - x1;
61 | double B = y - y1;
62 | double C = x2 - x1;
63 | double D = y2 - y1;
64 |
65 | double dot = A * C + B * D;
66 | double len_sq = C * C + D * D;
67 | double param = -1;
68 | if (len_sq != 0) //in case of 0 length line
69 | param = dot / len_sq;
70 |
71 | double xx, yy;
72 |
73 | if (param < 0)
74 | {
75 | xx = x1;
76 | yy = y1;
77 | }
78 | else if (param > 1)
79 | {
80 | xx = x2;
81 | yy = y2;
82 | }
83 | else
84 | {
85 | xx = x1 + param * C;
86 | yy = y1 + param * D;
87 | }
88 |
89 | double dx = x - xx;
90 | double dy = y - yy;
91 | return Math.Sqrt(dx * dx + dy * dy);
92 | }
93 |
94 | public static double GetAngle(Vector a, Vector b)
95 | {
96 | double lengthProduct = a.Length() * b.Length();
97 | if (lengthProduct < 1e-10)
98 | return 0.0f;
99 | double cosValue = (a ^ b) / lengthProduct;
100 | return Math.Acos(cosValue);
101 | }
102 |
103 | public Vector Rotate(double angle)
104 | {
105 | double cosValue = Math.Cos(angle), sinValue = Math.Sin(angle);
106 | return new Vector(cosValue * X - sinValue * Y, sinValue * X + cosValue * Y);
107 | }
108 | #endregion
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/PuzzleGraph/Decorator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Text;
5 | using System.Xml.Serialization;
6 | using PuzzleGraph.Decorators;
7 |
8 | namespace PuzzleGraph
9 | {
10 | [
11 | XmlInclude(typeof(BrokenDecorator)),
12 | XmlInclude(typeof(EliminatorDecorator)),
13 | XmlInclude(typeof(EndDecorator)),
14 | XmlInclude(typeof(HollowTetrisDecorator)),
15 | XmlInclude(typeof(PointDecorator)),
16 | XmlInclude(typeof(SquareDecorator)),
17 | XmlInclude(typeof(StarDecorator)),
18 | XmlInclude(typeof(StartDecorator)),
19 | XmlInclude(typeof(TetrisDecorator)),
20 | XmlInclude(typeof(TriangleDecorator)),
21 | XmlInclude(typeof(CircleDecorator)),
22 | XmlInclude(typeof(RingDecorator)),
23 | XmlInclude(typeof(TextDecorator)),
24 | XmlInclude(typeof(CombinedDecorator)),
25 | XmlInclude(typeof(SymmetryPuzzleDecorator)),
26 | XmlInclude(typeof(ThreeWayPuzzleDecorator)),
27 | XmlInclude(typeof(ParallelPuzzleDecorator)),
28 | XmlInclude(typeof(ArrowDecorator)),
29 | XmlInclude(typeof(SelfIntersectionDecorator)),
30 | XmlInclude(typeof(BoxDecorator)),
31 | ]
32 | public abstract class Decorator : ICloneable
33 | {
34 | public virtual bool IsFaceDecorable() => this is IFaceDecorable;
35 | public virtual bool IsEdgeDecorable() => this is IEdgeDecorable;
36 | public virtual bool IsNodeDecorable() => this is INodeDecorable;
37 |
38 | public bool IsDecorableFor(GraphElement element)
39 | {
40 | return (element is Node && IsNodeDecorable()) ||
41 | (element is Edge && IsEdgeDecorable()) ||
42 | (element is Face && IsFaceDecorable());
43 | }
44 | public object Clone()
45 | {
46 | using (MemoryStream ms = new MemoryStream())
47 | {
48 | XmlSerializer xml = new XmlSerializer(typeof(Decorator));
49 | xml.Serialize(ms, this);
50 | ms.Position = 0;
51 | return xml.Deserialize(ms);
52 | }
53 | }
54 | public override string ToString()
55 | {
56 | return Resources.Lang.ResourceManager.GetString(this.GetType().Name) ?? this.GetType().Name;
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/PuzzleGraph/Decorators/AbstractTetrisDecorator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace PuzzleGraph.Decorators
8 | {
9 | public class AbstractTetrisDecorator : TransformableDecorator
10 | {
11 | [LocalizedDisplayName("Shapes")]
12 | public List> Shapes { get; set; } = new List>();
13 | [LocalizedDisplayName("Indexes")]
14 | public List Indexes { get; set; } = new List();
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/PuzzleGraph/Decorators/ArrowDecorator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using System.Xml.Serialization;
8 |
9 | namespace PuzzleGraph.Decorators
10 | {
11 | public class ArrowDecorator : TransformableDecorator, IFaceDecorable, IEdgeDecorable, INodeDecorable
12 | {
13 | [LocalizedDisplayName("Count")]
14 | public int Count { get; set; } = 1;
15 | [LocalizedDisplayName("Color")]
16 | [XmlElement(Type = typeof(XmlColor))]
17 | public Color Color { get; set; } = Color.Purple;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/PuzzleGraph/Decorators/BoxDecorator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using System.Xml.Serialization;
8 |
9 | namespace PuzzleGraph.Decorators
10 | {
11 | public class BoxDecorator : TransformableDecorator, IFaceDecorable, IEdgeDecorable, INodeDecorable
12 | {
13 |
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/PuzzleGraph/Decorators/BrokenDecorator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace PuzzleGraph.Decorators
8 | {
9 | public class BrokenDecorator : Decorator, IEdgeDecorable
10 | {
11 |
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/PuzzleGraph/Decorators/CircleDecorator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using System.Xml.Serialization;
8 |
9 | namespace PuzzleGraph.Decorators
10 | {
11 | public class CircleDecorator : TransformableDecorator, IFaceDecorable, IEdgeDecorable, INodeDecorable
12 | {
13 | [LocalizedDisplayName("Color")]
14 | [XmlElement(Type = typeof(XmlColor))]
15 | public Color Color { get; set; } = Color.Brown;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/PuzzleGraph/Decorators/CombinedDecorator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace PuzzleGraph.Decorators
9 | {
10 | public class CombinedDecorator : Decorator
11 | {
12 | public override bool IsFaceDecorable()
13 | {
14 | if(First is null || Second is null) return false;
15 | return First.IsFaceDecorable() && Second.IsFaceDecorable();
16 | }
17 | public override bool IsEdgeDecorable()
18 | {
19 | if (First is null || Second is null) return false;
20 | return First.IsEdgeDecorable() && Second.IsEdgeDecorable();
21 | }
22 | public override bool IsNodeDecorable()
23 | {
24 | if (First is null || Second is null) return false;
25 | return First.IsNodeDecorable() && Second.IsNodeDecorable();
26 | }
27 | [LocalizedDisplayName("First")]
28 | [TypeConverter(typeof(ExpandableObjectConverter))]
29 | public Decorator First { get; set; }
30 | [LocalizedDisplayName("Second")]
31 | [TypeConverter(typeof(ExpandableObjectConverter))]
32 | public Decorator Second { get; set; }
33 |
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/PuzzleGraph/Decorators/EliminatorDecorator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using System.Xml.Serialization;
8 |
9 | namespace PuzzleGraph.Decorators
10 | {
11 | public class EliminatorDecorator : TransformableDecorator, IFaceDecorable, IEdgeDecorable, INodeDecorable
12 | {
13 | [LocalizedDisplayName("Color")]
14 | [XmlElement(Type = typeof(XmlColor))]
15 | public Color Color { get; set; } = Color.White;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/PuzzleGraph/Decorators/EndDecorator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using System.Xml.Serialization;
8 |
9 | namespace PuzzleGraph.Decorators
10 | {
11 | public class EndDecorator : Decorator, INodeDecorable, IEdgeDecorable
12 | {
13 | [LocalizedDisplayName("Length")]
14 | public double Length { get; set; } = 0.2;
15 | [LocalizedDisplayName("Angle")]
16 | public double Angle { get; set; } = 135;
17 | [LocalizedDisplayName("Color")]
18 | [XmlElement(Type = typeof(XmlColor))]
19 | public Color Color { get; set; } = Color.Transparent;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/PuzzleGraph/Decorators/HollowTetrisDecorator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using System.Xml.Serialization;
8 |
9 | namespace PuzzleGraph.Decorators
10 | {
11 | public class HollowTetrisDecorator : AbstractTetrisDecorator, IFaceDecorable, IEdgeDecorable, INodeDecorable
12 | {
13 | [LocalizedDisplayName("Color")]
14 | [XmlElement(Type = typeof(XmlColor))]
15 | public Color Color { get; set; } = Color.Blue;
16 | [LocalizedDisplayName("BorderSize")]
17 | public double BorderSize { get; set; } = 0.19;
18 | [LocalizedDisplayName("MarginSize")]
19 | public double MarginSize { get; set; } = 0.14;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/PuzzleGraph/Decorators/ParallelPuzzleDecorator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using System.Xml.Serialization;
8 |
9 | namespace PuzzleGraph.Decorators
10 | {
11 | public class ParallelPuzzleDecorator : TransformableDecorator, IFaceDecorable, IEdgeDecorable, INodeDecorable, IUnifiedScaleDecorator
12 | {
13 | [LocalizedDisplayName("SecondLineColor")]
14 | [XmlElement(Type = typeof(XmlColor))]
15 | public Color SecondLineColor { get; set; } = Color.Aqua;
16 |
17 | [LocalizedDisplayName("TranslationX")]
18 | public double TranslationX { get; set; } = 0.0;
19 | [LocalizedDisplayName("TranslationY")]
20 | public double TranslationY { get; set; } = 0.0;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/PuzzleGraph/Decorators/PointDecorator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using System.Xml.Serialization;
8 |
9 | namespace PuzzleGraph.Decorators
10 | {
11 | public class PointDecorator : TransformableDecorator, IFaceDecorable, IEdgeDecorable, INodeDecorable
12 | {
13 | [LocalizedDisplayName("Color")]
14 | [XmlElement(Type = typeof(XmlColor))]
15 | public Color Color { get; set; } = Color.Black;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/PuzzleGraph/Decorators/RingDecorator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using System.Xml.Serialization;
8 |
9 | namespace PuzzleGraph.Decorators
10 | {
11 | public class RingDecorator : TransformableDecorator, IFaceDecorable, IEdgeDecorable, INodeDecorable
12 | {
13 | [LocalizedDisplayName("Color")]
14 | [XmlElement(Type = typeof(XmlColor))]
15 | public Color Color { get; set; } = Color.Brown;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/PuzzleGraph/Decorators/SelfIntersectionDecorator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using System.Xml.Serialization;
8 |
9 | namespace PuzzleGraph.Decorators
10 | {
11 | public class SelfIntersectionDecorator : TransformableDecorator, IFaceDecorable, IEdgeDecorable, INodeDecorable
12 | {
13 | [LocalizedDisplayName("Color1")]
14 | [XmlElement(Type = typeof(XmlColor))]
15 | public Color Color1 { get; set; } = Color.Black;
16 | [LocalizedDisplayName("Color2")]
17 | [XmlElement(Type = typeof(XmlColor))]
18 | public Color Color2 { get; set; } = Color.Black;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/PuzzleGraph/Decorators/SquareDecorator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using System.Xml.Serialization;
8 |
9 | namespace PuzzleGraph.Decorators
10 | {
11 | public class SquareDecorator : TransformableDecorator, IFaceDecorable, IEdgeDecorable, INodeDecorable
12 | {
13 | [LocalizedDisplayName("Color")]
14 | [XmlElement(Type = typeof(XmlColor))]
15 | public Color Color { get; set; } = Color.Black;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/PuzzleGraph/Decorators/StarDecorator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using System.Xml.Serialization;
8 |
9 | namespace PuzzleGraph.Decorators
10 | {
11 | public class StarDecorator : TransformableDecorator, IFaceDecorable, IEdgeDecorable, INodeDecorable
12 | {
13 | [LocalizedDisplayName("Color")]
14 | [XmlElement(Type = typeof(XmlColor))]
15 | public Color Color { get; set; } = Color.Black;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/PuzzleGraph/Decorators/StartDecorator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using System.Xml.Serialization;
8 |
9 | namespace PuzzleGraph.Decorators
10 | {
11 | public class StartDecorator : Decorator, INodeDecorable, IEdgeDecorable
12 | {
13 | [LocalizedDisplayName("Color")]
14 | [XmlElement(Type = typeof(XmlColor))]
15 | public Color Color { get; set; } = Color.Transparent;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/PuzzleGraph/Decorators/SymmetryPuzzleDecorator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using System.Xml.Serialization;
8 |
9 | namespace PuzzleGraph.Decorators
10 | {
11 | public class SymmetryPuzzleDecorator: TransformableDecorator, IFaceDecorable, IEdgeDecorable, INodeDecorable, IUnifiedScaleDecorator
12 | {
13 | [LocalizedDisplayName("SecondLineColor")]
14 | [XmlElement(Type = typeof(XmlColor))]
15 | public Color SecondLineColor { get; set; } = Color.Aqua;
16 |
17 | [LocalizedDisplayName("IsRotational")]
18 | public bool IsRotational { get; set; } = false;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/PuzzleGraph/Decorators/TetrisDecorator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using System.Xml.Serialization;
8 |
9 | namespace PuzzleGraph.Decorators
10 | {
11 | public class TetrisDecorator : AbstractTetrisDecorator, IFaceDecorable, IEdgeDecorable, INodeDecorable
12 | {
13 | [LocalizedDisplayName("Color")]
14 | [XmlElement(Type = typeof(XmlColor))]
15 | public Color Color { get; set; } = Color.Yellow;
16 | [LocalizedDisplayName("MarginSize")]
17 | public double MarginSize { get; set; } = 0.14;
18 |
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/PuzzleGraph/Decorators/TextDecorator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.ComponentModel.Design;
5 | using System.Drawing;
6 | using System.Drawing.Design;
7 | using System.Linq;
8 | using System.Text;
9 | using System.Threading.Tasks;
10 | using System.Xml.Serialization;
11 |
12 | namespace PuzzleGraph.Decorators
13 | {
14 | public class TextDecorator : TransformableDecorator, IFaceDecorable, IEdgeDecorable, INodeDecorable
15 | {
16 | // [XmlElement(Type = typeof(XmlFont))]
17 | [LocalizedDisplayName("Font")]
18 | [XmlIgnore()]
19 | public Font Font { get { return SerializableFont?.ToFont(); }
20 | set { SerializableFont = new SerializableFont(value); }
21 | }
22 | [Browsable(false)]
23 | public SerializableFont SerializableFont { get; set; }
24 | [Editor(typeof(MultilineStringEditor), typeof(UITypeEditor))]
25 | [LocalizedDisplayName("Text")]
26 | public string Text { get; set; }
27 | [LocalizedDisplayName("Color")]
28 | [XmlElement(Type = typeof(XmlColor))]
29 | public Color Color { get; set; } = Color.Black;
30 |
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/PuzzleGraph/Decorators/ThreeWayPuzzleDecorator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using System.Xml.Serialization;
8 |
9 | namespace PuzzleGraph.Decorators
10 | {
11 | public class ThreeWayPuzzleDecorator: TransformableDecorator, IFaceDecorable, IEdgeDecorable, INodeDecorable, IUnifiedScaleDecorator
12 | {
13 | [LocalizedDisplayName("SecondLineColor")]
14 | [XmlElement(Type = typeof(XmlColor))]
15 | public Color SecondLineColor { get; set; } = Color.Aqua;
16 | [LocalizedDisplayName("ThirdLineColor")]
17 | [XmlElement(Type = typeof(XmlColor))]
18 | public Color ThirdLineColor { get; set; } = Color.LightGreen;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/PuzzleGraph/Decorators/TriangleDecorator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using System.Xml.Serialization;
8 |
9 | namespace PuzzleGraph.Decorators
10 | {
11 | public class TriangleDecorator : TransformableDecorator, IFaceDecorable, IEdgeDecorable, INodeDecorable
12 | {
13 | [LocalizedDisplayName("Count")]
14 | public int Count { get; set; } = 1;
15 | [LocalizedDisplayName("Color")]
16 | [XmlElement(Type = typeof(XmlColor))]
17 | public Color Color { get; set; } = Color.Gold;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/PuzzleGraph/Edge.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.Text;
5 | using System.Xml.Serialization;
6 |
7 | namespace PuzzleGraph
8 | {
9 | public class Edge : GraphElement
10 | {
11 | [LocalizedDisplayName("Start")]
12 | public Node Start { get; set; }
13 | [LocalizedDisplayName("End")]
14 | public Node End { get; set; }
15 | [LocalizedDisplayName("GraphElementColor")]
16 | [XmlElement(Type = typeof(XmlColor))]
17 | public Color GraphElementColor { get; set; } = Color.Transparent;
18 |
19 | public Edge(Node inputStart,Node inputEnd)
20 | {
21 | Start = inputStart;
22 | End = inputEnd;
23 | Decorator = null;
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/PuzzleGraph/Face.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.Text;
5 | using System.Xml.Serialization;
6 |
7 | namespace PuzzleGraph
8 | {
9 | public class Face : GraphElement
10 | {
11 | [LocalizedDisplayName("Nodes")]
12 | public List Nodes { get; set; }
13 | [LocalizedDisplayName("GraphElementColor")]
14 | [XmlElement(Type = typeof(XmlColor))]
15 | public Color GraphElementColor { get; set; } = Color.Transparent;
16 |
17 | public Face(List inputNodes)
18 | {
19 | Nodes = inputNodes;
20 | Decorator = null;
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/PuzzleGraph/Graph.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System;
3 | using System.IO;
4 | using System.Text;
5 | using System.Xml.Serialization;
6 | using System.Linq;
7 | using System.ComponentModel;
8 |
9 | namespace PuzzleGraph
10 | {
11 | public class Graph : ICloneable
12 | {
13 | [LocalizedDisplayName("Nodes")]
14 | public List Nodes { get; private set; }
15 | [LocalizedDisplayName("Edges")]
16 | public List Edges { get; private set; }
17 | [LocalizedDisplayName("Faces")]
18 | public List Faces { get; private set; }
19 | [LocalizedDisplayName("MetaData")]
20 | [TypeConverter(typeof(ExpandableObjectConverter))]
21 | public MetaData MetaData { get; private set; }
22 | public Graph()
23 | {
24 | Nodes = new List();
25 | Edges = new List();
26 | Faces = new List();
27 | MetaData = new MetaData();
28 | }
29 | private Graph(SaveState state)
30 | {
31 | Nodes = state.Nodes;
32 | Edges = state.EdgesID.Select(edgeID => new Edge(Nodes[edgeID.Start], Nodes[edgeID.End]) { Decorator = edgeID.Decorator, GraphElementColor=edgeID.GraphElementColor }).ToList();
33 | Faces = state.FacesID.Select(faceID => new Face(faceID.Nodes.Select(id => Nodes[id]).ToList()) { Decorator = faceID.Decorator, GraphElementColor = faceID.GraphElementColor }).ToList();
34 | MetaData = state.MetaData;
35 | }
36 | public override string ToString()
37 | {
38 | XmlSerializer xml = new XmlSerializer(typeof(SaveState));
39 | using(MemoryStream ms=new MemoryStream())
40 | {
41 | xml.Serialize(ms, new SaveState(this));
42 | return Encoding.UTF8.GetString(ms.ToArray());
43 | }
44 | }
45 | public Graph(string saveState):this(new XmlSerializer(typeof(SaveState))
46 | .Deserialize(new MemoryStream(Encoding.UTF8.GetBytes(saveState))) as SaveState)
47 | {
48 |
49 | }
50 | public static Graph LoadFromFile(string fileName)
51 | {
52 | XmlSerializer xml = new XmlSerializer(typeof(SaveState));
53 | using (FileStream fs=new FileStream(fileName,FileMode.Open))
54 | {
55 | return new Graph(xml.Deserialize(fs) as SaveState);
56 | }
57 | }
58 | public void SaveToFile(string fileName)
59 | {
60 | XmlSerializer xml = new XmlSerializer(typeof(SaveState));
61 | using (FileStream fs = new FileStream(fileName, FileMode.Create))
62 | {
63 | xml.Serialize(fs, new SaveState(this));
64 | }
65 | }
66 |
67 | public void RemoveElement(GraphElement element)
68 | {
69 | if(element is Node node)
70 | {
71 | List elementsToDelete = new List();
72 | foreach(Edge edge in Edges)
73 | {
74 | if(edge.Start== node || edge.End==node)
75 | {
76 | elementsToDelete.Add(edge);
77 | }
78 | }
79 | foreach (Face face in Faces)
80 | {
81 | if (face.Nodes.Contains(node))
82 | {
83 | elementsToDelete.Add(face);
84 | }
85 | }
86 | foreach (GraphElement newElement in elementsToDelete)
87 | RemoveElement(newElement);
88 | Nodes.Remove(node);
89 | }
90 | else if(element is Edge edge)
91 | {
92 | List elementsToDelete = new List();
93 | foreach (Face face in Faces)
94 | {
95 | for (int i = 0; i < face.Nodes.Count; ++i)
96 | {
97 | Node firstNode = face.Nodes[i];
98 | Node secondNode = face.Nodes[i + 1 < face.Nodes.Count ? i + 1 : 0];
99 | if ((firstNode == edge.End && secondNode == edge.Start) ||
100 | (firstNode == edge.Start && secondNode == edge.End))
101 | {
102 | elementsToDelete.Add(face);
103 | break;
104 | }
105 | }
106 | }
107 | foreach (GraphElement newElement in elementsToDelete)
108 | RemoveElement(newElement);
109 | Edges.Remove(edge);
110 | }
111 | else if(element is Face face)
112 | {
113 | Faces.Remove(face);
114 | }
115 | }
116 |
117 | public enum FlipType
118 | {
119 | XY=0,
120 | Horizontal=1,
121 | Vertical=2,
122 | Rotate=3
123 | }
124 | private static Node TransformNode(Node node,FlipType flipType,double angle=0)
125 | {
126 | if (flipType == FlipType.XY)
127 | return new Node(node.Y, node.X);
128 | else if (flipType == FlipType.Horizontal)
129 | return new Node(-node.X, node.Y);
130 | else if (flipType == FlipType.Vertical)
131 | return new Node(node.X, -node.Y);
132 | else if (flipType == FlipType.Rotate)
133 | {
134 | double cosValue = Math.Cos(angle), sinValue = Math.Sin(angle);
135 | return new Node(cosValue * node.X - sinValue * node.Y, sinValue * node.X + cosValue * node.Y);
136 | }
137 | else throw new NotSupportedException();
138 | }
139 | public static Graph FlipGraph(Graph graph, FlipType flipType)
140 | {
141 | Graph graphClone = new Graph(graph.ToString());
142 | Graph newGraph = new Graph();
143 | Dictionary mapping = new Dictionary();
144 | foreach (Node node in graphClone.Nodes)
145 | {
146 | mapping[node] = TransformNode(node, flipType);
147 | mapping[node].Decorator = node.Decorator;
148 | }
149 | foreach (Node node in graphClone.Nodes)
150 | {
151 | newGraph.Nodes.Add(mapping[node]);
152 | }
153 | foreach (Edge edge in graphClone.Edges)
154 | {
155 | Edge newEdge = new Edge(mapping[edge.Start], mapping[edge.End]);
156 | newEdge.Decorator = edge.Decorator;
157 | newEdge.GraphElementColor = edge.GraphElementColor;
158 | newGraph.Edges.Add(newEdge);
159 | }
160 | foreach (Face face in graphClone.Faces)
161 | {
162 | List nodes = new List();
163 | nodes.AddRange(face.Nodes);
164 | nodes.Reverse();
165 | Face newFace = new Face(nodes.Select(node => mapping[node]).ToList());
166 | newFace.Decorator = face.Decorator;
167 | newFace.GraphElementColor = face.GraphElementColor;
168 | newGraph.Faces.Add(newFace);
169 | }
170 | TetrisTemplate oldTetrisTemplate = graphClone.MetaData.TetrisTemplate;
171 | newGraph.MetaData = graphClone.MetaData;
172 | newGraph.MetaData.TetrisTemplate = new TetrisTemplate();
173 | foreach (List shape in oldTetrisTemplate.Shapes)
174 | {
175 | List newShape = new List();
176 | newShape.AddRange(shape);
177 | newShape.Reverse();
178 | newGraph.MetaData.TetrisTemplate.Shapes.Add(newShape.Select(node => TransformNode(node, flipType)).ToList());
179 | }
180 | return newGraph;
181 | }
182 | public static Graph RotateGraph(Graph graph, double angle)
183 | {
184 | Graph graphClone = new Graph(graph.ToString());
185 | Graph newGraph = new Graph();
186 | Dictionary mapping = new Dictionary();
187 | foreach (Node node in graphClone.Nodes)
188 | {
189 | mapping[node] = TransformNode(node, FlipType.Rotate, angle);
190 | mapping[node].Decorator = node.Decorator;
191 | }
192 | foreach (Node node in graphClone.Nodes)
193 | {
194 | newGraph.Nodes.Add(mapping[node]);
195 | }
196 | foreach (Edge edge in graphClone.Edges)
197 | {
198 | Edge newEdge = new Edge(mapping[edge.Start], mapping[edge.End]);
199 | newEdge.Decorator = edge.Decorator;
200 | newGraph.Edges.Add(newEdge);
201 | }
202 | foreach (Face face in graphClone.Faces)
203 | {
204 | List nodes = new List();
205 | nodes.AddRange(face.Nodes);
206 | Face newFace = new Face(nodes.Select(node => mapping[node]).ToList());
207 | newFace.Decorator = face.Decorator;
208 | newGraph.Faces.Add(newFace);
209 | }
210 | TetrisTemplate oldTetrisTemplate = graphClone.MetaData.TetrisTemplate;
211 | newGraph.MetaData = graphClone.MetaData;
212 | newGraph.MetaData.TetrisTemplate = new TetrisTemplate();
213 | foreach (List shape in oldTetrisTemplate.Shapes)
214 | {
215 | List newShape = new List();
216 | newShape.AddRange(shape);
217 | newGraph.MetaData.TetrisTemplate.Shapes.Add(newShape.Select(node => TransformNode(node, FlipType.Rotate, angle)).ToList());
218 | }
219 | return newGraph;
220 |
221 | }
222 | public static Graph ScaleGraph(Graph graph, double scaleX, double scaleY)
223 | {
224 | Graph graphClone = new Graph(graph.ToString());
225 | Graph newGraph = new Graph();
226 | Dictionary mapping = new Dictionary();
227 | foreach (Node node in graphClone.Nodes)
228 | {
229 | mapping[node] = new Node(node.X * scaleX, node.Y * scaleY);
230 | mapping[node].Decorator = node.Decorator;
231 | }
232 | foreach (Node node in graphClone.Nodes)
233 | {
234 | newGraph.Nodes.Add(mapping[node]);
235 | }
236 | foreach (Edge edge in graphClone.Edges)
237 | {
238 | Edge newEdge = new Edge(mapping[edge.Start], mapping[edge.End]);
239 | newEdge.Decorator = edge.Decorator;
240 | newGraph.Edges.Add(newEdge);
241 | }
242 | foreach (Face face in graphClone.Faces)
243 | {
244 | List nodes = new List();
245 | nodes.AddRange(face.Nodes);
246 | Face newFace = new Face(nodes.Select(node => mapping[node]).ToList());
247 | newFace.Decorator = face.Decorator;
248 | newGraph.Faces.Add(newFace);
249 | }
250 | TetrisTemplate oldTetrisTemplate = graphClone.MetaData.TetrisTemplate;
251 | newGraph.MetaData = graphClone.MetaData;
252 | newGraph.MetaData.TetrisTemplate = new TetrisTemplate();
253 | foreach (List shape in oldTetrisTemplate.Shapes)
254 | {
255 | List newShape = new List();
256 | newShape.AddRange(shape);
257 | newGraph.MetaData.TetrisTemplate.Shapes.Add(newShape.Select(node => new Node(node.X * scaleX, node.Y * scaleY)).ToList());
258 | }
259 | return newGraph;
260 |
261 | }
262 |
263 | public object Clone()
264 | {
265 | return new Graph(ToString());
266 | }
267 | }
268 | }
269 |
--------------------------------------------------------------------------------
/PuzzleGraph/GraphElement.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Drawing;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 | using System.Xml.Serialization;
9 |
10 | namespace PuzzleGraph
11 | {
12 | public abstract class GraphElement
13 | {
14 | [LocalizedDisplayName("Decorator")]
15 | [TypeConverter(typeof(ExpandableObjectConverter))]
16 | public Decorator Decorator { get; set; }
17 | public override string ToString()
18 | {
19 | return Resources.Lang.ResourceManager.GetString(this.GetType().Name) ?? this.GetType().Name;
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/PuzzleGraph/IEdgeDecorable.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace PuzzleGraph
8 | {
9 | internal interface IEdgeDecorable
10 | {
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/PuzzleGraph/IFaceDecorable.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace PuzzleGraph
8 | {
9 | internal interface IFaceDecorable
10 | {
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/PuzzleGraph/INodeDecorable.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace PuzzleGraph
8 | {
9 | internal interface INodeDecorable
10 | {
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/PuzzleGraph/IUnifiedScaleDecorator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace PuzzleGraph
8 | {
9 | public interface IUnifiedScaleDecorator
10 | {
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/PuzzleGraph/LocalizedDisplayNameAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace PuzzleGraph
9 | {
10 | class LocalizedDisplayNameAttribute : DisplayNameAttribute
11 | {
12 | private readonly string resourceName;
13 | public LocalizedDisplayNameAttribute(string resourceName) : base()
14 | {
15 | this.resourceName = resourceName;
16 | }
17 |
18 | public override string DisplayName
19 | {
20 | get
21 | {
22 | return Resources.Lang.ResourceManager.GetString(this.resourceName) ?? "";
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/PuzzleGraph/MetaData.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.Text;
5 | using System.Xml.Serialization;
6 |
7 | namespace PuzzleGraph
8 | {
9 | [LocalizedDisplayName("MetaData")]
10 | public class MetaData
11 | {
12 | [LocalizedDisplayName("PuzzleTitle")]
13 | public string PuzzleTitle { get; set; } = "";
14 | [LocalizedDisplayName("BackgroundColor")]
15 | [XmlElement(Type = typeof(XmlColor))]
16 | public Color BackgroundColor { get; set; } = Color.LightGray;
17 | [LocalizedDisplayName("ForegroundColor")]
18 | [XmlElement(Type = typeof(XmlColor))]
19 | public Color ForegroundColor { get; set; } = Color.DarkGray;
20 | [LocalizedDisplayName("EdgeWidth")]
21 | public double EdgeWidth { get; set; } = 0.2;
22 | [LocalizedDisplayName("TetrisTemplate")]
23 | public TetrisTemplate TetrisTemplate { get; set; } = new TetrisTemplate();
24 | [LocalizedDisplayName("TetrisScale")]
25 | public double TetrisScale { get; set; } = 0.2;
26 | [LocalizedDisplayName("FaceDecorationScale")]
27 | public double FaceDecorationScale { get; set; } = 1.0;
28 | [LocalizedDisplayName("ExportWidth")]
29 | public int ExportWidth { get; set; } = 768;
30 | [LocalizedDisplayName("ExportHeight")]
31 | public int ExportHeight { get; set; } = 768;
32 | [LocalizedDisplayName("LineColor")]
33 | [XmlElement(Type = typeof(XmlColor))]
34 | public Color LineColor { get; set; } = Color.Yellow;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/PuzzleGraph/Node.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace PuzzleGraph
4 | {
5 | public class Node: GraphElement
6 | {
7 | [LocalizedDisplayName("X")]
8 | public double X { get; set; }
9 | [LocalizedDisplayName("Y")]
10 | public double Y { get; set; }
11 | [LocalizedDisplayName("Hidden")]
12 | public bool Hidden { get; set; }
13 |
14 | private Node() { }
15 | public Node(double inputX,double inputY)
16 | {
17 | X = inputX;
18 | Y = inputY;
19 | Decorator = null;
20 | Hidden = false;
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/PuzzleGraph/ObsolateFormatFixer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace PuzzleGraph
8 | {
9 | public class ObsolateFormatFixer
10 | {
11 | private static List> IndexToShape(Graph graph, List indexes)
12 | {
13 | List> result = new List>();
14 | TetrisTemplate template = graph.MetaData.TetrisTemplate;
15 | foreach (int index in indexes)
16 | {
17 | if (index < template.Shapes.Count)
18 | {
19 | result.Add(template.Shapes[index].Select(node => new Node(node.X, node.Y)).ToList());
20 | }
21 | }
22 | return result;
23 | }
24 |
25 | public static bool FixObsoletedTetrisFormat(Graph graph)
26 | {
27 | bool upgraded = false;
28 | foreach (Face face in graph.Faces)
29 | {
30 | if (face.Decorator is Decorators.AbstractTetrisDecorator tetris)
31 | {
32 | if(tetris.Shapes.Count == 0 && tetris.Indexes.Count > 0)
33 | {
34 | upgraded = true;
35 | tetris.Shapes = IndexToShape(graph, tetris.Indexes);
36 | if (tetris.Shapes.Count == 0)
37 | tetris.Indexes.Clear();
38 | }
39 | }
40 | }
41 | return upgraded;
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/PuzzleGraph/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // 有关程序集的一般信息由以下
6 | // 控制。更改这些特性值可修改
7 | // 与程序集关联的信息。
8 | [assembly: AssemblyTitle("PuzzleGraph")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("PuzzleGraph")]
13 | [assembly: AssemblyCopyright("Copyright © 2019")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // 将 ComVisible 设置为 false 会使此程序集中的类型
18 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
19 | //请将此类型的 ComVisible 特性设置为 true。
20 | [assembly: ComVisible(false)]
21 |
22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23 | [assembly: Guid("e6e86344-2472-4da8-8012-70eadba9841c")]
24 |
25 | // 程序集的版本信息由下列四个值组成:
26 | //
27 | // 主版本
28 | // 次版本
29 | // 生成号
30 | // 修订号
31 | //
32 | //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
33 | //通过使用 "*",如下所示:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/PuzzleGraph/PuzzleGraph.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {E6E86344-2472-4DA8-8012-70EADBA9841C}
8 | Library
9 | Properties
10 | PuzzleGraph
11 | PuzzleGraph
12 | v4.7.2
13 | 512
14 | true
15 |
16 |
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | pdbonly
27 | true
28 | bin\Release\
29 | TRACE
30 | prompt
31 | 4
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 | True
83 | True
84 | Lang.resx
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 | ResXFileCodeGenerator
96 | Lang.Designer.cs
97 |
98 |
99 |
100 |
101 |
--------------------------------------------------------------------------------
/PuzzleGraph/Resources/Lang.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // 此代码由工具生成。
4 | // 运行时版本:4.0.30319.42000
5 | //
6 | // 对此文件的更改可能会导致不正确的行为,并且如果
7 | // 重新生成代码,这些更改将会丢失。
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace PuzzleGraph.Resources {
12 | using System;
13 |
14 |
15 | ///
16 | /// 一个强类型的资源类,用于查找本地化的字符串等。
17 | ///
18 | // 此类是由 StronglyTypedResourceBuilder
19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
20 | // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
21 | // (以 /str 作为命令选项),或重新生成 VS 项目。
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Lang {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Lang() {
33 | }
34 |
35 | ///
36 | /// 返回此类使用的缓存的 ResourceManager 实例。
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | internal static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("PuzzleGraph.Resources.Lang", typeof(Lang).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// 重写当前线程的 CurrentUICulture 属性
51 | /// 重写当前线程的 CurrentUICulture 属性。
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | internal static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/PuzzleGraph/Resources/Lang.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
--------------------------------------------------------------------------------
/PuzzleGraph/Resources/Lang.zh-CN.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
121 | 角度
122 |
123 |
124 | 背景色
125 |
126 |
127 | 边框大小
128 |
129 |
130 | 断线装饰
131 |
132 |
133 | 圆圈装饰
134 |
135 |
136 | 颜色
137 |
138 |
139 | 合并装饰
140 |
141 |
142 | 数量
143 |
144 |
145 | 装饰元素
146 |
147 |
148 | ΔX
149 |
150 |
151 | ΔY
152 |
153 |
154 | 线段
155 |
156 |
157 | 路径宽度
158 |
159 |
160 | 抗体装饰
161 |
162 |
163 | 终点
164 |
165 |
166 | 终点装饰
167 |
168 |
169 | 导出高度
170 |
171 |
172 | 导出宽度
173 |
174 |
175 | 额外缩放
176 |
177 |
178 | 面
179 |
180 |
181 | 面装饰元素缩放
182 |
183 |
184 | 甲
185 |
186 |
187 | 字体
188 |
189 |
190 | 字体名
191 |
192 |
193 | 前景色
194 |
195 |
196 | 网格颜色
197 |
198 |
199 | 图像单位
200 |
201 |
202 | 空心俄罗斯方块装饰
203 |
204 |
205 | 编号
206 |
207 |
208 | 长度
209 |
210 |
211 | 边距大小
212 |
213 |
214 | 元数据
215 |
216 |
217 | 结点
218 |
219 |
220 | 结点
221 |
222 |
223 | 点装饰
224 |
225 |
226 | 谜题标题
227 |
228 |
229 | 圆环装饰
230 |
231 |
232 | 乙
233 |
234 |
235 | 形状
236 |
237 |
238 | 大小
239 |
240 |
241 | 色块装饰
242 |
243 |
244 | 星形装饰
245 |
246 |
247 | 起点
248 |
249 |
250 | 起点装饰
251 |
252 |
253 | 样式
254 |
255 |
256 | 俄罗斯方块装饰
257 |
258 |
259 | 俄罗斯方块缩放
260 |
261 |
262 | 俄罗斯方块模板
263 |
264 |
265 | 文本
266 |
267 |
268 | 文本装饰
269 |
270 |
271 | 三角装饰
272 |
273 |
274 | X坐标
275 |
276 |
277 | Y坐标
278 |
279 |
--------------------------------------------------------------------------------
/PuzzleGraph/SaveState.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using System.Xml.Serialization;
8 |
9 | namespace PuzzleGraph
10 | {
11 | public class SaveState
12 | {
13 | public class SaveEdge
14 | {
15 | public int Start { get; set; }
16 | public int End { get; set; }
17 | public Decorator Decorator { get; set; }
18 | [XmlElement(Type = typeof(XmlColor))]
19 | public Color GraphElementColor { get; set; } = Color.Transparent;
20 | }
21 | public class SaveFace
22 | {
23 | public List Nodes { get; set; }
24 | public Decorator Decorator { get; set; }
25 | [XmlElement(Type = typeof(XmlColor))]
26 | public Color GraphElementColor { get; set; } = Color.Transparent;
27 | }
28 |
29 | public List Nodes { get; set; }
30 | public List EdgesID { get; set; }
31 | public List FacesID { get; set; }
32 | public MetaData MetaData { get; set; }
33 |
34 | private SaveState() { }
35 | public SaveState(Graph graph)
36 | {
37 | Dictionary