Skip to content

Commit

Permalink
Added validation stats
Browse files Browse the repository at this point in the history
  • Loading branch information
HHogg committed Dec 6, 2024
1 parent 6eb1c41 commit 344f22e
Show file tree
Hide file tree
Showing 28 changed files with 404 additions and 166 deletions.
Binary file modified .yarn/install-state.gz
Binary file not shown.
8 changes: 4 additions & 4 deletions workspaces/circular-sequence/src/Article/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ let seq_2: Sequence = [6, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0];
id="get-length"
description="Implementation to return the actual length of a sequence"
language="rust"
startLineNumber={7}
endLineNumber={23}
startLineNumber={10}
endLineNumber={26}
>
{fileContentsSequence}
</ArticleFigCodeBlock>
Expand Down Expand Up @@ -271,8 +271,8 @@ let seq_2: Sequence = [6, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0];
id="is-symmetrical"
description="Implementation to retrieve the starting index of the reverse sequence if it exists"
language="rust"
startLineNumber={25}
endLineNumber={61}
startLineNumber={28}
endLineNumber={64}
>
{fileContentsSequence}
</ArticleFigCodeBlock>
Expand Down
2 changes: 1 addition & 1 deletion workspaces/circular-sequence/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const meta: Project = {
id: ProjectKey.circular_sequence,
name: 'Matching symmetric circular sequences with Knuth-Morris-Pratt (KMP)',
description:
'identifying and comparing unique geometric shape arrangements without a defined start or endpoint using the Knuth-Morris-Pratt algorithm in Rust.',
'Identifying and comparing unique geometric shape arrangements without a defined start or endpoint using the Knuth-Morris-Pratt algorithm in Rust.',
image,
tags: ['algorithms', 'data structures', 'sequences', 'rust'],
deploy: true,
Expand Down
4 changes: 2 additions & 2 deletions workspaces/common/src/ProjectPage/ProjectPageLink.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Link } from 'preshape';
import { Link, LinkProps } from 'preshape';
import { Project } from '../types';
import { getProjectRoutePath } from '../utils';

type Props = {
project: Project;
};

