Skip to content

Commit

Permalink
- Complete Serialization and Visualization sections of README.md
Browse files Browse the repository at this point in the history
- Release patch
  • Loading branch information
alexbol99 committed Apr 29, 2020
1 parent 53bd744 commit e61232c
Show file tree
Hide file tree
Showing 53 changed files with 424 additions and 203 deletions.
106 changes: 53 additions & 53 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 47 additions & 5 deletions README.md
Expand Up @@ -268,10 +268,12 @@ console.log(p) // true / false

### Boolean operations

Package implements the modification of Weiler-Atherton clipping algorithm,
described in the article **Hidden Surface Removal Using Polygon Area Sorting** see <https://www.cs.drexel.edu/~david/Classes/CS430/HWs/p214-weiler.pdf>
Boolean operations on polygons available via namespace **BooleanOperations**.
Polygons in boolean operation should be valid: both operands should have same meaning of face orientation,
faces should not overlap each other and should not have self-intersections.

User is responsible to provide valid polygons, boolean operation methods do not check validity.

Methods available via namespace BooleanOperations.
```javascript
let {unify, subtract, intersect, innerClip, outerClip} = BooleanOp;
```
Expand All @@ -282,11 +284,51 @@ let {unify, subtract, intersect, innerClip, outerClip} = BooleanOp;
The first aray contains edges of the first polygon, the second - the edges of the second
* `outerClip` - clip boundary of the first polygon with the interior of the second polygon

Implementation based on Weiler-Atherton clipping algorithm,
described in the article [Hidden Surface Removal Using Polygon Area Sorting](https://www.cs.drexel.edu/~david/Classes/CS430/HWs/p214-weiler.pdf)

### Serialization

...to be completed
All **flatten-js** shape objects may be serialized using `JSON.stringify()` method.
`JSON.stringify` transforms object to string using `.toJSON()` formatter implemented in the class.
`JSON.parse` restore object from a string, and then constructor can use this object to create Flatten object.

```javascript
let {lint, point} = Flatten;
let l = line(point(4, 0), point(0, 4));
// Serialize
let str = JSON.stringify(l);
// Parse and reconstruct
let l_json = JSON.parse(str);
let l_parsed = line(l_json);
```

### Visualization

... to be completed
All classes provide `svg()` method, that create svg string that may be inserted into svg container element
in a very straightforward way:

```html
<body>
<svg id="stage" width="500" height="500"></svg>
<script>
const Flatten = window["@flatten-js/core"];
const {point, circle, segment} = Flatten;
// make some construction
let s1 = segment(10,10,200,200);
let s2 = segment(10,160,200,30);
let c = circle(point(200, 110), 50);
let ip = s1.intersect(s2);
document.getElementById("stage").innerHTML = s1.svg() + s2.svg() + c.svg() + ip[0].svg();
</script>
</body>
```

Method `svg()` may accept as a parameter an object that enables to define
several basic attributes of svg element:
`stroke`, `strokeWidth`, `fill`, `fillRule`, `fillOpacity`, `id` and `className`.
If attributes not provided, method `svg()` use default values.


2 changes: 1 addition & 1 deletion docs/Arc.html
Expand Up @@ -3392,7 +3392,7 @@ <h5>Returns:</h5>
<br class="clear">

<footer>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Sat Apr 11 2020 13:49:15 GMT+0300 (Israel Daylight Time) using the Minami theme.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Wed Apr 29 2020 12:11:56 GMT+0300 (Israel Daylight Time) using the Minami theme.
</footer>

<script>prettyPrint();</script>
Expand Down
2 changes: 1 addition & 1 deletion docs/Box.html
Expand Up @@ -2391,7 +2391,7 @@ <h5>Returns:</h5>
<br class="clear">

<footer>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Sat Apr 11 2020 13:49:15 GMT+0300 (Israel Daylight Time) using the Minami theme.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Wed Apr 29 2020 12:11:57 GMT+0300 (Israel Daylight Time) using the Minami theme.
</footer>

<script>prettyPrint();</script>
Expand Down
2 changes: 1 addition & 1 deletion docs/Circle.html
Expand Up @@ -1554,7 +1554,7 @@ <h5>Returns:</h5>
<br class="clear">

<footer>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Sat Apr 11 2020 13:49:15 GMT+0300 (Israel Daylight Time) using the Minami theme.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Wed Apr 29 2020 12:11:57 GMT+0300 (Israel Daylight Time) using the Minami theme.
</footer>

<script>prettyPrint();</script>
Expand Down
2 changes: 1 addition & 1 deletion docs/CircularLinkedList.html
Expand Up @@ -663,7 +663,7 @@ <h5>Returns:</h5>
<br class="clear">

<footer>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Sat Apr 11 2020 13:49:15 GMT+0300 (Israel Daylight Time) using the Minami theme.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Wed Apr 29 2020 12:11:57 GMT+0300 (Israel Daylight Time) using the Minami theme.
</footer>

<script>prettyPrint();</script>
Expand Down

0 comments on commit e61232c

Please sign in to comment.