-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathProgram.cs
110 lines (95 loc) · 2.94 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
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
110
using System.Numerics;
using GdsSharp.Lib;
using GdsSharp.Lib.Builders;
using GdsSharp.Lib.NonTerminals;
using GdsSharp.Lib.NonTerminals.Elements;
var file = new GdsFile
{
LibraryName = "RandomObjects",
UserUnits = 1,
PhysicalUnits = 1e-8,
Version = 600
};
var elements = new List<GdsElement>
{
// Generate a line from a Bézier curve with width 20.
// When using BuildPolygon the curve will be a GdsBoundaryElement.
new BezierBuilder()
.AddPoint(0, 0)
.AddPoint(0, 1000)
.AddPoint(1000, 1000)
.AddPoint(1000, 0)
.BuildPolygon(200),
// When using BuildLine the curve will be a GdsPathElement.
new BezierBuilder()
.AddPoint(-3000, 0)
.AddPoint(-3000, 1000)
.AddPoint(-2000, 1000)
.AddPoint(-2000, 0)
.BuildLine(200),
// Create a rectangle
RectBuilder.CreateRect(-3100, -1000, 4200, 1000),
// Create a circle
CircleBuilder.CreateCircle(-1000, 744, 350, 128),
// Create a polygon by manually specifying the points
new()
{
Element = new GdsBoundaryElement
{
Points =
[
new GdsPoint(-1250, 0),
new GdsPoint(-1250, 500),
new GdsPoint(-1000, 250),
new GdsPoint(-750, 500),
new GdsPoint(-750, 0),
new GdsPoint(-1250, 0)
],
NumPoints = 6
}
}
};
// Use the path builder to create a path
// Returns an IEnumerable of GdsElement because the path may be split into multiple elements
elements.AddRange(
new PathBuilder(
100f,
new Vector2(-3100, -3300),
Vector2.UnitX)
// Straight ahead for 2000 units
.Straight(2000)
// Bend 45 degrees to the left with a radius of 500 units
.BendDeg(-45, 500)
// Generate shape like <=>
.Straight(100, widthEnd: 250)
.Straight(100)
.Straight(100, widthEnd: 100)
// Some more bends
.BendDeg(-45, 500)
.Straight(100)
.Straight(200, 250)
.BendDeg(180, 300)
.BendDeg(-180, 300)
// Example of using a function to change the width
.BendDeg(-180, 900, f => MathF.Cos(f * 50) * 100 + 150)
// PathBuilder also supports Bézier curves
.Bezier(b => b
.AddPoint(0, 0)
.AddPoint(0, 1000)
.AddPoint(2000, 1000)
.AddPoint(1000, 0),
t => 250 - (250 - 50) * t)
.Straight(800)
// Build the path in sections of 200 vertices
// This is the 'official' maximum number of vertices per element in GDSII
// In practice, the number of vertices per element can be much higher
.Build(200)
);
var structure = new GdsStructure
{
Name = "Example structure",
Elements = elements
};
file.Structures = [structure];
using var write = File.OpenWrite("example.gds");
file.WriteTo(write);