forked from skymakerolof/dxf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a 'toPolylines' intermediate step for third party renderers
- Loading branch information
Showing
5 changed files
with
19,876 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { Box2 } from 'vecks' | ||
|
||
import colors from './util/colors' | ||
import denormalise from './denormalise' | ||
import entityToPolyline from './entityToPolyline' | ||
import logger from './util/logger' | ||
|
||
export default (parsed) => { | ||
const entities = denormalise(parsed) | ||
const polylines = entities.map(entity => { | ||
const layerTable = parsed.tables.layers[entity.layer] | ||
let rgb | ||
if (layerTable) { | ||
let colorNumber = ('colorNumber' in entity) ? entity.colorNumber : layerTable.colorNumber | ||
rgb = colors[colorNumber] | ||
if (rgb === undefined) { | ||
logger.warn('Color index', colorNumber, 'invalid, defaulting to black') | ||
rgb = [0, 0, 0] | ||
} | ||
} else { | ||
logger.warn('no layer table for layer:' + entity.layer) | ||
rgb = [0, 0, 0] | ||
} | ||
|
||
return { rgb, vertices: entityToPolyline(entity) } | ||
}) | ||
|
||
const bbox = new Box2() | ||
polylines.forEach(polyline => { | ||
polyline.vertices.forEach(vertex => { | ||
bbox.expandByPoint({ x: vertex[0], y: vertex[1] }) | ||
}) | ||
}) | ||
|
||
return { bbox, polylines } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.