Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
NaridaL committed Aug 20, 2023
1 parent 03376d4 commit 40132f0
Show file tree
Hide file tree
Showing 24 changed files with 724 additions and 581 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
Expand Down
864 changes: 475 additions & 389 deletions package-lock.json

Large diffs are not rendered by default.

43 changes: 22 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,67 +31,68 @@
"parser": "glsl-parser"
}
}
]
],
"plugins": ["prettier-plugin-glsl"]
},
"devDependencies": {
"@emotion/react": "11.11.1",
"@emotion/styled": "11.11.0",
"@loadable/component": "5.15.3",
"@mui/icons-material": "5.14.0",
"@mui/material": "5.14.0",
"@mui/icons-material": "5.14.3",
"@mui/material": "5.14.3",
"@sucrase/webpack-loader": "2.0.0",
"@types/blob-stream": "0.1.30",
"@types/chai": "4.3.5",
"@types/copy-webpack-plugin": "8.0.1",
"@types/loadable__component": "5.13.4",
"@types/lodash": "4.14.195",
"@types/lodash": "4.14.196",
"@types/opentype.js": "1.3.4",
"@types/pdfkit": "0.12.10",
"@types/react": "18.2.15",
"@types/react": "18.2.18",
"@types/react-dom": "18.2.7",
"@types/react-router-dom": "5.3.3",
"@types/seedrandom": "3.0.5",
"@types/webpack-env": "1.18.1",
"@typescript-eslint/eslint-plugin": "6.0.0",
"@typescript-eslint/parser": "6.0.0",
"@typescript-eslint/eslint-plugin": "6.2.1",
"@typescript-eslint/parser": "6.2.1",
"aesthetically": "0.0.6",
"blob-stream": "0.1.3",
"chai": "4.3.7",
"chroma.ts": "1.0.10",
"copy-webpack-plugin": "11.0.0",
"eslint": "8.45.0",
"eslint-config-prettier": "8.8.0",
"eslint-plugin-import": "2.27.5",
"eslint": "8.46.0",
"eslint-config-prettier": "9.0.0",
"eslint-plugin-import": "2.28.0",
"eslint-plugin-react-hooks": "4.6.0",
"html-webpack-plugin": "5.5.3",
"js-file-download": "0.4.12",
"lodash": "4.17.21",
"lodash": "^4.17.21",
"opentype.js": "1.3.4",
"path-browserify": "^1.0.1",
"pdfkit": "0.13.0",
"prettier": "2.8.8",
"prettier-plugin-glsl": "0.0.10",
"prettier": "3.0.1",
"prettier-plugin-glsl": "0.1.2",
"react": "18.2.0",
"react-dnd": "16.0.1",
"react-dnd-html5-backend": "16.0.1",
"react-dom": "18.2.0",
"react-router-dom": "6.14.1",
"react-router-dom": "6.14.2",
"seedrandom": "3.0.5",
"simple-git-hooks": "2.8.1",
"simple-git-hooks": "2.9.0",
"sleep-promise": "9.1.0",
"source-map": "^0.7.4",
"source-map-js": "^1.0.2",
"source-map-loader": "4.0.1",
"sucrase": "3.33.0",
"sucrase": "3.34.0",
"svg-pathdata": "6.0.3",
"svg-to-pdfkit": "0.1.8",
"ts3dutils": "1.1.6",
"tsgl": "1.1.9",
"typescript": "5.1.6",
"val-loader": "5.0.1",
"webgl-strict-types": "1.0.5",
"webpack": "5.88.1",
"webpack": "5.88.2",
"webpack-cli": "5.1.4",
"webpack-dev-server": "4.15.1",
"path-browserify": "^1.0.1",
"source-map": "^0.7.4",
"source-map-js": "^1.0.2"
"webpack-dev-server": "4.15.1"
}
}
11 changes: 7 additions & 4 deletions src/common/useHashState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ const parseHash = (hash: string): Record<string, string> => {
const [key, value] = part.split("=")
return [decodeURIComponent(key), decodeURIComponent(value)]
})
.reduce((obj, [key, value]) => {
obj[key] = value
return obj
}, {} as Record<string, string>)
.reduce(
(obj, [key, value]) => {
obj[key] = value
return obj
},
{} as Record<string, string>,
)
}
const objectToHash = (o: Record<string, string>): string => {
return (
Expand Down
5 changes: 4 additions & 1 deletion src/delta3d/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,10 @@ function quickhull(gl: TSGLContext) {
),
)
const zBases = [0, 1, 2].map((i) =>
tree.getTransform(zAssemblies[i]).transformPoint(V(-2.5, 0, 0)).xy(),
tree
.getTransform(zAssemblies[i])
.transformPoint(V(-2.5, 0, 0))
.xy(),
) as [V3, V3, V3]

function fixJoints() {
Expand Down
5 changes: 4 additions & 1 deletion src/hexSandpiles/HexSandpiles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ const loadFont = (url: string): Promise<Font> =>
class HexSand {
readonly data: Uint8Array

public constructor(public readonly w: int, public readonly h: int) {
public constructor(
public readonly w: int,
public readonly h: int,
) {
this.data = new Uint8Array(w * h)
}

Expand Down
7 changes: 2 additions & 5 deletions src/paperArcBox/ArcBoxSvg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as React from "react"
import { CSSProperties, ReactElement, useContext } from "react"
import { SVGPathData } from "svg-pathdata"
import { CommandA } from "svg-pathdata/lib/types"
import { INCH } from "../paperBox1/common"
import { Measure, SvgPrintContext } from "../paperBox1/Measure"
import { PaperSize } from "../paperBox1/PaperSize"
import * as path from "../paperBox1/svg"
Expand Down Expand Up @@ -109,9 +108,6 @@ export function ArcBoxSvg({
<svg
xmlns="http://www.w3.org/2000/svg"
style={{
fill: "none",
stroke: "#123456",
strokeWidth: (2 * INCH) / 300,
...style,
}}
width={width + "mm"}
Expand All @@ -126,7 +122,7 @@ export function ArcBoxSvg({
</defs>
<SvgCommonDefs />
{!print && <path d={glue} className="glue" />}
<path d={outline} />
<path d={outline} className="cut" />
<path d={fold} className="valley" />
<g>
<Measure from={[w / 2, 0]} to={[w / 2, h + 2 * rise]} offset={-0.5} />
Expand All @@ -136,6 +132,7 @@ export function ArcBoxSvg({
from={[1.5 * w, radius]}
to={[2 * w, rise]}
offset={-0.5}
R
hideRight={true}
/>
</g>
Expand Down
4 changes: 3 additions & 1 deletion src/paperBox1/Measure.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ export function Measure({
from,
to,
children,
R,
hideRight = false,
offset = 0,
}: {
from: R2 | V3
to: R2 | V3
children?: string
R?: boolean
hideRight?: boolean
offset?: number
}): ReactElement | null {
Expand All @@ -37,7 +39,7 @@ export function Measure({
const isSvgPrint = useContext(SvgPrintContext)
if (isSvgPrint) return null
if (length < 0.05) return null
children ||= "" + round10(length, -1)
children ||= (R ? "R" : "") + round10(length, -1)
const textBlank = 3 * children.length

return (
Expand Down
4 changes: 0 additions & 4 deletions src/paperBox1/PrismBoxSvg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { arrayRange, DEG, round10, TAU, V, V3 } from "ts3dutils"
import {
centerToSideFromSideWidth,
fmtdeg,
INCH,
radiusFromSideWidth,
} from "./common"
import { Guide, Measure, SvgPrintContext } from "./Measure"
Expand Down Expand Up @@ -117,9 +116,6 @@ export function PrismBoxSvg({
<svg
xmlns="http://www.w3.org/2000/svg"
style={{
fill: "none",
stroke: "#123456",
strokeWidth: (2 * INCH) / 300,
...style,
}}
width={svgViewBox[2] + "mm"}
Expand Down
5 changes: 5 additions & 0 deletions src/paperBox1/SvgCommonDefs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ export const SvgCommonDefs = () => {
</pattern>
</defs>
<style>{`
.adrian * {
stroke: black;
stroke-width: .05mm;
fill: none;
}
.mountain, .mountain * { stroke-dasharray: 10,2,1,1,1,2; }
.valley, .valley * { stroke-dasharray: 1,1; }
.cut, .cut * { stroke: 1; }
Expand Down
34 changes: 8 additions & 26 deletions src/paperBox1/common.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from "react"
import { ReactElement, ReactNode, SVGProps } from "react"
import { arrayRange, DEG, int, raddd, round10, TAU, V3 } from "ts3dutils"
import { encode, L, M, Z } from "./svg"

export const INCH = 25.4
export const fmtdeg = (x: raddd): string => "" + round10(x / DEG, -1) + "°"
Expand Down Expand Up @@ -41,14 +42,15 @@ export function RegularPolygon({
if (undefined === radius) {
radius = radiusFromSideWidth(sides, sideLength!)
}
const { x, y } = V3.polar(radius, startAngle)
return (
<path
d={dTpl`
M${x},${y}
${arrayRange(0, sides).map(
(i) => dTpl`L${V3.polar(radius!, startAngle + i * (TAU / sides))}`,
)}Z`}
d={encode(
M(V3.polar(radius, startAngle)),
...arrayRange(0, sides).map((i) =>
L(V3.polar(radius!, startAngle + i * (TAU / sides))),
),
Z(),
)}
{...props}
/>
)
Expand Down Expand Up @@ -81,26 +83,6 @@ export function RotStep({
)
}

export function dTpl(
strings: TemplateStringsArray,
...exps: (number | V3 | string | string[])[]
): string {
const format = (x: number | V3 | string | string[]): string =>
"number" === typeof x
? "" + x
: "string" === typeof x
? x
: Array.isArray(x)
? x.map(format).join(" ")
: x.x + "," + x.y
let result = strings[0]
for (let i = 0; i < exps.length; i++) {
result += format(exps[i])
result += strings[i + 1]
}
return result
}

export const openInNewTab = (url: string): void => {
const newWindow = window.open(url, "_blank", "noopener,noreferrer")
if (newWindow) newWindow.opener = null
Expand Down
84 changes: 71 additions & 13 deletions src/paperBox1/svg.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,58 @@
import { SVGPathData } from "svg-pathdata"
import { CommandL, CommandS, CommandV } from "svg-pathdata/lib/types"
import {
CommandA,
CommandC,
CommandH,
CommandL,
CommandM,
CommandS,
CommandV,
SVGCommand,
} from "svg-pathdata/lib/types"
import { V3 } from "ts3dutils"

export function H(x: number): CommandH {
return { type: SVGPathData.HORIZ_LINE_TO, relative: false, x: x }
}

export function A(
rx: number,
ry: number,
xAxisRotation: number,
largeArcFlag: 0 | 1,
sweepFlag: 0 | 1,
p: V3,
): CommandA {
return {
lArcFlag: largeArcFlag,
rX: rx,
rY: ry,
relative: false,
sweepFlag: sweepFlag,
type: SVGPathData.ARC,
x: p.x,
xRot: 0,
y: p.y,
}
}

export const C = (
x1: number,
y1: number,
x2: number,
y2: number,
x: number,
y: number,
): CommandC => ({
type: SVGPathData.CURVE_TO,
x1,
y1,
x2,
y2,
x,
y,
relative: false,
})

export const V = (y: number): CommandV => ({
type: SVGPathData.VERT_LINE_TO,
Expand All @@ -16,24 +69,25 @@ export const S = (x2: number, y2: number, x: number, y: number): CommandS => ({
relative: false,
})

export const M = (x: number, y: number) => ({
type: SVGPathData.MOVE_TO,
x,
y,
relative: false,
})
export function M(p: V3): CommandM
export function M(x: number, y: number): CommandM
export function M(a1: number | V3, a2?: number) {
const [x, y] = a2 === undefined ? [(a1 as V3).x, (a1 as V3).y] : [a1, a2]
return { type: SVGPathData.MOVE_TO, x, y, relative: false }
}

export const m = (x: number, y: number) => ({
type: SVGPathData.MOVE_TO,
x,
y,
relative: true,
})
export const L = (x: number, y: number) => ({
type: SVGPathData.LINE_TO,
x,
y,
relative: false,
})
export function L(p: V3): CommandL
export function L(x: number, y: number): CommandL
export function L(a1: number | V3, a2?: number) {
const [x, y] = a2 === undefined ? [(a1 as V3).x, (a1 as V3).y] : [a1, a2]
return { type: SVGPathData.LINE_TO, x, y, relative: false }
}
export const l = (x: number, y: number): CommandL => ({
type: SVGPathData.LINE_TO,
x,
Expand All @@ -42,3 +96,7 @@ export const l = (x: number, y: number): CommandL => ({
})

export const Z = () => ({ type: SVGPathData.CLOSE_PATH })

export const encode = (...path: SVGCommand[]): string => {
return new SVGPathData(path).round(3).encode()
}
Loading

0 comments on commit 40132f0

Please sign in to comment.