Skip to content

Commit

Permalink
- Update README.md to include @flatten-js/core as peer dependency
Browse files Browse the repository at this point in the history
- Add create-react-app example, remove all other examples
  • Loading branch information
alexbol99 committed Apr 19, 2019
1 parent 92f2f7c commit 37deedb
Show file tree
Hide file tree
Showing 17 changed files with 396 additions and 77 deletions.
39 changes: 39 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules
jspm_packages

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history

.idea/
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
# Offset polygon

This package implements algorithm of equidistant offset of polygon. It relies on the [flatten-js](<https://github.com/alexbol99/flatten-js>)
library and its polygon model, which is multi polygon comprised from a number of islands and holes,
see [this](https://beta.observablehq.com/@alexbol99/flattenjs-tutorials-polygons) interactive notebook for more details.
library and its polygon model, which is multi polygon comprised from a number of islands and holes.
See [this](https://beta.observablehq.com/@alexbol99/flattenjs-tutorials-polygons) interactive notebook for more details.

Algorithm is based on the idea of morphological offset, when each edge of the polygon is mapped to its offset,
and then [boolean operation](https://github.com/alexbol99/flatten-boolean-op) performed between original contour and offset edges.
When offset value is positive, offset edges are united with original contour, when negative - they are
When offset value is positive, offset edges are unified with original contour, when negative - they are
subtracted from original contour.

## Contacts
Expand All @@ -19,8 +19,16 @@ Follow me on Twitter [@alex_bol_](https://twitter.com/alex_bol_)


## Installation

```bash
npm install --save @flatten-js/polygon-offset
```

The package [@flatten-js/core](<https://github.com/alexbol99/flatten-js>) is peer dependency of this package
and have to be installed separately:

```bash
npm install --save @flatten-js/core
```

## Usage

Expand Down
27 changes: 27 additions & 0 deletions examples/create-react-app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "react-polygon-offset",
"version": "0.1.0",
"private": true,
"dependencies": {
"@flatten-js/core": "^1.0.14",
"@flatten-js/polygon-offset": "^1.0.2",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "2.1.8"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
Binary file added examples/create-react-app/public/favicon.ico
Binary file not shown.
41 changes: 41 additions & 0 deletions examples/create-react-app/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<meta name="theme-color" content="#000000" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
15 changes: 15 additions & 0 deletions examples/create-react-app/public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
33 changes: 33 additions & 0 deletions examples/create-react-app/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
.App {
text-align: center;
}

.App-logo {
animation: App-logo-spin infinite 20s linear;
height: 40vmin;
pointer-events: none;
}

.App-header {
background-color: #282c34;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
}

.App-link {
color: #61dafb;
}

@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
38 changes: 38 additions & 0 deletions examples/create-react-app/src/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React from 'react';
import {point, segment, Polygon} from "@flatten-js/core";
import {offset} from "@flatten-js/polygon-offset";

const shapes = [
segment(point(200,100), point(200,300)),
segment(point(200,300), point(440,300)),
segment(point(440,300), point(300,200)),
segment(point(300,200), point(440,150)),
segment(point(440,150), point(500,150)),
segment(point(500,150), point(640,200)),
segment(point(640,200), point(500,300)),
segment(point(500,300), point(740,300)),
segment(point(740,300), point(740,100)),
segment(point(740,100), point(200,100))
];

const polygon = new Polygon();
polygon.addFace(shapes);

const App = () => {
const path = (polygon) => [...polygon.faces].reduce( (d, face) => d + face.svg(), "");
return (
<div>
<h1>Hello Flatten World!</h1>;
<svg width="1500" height="500">
<path stroke="black" stroke-width="1" fill="lightblue" fill-rule="evenodd" fill-opacity="1"
d={path(polygon)} >
</path>
<path stroke="black" stroke-width="1" fill="lightcyan" fill-rule="evenodd" fill-opacity="0.4"
d={path(offset(polygon,40))} >
</path>
</svg>
</div>
);
};

export default App;
9 changes: 9 additions & 0 deletions examples/create-react-app/src/App.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<App />, div);
ReactDOM.unmountComponentAtNode(div);
});
14 changes: 14 additions & 0 deletions examples/create-react-app/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
body {
margin: 0;
padding: 0;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
"Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

code {
font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
monospace;
}
12 changes: 12 additions & 0 deletions examples/create-react-app/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';

ReactDOM.render(<App />, document.getElementById('root'));

// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: https://bit.ly/CRA-PWA
serviceWorker.unregister();
7 changes: 7 additions & 0 deletions examples/create-react-app/src/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 37deedb

Please sign in to comment.