Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move from normalizePLine2WithErr to normalize. #92

Open
wants to merge 206 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
206 commits
Select commit Hold shift + click to select a range
b7b196c
move from normalizePLine2WithErr to normalize.
julialongtin Oct 14, 2022
2c13c6a
add short circuits to skip computation, and the error of computation,…
julialongtin Oct 14, 2022
506ce31
add short circuits to skip computation, and the error of computation,…
julialongtin Oct 14, 2022
586d7af
expand PLine2Err usage, and correct some lost precision in the normal…
julialongtin Oct 14, 2022
346873f
use canonicalize instead of canonicalizePPoint2WithErr directly.
julialongtin Oct 14, 2022
f28e6e3
introduce PPoint2Err, and use it for canonicalization.
julialongtin Oct 14, 2022
5d48b74
move idealNormOfPPoint2 to idealNormOfP in the typeclass.
julialongtin Oct 14, 2022
6bde313
rename pPToEP to pToEP, use idealNormOfP more, and eliminate pToEPoin…
julialongtin Oct 14, 2022
fc0e06a
remove cPToEPoint2
julialongtin Oct 14, 2022
8732b98
implement flipL, and use consLike to rebuild flipL and force*basis in…
julialongtin Oct 15, 2022
f542f39
somplify reverse and dual vector operations.
julialongtin Oct 15, 2022
9374a6d
rename pPointToPoint2 to projectivePointToPoint2, and simplify.
julialongtin Oct 15, 2022
f215e71
remove PPoint2PosErr newtype.
julialongtin Oct 15, 2022
bce250a
add meetOf2PL to the ProjectiveLine2 typeclass, and rename forecPLine…
julialongtin Oct 15, 2022
b301652
remove eToCPPoint2WithErr, move from eToPPoint2WithErr to eToPPoint2,…
julialongtin Oct 15, 2022
9e9994a
move from distanceBetweenNPLine2sWithErr to distanceBetweenPLinesWith…
julialongtin Oct 15, 2022
2e9f0ab
remove join2CPPoint2WithErr, rename makeCPPoint2 to makePPoint2, rena…
julialongtin Oct 15, 2022
f5d0fc1
remove distanceCPPointToNPLine.
julialongtin Oct 16, 2022
3ffac1c
remove pLineFromEndpointsWithErr.
julialongtin Oct 16, 2022
715f19e
create Arcs.hs, and move arc calculating code there.
julialongtin Oct 16, 2022
d57dc31
separate Primitive operations from complex operations.
julialongtin Oct 16, 2022
e1b12ae
whoops, actually commit PGAPrimitives.hs .
julialongtin Oct 16, 2022
a30967b
formatting changes.
julialongtin Oct 17, 2022
7d7ec50
make projectivePointToPoint2, join2ProjectivePointsWithErr, and canon…
julialongtin Oct 17, 2022
e12c95e
remove warnings
julialongtin Oct 17, 2022
37e78f2
add error crushing function for pToEP.
julialongtin Oct 17, 2022
ee26c14
change some of the variable names.
julialongtin Oct 17, 2022
a20390f
move angleBetweenWithErr into our ProjectiveLine2 typeclass, as angle…
julialongtin Oct 18, 2022
13c0271
do not forget to dual the error values of the join operation.
julialongtin Oct 18, 2022
3455ad3
relabel some variables and formatting.
julialongtin Oct 18, 2022
bd9dbee
move intersection into our ProjectiveLine2 typeclass.
julialongtin Oct 18, 2022
42f55f7
add eToPL and normalizeL. use those to change angleBetweenWithErr to …
julialongtin Oct 21, 2022
4904957
add xIntercept and yIntercept, along with tests for them.
julialongtin Oct 22, 2022
34feb01
move distanceBetweenPPointsWithErr into PGAPrimitives.hs, and rename …
julialongtin Oct 23, 2022
e744f82
make motorcycles, inodes, and enodes use PLine2Err to track the error…
julialongtin Oct 24, 2022
62c7667
make angleBetween2PL expose normalization ammounts, if they were foun…
julialongtin Oct 25, 2022
9fbcc86
remove old normalize interface, replacing it with normalizeL.
julialongtin Oct 25, 2022
cf7a233
normalize names of projective line handling functions.
julialongtin Oct 25, 2022
45b8755
move pPointBetweenPPointsWithErr into our typeclass, renaming it inte…
julialongtin Oct 27, 2022
a021514
add fuzzinessOfL and pLineErrAtPPoint, and clean up the types of seve…
julialongtin Oct 29, 2022
dd60c1d
expose fuzzinessOfL, for testing.
julialongtin Oct 29, 2022
32b2d8a
add angleCosBetween2PL and fuzzinessOfP to PGAPrimitives, and adapt a…
julialongtin Oct 29, 2022
0c88df2
move canonicalizedIntersectionOf2PL into the ProjectiveLine2 typeclass.
julialongtin Oct 30, 2022
36066fd
let canonicalizedIntersectionOf2PL do normalization error calculation…
julialongtin Oct 30, 2022
f99cc2c
change translateL to return a PLine2Err instead of a UlpSum.
julialongtin Oct 30, 2022
a6479eb
comment changes, and internal function name changes. mostly removing …
julialongtin Oct 30, 2022
8b51cef
rename functions and clean up comments.
julialongtin Oct 31, 2022
6fd59a9
make projectivePointBetweenProjectivePoints return a saner error comp…
julialongtin Oct 31, 2022
16fa8b3
slightly better name
julialongtin Oct 31, 2022
da2d801
change the definition of distanceBetweenProjectivePoints to handle th…
julialongtin Nov 1, 2022
c3319f9
make join2PP return canonicalize results of its input points.
julialongtin Nov 1, 2022
37dcca5
stop crushing the error component out of pToEP. return a PPoint2Err i…
julialongtin Nov 1, 2022
33ff78e
make distance2PP return canonicalization error, if needed.
julialongtin Nov 1, 2022
dc2b65c
variable naming and comment changes.
julialongtin Nov 2, 2022
a40bb55
comment fixes.
julialongtin Nov 2, 2022
0a28f44
comment changes, and break projectivePointIsIdeal out as a utility fu…
julialongtin Nov 2, 2022
8e133ec
move distanceBetweenPLinesWithErr into PGRPrimitives, naming it dista…
julialongtin Nov 2, 2022
900b7e1
add input error into plinesIntersectIn.
julialongtin Nov 3, 2022
65f1595
introduce outAndErrOf, and use it to make code a bit more readable.
julialongtin Nov 3, 2022
226496a
add in code to promote parallel lines to colinear if they are too clo…
julialongtin Nov 4, 2022
44e906f
comment and variable clarity changes.
julialongtin Nov 4, 2022
45d67de
make pLineIsLeft accept error quotents.
julialongtin Nov 5, 2022
f7e422d
use the angleFuzz returned by angleCosNetween2PL.
julialongtin Nov 5, 2022
50778f0
expose projectivePointIsIdeal as isIdealP, and use it through the typ…
julialongtin Nov 5, 2022
263689c
make distancePPointToPLineWithErr take input error, and use distance2…
julialongtin Nov 9, 2022
99fc2e9
make distancePPointToPLineWithErr take input error, and use distance2…
julialongtin Nov 9, 2022
49926cd
change error calculation for distancePPointtoPLineWithErr, and commen…
julialongtin Nov 9, 2022
ec9ce0a
force pPointOnPerpWithErr to return some of the error quotent, and us…
julialongtin Nov 11, 2022
54da1ec
break out perpLineAt.
julialongtin Nov 11, 2022
8eacd4a
better implementation of GaIScaledErr.
julialongtin Nov 11, 2022
cf0cb3b
rename translateRotatePPoint2 to translateRotatePPoint2WithErr.
julialongtin Nov 12, 2022
8bc1c79
rename translateRotatePPoint2 to translateRotatePPoint2WithErr.
julialongtin Nov 12, 2022
f5cc738
make translateRotatePPoint2WithErr return an error quotent.
julialongtin Nov 12, 2022
5da1dd5
completely rebuild translateRotatePPoint2WithErr. actually return a l…
julialongtin Nov 13, 2022
7e0e838
remove intersectsWith, ulpOfPLine2, ulpOfLineSeg, and stop pretending…
julialongtin Nov 13, 2022
b1e90b6
pass PLine2Err instead of UlpSum.
julialongtin Nov 14, 2022
e907a44
allow intersectionWithErr to use the ProjectiveLine2 typeclass.
julialongtin Nov 15, 2022
de5af04
move Arcable and Pointable back into PGA.hs.
julialongtin Nov 15, 2022
e56835e
remove members of the ProjectiveLine2 and ProjectivePoint2 typeclasse…
julialongtin Nov 18, 2022
15f81d3
move outAndErrOf out of the typeclass, and add the Show restriction t…
julialongtin Nov 19, 2022
c1c2e34
make euclidianToProjectiveLine more visible, and minor reorder / vari…
julialongtin Nov 19, 2022
6f29a71
reordering, make noIntersection contain components similar to Interse…
julialongtin Nov 19, 2022
a777b62
use vecOfP instead of hand rolling, move to a single call to plinesIn…
julialongtin Nov 19, 2022
52738ba
un and reconstruct UlpSums less.
julialongtin Nov 20, 2022
b92b6bf
skip valOf 0, use isJust instead.
julialongtin Nov 20, 2022
08d5061
move ulpScale haanndling into pLineIntersectsLineSeg.
julialongtin Nov 20, 2022
be9a70f
add normalization error to pl1Err, and remove test for logically impo…
julialongtin Nov 20, 2022
6b22be8
reduce the number of values returned as part of an IntersectsIn, or a…
julialongtin Nov 20, 2022
12af1cc
break hitSegment into a separate test, and take fuzzinessOfL into acc…
julialongtin Nov 20, 2022
823f7a8
remove ulpMultiplier, rely on pLineErrAtPPoint, and debugging changes.
julialongtin Nov 20, 2022
58ed189
move distance checking to later, to allow faster paths to complete fi…
julialongtin Nov 21, 2022
5c7a889
use pLineErrAtPPoint in onSegment.
julialongtin Nov 21, 2022
abd4f97
label language pragmas better, remove an unused one. re-order and re-…
julialongtin Nov 21, 2022
dff7bd4
make noIntersection and isCollinear accept error quotents, and make n…
julialongtin Nov 22, 2022
86c5b65
use loss preserving functions, but make it clear we are losing throug…
julialongtin Nov 24, 2022
2a2082b
make intersectionOf accept error quotents.
julialongtin Nov 24, 2022
a28b155
use concatMap.
julialongtin Nov 24, 2022
d251ff0
use mapMaybe.
julialongtin Nov 25, 2022
6c92a9c
use mapMaybe instead of catMaybes <$>.
julialongtin Nov 25, 2022
f315940
move getOutsideArc and towardIntersection into Arcs.hs.
julialongtin Nov 26, 2022
31b3eda
remove WithErr from names of Arc functions, and reorder Arcs.hs alpha…
julialongtin Nov 27, 2022
6a7a608
normalize lines before adding them when generating insideArcs.
julialongtin Nov 27, 2022
8a32735
dont bother normalizing getInsideArc output.
julialongtin Nov 27, 2022
167f831
skip normalization in output of getFirstArc.
julialongtin Nov 27, 2022
cd5583b
fix unit test.
julialongtin Nov 27, 2022
11e6b0e
wrap the Arc functions, providing them with better names, and exposin…
julialongtin Nov 28, 2022
ff4c58d
better name.
julialongtin Nov 29, 2022
98a835d
accept error quotents along with projective lines in arc functions.
julialongtin Nov 30, 2022
884384e
Accept projective points with error quotents, in Arc functions.
julialongtin Nov 30, 2022
b58e81c
add more sanity tests, rename a function, and clean up error messages.
julialongtin Dec 1, 2022
4fa0e3d
cleanup comments.
julialongtin Dec 1, 2022
4d1c6a3
introduce join2EP, and use it to shorten up contour.hs.
julialongtin Dec 2, 2022
c3a5288
introduce join2EP, remove eToPPoint2 renaming it eToPP, and improve v…
julialongtin Dec 2, 2022
c4723d9
fix spacing and variable names.
julialongtin Dec 2, 2022
fd2fdca
move contourIntersectionCount into ContourIntersectionos.hs.
julialongtin Dec 2, 2022
f6fcb3e
move getPLine2Intersections into ContourIntersections.hs, and change …
julialongtin Dec 2, 2022
b273d82
make getLineContourIntersections use the ProjectiveLine2 Typeclass an…
julialongtin Dec 3, 2022
5da3264
one more use of the ProjectiveLine2 typeclass.
julialongtin Dec 3, 2022
96e8f84
split Ganja.hs random geometry components into RandomGeometry.hs
julialongtin Dec 3, 2022
4d06616
put functions in order.
julialongtin Dec 3, 2022
8a1ed0d
move getMotorcycleContourIntersections to ContourIntersections.hs
julialongtin Dec 3, 2022
b381baa
use outputIntersectsLineSeg directly, instead of wrapping it.
julialongtin Dec 3, 2022
13597e0
move getMotorcycleSegSetIntersections to contourInterseections.hs.
julialongtin Dec 3, 2022
b058235
move filterInntersections into ContourIntersections.hs.
julialongtin Dec 3, 2022
f512815
use concatMap.
julialongtin Dec 3, 2022
c453196
clean up LANGUAGE pragmas.
julialongtin Dec 3, 2022
d9dc2d7
add an instance for PPoint2, PPoint2Err, and simplify instances by us…
julialongtin Dec 3, 2022
7847362
reorder Intersections.
julialongtin Dec 4, 2022
c97a049
formatting changes, and make isParallel accept error quotents.
julialongtin Dec 4, 2022
9444ee9
make isAntiParallel accept error quotents, and change variable names.
julialongtin Dec 4, 2022
6a05cac
comment fixes and spacing changes.
julialongtin Dec 4, 2022
a5d962c
make intersectionBetween accept error components, and use the Project…
julialongtin Dec 4, 2022
871bcf0
add error quotent to both sides of the returned value from intersecti…
julialongtin Dec 4, 2022
ca1e35d
format clearer.
julialongtin Dec 6, 2022
a288743
comment cleanups.
julialongtin Dec 7, 2022
83903ae
add pointBetweenPoints, remove angleBetween.
julialongtin Dec 7, 2022
1fc3bf8
use linear pointBetweenPoints instead of projective pPointBetweenPoin…
julialongtin Dec 10, 2022
1f711d1
add intersectionBetweenArcsOf.
julialongtin Dec 10, 2022
3c44192
remove unnecessary canonicalization.
julialongtin Dec 10, 2022
75e8ce3
add outputIntersectsPLineAt, and use distance2PP to eliminate a usage…
julialongtin Dec 10, 2022
e8d437e
make intersectionSameSide accept canonicalized points, and error quot…
julialongtin Dec 10, 2022
2c385ba
make findINodes easier to read.
julialongtin Dec 10, 2022
6822b2a
make findINodes easier to read.
julialongtin Dec 11, 2022
c42353c
remove fudge factor, and add more error checking.
julialongtin Dec 11, 2022
4b153fc
remove eToCPPoint2, replacing it with the equivilent function eToPP.
julialongtin Dec 11, 2022
99b3d98
create translateRotatePPoint2.
julialongtin Dec 11, 2022
73d0854
remove unnecessary normalisation when generation random INodes, and e…
julialongtin Dec 11, 2022
8c6b5d2
simplify logic, and drop a few more unnecessary normalizations
julialongtin Dec 11, 2022
92a5f75
use concatMap instead of concat and <$>.
julialongtin Dec 13, 2022
6c2e718
create intersectionsAtSamePoint, and use it in the Pointable instance…
julialongtin Dec 15, 2022
44f4daa
formatting changes.
julialongtin Dec 16, 2022
5d40f25
add more performant EQ instances, and move unused Eq instances from t…
julialongtin Dec 17, 2022
421e99c
minor formatting change.
julialongtin Dec 17, 2022
4cb35cf
take error quotents into account when getting distances.
julialongtin Dec 17, 2022
2b3f4c0
make some loss more visible.
julialongtin Dec 17, 2022
918ae06
use intersectionsAtSamePoint in skeletonOfNodes, and formatting changes.
julialongtin Dec 17, 2022
1780e04
remove warnings, and move outputIntersetsLineSeg into Intersections.hs
julialongtin Dec 17, 2022
6506c96
better spacing, and a missing inlinable.
julialongtin Dec 18, 2022
66b98e5
rename distancePPointToPLineWithErr to distancePPToPL, and add a loss…
julialongtin Dec 18, 2022
20104ea
split averageNodes into averageNodes and safeAverageNodes.
julialongtin Dec 18, 2022
0e755f7
pass the original segment set through skepetonOfNodes, so we can gene…
julialongtin Dec 18, 2022
2e07211
use safeAverageNodes more, and change errorLen3 into being a string.
julialongtin Dec 19, 2022
8b18837
use errorLen3 in safeAverageNodes, and use filter and uncurry instead…
julialongtin Dec 19, 2022
a1c5f87
make shortest node finding easier to read.
julialongtin Dec 19, 2022
beb47c2
typo.
julialongtin Dec 19, 2022
653d62d
break ulpVal into ulpRaw and ulpVal, remove a LOT of realtofrac calls.
julialongtin Dec 21, 2022
308dae2
precision increases, and spacing fixes.
julialongtin Dec 22, 2022
8184c12
use Lossy functions better, and comment changes.
julialongtin Dec 24, 2022
8ebdd12
use isEmpty instead of len, and formatting changes.
julialongtin Dec 25, 2022
ce1e8eb
normalize comments.
julialongtin Dec 26, 2022
77bf640
use eToPLine2 instead of constructing it.
julialongtin Dec 26, 2022
ed40b55
eliminate eToNPLine2, use isEmpty instead of len, and use outAndErrOf.
julialongtin Dec 26, 2022
adad0ac
preserve error in translation result.
julialongtin Dec 26, 2022
cbc8be5
avoid some canonicalization.
julialongtin Dec 26, 2022
a40bc96
stop pretending some functions return anything but a CPPoint2. also, …
julialongtin Dec 28, 2022
64a774b
eliminate distanceBetweenPLines, and use the resErr from distance2PL …
julialongtin Dec 28, 2022
0a819c2
remove unused lossy version of getInsideArc.
julialongtin Dec 28, 2022
68b6001
remove unused join2CPPoint2
julialongtin Dec 28, 2022
4f43afb
remove unnecessary type casting.
julialongtin Dec 28, 2022
3c69e79
remove unnecessary normalization.
julialongtin Dec 28, 2022
d5427ca
remove lossy normalizePLine2.
julialongtin Dec 28, 2022
11dabe5
remove unused pLineFromEndpoints.
julialongtin Dec 28, 2022
88ecb6b
comment cleanups.
julialongtin Dec 29, 2022
c3964c6
rename errOfPPoint to errOfCPPoint.
julialongtin Dec 29, 2022
3bcb76e
formatting changes.
julialongtin Dec 30, 2022
a851060
raise the err amount of angle comparison, so that isCollinear operate…
julialongtin Jan 1, 2023
ca2852d
remove warnings.
julialongtin Jan 1, 2023
8d74dfc
fix intersect at origin test.
julialongtin Jan 1, 2023
f08ddef
make the whole node tree traversal system aware of error quotents, bu…
julialongtin Jan 1, 2023
ab3c4d4
add INLINABLE pragmas GHC requests.
julialongtin Jan 1, 2023
89944f5
sort better.
julialongtin Jan 1, 2023
4e659fd
remove some ID tests, and use startPoint/endPoint.
julialongtin Jan 1, 2023
af88dfb
add short circuits for Eq case of angleBetweenProjectiveLines, and di…
julialongtin Jan 2, 2023
c8b779a
use oppositeDirection rather than re-implementing it (poorly).
julialongtin Jan 2, 2023
509f426
remove three more manual implementations.
julialongtin Jan 2, 2023
299d765
remove more bad implementations of oppositeDirection.
julialongtin Jan 2, 2023
8edde5b
use ProjectivePoint2 more.
julialongtin Jan 2, 2023
34eadf8
INLINABLE, not INLINEABLE
julialongtin Jan 3, 2023
dfd5228
use Typeable to implement short circuits for distance, and join of po…
julialongtin Jan 3, 2023
b2972b4
make onSegment have a smaller hit box, make pLineIsLeft stop acceptin…
julialongtin Jan 10, 2023
0444b1f
add fuzzinessOfP when determining whether we can sufficiently resolve…
julialongtin Jan 14, 2023
a10795c
move pointsOfContour into Definitions.hs, so that Ganja.hs can be use…
julialongtin Jan 15, 2023
d99e33b
change module definition format.
julialongtin Jan 15, 2023
10450b8
move function order.
julialongtin Jan 15, 2023
4c89d20
export angleCosBetween2PL.
julialongtin Jan 15, 2023
e6c8961
use an outside point and a lineseg as close to perpendicular as possi…
julialongtin Jan 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 8 additions & 25 deletions Graphics/Slicer/Machine/Contour.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

