forked from m426-2026/math
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.ts
More file actions
27 lines (22 loc) · 1020 Bytes
/
demo.ts
File metadata and controls
27 lines (22 loc) · 1020 Bytes
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
import { Fraction } from "./fraction.ts";
import { Circle, Point2D, Rectangle } from "./geometry.ts";
const oneThird: Fraction = new Fraction(1, 3);
const oneFourth: Fraction = new Fraction(1, 4);
console.log(`one third: ${oneThird} = ${oneThird.toFloat(0.01)}`);
console.log(`one fourth: ${oneFourth} = ${oneFourth.toFloat(0.01)}`);
const parsed = Fraction.parse("5 / 6");
console.log(`${parsed} ~= ${parsed.toFloat(0.01)}`);
const circle: Circle = new Circle(new Point2D(0, 0), 3);
console.log(`circle: C = ${circle.circumference()}`);
console.log(`circle: A = ${circle.area()}`);
console.log(`circle: D = ${circle.diameter()}`);
const rectangle: Rectangle = new Rectangle(
new Point2D(0, 0),
new Point2D(2, 3),
);
console.log(`rectangle: C = ${rectangle.circumference()}`);
console.log(`rectangle: A = ${rectangle.area()}`);
console.log(`rectangle: D = ${rectangle.diagonal()}`);
const p: Point2D = new Point2D(0, 0);
const q: Point2D = new Point2D(3, 4);
console.log(`distance p to q: ${p.distanceTo(q)}`);