/** This file is part of Shapes. ** ** Shapes is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** any later version. ** ** Shapes is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** ** You should have received a copy of the GNU General Public License ** along with Shapes. If not, see . ** ** Copyright 2008, 2010, 2013, 2014 Henrik Tidefelt **/ ##needs ..Shapes..Geometry / linkpaths ##needs ..Shapes..Data / seq-support ##lookin ..Shapes ##lookin ..Shapes..Geometry /** The mergepaths function turned out difficult to implement since the subpath function ** does not return the control point at the free end of the cut (this is often a desirable ** behavior). Instead the function meetpaths was added to the kernel. **/ |**pathpoint: \ p t → |** (+[reversespeed p t]*[reversedirection p t])< |** [point p t] |** >(+[speed p t]*[direction p t]) |** |**mergepaths: \ p1 p2 → |** [if [Geometry..duration p1]>1 |** { t:([Geometry..duration p1]-1) [subpath p1 0 t]>(+[speed p1 t]*[direction p1 t]) } |** [pathpoint p1 0]] |** -- |** (+[reversespeed p1 ∞]*[reversedirection p1 ∞])< |** ( 0.5 * ( [point p1 ∞] + [point p2 0] ) ) |** >(+[speed p2 0]*[direction p2 0]) |** -- |** [if [Geometry..duration p2]>1 |** (+[reversespeed p 1]*[reversedirection p 1])<[subpath p2 1 ∞] |** [pathpoint p2 ∞]] Geometry..@defaultunit: 1%c | { pth1: (~1cm,0cm)--(^)<(0cm,0cm)>(1cm,1cm)--(2cm,3cm)<(4cm,4cm)>(^) pth2: (^)<(5cm,4cm)>(5cm,5cm)--(1cm^180°)<(7cm,3cm)>(^)--(7cm,2cm) Traits..@stroking:[Traits..gray 0.7] | { IO..•page << [Graphics..stroke pth1] IO..•page << [Graphics..stroke pth2] } IO..•page << [Graphics..stroke [Geometry..meetpaths pth1 pth2]] } Geometry..@defaultunit: 1%c | { pth1: (0cm,~3cm)>(2cm^70°)--(5cm,5cm) pth2: (3cm,~2cm)>(2cm^140°)--(0cm,4cm) Traits..@stroking:[Traits..gray 0.7] | { IO..•page << [Graphics..stroke pth1] << [Graphics..stroke pth2] } IO..•page << [Graphics..stroke [Geometry..linkpaths pth1 pth2]] } { subpath: \ pth t1 t2 → [pth t1]--[pth t2] seg: \ a → [shift (5cm,0)]*[rotate a]*[shift (0,~1.2cm)] [] [Geometry..reverse [subpath [Geometry..circle 1cm] 0 1.5]] c1: [seg 0°] c2: [seg 90°] c3: [seg 180°] c4: [seg 270°] IO..•page << [Graphics..stroke c1] pths: [Data..list c1 c2 c3 c4] IO..•page << [pths.foldl \ p e → p & [Graphics..stroke e] Graphics..null] scaleAroundCenter: \ factor pth → { c: [Geometry..mean pth] [shift c]*[scale factor]*[shift ~c] [] pth } IO..•page << Traits..@stroking: Traits..RGB..RED | [Graphics..stroke [scaleAroundCenter 1.3 ...][] [Geometry..buildchain pths]--cycle] }