module Graphics.Slicer.Machine.Contour (cleanContour, shrinkContour, expandContour) where

import Prelude (($), otherwise, Eq, (<>), show, error, (==), (&&), Bool(True, False), Show)
import Prelude (($), Eq((==)), (<>), (&&), Show(show), error, fst, not, otherwise)

import Data.List (null, foldl')

Expand All @@ -31,15 +31,15 @@ import Graphics.Slicer.Math.Contour (lineSegsOfContour, makeLineSegContour)

import Graphics.Slicer.Math.Definitions (Contour, LineSeg, mapWithNeighbors, makeLineSeg)

import Graphics.Slicer.Math.Intersections (noIntersection)
import Graphics.Slicer.Math.Intersections (noIntersection, intersectionOf)

import Graphics.Slicer.Math.Line (combineLineSegs)

import Graphics.Slicer.Math.Lossy (eToPLine2, translatePLine2)
import Graphics.Slicer.Math.Lossy (eToPLine2, pToEPoint2)

import Graphics.Slicer.Math.PGA (combineConsecutiveLineSegs, PIntersection(IntersectsIn), plinesIntersectIn, cPToEPoint2)
import Graphics.Slicer.Math.PGA (combineConsecutiveLineSegs, eToPL, translateL)

import Graphics.Slicer.Definitions(ℝ)
import Graphics.Slicer.Definitions (ℝ)

---------------------------------------------------------------
-------------------- Contour Optimizer ------------------------
Expand Down Expand Up @@ -101,29 +101,12 @@ modifyContour pathWidth contour direction
(Just (middleSegs,lastSeg)) -> middleSegs <> if noIntersection (inwardAdjust lastSeg) (inwardAdjust oneSeg)
then maybeToList (combineLineSegs lastSeg oneSeg)
else [lastSeg,oneSeg]
inwardAdjust l1 = translatePLine2 (eToPLine2 l1) (if direction == Inward then pathWidth else (-pathWidth))
inwardAdjust l1 = translateL (eToPLine2 l1) (if direction == Inward then pathWidth else (-pathWidth))
findLineSeg :: LineSeg -> LineSeg -> LineSeg -> Maybe LineSeg
findLineSeg previousln ln nextln
-- The ideal case.
| isIntersection previousln ln &&
isIntersection ln nextln = Just $ makeLineSeg (intersectionPoint (inwardAdjust previousln) (inwardAdjust ln)) (intersectionPoint (inwardAdjust ln) (inwardAdjust nextln))
isIntersection ln nextln = Just $ makeLineSeg (pToEPoint2 $ fst $ intersectionOf (inwardAdjust previousln) (inwardAdjust ln)) (pToEPoint2 $ fst $ intersectionOf (inwardAdjust ln) (inwardAdjust nextln))
| otherwise = error $ "no intersection?\n" <> show (isIntersection previousln ln) <> "\n" <> show (isIntersection ln nextln) <> "\n" <> show previousln <> "\n" <> show ln <> "\n" <> show nextln <> "\n"
where
isIntersection l1 l2 = case plinesIntersectIn (inwardAdjust l1) (inwardAdjust l2) of
IntersectsIn _ _ -> True
_other -> False
intersectionPoint pl1 pl2 = case plinesIntersectIn pl1 pl2 of
IntersectsIn p2 _ -> cPToEPoint2 p2
a -> error $ "impossible result!\nresult: " <> show a <> "\npline 1: " <> show pl1
<> "\npline 2: " <> show pl2
<> "\nEvaluating line intersections between:\nFirst: " <> show previousln
<> "\nSecond: " <> show ln
<> "\nThird: " <> show nextln <> "\n"<> show (inwardAdjust previousln)
<> "\n" <> show (eToPLine2 previousln)
<> "\n" <> show (inwardAdjust ln)
<> "\n" <> show (eToPLine2 ln)
<> "\n" <> show (inwardAdjust nextln)
<> "\n" <> show (eToPLine2 nextln)
<> "\n" <> show direction
<> "\n" <> show contour
<> "\n"
isIntersection l1 l2 = not $ noIntersection (eToPL l1) (eToPL l2)
17 changes: 9 additions & 8 deletions Graphics/Slicer/Machine/GCode.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module Graphics.Slicer.Machine.GCode (GCode(GCMarkOuterWallStart, GCMarkInnerWal

import GHC.Generics (Generic)

import Prelude (Eq, Int, Rational, Show, ($), zipWith, concat, (<>), show, error, otherwise, (==), length, fst, pi, (/), (*), pure, toRational, fromRational, (+), div, Bool, snd)
import Prelude (Bool, Eq, Int, Rational, Show, ($), (<>), (==), (/), (*), (+), concat, div, error, fromRational, fst, head, length, otherwise, pi, pure, show, snd, tail, toRational, zipWith)

import Data.ByteString (ByteString)

Expand All @@ -50,9 +50,9 @@ import Control.DeepSeq (NFData)

import Graphics.Slicer.Definitions(ℝ, ℝ2, ℝ3, ℕ, Fastℕ, fromFastℕ)

import Graphics.Slicer.Math.Contour (pointsOfContour, lastPointOfContour)
import Graphics.Slicer.Math.Contour (lastPointOfContour)

import Graphics.Slicer.Math.Definitions (Point3(Point3), Point2(Point2), Contour, LineSeg(LineSeg), distance, endPoint, roundToFifth)
import Graphics.Slicer.Math.Definitions (Point3(Point3), Point2(Point2), Contour, LineSeg(LineSeg), distance, endPoint, pointsOfContour, roundToFifth)

import Graphics.Slicer.Math.Slicer (accumulateValues)

Expand Down Expand Up @@ -205,11 +205,12 @@ gcodeForContour lh pathWidth feedRate contour = addFeedRate feedRate headRes : t
-- | For each group of lines, generate gcode for the segments, with move commands between them.
gcodeForInfill :: ℝ -> ℝ -> ℝ -> ℝ -> [[LineSeg]] -> [GCode]
gcodeForInfill _ _ _ _ [] = []
gcodeForInfill lh pathWidth infillFeedRate travelFeedRate lineGroups =
case lineGroups of
[] -> []
(headGroup:tailGroups) -> concat $ renderLineSegGroup headGroup : zipWith (\group1 group2 -> moveBetweenLineSegGroups group1 group2 <> renderLineSegGroup group2) lineGroups tailGroups
gcodeForInfill lh pathWidth infillFeedRate travelFeedRate lineGroups
| lineGroups == [] = []
| lineGroups == [[]] = []
| otherwise = concat $ renderLineSegGroup headGroup : zipWith (\group1 group2 -> moveBetweenLineSegGroups group1 group2 <> renderLineSegGroup group2) lineGroups tailGroups
where
(headGroup, tailGroups) = (head lineGroups, tail lineGroups)
-- FIXME: this should be a single gcode. why are we getting empty line groups given to us?
moveBetweenLineSegGroups :: [LineSeg] -> [LineSeg] -> [GCode]
moveBetweenLineSegGroups g1 g2 = case unsnoc g1 of
Expand All @@ -220,7 +221,7 @@ gcodeForInfill lh pathWidth infillFeedRate travelFeedRate lineGroups =
renderLineSegGroup :: [LineSeg] -> [GCode]
renderLineSegGroup lineSegSet = case lineSegSet of
[] -> []
(headGroup:tailGroups) -> renderSegment headGroup : concat (zipWith (\ l1 l2 -> moveBetween l1 l2 : [renderSegment l2]) lineSegSet tailGroups)
(myHeadGroup:myTailGroups) -> renderSegment myHeadGroup : concat (zipWith (\ l1 l2 -> moveBetween l1 l2 : [renderSegment l2]) lineSegSet myTailGroups)
moveBetween :: LineSeg -> LineSeg -> GCode
moveBetween l1 (LineSeg startPointl2 _) = addFeedRate travelFeedRate $ make2DTravelGCode (endPoint l1) startPointl2
renderSegment :: LineSeg -> GCode
Expand Down
44 changes: 22 additions & 22 deletions Graphics/Slicer/Machine/Infill.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@

module Graphics.Slicer.Machine.Infill (makeInfill, InfillType(Diag1, Diag2, Vert, Horiz), infillLineSegInside, coveringPLinesVertical) where

import Prelude ((+), (<$>), ($), (.), (*), sqrt, (-), Ordering(EQ, GT, LT), otherwise, (==), length, concat, not, null, (!!), fromIntegral, ceiling, (/), floor, Integer, compare)
import Prelude ((+), (<$>), ($), (.), (*), sqrt, (-), Ordering(EQ, GT, LT), otherwise, (==), length, not, null, (!!), fromIntegral, ceiling, (/), floor, Integer, compare)

import Data.List (concatMap)

import Data.List.Ordered (sort)

import Data.Maybe (Maybe(Just, Nothing), catMaybes)
import Data.Maybe (Maybe(Just, Nothing), mapMaybe)

import Graphics.Slicer.Definitions (ℝ)

import Graphics.Slicer.Math.Definitions (Point2(Point2), Contour, LineSeg, addPoints, distance, makeLineSeg, minMaxPoints, xOf, yOf, roundToFifth)
import Graphics.Slicer.Math.Definitions (Point2(Point2), Contour, LineSeg, addPoints, distance, minMaxPoints, xOf, yOf, roundToFifth)

import Graphics.Slicer.Math.Intersections (getPLine2Intersections)
import Graphics.Slicer.Math.ContourIntersections (getLineContourIntersections)

import Graphics.Slicer.Math.Line (makeLineSegs)

import Graphics.Slicer.Math.Lossy (eToPLine2)

import Graphics.Slicer.Math.PGA (PLine2)
import Graphics.Slicer.Math.PGA (PLine2, PLine2Err, ProjectiveLine2, join2EP)

-- | what direction to put down infill lines.
data InfillType = Diag1 | Diag2 | Vert | Horiz
Expand All @@ -48,33 +48,33 @@ data InfillType = Diag1 | Diag2 | Vert | Horiz
-- Basically, cover the build plane in lines, then remove the portions of those lines that are not inside of the target contour.
-- The target contour should be pre-shrunk to the innermost parameter, and the target inside contours should also be the outermost parameters.
makeInfill :: Contour -> [Contour] -> ℝ -> InfillType -> [[LineSeg]]
makeInfill contour insideContours ls layerType = catMaybes $ infillLineSegInside contour insideContours <$> infillCover layerType
makeInfill contour insideContours ls layerType = mapMaybe (infillLineSegInside contour insideContours) $ infillCover layerType
where
infillCover Vert = coveringPLinesVertical contour ls
infillCover Horiz = coveringPLinesHorizontal contour ls
infillCover Diag1 = coveringPLinesPositive contour ls
infillCover Diag2 = coveringPLinesNegative contour ls

-- Get the segments of an infill line that are inside of a contour, skipping space occluded by any of the child contours.
infillLineSegInside :: Contour -> [Contour] -> PLine2 -> Maybe [LineSeg]
infillLineSegInside :: (ProjectiveLine2 a) => Contour -> [Contour] -> (a, PLine2Err) -> Maybe [LineSeg]
infillLineSegInside contour childContours line
| not (null allLines) = Just $ (allLines !!) <$> [0,2..length allLines - 1]
| otherwise = Nothing
where
allLines :: [LineSeg]
allLines = makeLineSegs allPoints
where
allPoints = filterTooShort . sort . concat $ getPLine2Intersections line <$> contour:childContours
allPoints = (filterTooShort . sort) $ concatMap (getLineContourIntersections line) (contour:childContours)
filterTooShort :: [Point2] -> [Point2]
filterTooShort [] = []
filterTooShort [a] = [a]
filterTooShort (a:b:xs) = if roundToFifth (distance a b) == 0 then filterTooShort xs else a:filterTooShort (b:xs)

-- Generate lines covering the entire contour, where each one is aligned with a +1 slope, which is to say, lines parallel to a line where x = y.
coveringPLinesPositive :: Contour -> ℝ -> [PLine2]
coveringPLinesPositive contour ls = eToPLine2 . makeSeg <$> [0,lss..(xMax-xMinRaw)+(yMax-yMin)+lss]
coveringPLinesPositive :: Contour -> ℝ -> [(PLine2, PLine2Err)]
coveringPLinesPositive contour ls = makeLine <$> [0,lss..(xMax-xMinRaw)+(yMax-yMin)+lss]
where
makeSeg a = makeLineSeg (f a) $ addPoints (f a) slope
makeLine a = join2EP (f a) $ addPoints (f a) slope
(minPoint, maxPoint) = minMaxPoints contour
slope = Point2 (1,1)
f v = Point2 (v-xDiff,0)
Expand All @@ -91,10 +91,10 @@ coveringPLinesPositive contour ls = eToPLine2 . makeSeg <$> [0,lss..(xMax-xMinRa
lss = sqrt $ ls*ls+ls*ls

-- Generate lines covering the entire contour, where each one is aligned with a -1 slope, which is to say, lines parallel to a line where x = -y.
coveringPLinesNegative :: Contour -> ℝ -> [PLine2]
coveringPLinesNegative contour ls = eToPLine2 . makeSeg <$> [0,lss..(xMax-xMin)+(yMax-yMin)+lss]
coveringPLinesNegative :: Contour -> ℝ -> [(PLine2, PLine2Err)]
coveringPLinesNegative contour ls = makeLine <$> [0,lss..(xMax-xMin)+(yMax-yMin)+lss]
where
makeSeg a = makeLineSeg (f a) $ addPoints (f a) slope
makeLine a = join2EP (f a) $ addPoints (f a) slope
(minPoint, maxPoint) = minMaxPoints contour
slope = Point2 (1,-1)
f v = Point2 (v+yDiff,0)
Expand All @@ -111,10 +111,10 @@ coveringPLinesNegative contour ls = eToPLine2 . makeSeg <$> [0,lss..(xMax-xMin)+
lss = sqrt $ ls*ls+ls*ls

-- Generate lines covering the entire contour, where each line is aligned with the Y axis, which is to say, parallel to the Y basis vector.
coveringPLinesVertical :: Contour -> ℝ -> [PLine2]
coveringPLinesVertical contour ls = eToPLine2 . makeSeg <$> [xMin,xMin+ls..xMax]
coveringPLinesVertical :: Contour -> ℝ -> [(PLine2, PLine2Err)]
coveringPLinesVertical contour ls = makeLine <$> [xMin,xMin+ls..xMax]
where
makeSeg a = makeLineSeg (f a) $ addPoints (f a) slope
makeLine a = join2EP (f a) $ addPoints (f a) slope
(minPoint, maxPoint) = minMaxPoints contour
slope = Point2 (0,1)
f v = Point2 (v,0)
Expand All @@ -126,10 +126,10 @@ coveringPLinesVertical contour ls = eToPLine2 . makeSeg <$> [xMin,xMin+ls..xMax]
xMax = xOf maxPoint

-- Generate lines covering the entire contour, where each line is aligned with the X axis, which is to say, parallel to the X basis vector.
coveringPLinesHorizontal :: Contour -> ℝ -> [PLine2]
coveringPLinesHorizontal contour ls = eToPLine2 . makeSeg <$> [yMin,yMin+ls..yMax]
coveringPLinesHorizontal :: Contour -> ℝ -> [(PLine2, PLine2Err)]
coveringPLinesHorizontal contour ls = makeLine <$> [yMin,yMin+ls..yMax]
where
makeSeg a = makeLineSeg (f a) $ addPoints (f a) slope
makeLine a = join2EP (f a) $ addPoints (f a) slope
(minPoint, maxPoint) = minMaxPoints contour
slope = Point2 (1,0)
f v = Point2 (0,v)
Expand Down
Loading