export default function ProjectPageLink({ project }: Props) {
export default function ProjectPageLink({ project }: Props & LinkProps) {
return (
<Link to={getProjectRoutePath(project)} underline>
'{project.name}'
Expand Down
15 changes: 15 additions & 0 deletions workspaces/common/src/ProjectPage/ProjectPageWIP.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Box, BoxProps } from 'preshape';
import { useProjectPageContext } from '..';
import ProjectPageHeader from './ProjectPageHeader';

type ProjectPageWIPProps = BoxProps;

export default function ProjectPageWIP(props: ProjectPageWIPProps) {
const {} = useProjectPageContext();

return (
<Box {...props} flex="vertical" grow maxWidth="800px">
<ProjectPageHeader />
</Box>
);
}
1 change: 1 addition & 0 deletions workspaces/common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export {
default as ProjectPage,
type ProjectPageProps,
} from './ProjectPage/ProjectPage';
export { default as ProjectPageWIP } from './ProjectPage/ProjectPageWIP';
export { default as ProjectPageLink } from './ProjectPage/ProjectPageLink';
export { default as ProjectPageProvider } from './ProjectPage/ProjectPageProvider';
export { useProjectPageContext } from './ProjectPage/useProjectPageContext';
Expand Down
1 change: 1 addition & 0 deletions workspaces/common/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export enum ProjectKey {
circle_art = 'circle-art',
circle_intersections = 'circle-intersections',
circular_sequence = 'circular-sequence',
gap_validation = 'gap-validation',
evolution = 'evolution',
line_segment_extending = 'line-segment-extending',
snake = 'snake',
Expand Down
22 changes: 22 additions & 0 deletions workspaces/gap-validation/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "@hogg/gap-validation",
"version": "0.0.0",
"author": "Harry Hogg <[email protected]>",
"private": true,
"type": "module",
"main": "./src/index.ts",
"exports": {
".": "./src/index.ts",
"./types": "./src/types.ts"
},
"dependencies": {
"@hogg/common": "workspace:^",
"lucide-react": "0.445.0",
"preshape": "^19.1.5",
"react": "^18.2.0"
},
"devDependencies": {
"@types/react": "^18.0.28",
"typescript": "^5.0.4"
}
}
61 changes: 61 additions & 0 deletions workspaces/gap-validation/src/Article/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import {
ArticleFig,
ArticleFigCodeBlock,
ArticleFigLink,
ArticleFigs,
ArticlePage,
ProjectPageLink,
} from '@hogg/common';
import { ColorMode, TilingRenderer, meta as tilingsMeta } from '@hogg/tilings';
import {
ArticleHeading,
ArticleParagraph,
ArticleSection,
Code,
Link,
Text,
sizeX12Px,
} from 'preshape';

const Article = () => {
return (
<ArticlePage>
<ArticleSection>
<ArticleHeading>Introduction</ArticleHeading>

{/* <ArticleParagraph>
While working on my <ProjectPageLink project={tilingsMeta} /> project,
I was needing to build up a list of distinct shape arrangements (
<ArticleFigLink fig="dodecagon-shape-arrangement" />
). This needed a way to check an arrangement against a list of
previously seen arrangements.
</ArticleParagraph>
<ArticleParagraph>
The complexity and interesting part of this problem came because the
shapes could be arranged cyclicly, and there was no defined start or
end point. This meant that the same arrangement could be represented
in multiple ways. I was also dealing with an infinite amount of these
arrangements, and 100,000s of them every second.
</ArticleParagraph>
<ArticleFigs>
<ArticleFig
id="dodecagon-shape-arrangement"
description="Shape arrangement of a dodecagon at the center, with alternating triangles, squares and hexagons on it's edges."
>
<TilingRenderer
height="200px"
notation="12-3,4,6,4,3,4,6,4,3,4,6,4"
options={{
colorMode: ColorMode.None,
}}
/>
</ArticleFig>
</ArticleFigs> */}
</ArticleSection>
</ArticlePage>
);
};

export default Article;
6 changes: 6 additions & 0 deletions workspaces/gap-validation/src/Project.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { ProjectPage, ProjectPageProps } from '@hogg/common';
import Article from './Article';

export default function Project(props: ProjectPageProps) {
return <ProjectPage {...props} article={<Article />} />;
}
15 changes: 15 additions & 0 deletions workspaces/gap-validation/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { type Project, ProjectKey } from '@hogg/common';

export { default as Project } from './Project';

export const meta: Project = {
id: ProjectKey.gap_validation,
name: 'Validating a tiled plane for gaps',
description:
'An approach for checking a tiled plane for gaps by ensure there is a single continuous perimeter.',
tags: ['algorithms', 'data structures', 'sequences', 'rust'],
deploy: false,
wip: true,
created: '2024-03-17',
updated: '2024-04-10',
};
3 changes: 3 additions & 0 deletions workspaces/tilings/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
"generate:results": "cargo run --release --bin tiling-searcher -- --reset --log-to-file"
},
"dependencies": {
"@hogg/circular-sequence": "workspace:^",
"@hogg/common": "workspace:^",
"@hogg/gap-validation": "workspace:^",
"@hogg/spatial-grid-map": "workspace:^",
"@hogg/wasm": "workspace:^",
"@visx/axis": "^3.5.0",
"@visx/curve": "^3.3.0",
Expand Down
8 changes: 4 additions & 4 deletions workspaces/tilings/src-rust/tiling/src/validation/flag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ impl Flag {
impl From<Flag> for &'static str {
fn from(flag: Flag) -> Self {
match flag {
Flag::Overlaps => "validation_overlaps",
Flag::Gaps => "validation_gaps",
Flag::Expanded => "validation_expansion",
Flag::VertexTypes => "validation_vertex_types",
Flag::Overlaps => "validation_Overlaps",
Flag::Gaps => "validation_Gaps",
Flag::Expanded => "validation_Expanded",
Flag::VertexTypes => "validation_VertexTypes",
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl Validator {

loop {
let mid_point: (f64, f64) = current_line_segment.mid_point().into();
let near_by = line_segments.iter_values_around(&mid_point, 3);
let near_by = line_segments.iter_values_around(&mid_point, 1);

let mut found = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import { Box } from 'preshape';
import ArrangementStatsProvider from './ArrangementStatsProvider';
import PolygonsBreakdown from './PolygonsBreakdown';
import TotalDurationBreakdown from './TotalDurationBreakdown';
import ValidationDurationBreakdown from './ValidationDurationBreakdown';

export default function ArrangementStats() {
return (
<ArrangementStatsProvider>
<Box flex="vertical" gap="x10">
<TotalDurationBreakdown />
<PolygonsBreakdown />
<ValidationDurationBreakdown />
</Box>
</ArrangementStatsProvider>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { Point, SvgLabelsProvider } from '@hogg/common';
import { Box, BoxProps, useResizeObserver } from 'preshape';
import BreakdownBarSection from './BreakdownBarSection';
import { barHeight } from './utils';

const heightWithLabels = 50;
const gap = barHeight * 0.5;
const labelHeight = 46;

// Even points will move to the left from half way to 0
// Odd points will move to the right from half way to width
Expand All @@ -24,20 +22,27 @@ const toEitherSide = (count: number, width: number) => {
};

type BreakdownBarProps = BoxProps & {
height?: number;
sections: {
name?: string;
color: string;
value: number;
}[];
};

export default function BreakdownBar({ sections, ...rest }: BreakdownBarProps) {
export default function BreakdownBar({
height = 6,
sections,
...rest
}: BreakdownBarProps) {
const [size, ref] = useResizeObserver();
const { width } = size;

const gap = height * 0.5;
const hasLabels = sections.some(({ name }) => name);
const total = sections.reduce((acc, { value }) => acc + value, 0);
const widths = sections.map(({ value }) =>
Math.max(barHeight, total ? (value / total) * width : 0)
Math.max(height, total ? (value / total) * width : 0)
);
const lefts = sections.map((_, i) =>
widths.slice(0, i).reduce((acc, width) => acc + width + gap, 0)
Expand All @@ -47,18 +52,20 @@ export default function BreakdownBar({ sections, ...rest }: BreakdownBarProps) {
(lefts[lefts.length - 1] ?? 0) + (widths[widths.length - 1] ?? 0);
const offsetScaleX = width / totalWidth;

const height = sections.some(({ name }) => name)
? heightWithLabels
: barHeight;
const heightWithLabels = hasLabels ? height + labelHeight : height;

return (
<Box {...rest} ref={ref}>
<SvgLabelsProvider width={width} height={height} getPoints={toEitherSide}>
<SvgLabelsProvider
width={width}
height={heightWithLabels}
getPoints={toEitherSide}
>
<Box
tag="svg"
height={height}
height={heightWithLabels}
width={width}
viewBox={`0 0 ${width} ${height}`}
viewBox={`0 0 ${width} ${heightWithLabels}`}
style={{
shapeRendering: 'geometricPrecision',
}}
Expand All @@ -67,6 +74,7 @@ export default function BreakdownBar({ sections, ...rest }: BreakdownBarProps) {
<BreakdownBarSection
color={section.color}
first={index === 0}
height={height}
key={index}
last={index === sections.length - 1}
name={section.name}
Expand Down
Loading

0 comments on commit 344f22e

Please sign in to comment.