Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import {Point, Line} from '@mathigon/fermat';
import {CanvasView, CustomElementView, register, slide} from '@mathigon/boost';
import {Select} from '../../shared/types';
// -------------------------------------------------------------------------
// Symmetry Functions
const width = 1920;
const height = 1280;
const pointX1M = new Point(240, 320);
const pointX1Y1 = new Point(480, 320);
const lineX1 = new Line(new Point(0, 320), new Point(480, 320));
const lineY1 = new Line(new Point(480, 0), new Point(480, 320));
const lineY2 = new Line(new Point(640, 0), new Point(640, 320));
const pointS = new Point(360, 360);
const lineS = new Line(new Point(0, 0), new Point(360, 360));
const lineSI = new Line(new Point(0, 720), new Point(720, 0));
function grid(points: Point[], x: number, y: number) {
return flatten(tabulate2D((i, j) =>
points.map((p: Point) => p.shift(i * x, j * y)), width / x, height / y));
}
function applyTransforms(point: Point, [x, y]: [number, number],
transforms: ((p: Point) => Point)[]) {
let points = [point.mod(x, y)];
for (let t of transforms) {
for (let p of points.map(p => t(p))) {
import { tabulate, flatten } from '@mathigon/core';
import { Point, Line } from '@mathigon/fermat';
import { CustomElement, registerElement, slide } from '@mathigon/boost';
// -------------------------------------------------------------------------
// Symmetry Functions
const width = 1920;
const height = 1280;
const pointX1M = new Point(240, 320);
const pointX1Y1 = new Point(480, 320);
const lineX1 = new Line(new Point(0,320), new Point(480,320));
const lineY1 = new Line(new Point(480,0), new Point(480,320));
const lineY2 = new Line(new Point(640,0), new Point(640, 320));
const pointS = new Point(360, 360);
const lineS = new Line(new Point(0, 0), new Point(360, 360));
const lineSI = new Line(new Point(0, 720), new Point(720, 0));
function grid(points, x, y) {
return flatten(tabulate((i, j) => points.map(p => p.shift(i * x, j * y)),
width/x, height/y));
}
function applyTransforms(point, [x, y], transforms) {
let points = [point.mod(x, y)];
for (let t of transforms) {
for (let p of points.map(p => t(p))) {
// -------------------------------------------------------------------------
// Symmetry Functions
const width = 1920;
const height = 1280;
const pointX1M = new Point(240, 320);
const pointX1Y1 = new Point(480, 320);
const lineX1 = new Line(new Point(0,320), new Point(480,320));
const lineY1 = new Line(new Point(480,0), new Point(480,320));
const lineY2 = new Line(new Point(640,0), new Point(640, 320));
const pointS = new Point(360, 360);
const lineS = new Line(new Point(0, 0), new Point(360, 360));
const lineSI = new Line(new Point(0, 720), new Point(720, 0));
function grid(points, x, y) {
return flatten(tabulate((i, j) => points.map(p => p.shift(i * x, j * y)),
width/x, height/y));
}
function applyTransforms(point, [x, y], transforms) {
let points = [point.mod(x, y)];
for (let t of transforms) {
for (let p of points.map(p => t(p))) {
if (!points.some(q => q.equals(p))) points.push(p);
}
}
function lineX(y) { return new Line(new Point(0, y), new Point(1, y)); }
function lineY(x) { return new Line(new Point(x, 0), new Point(x, 1)); }
function lineX(y) { return new Line(new Point(0, y), new Point(1, y)); }
function lineY(x) { return new Line(new Point(x, 0), new Point(x, 1)); }
function line(a1, a2, b1, b2) { return new Line(new Point(a1, a2), new Point(b1, b2)); }
checkForIntersects() {
if (!this.options.intersect || this.paths.length <= 1) return;
let path1 = last(this.paths);
let points1 = path1.points;
let line1 = new Line(points1[points1.length-2], points1[points1.length-1]);
for (let i = 0; i < this.paths.length - 1; ++i) {
let path2 = this.paths[i];
let points2 = path2.points;
for (let j = 1; j < points2.length - 2; ++j) {
let line2 = new Line(points2[j], points2[j + 1]);
let t = Line.intersect(line1, line2);
if (t) {
this.trigger('intersect', { point: t, paths: [path1, path2] });
return;
}
}
}
}
drawPath(start: Point) {
const ellipse = new Ellipse(new Point(380, 220), 360, 200);
const points = [start];
let line = new Line(start, start.shift(1, -1));
for (let i = 0; i < 100; ++i) {
const p = ellipse.intersect(line)[0];
points.push(p);
const q = line.p1.reflect(ellipse.normalAt(p));
line = new Line(p, q);
}
this.$path.points = points;
this.$end.setCenter(last(points));
}
}
checkForIntersects() {
if (!this.options.intersect || this.paths.length <= 1) return;
let path1 = last(this.paths);
let points1 = path1.points;
let line1 = new Line(points1[points1.length-2], points1[points1.length-1]);
for (let i = 0; i < this.paths.length - 1; ++i) {
let path2 = this.paths[i];
let points2 = path2.points;
for (let j = 1; j < points2.length - 2; ++j) {
let line2 = new Line(points2[j], points2[j + 1]);
let t = Line.intersect(line1, line2);
if (t) {
this.trigger('intersect', { point: t, paths: [path1, path2] });
return;
}
}
}
}
function lineY(x) { return new Line(new Point(x, 0), new Point(x, 1)); }
function line(a1, a2, b1, b2) { return new Line(new Point(a1, a2), new Point(b1, b2)); }