1
+ """
2
+ Abstract Geometry in R{Dim} with Number type T
3
+ """
4
+ abstract type AbstractGeometry{Dim, T <: Real } end
5
+
1
6
"""
2
7
Geometry made of N connected points. Connected as one flat geometry, it makes a Ngon / Polygon.
3
8
Connected as volume it will be a Simplex / Tri / Cube.
4
9
Note That `Polytype{N} where N == 3` denotes a Triangle both as a Simplex or Ngon.
5
10
"""
6
- abstract type Polytope{Dim, T <: Real } end
11
+ abstract type Polytope{Dim, T} <: AbstractGeometry{Dim, T } end
7
12
abstract type AbstractPolygon{Dim, T} <: Polytope{Dim, T} end
8
13
9
14
abstract type AbstractPoint{Dim, T} <: StaticVector{Dim, T} end
@@ -38,10 +43,9 @@ const TriangleFace{T} = NgonFace{3, T}
38
43
Base. show (io:: IO , x:: Type{<: TriangleFace{T}} ) where T = print (io, " TriangleFace{" , T, " }" )
39
44
Face (:: Type{<: NgonFace{N}} , :: Type{T} ) where {N, T} = NgonFace{N, T}
40
45
41
-
42
46
@propagate_inbounds Base. getindex (x:: Polytope , i:: Integer ) = coordinates (x)[i]
43
47
@propagate_inbounds Base. iterate (x:: Polytope ) = iterate (coordinates (x))
44
- @propagate_inbounds Base. iterate (x:: Polytope , i:: Integer ) = iterate (coordinates (x), i)
48
+ @propagate_inbounds Base. iterate (x:: Polytope , i) = iterate (coordinates (x), i)
45
49
46
50
"""
47
51
Fixed Size Polygon, e.g.
88
92
# Simplex{D, T, 3} & Ngon{D, T, 3} are both representing a triangle.
89
93
# Since Ngon is supposed to be flat and a triangle is flat, lets prefer Ngon
90
94
# for triangle:
91
- const Triangle{Dim, T} = Ngon{Dim, T, 3 , P} where P <: AbstractPoint{Dim, T}
95
+ const TriangleP{Dim, T, P <: AbstractPoint{Dim, T} } = Ngon{Dim, T, 3 , P}
96
+
97
+ const Triangle{Dim, T} = TriangleP{Dim, T, Point{Dim, T}}
98
+ const Triangle3d{T} = Triangle{3 , T}
99
+
100
+ function Base. show (io:: IO , :: Type{TriangleP{D, T, P}} ) where {D, T, P}
101
+ print (io, " Tetrahedron{" , D, " , " , T, " }" )
102
+ end
103
+ Base. show (io:: IO , :: Type{Triangle} ) = print (io, " Triangle" )
104
+ Base. show (io:: IO , x:: TriangleP ) = print (io, " Triangle(" , join (x, " , " ), " )" )
105
+
92
106
const Quadrilateral{Dim, T} = Ngon{Dim, T, 4 , P} where P <: AbstractPoint{Dim, T}
93
107
94
108
"""
@@ -115,9 +129,19 @@ struct Simplex{
115
129
116
130
points:: SVector{N, Point}
117
131
end
132
+
118
133
const NSimplex{N} = Simplex{Dim, T, N, P} where {Dim, T, P}
119
- const Line{Dim, T, P <: AbstractPoint{Dim, T} } = Simplex{Dim, T, 2 , P}
120
- const Tetrahedron{Dim, T, P <: AbstractPoint{Dim, T} } = Simplex{Dim, T, 3 , P}
134
+ const LineP{Dim, T, P <: AbstractPoint{Dim, T} } = Simplex{Dim, T, 2 , P}
135
+ const Line{Dim, T} = LineP{Dim, T, Point{Dim, T}}
136
+ const TetrahedronP{T, P <: AbstractPoint{3, T} } = Simplex{3 , T, 4 , P}
137
+ const Tetrahedron{T} = TetrahedronP{T, Point{3 , T}}
138
+
139
+ function Base. show (io:: IO , :: Type{TetrahedronP{T, P}} ) where {T, P}
140
+ print (io, " Tetrahedron{" , T, " }" )
141
+ end
142
+ Base. show (io:: IO , :: Type{Tetrahedron} ) = print (io, " Tetrahedron" )
143
+ Base. show (io:: IO , x:: TetrahedronP ) = print (io, " Tetrahedron(" , join (x, " , " ), " )" )
144
+
121
145
122
146
coordinates (x:: Simplex ) = x. points
123
147
function (:: Type{<: NSimplex{N}} )(points:: Vararg{P, N} ) where {P <: AbstractPoint{Dim, T} , N} where {Dim, T}
@@ -142,26 +166,20 @@ function Polytope(::Type{<: NSimplex{N}}, P::Type{<: AbstractPoint{NDim, T}}) wh
142
166
Simplex{NDim, T, N, P}
143
167
end
144
168
145
- function Base. show (io:: IO , :: Type{Line {D, T, P}} ) where {D, T, P}
169
+ function Base. show (io:: IO , :: Type{LineP {D, T, P}} ) where {D, T, P}
146
170
print (io, " Line{" , D, " , " , T, " }" )
147
171
end
148
-
149
- function Base. show (io:: IO , :: Type{Line} )
150
- print (io, " Line" )
151
- end
152
-
153
- function Base. show (io:: IO , x:: Line{D, T} ) where {D, T}
154
- print (io, " Line: " , x[1 ], " => " , x[2 ])
155
- end
172
+ Base. show (io:: IO , :: Type{Line} ) = print (io, " Line" )
173
+ Base. show (io:: IO , x:: LineP ) = print (io, " Line(" , x[1 ], " => " , x[2 ], " )" )
156
174
157
175
"""
158
176
A LineString is a geometry of connected line segments
159
177
"""
160
178
struct LineString{
161
179
Dim, T <: Real ,
162
180
P <: AbstractPoint ,
163
- V <: AbstractVector{<: Line {Dim, T, P}}
164
- } <: AbstractVector{Line {Dim, T}}
181
+ V <: AbstractVector{<: LineP {Dim, T, P}}
182
+ } <: AbstractVector{LineP {Dim, T}}
165
183
points:: V
166
184
end
167
185
coordinates (x:: LineString ) = x. points
@@ -170,7 +188,7 @@ Base.size(x::LineString) = size(coordinates(x))
170
188
Base. getindex (x:: LineString , i) = getindex (coordinates (x), i)
171
189
172
190
173
- function LineString (points:: AbstractVector{Line {Dim, T, P}} ) where {Dim, T, P}
191
+ function LineString (points:: AbstractVector{LineP {Dim, T, P}} ) where {Dim, T, P}
174
192
LineString {Dim, T, P, typeof(points)} (points)
175
193
end
176
194
@@ -186,11 +204,11 @@ linestring = LineString(points)
186
204
```
187
205
"""
188
206
function LineString (points:: AbstractVector{<: AbstractPoint} , skip = 1 )
189
- LineString (connect (points, Line , skip))
207
+ LineString (connect (points, LineP , skip))
190
208
end
191
209
192
210
function LineString (points:: AbstractVector{<: Pair{P, P}} ) where P <: AbstractPoint{N, T} where {N, T}
193
- LineString (reinterpret (Line {N, T, P}, points))
211
+ LineString (reinterpret (LineP {N, T, P}, points))
194
212
end
195
213
196
214
function LineString (points:: AbstractVector{<: AbstractPoint} , faces:: AbstractVector{<: LineFace} )
223
241
224
242
struct Polygon{
225
243
Dim, T <: Real ,
226
- L <: AbstractVector{<: Line{Dim, T}} ,
244
+ P <: AbstractPoint{Dim, T} ,
245
+ L <: AbstractVector{<: LineP{Dim, T, P}} ,
227
246
V <: AbstractVector{L}
228
247
} <: AbstractPolygon{Dim, T}
229
248
exterior:: L
@@ -232,11 +251,11 @@ end
232
251
233
252
Base.:(== )(a:: Polygon , b:: Polygon ) = (a. exterior == b. exterior) && (a. interiors == b. interiors)
234
253
235
- function Polygon (exterior:: AbstractVector{Line {Dim, T, P}} , interiors:: V ) where {Dim, T, P, V <: AbstractVector{<: AbstractVector{Line {Dim, T, P}}} }
254
+ function Polygon (exterior:: AbstractVector{LineP {Dim, T, P}} , interiors:: V ) where {Dim, T, P, V <: AbstractVector{<: AbstractVector{LineP {Dim, T, P}}} }
236
255
Polygon {Dim, T, typeof(exterior), V} (exterior, interiors)
237
256
end
238
257
239
- Polygon (exterior:: L ) where L <: AbstractVector{<: Line } = Polygon (exterior, L[])
258
+ Polygon (exterior:: L ) where L <: AbstractVector{<: LineP } = Polygon (exterior, L[])
240
259
241
260
function Polygon (exterior:: AbstractVector{P} , skip:: Int = 1 ) where P <: AbstractPoint{Dim, T} where {Dim, T}
242
261
Polygon (LineString (exterior, skip))
0 commit comments