1 # This file is part of NIT (http://www.nitlanguage.org).
3 # Copyright 2014 Alexis Laferrière <alexis.laf@xymus.net>
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # Provides interfaces and classes to represent basic geometry needs.
18 module points_and_lines
20 # An abstract 2d point, strongly linked to its implementation `Point`
21 interface IPoint[N
: Numeric]
22 # horizontal coordinate
27 redef fun to_s
do return "({x}, {y})"
30 # A 2d point and an implementation of `IPoint`
31 class Point[N
: Numeric]
44 # An abstract 3d point, strongly linked to its implementation `Point3d`
45 interface IPoint3d[N
: Numeric]
51 redef fun to_s
do return "({x}, {y}, {z})"
54 # A 3d point and an implementation of `IPoint3d`
55 class Point3d[N
: Numeric]
68 # An abstract 2d line segment
69 interface ILine[N
: Numeric]
72 fun point_left
: P
is abstract
73 fun point_right
: P
is abstract
75 redef fun to_s
do return "{point_left}--{point_right}"
79 class Line[N
: Numeric]
82 redef var point_left
: P
83 redef var point_right
: P
98 # An abstract 3d line segment
99 interface ILine3d[N
: Numeric]
102 redef type P
: IPoint3d[N
]
106 class Line3d[N
: Numeric]