PenroseKiteDart-1.3: Library to explore Penrose's Kite and Dart Tilings.
Copyright(c) Chris Reade 2024
LicenseBSD-style
Maintainerchrisreade@mac.com
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

PKD

Description

This is the main module to re-export both Tgraphs and TileLib (which includes Halftile) modules. However it does not export the data constructor Forced (only the newtype operator). There is a warning about using makeUncheckedTgraph.

Synopsis

Documentation

data EdgeType Source #

type used to classify edges of faces

Constructors

Short 
Long 
Join 

Instances

Instances details
Show EdgeType Source # 
Instance details

Defined in Tgraph.Prelude

Eq EdgeType Source # 
Instance details

Defined in Tgraph.Prelude

decompose :: Tgraph -> Tgraph Source #

Decompose a Tgraph.

compose :: Tgraph -> Tgraph Source #

The main compose (partial) function which simply drops the remainder faces from partCompose to return just the composed Tgraph. It will raise an error if the result is not a valid Tgraph (i.e. if it fails the connectedness, no crossing boundary check). It does not assume the given Tgraph is forced.

type Vertex = Int Source #

Tgraph vertex labels (must be positive)

force :: Forcible a => a -> a Source #

The main force (partial) function using defaultAllUGen representing all 10 rules for updates. This raises an error on discovering a stuck/incorrect Forcible.

data Forced a Source #

Forced a explicitly indicates that a is Forced. This is to enable restricting some functions which are only total on a Forced forcible. (Similar to the way Data.List.NonEmpty is used to explicitly indicate a non-empty list)

To access the forcible use: forgetF :: Forced a -> a

Create using forceF or tryForceF

Instances

Instances details
Functor Forced Source # 
Instance details

Defined in Tgraph.Force

Methods

fmap :: (a -> b) -> Forced a -> Forced b #

(<$) :: a -> Forced b -> Forced a #

Show a => Show (Forced a) Source # 
Instance details

Defined in Tgraph.Force

Methods

showsPrec :: Int -> Forced a -> ShowS #

show :: Forced a -> String #

showList :: [Forced a] -> ShowS #

data HalfTile rep Source #

Representing Half Tile Pieces Polymorphicly. Common code for both graphs and vector representations of tilings. For Pieces - rep is V2 Double For TileFaces (in Tgraphs) rep is (Vertex,Vertex,Vertex)

Constructors

LD !rep

Left Dart

RD !rep

Right Dart

LK !rep

Left Kite

RK !rep

Right Kite

Instances

Instances details
Drawable Patch Source #

Patches are drawable

Instance details

Defined in TileLib

Methods

drawWith :: OKBackend b => (Piece -> Diagram b) -> Patch -> Diagram b Source #

Functor HalfTile Source #

Make Halftile a Functor

Instance details

Defined in HalfTile

Methods

fmap :: (a -> b) -> HalfTile a -> HalfTile b #

(<$) :: a -> HalfTile b -> HalfTile a #

Show rep => Show (HalfTile rep) Source # 
Instance details

Defined in HalfTile

Methods

showsPrec :: Int -> HalfTile rep -> ShowS #

show :: HalfTile rep -> String #

showList :: [HalfTile rep] -> ShowS #

Transformable a => Transformable (HalfTile a) Source #

HalfTile inherits Transformable - Requires FlexibleInstances

Instance details

Defined in HalfTile

Methods

transform :: Transformation (V (HalfTile a)) (N (HalfTile a)) -> HalfTile a -> HalfTile a #

Eq rep => Eq (HalfTile rep) Source # 
Instance details

Defined in HalfTile

Methods

(==) :: HalfTile rep -> HalfTile rep -> Bool #

(/=) :: HalfTile rep -> HalfTile rep -> Bool #

Ord rep => Ord (HalfTile rep) Source #

Note this ignores the tileLabels when comparing. However we should never have 2 different HalfTiles with the same rep

Instance details

Defined in HalfTile

Methods

compare :: HalfTile rep -> HalfTile rep -> Ordering #

(<) :: HalfTile rep -> HalfTile rep -> Bool #

(<=) :: HalfTile rep -> HalfTile rep -> Bool #

(>) :: HalfTile rep -> HalfTile rep -> Bool #

(>=) :: HalfTile rep -> HalfTile rep -> Bool #

max :: HalfTile rep -> HalfTile rep -> HalfTile rep #

min :: HalfTile rep -> HalfTile rep -> HalfTile rep #

type N (HalfTile a) Source #

Needed for Transformable instance of HalfTile - requires TypeFamilies

Instance details

Defined in HalfTile

type N (HalfTile a) = N a
type V (HalfTile a) Source #

Needed for Transformable instance of HalfTile - requires TypeFamilies

Instance details

Defined in HalfTile

type V (HalfTile a) = V a

tileRep :: HalfTile rep -> rep Source #

return the representation of a half-tile

isLD :: HalfTile rep -> Bool Source #

half-tile predicate

isRD :: HalfTile rep -> Bool Source #

half-tile predicate

isLK :: HalfTile rep -> Bool Source #

half-tile predicate

isRK :: HalfTile rep -> Bool Source #

half-tile predicate

isDart :: HalfTile rep -> Bool Source #

half-tile predicate

isKite :: HalfTile rep -> Bool Source #

half-tile predicate

type HalfTileLabel = HalfTile () Source #

By having () as the half tile representation we treat the constructors as just labels

tileLabel :: HalfTile a -> HalfTileLabel Source #

convert a half tile to its label (HalfTileLabel can be compared for equality)

isMatched :: HalfTile rep1 -> HalfTile rep2 -> Bool Source #

isMatched t1 t2 is True if t1 and t2 have the same HalfTileLabel (i.e. use the same constructor - both LD or both RD or both LK or both RK)

type Try a = Either String a Source #

Try is a synonym for Either String. Used for results of partial functions which return either Right something when defined or Left string when there is a problem where string is a failure report. Note: Either String (and hence Try) is a monad, and this is used frequently for combining partial operations.

onFail :: String -> Try a -> Try a Source #

onFail s exp - inserts s at the front of failure report if exp fails with Left report but does nothing otherwise.

nothingFail :: Maybe b -> String -> Try b Source #

nothingFail a s - Converts a Maybe Result (a) into a Try result by treating Nothing as a failure (the string s is the failure report on failure). Usually used as infix (exp nothingFail s)

runTry :: Try a -> a Source #

Extract the (Right) result from a Try, producing an error if the Try is Left s. The failure report (s) is passed to error for an error report.

ifFail :: a -> Try a -> a Source #

ifFail a tr - extracts the (Right) result from tr but returning a if tr is Left s.

isFail :: Try a -> Bool Source #

a try result is a failure if it is a Left

concatFails :: [Try a] -> Try [a] Source #

Combines a list of Trys into a single Try with failure overriding success. It concatenates all failure reports if there are any and returns a single Left r. Otherwise it produces Right rs where rs is the list of all (successful) results. In particular, concatFails [] = Right [] (so is NOT a fail)

ignoreFails :: [Try a] -> [a] Source #

Combines a list of Trys into a list of the successes, ignoring any failures. In particular, ignoreFails [] = []

atLeastOne :: [Try a] -> [a] Source #

atLeastOne rs - returns the list of successful results if there are any, but fails with an error otherwise. The error report will include the concatenated reports from the failures.

smart :: OKBackend b => (VPatch -> Diagram b) -> Tgraph -> Diagram b Source #

smart dr g - uses VPatch drawing function dr after converting g to a VPatch It will add boundary joins regardless of the drawing function. Examples:

smart draw g

smart (labelled draw) g

smart (labelSize normal draw) g

boundaryJoinFaces :: Tgraph -> [TileFace] Source #

select the halftile faces of a Tgraph with a join edge on the boundary. Useful for drawing join edges only on the boundary.

drawBoundaryJoins :: OKBackend b => Tgraph -> VPatch -> Diagram b Source #

draw boundary join edges of a Tgraph using a given VPatch

drawJoinsFor :: OKBackend b => [TileFace] -> VPatch -> Diagram b Source #

Given a list of faces and a VPatch with suitable locations, draw just the dashed joins for those faces. Will raise an error if any vertex in the faces does not have a location in the VPatch.

smartdraw :: OKBackend b => Tgraph -> Diagram b Source #

same as draw except adding dashed lines on boundary join edges.

restrictSmart :: OKBackend b => Tgraph -> (VPatch -> Diagram b) -> VPatch -> Diagram b Source #

restrictSmart g dr vp - assumes vp has locations for vertices in g. It uses the VPatch drawing function dr to draw g and adds dashed boundary joins. This can be used instead of smart when an appropriate vp is already available.

smartRotateBefore :: OKBackend b => (VPatch -> Diagram b) -> Angle Double -> Tgraph -> Diagram b Source #

smartRotateBefore vfun a g - a tricky combination of smart with rotateBefore. Uses vfun to produce a Diagram after converting g to a rotated VPatch but also adds the dashed boundary join edges of g.

Example: smartRotateBefore (labelled draw) angle g

smartAlignBefore :: OKBackend b => (VPatch -> Diagram b) -> (Vertex, Vertex) -> Tgraph -> Diagram b Source #

smartAlignBefore vfun (a,b) g - a tricky combination of smart with alignBefore. Uses vfun to produce a Diagram after converting g to an aligned VPatch but also adds the dashed boundary join edges of g.

Example: smartAlignBefore (labelled draw) (a,b) g

drawPCompose :: OKBackend b => Tgraph -> Diagram b Source #

applies partCompose to a Tgraph g, then draws the composed graph with the remainder faces (in lime). (Relies on the vertices of the composition and remainder being subsets of the vertices of g.)

drawForce :: OKBackend b => Tgraph -> Diagram b Source #

drawForce g is a diagram showing the argument g in red overlayed on force g It adds dashed join edges on the boundary of g

drawSuperForce :: OKBackend b => Tgraph -> Diagram b Source #

drawSuperForce g is a diagram showing the argument g in red overlayed on force g in black overlaid on superForce g in blue. It adds dashed join edges on the boundary of g.

drawWithMax :: OKBackend b => Tgraph -> Diagram b Source #

drawWithMax g - draws g and overlays the maximal composition of force g in red. This relies on g and all compositions of force g having vertices in force g.

addBoundaryAfter :: OKBackend b => (VPatch -> Diagram b) -> Tgraph -> Diagram b Source #

addBoundaryAfter f g - displaying the boundary of a Tgraph g in lime (overlaid on g drawn with f).

drawCommonFaces :: OKBackend b => (Tgraph, Dedge) -> (Tgraph, Dedge) -> Diagram b Source #

drawCommonFaces (g1,e1) (g2,e2) uses commonFaces (g1,e1) (g2,e2) to find the common faces and emphasizes them on the background g1.

emphasizeFaces :: OKBackend b => [TileFace] -> Tgraph -> Diagram b Source #

emphasizeFaces fcs g emphasizes the given faces (that are in g) overlaid on the background draw g.

composeK :: Tgraph -> Tgraph Source #

An unsound version of composition which defaults to kites when there are choices (unknowns). This is unsound in that it can create an incorrect Tgraph from a correct Tgraph.

compForce :: Tgraph -> Forced Tgraph Source #

compForce is a partial function similar to (compose . force), i.e it does a force then compose (raising an error if the force fails with an incorrect Tgraph). However it produces an explicitly Forced Tgraph, and is more efficient because it omits the check for connected, and no crossing boundaries (and uses getDartWingInfoForced instead of getDartWingInfo) This relies on a proof that composition does not need to be checked for a forced Tgraph. (We also have a proof that the result must be a forced Tgraph when the initial force succeeds.)

allCompForce :: Tgraph -> [Forced Tgraph] Source #

allCompForce g produces a list of the non-null iterated (forced) compositions of force g. It will raise an error if the initial force fails with an incorrect Tgraph. The list will be [] if g is the emptyTgraph, otherwise the list begins with force g (when the force succeeds). The definition relies on (1) a proof that the composition of a forced Tgraph is forced and (2) a proof that composition does not need to be checked for a forced Tgraph.

maxCompForce :: Tgraph -> Forced Tgraph Source #

maxCompForce g produces the maximally composed (non-null) Tgraph starting from force g, provided g is not the emptyTgraph and just the emptyTgraph otherwise. It will raise an error if the initial force fails with an incorrect Tgraph.

allForceDecomps :: Tgraph -> [Tgraph] Source #

allForceDecomps g - produces an infinite list (starting with g) of forced decompositions of g (raising an error if a force fails with an incorrect Tgraph).

forcedBoundaryECovering :: Tgraph -> [Forced Tgraph] Source #

forcedBoundaryECovering g - produces a list of all boundary covers of force g, each of which extends force g to cover the entire boundary directed edges in (force g). (So the boundary of force g is entirely internal edges in each cover). The covers include all possible ways faces can be added on the boundary that are correct. The common faces of the covers constitute the empire (level 1) of g. This will raise an error if the initial force fails with a stuck graph.

forcedBoundaryVCovering :: Tgraph -> [Forced Tgraph] Source #

forcedBoundaryVCovering g - produces a list of all boundary covers of force g as with forcedBoundaryECovering g but covering all boundary vertices rather than just boundary edges. This will raise an error if the initial force fails with a stuck graph.

boundaryECovering :: Forced BoundaryState -> [Forced BoundaryState] Source #

boundaryECovering - for an explicitly Forced BoundaryState fbd, produces a list of all possible covers of the boundary directed edges in fbd. A cover is an explicitly Forced extension (of fbd) such that the original boundary directed edges of fbd are all internal edges. Extensions are made by repeatedly adding a face to any edge on the original boundary that is still on the boundary and forcing, repeating this until the orignal boundary is all internal edges. The resulting covers account for all possible ways the boundary can be extended. This can raise an error if both choices on a boundary edge fail when forced (using atLeastOne).

boundaryEdgeSet :: BoundaryState -> Set Dedge Source #

Make a set of the directed boundary edges of a BoundaryState

commonBdry :: Set Dedge -> BoundaryState -> Set Dedge Source #

commonBdry des b - returns those directed edges in des that are boundary directed edges of bd

boundaryVCovering :: Forced BoundaryState -> [Forced BoundaryState] Source #

boundaryVCovering fbd - similar to boundaryECovering, but produces a list of all possible covers of the boundary vertices in fbd (rather than just boundary edges). This can raise an error if both choices on a boundary edge fail when forced (using atLeastOne).

boundaryVertexSet :: BoundaryState -> VertexSet Source #

returns the set of boundary vertices of a BoundaryState

internalVertexSet :: BoundaryState -> VertexSet Source #

returns the set of internal vertices of a BoundaryState

tryDartAndKiteForced :: Forcible a => Dedge -> a -> [Try a] Source #

tryDartAndKiteForced de b - returns the list of (2) results after adding a dart (respectively kite) to edge de of a Forcible b and then tries forcing. Each of the results is a Try.

tryDartAndKite :: Forcible a => Dedge -> a -> [Try a] Source #

tryDartAndKite de b - returns the list of (2) results after adding a dart (respectively kite) to edge de of a Forcible b. Each of the results is a Try.

drawFBCovering :: OKBackend b => Tgraph -> Diagram b Source #

test function to draw a column of the list of graphs resulting from forcedBoundaryVCovering g.

empire1 :: Tgraph -> TrackedTgraph Source #

empire1 g - produces a TrackedTgraph representing the level 1 empire of g. Raises an error if force g fails with a stuck/incorrect Tgraph. The tgraph of the result is the first boundary vertex cover of force g, and the tracked list of the result has the common faces of all the boundary vertex covers (of force g) at the head, followed by the original faces of g.

empire2 :: Tgraph -> TrackedTgraph Source #

empire2 g - produces a TrackedTgraph representing the level 2 empire of g. Raises an error if force g fails with a stuck/incorrect Tgraph. NB since very large graphs can be generated with boundary vertex covers, we use boundary edge covers only. That is, after finding all boundary edge covers of force g, boundary edge covers are then found for each boundary edge cover to form a list of doubly-extended boundary edge covers. The tgraph of the result is the first (doubly-extended) boundary edge cover (of force g), and the tracked list of the result has the common faces of all the (doubly-extended) boundary edge covers at the head, followed by the original faces of g.

empire2Plus :: Tgraph -> TrackedTgraph Source #

empire2Plus g - produces a TrackedTgraph representing an extended level 2 empire of g similar to empire2, but using boundaryVCovering instead of boundaryECovering. Raises an error if force g fails with a stuck/incorrect Tgraph.

drawEmpire :: OKBackend b => TrackedTgraph -> Diagram b Source #

drawEmpire e - produces a diagram for an empire e represented as a TrackedTgraph as calcultaed by e.g. empire1 or empire2 or empire2Plus. The diagram draws the underlying Tgraph, with the first tracked faces - the starting Tgraph shown red, and emphasising the second tracked faces - the common faces.

showEmpire1 :: OKBackend b => Tgraph -> Diagram b Source #

showEmpire1 g - produces a diagram emphasising the common faces of all boundary covers of force g. This is drawn over one of the possible boundary covers and the faces of g are shown in red.

showEmpire2 :: OKBackend b => Tgraph -> Diagram b Source #

showEmpire2 g - produces a diagram emphasising the common faces of a doubly-extended boundary cover of force g. This is drawn over one of the possible doubly-extended boundary covers and the faces of g are shown in red.

superForce :: Forcible a => a -> a Source #

superForce g - after forcing g this looks for single choice boundary edges. That is a boundary edge for which only a dart or only a kite addition occurs in all boundary edge covers. If there is at least one such edge, it makes the choice for the first such edge and recurses, otherwise it returns the forced result. This will raise an error if force encounters a stuck (incorrect) tiling or if both forced extensions fail for some boundary edge. Otherwise, the result has exactly two correct possible extensions for each boundary edge.

trySuperForce :: Forcible a => a -> Try a Source #

trySuperForce g - this looks for single choice edges after trying to force g. If there is at least one, it makes that choice and recurses. It returns a Left s if force fails or if both choices fail for some edge (where s is a failure report). Otherwise Right g' is returned where g' is the super forced g.

singleChoiceEdges :: Forced BoundaryState -> [(Dedge, HalfTileLabel)] Source #

singleChoiceEdges bd - if bd is an explicitly Forced boundary state (of a forced Tgraph) this finds those boundary edges of bd which have a single choice (i.e. the other choice is incorrect), by inspecting boundary edge covers of bd. The result is a list of pairs of (edge,label) where edge is a boundary edge with a single choice and label indicates the choice as the common face label.

tryBoundaryFaceGraph :: Tgraph -> Try Tgraph Source #

Tries to create a new Tgraph from all faces with a boundary vertex in a Tgraph. The resulting faces could have a crossing boundary and also could be disconnected if there is a hole in the starting Tgraph so these conditions are checked for, producing a Try result.

boundaryLoopsG :: Tgraph -> [[Vertex]] Source #

Returns a list of (looping) vertex trails for the boundary of a Tgraph. There will usually be a single trail, but more than one indicates the presence of boundaries round holes. Each trail starts with the lowest numbered vertex in that trail, and ends with the same vertex. The trails will have disjoint sets of vertices because of the no-crossing-boundaries condition of Tgraphs.

boundaryLoops :: BoundaryState -> [[Vertex]] Source #

Returns a list of (looping) vertex trails for a BoundaryState. There will usually be a single trail, but more than one indicates the presence of boundaries round holes. Each trail starts with the lowest numbered vertex in that trail, and ends with the same vertex. The trails will have disjoint sets of vertices because of the no-crossing-boundaries condition of Tgraphs (and hence BoundaryStates).

findLoops :: [Dedge] -> [[Vertex]] Source #

When applied to a boundary edge list this returns a list of (looping) vertex trails. I.e. if we follow the boundary edges of a Tgraph recording vertices visited as a list returning to the starting vertex we get a looping trail. There will usually be a single trail, but more than one indicates the presence of boundaries round holes. Each trail starts with the lowest numbered vertex in that trail, and ends with the same vertex.

pathFromBoundaryLoops :: VertexLocMap -> [[Vertex]] -> Path V2 Double Source #

Given a suitable vertex to location map and boundary loops (represented as a list of lists of vertices), this will return a (Diagrams) Path for the boundary. It will raise an error if any vertex listed is not a map key. (The resulting path can be filled when converted to a diagram.)

data TrackedTgraph Source #

TrackedTgraph - introduced to allow tracking of subsets of faces in both force and decompose operations. Mainly used for drawing purposes but also for empires. A TrackedTgraph has a main Tgraph (tgraph) and a list of subsets (sublists) of faces (tracked). The list allows for tracking different subsets of faces at the same time.

Constructors

TrackedTgraph 

Fields

data Tgraph Source #

A Tgraph is a list of faces (TileFaces). All vertex labels should be positive, so 0 is not used as a vertex label. Tgraphs should be constructed with makeTgraph or checkedTgraph to check required properties. The data constructor Tgraph is not exported (but see also makeUncheckedTgraph).

Instances

Instances details
Forcible Tgraph Source #

Tgraphs are Forcible

Instance details

Defined in Tgraph.Force

DrawableLabelled Tgraph Source #

Tgraphs can be drawn with labels

Instance details

Defined in Tgraph.Prelude

Drawable Tgraph Source #

Tgraphs are Drawable

Instance details

Defined in Tgraph.Prelude

Methods

drawWith :: OKBackend b => (Piece -> Diagram b) -> Tgraph -> Diagram b Source #

Show Tgraph Source # 
Instance details

Defined in Tgraph.Prelude

newtype Relabelling Source #

Relabelling is a special case of mappings from vertices to vertices that are not the identity on a finite number of vertices. They are represented by keeping the non identity cases in a finite map. When applied, we assume the identity map for vertices not found in the representation domain (see relabelV). Relabellings must be 1-1 on their representation domain, and redundant identity mappings are removed in the representation. Vertices in the range of a relabelling must be >0.

Constructors

Relabelling (IntMap Vertex) 

newTrackedTgraph :: Tgraph -> TrackedTgraph Source #

newTrackedTgraph g creates a TrackedTgraph from a Tgraph g with an empty tracked list

makeTrackedTgraph :: Tgraph -> [[TileFace]] -> TrackedTgraph Source #

makeTrackedTgraph g trackedlist creates a TrackedTgraph from a Tgraph g from trackedlist where each list in trackedlist is a subset of the faces of g. Any faces not in g are ignored.

trackFaces :: TrackedTgraph -> TrackedTgraph Source #

trackFaces ttg - pushes the maingraph tilefaces onto the stack of tracked subsets of ttg

unionTwoTracked :: TrackedTgraph -> TrackedTgraph Source #

unionTwoTracked ttg - combines the top two lists of tracked tilefaces replacing them with the list union.

addHalfDartTracked :: Dedge -> TrackedTgraph -> TrackedTgraph Source #

addHalfDartTracked ttg e - add a half dart to the tgraph of ttg on the given edge e, and push the new singleton face list onto the tracked list.

addHalfKiteTracked :: Dedge -> TrackedTgraph -> TrackedTgraph Source #

addHalfKiteTracked ttg e - add a half kite to the tgraph of ttg on the given edge e, and push the new singleton face list onto the tracked list.

decomposeTracked :: TrackedTgraph -> TrackedTgraph Source #

decompose a TrackedTgraph - applies decomposition to all tracked subsets as well as the full Tgraph. Tracked subsets get the same numbering of new vertices as the main Tgraph.

drawTrackedTgraph :: OKBackend b => [VPatch -> Diagram b] -> TrackedTgraph -> Diagram b Source #

To draw a TrackedTgraph, we use a list of functions each turning a VPatch into a diagram. The first function is applied to a VPatch for untracked faces. Subsequent functions are applied to VPatches for the respective tracked subsets. Each diagram is beneath later ones in the list, with the diagram for the untracked VPatch at the bottom. The VPatches are all restrictions of a single VPatch for the Tgraph, so consistent. (Any extra draw functions are applied to the VPatch for the main tgraph and the results placed atop.)

drawTrackedTgraphRotated :: OKBackend b => [VPatch -> Diagram b] -> Angle Double -> TrackedTgraph -> Diagram b Source #

To draw a TrackedTgraph rotated. Same as drawTrackedTgraph but with additional angle argument for the rotation. This is useful when labels are being drawn. The angle argument is used to rotate the common vertex location map (anticlockwise) before drawing to ensure labels are not rotated.

drawTrackedTgraphAligned :: OKBackend b => [VPatch -> Diagram b] -> (Vertex, Vertex) -> TrackedTgraph -> Diagram b Source #

To draw a TrackedTgraph aligned. Same as drawTrackedTgraph but with additional vertex pair argument for the (x-axis) alignment. This is useful when labels are being drawn. The vertex pair argument is used to align the common vertex location map before drawing (to ensure labels are not rotated). This will raise an error if either of the pair of vertices is not a vertex of (the tgraph of) the TrackedTgraph

type TileFace = HalfTile (Vertex, Vertex, Vertex) Source #

A TileFace is a HalfTile with 3 vertex labels (clockwise starting with the origin vertex). Usually referred to as a face.

type VertexSet = IntSet Source #

Vertex label sets

type VertexMap a = IntMap a Source #

Abbreviation for Mapping from Vertex keys (also used for Boundaries)

type Dedge = (Vertex, Vertex) Source #

directed edge

makeTgraph :: [TileFace] -> Tgraph Source #

makeTgraph performs a no touching vertex check as well as using tryTgraphProps for other required properties. It produces an error if either check fails. Note that the other Tgraph properties are checked first, to ensure that calculation of vertex locations can be done for a touching vertex check.

tryMakeTgraph :: [TileFace] -> Try Tgraph Source #

tryMakeTgraph performs the same checks for Tgraph properties as tryTgraphProps but in addition it also checks that there are no touching vertices (distinct labels for the same vertex) using touchingVertices (which calculates vertex locations). It produces Left ... if either check fails and Right g otherwise where g is the Tgraph. Note that the other Tgraph properties are checked first, to ensure that calculation of vertex locations can be done.

tryCorrectTouchingVs :: [TileFace] -> Try Tgraph Source #

tryCorrectTouchingVs fcs finds touching vertices by calculating locations for vertices in the faces fcs, then renumbers to remove touching vertices (renumbers higher to lower numbers), then checks for Tgraph properties of the resulting faces to produce a Tgraph. NB fcs needs to be tile-connected before the renumbering and the renumbering need not be 1-1 (hence Relabelling is not used)

evalFaces :: [TileFace] -> [TileFace] Source #

force evaluation of a list of faces.

checkedTgraph :: [TileFace] -> Tgraph Source #

Creates a Tgraph from a list of faces using tryTgraphProps to check required properties and producing an error if a check fails.

Note: This does not check for touching vertices (distinct labels for the same vertex). To perform this additional check use makeTgraph which also uses tryTgraphProps.

tryTgraphProps :: [TileFace] -> Try Tgraph Source #

Checks a list of faces to ensure: no edge loops, no edge conflicts (same directed edge on two or more faces), legal tiling (obeys rules for legal tiling), all vertex labels >0 , no crossing boundaries, and connectedness.

Returns Right g where g is a Tgraph on passing checks. Returns Left lines if a test fails, where lines describes the problem found.

tryConnectedNoCross :: [TileFace] -> Try Tgraph Source #

Checks a list of faces for no crossing boundaries and connectedness. (No crossing boundaries and connected implies tile-connected). Returns Right g where g is a Tgraph on passing checks. Returns Left lines if a test fails, where lines describes the problem found. This is used by tryTgraphProps after other checks have been made, but can be used alone when other properties are known to hold (e.g. in tryPartCompose)

hasEdgeLoops :: [TileFace] -> Bool Source #

Checks if there are repeated vertices within any TileFace for a list of TileFaces. Returns True if there are any.

duplicates :: Eq a => [a] -> [a] Source #

duplicates finds duplicated items in a list (reverses order but unique results)

edgeType :: Dedge -> TileFace -> EdgeType Source #

edgeType d f - classifies the directed edge d which must be one of the three directed edges of face f. An error is raised if it is not a directed edge of the face

noNewConflict :: TileFace -> [TileFace] -> Bool Source #

noNewConflict face fcs returns True if face has an illegal shared edge with fcs. It does not check for illegal cases within the fcs.

illegalTiling :: [TileFace] -> Bool Source #

Returns True if there are conflicting directed edges or if there are illegal shared edges in the list of tile faces

crossingVertices :: [Dedge] -> [Vertex] Source #

Given a list of directed boundary edges, crossingVertices returns a list of vertices occurring more than once at the start of the directed edges in the list. Used for finding crossing boundary vertices when the boundary is already calculated.

crossingBoundaries :: [TileFace] -> Bool Source #

There are crossing boundaries if vertices occur more than once at the start of all boundary directed edges (or more than once at the end of all boundary directed edges).

connected :: [TileFace] -> Bool Source #

Predicate to check a Tgraph is a connected graph.

faces :: Tgraph -> [TileFace] Source #

Retrieve the faces of a Tgraph

emptyTgraph :: Tgraph Source #

The empty Tgraph

nullGraph :: Tgraph -> Bool Source #

is the Tgraph empty?

maxV :: Tgraph -> Int Source #

find the maximum vertex number in a Tgraph, returning 0 for an empty Tgraph.

ldarts :: Tgraph -> [TileFace] Source #

selecting left darts from a Tgraph

rdarts :: Tgraph -> [TileFace] Source #

selecting right darts from a Tgraph

lkites :: Tgraph -> [TileFace] Source #

selecting left kites from a Tgraph

rkites :: Tgraph -> [TileFace] Source #

selecting right kites from a Tgraph

kites :: Tgraph -> [TileFace] Source #

selecting half kites from a Tgraph

darts :: Tgraph -> [TileFace] Source #

selecting half darts from a Tgraph

selectFaces :: [TileFace] -> Tgraph -> Tgraph Source #

selects faces from a Tgraph (removing any not in the list), but checks resulting Tgraph for connectedness and no crossing boundaries.

removeFaces :: [TileFace] -> Tgraph -> Tgraph Source #

removes faces from a Tgraph, but checks resulting Tgraph for connectedness and no crossing boundaries.

removeVertices :: [Vertex] -> Tgraph -> Tgraph Source #

removeVertices vs g - removes any vertex in the list vs from g by removing all faces at those vertices. Resulting Tgraph is checked for required properties e.g. connectedness and no crossing boundaries.

selectVertices :: [Vertex] -> Tgraph -> Tgraph Source #

selectVertices vs g - removes any face that does not have at least one vertex in the list vs from g. Resulting Tgraph is checked for required properties e.g. connectedness and no crossing boundaries.

vertexSet :: Tgraph -> VertexSet Source #

the set of vertices of a Tgraph

graphBoundaryVs :: Tgraph -> [Vertex] Source #

list of vertices that are on the boundary of a Tgraph

graphDedges :: Tgraph -> [Dedge] Source #

A list of all the directed edges of a Tgraph (going clockwise round faces)

graphEdges :: Tgraph -> [Dedge] Source #

graphEdges returns a list of all the edges of a Tgraph (both directions of each edge).

internalEdges :: Tgraph -> [Dedge] Source #

internal edges are shared by two faces = all edges except boundary edges

graphBoundary :: Tgraph -> [Dedge] Source #

graphBoundary g are missing reverse directed edges in graphDedges g (the result contains single directions only) Direction is such that a face is on LHS and exterior is on RHS of each boundary directed edge.

phiEdges :: Tgraph -> [Dedge] Source #

phiEdges returns a list of the longer (phi-length) edges of a Tgraph (including kite joins). This includes both directions of each edge.

nonPhiEdges :: Tgraph -> [Dedge] Source #

nonPhiEdges returns a list of the shorter edges of a Tgraph (including dart joins). This includes both directions of each edge.

graphEFMap :: Tgraph -> Map Dedge TileFace Source #

graphEFMap g - is a mapping associating with each directed edge of g, the unique TileFace with that directed edge. This is more efficient than using dedgesFacesMap for the complete mapping.

defaultAlignment :: Tgraph -> (Vertex, Vertex) Source #

the default alignment of a non-empty Tgraph is (v1,v2) where v1 is the lowest numbered face origin, and v2 is the lowest numbered opp vertex of faces with origin at v1. This is the lowest join of g. An error will be raised if the Tgraph is empty.

makeRD :: Vertex -> Vertex -> Vertex -> TileFace Source #

make an RD (strict in arguments)

makeLD :: Vertex -> Vertex -> Vertex -> TileFace Source #

make an LD (strict in arguments)

makeRK :: Vertex -> Vertex -> Vertex -> TileFace Source #

make an RK (strict in arguments)

makeLK :: Vertex -> Vertex -> Vertex -> TileFace Source #

make an LK (strict in arguments)

faceVs :: TileFace -> (Vertex, Vertex, Vertex) Source #

triple of face vertices in order clockwise starting with origin - tileRep specialised to TileFace

faceVList :: TileFace -> [Vertex] Source #

list of (three) face vertices in order clockwise starting with origin

faceVSet :: TileFace -> VertexSet Source #

the set of vertices of a face

facesVSet :: [TileFace] -> VertexSet Source #

the set of vertices of a list of faces

facesMaxV :: [TileFace] -> Vertex Source #

find the maximum vertex for a list of faces (0 for an empty list).

firstV :: TileFace -> Vertex Source #

firstV, secondV and thirdV vertices of a face are counted clockwise starting with the origin

secondV :: TileFace -> Vertex Source #

firstV, secondV and thirdV vertices of a face are counted clockwise starting with the origin

thirdV :: TileFace -> Vertex Source #

firstV, secondV and thirdV vertices of a face are counted clockwise starting with the origin

originV :: TileFace -> Vertex Source #

the origin vertex of a face (firstV)

wingV :: TileFace -> Vertex Source #

wingV returns the vertex not on the join edge of a face

oppV :: TileFace -> Vertex Source #

oppV returns the vertex at the opposite end of the join edge from the origin of a face

indexV :: Vertex -> TileFace -> Int Source #

indexV finds the index of a vertex in a face (firstV -> 0, secondV -> 1, thirdV -> 2)

nextV :: Vertex -> TileFace -> Vertex Source #

nextV returns the next vertex in a face going clockwise from v where v must be a vertex of the face

prevV :: Vertex -> TileFace -> Vertex Source #

prevV returns the previous vertex in a face (i.e. next going anti-clockwise) from v where v must be a vertex of the face

isAtV :: Vertex -> TileFace -> Bool Source #

isAtV v f asks if a face f has v as a vertex

hasVIn :: [Vertex] -> TileFace -> Bool Source #

hasVIn vs f - asks if face f has an element of vs as a vertex

faceDedges :: TileFace -> [Dedge] Source #

directed edges (clockwise) round a face.

facesDedges :: [TileFace] -> [Dedge] Source #

Returns the list of all directed edges (clockwise round each) of a list of tile faces.

reverseD :: Dedge -> Dedge Source #

opposite directed edge.

joinE :: TileFace -> Dedge Source #

the join directed edge of a face in the clockwise direction going round the face (see also joinOfTile).

shortE :: TileFace -> Dedge Source #

The short directed edge of a face in the clockwise direction going round the face. This is the non-join short edge for darts.

longE :: TileFace -> Dedge Source #

The long directed edge of a face in the clockwise direction going round the face. This is the non-join long edge for kites.

joinOfTile :: TileFace -> Dedge Source #

The join edge of a face directed from the origin (not clockwise for RD and LK)

facePhiEdges :: TileFace -> [Dedge] Source #

The phi edges of a face (both directions) which is long edges for darts, and join and long edges for kites

faceNonPhiEdges :: TileFace -> [Dedge] Source #

The non-phi edges of a face (both directions) which is short edges for kites, and join and short edges for darts.

matchingLongE :: TileFace -> TileFace -> Bool Source #

check if two TileFaces have opposite directions for their long edge.

matchingShortE :: TileFace -> TileFace -> Bool Source #

check if two TileFaces have opposite directions for their short edge.

matchingJoinE :: TileFace -> TileFace -> Bool Source #

check if two TileFaces have opposite directions for their join edge.

hasDedge :: TileFace -> Dedge -> Bool Source #

hasDedge f e returns True if directed edge e is one of the directed edges of face f

hasDedgeIn :: TileFace -> [Dedge] -> Bool Source #

hasDedgeIn f es - is True if face f has a directed edge in the list of directed edges es.

facesEdges :: [TileFace] -> [Dedge] Source #

facesEdges returns a list of all the edges of a list of TileFaces (both directions of each edge).

facesBoundary :: [TileFace] -> [Dedge] Source #

facesBoundary fcs are missing reverse directed edges in facesDedges fcs (the result contains single directions only) Direction is such that a face is on LHS and exterior is on RHS of each boundary directed edge.

edgeNb :: TileFace -> TileFace -> Bool Source #

two tile faces are edge neighbours

vertexFacesMap :: [Vertex] -> [TileFace] -> VertexMap [TileFace] Source #

vertexFacesMap vs fcs - For list of vertices vs and list of faces fcs, create an IntMap from each vertex in vs to a list of those faces in fcs that are at that vertex.

dedgesFacesMap :: [Dedge] -> [TileFace] -> Map Dedge TileFace Source #

dedgesFacesMap des fcs - Produces an edge-face map. Each directed edge in des is associated with a unique TileFace in fcs that has that directed edge (if there is one). It will report an error if more than one TileFace in fcs has the same directed edge in des. If the directed edges and faces are all those from a Tgraph, graphEFMap will be more efficient. dedgesFacesMap is intended for a relatively small subset of directed edges in a Tgraph.

buildEFMap :: [TileFace] -> Map Dedge TileFace Source #

Build a Map from directed edges to faces (the unique face containing the directed edge)

faceForEdge :: Dedge -> Map Dedge TileFace -> Maybe TileFace Source #

look up a face for an edge in an edge-face map

edgeNbs :: TileFace -> Map Dedge TileFace -> [TileFace] Source #

Given a tileface (face) and a map from each directed edge to the tileface containing it (efMap) return the list of edge neighbours of face.

lowestJoin :: [TileFace] -> Dedge Source #

Return the join edge with lowest origin vertex (and lowest oppV vertex if there is more than one). The resulting edge is always directed from the origin to the opp vertex, i.e (orig,opp).

data VPatch Source #

A VPatch has a map from vertices to points along with a list of tile faces. It is an intermediate form between Tgraphs and Diagrams

Constructors

VPatch 

Instances

Instances details
DrawableLabelled VPatch Source #

VPatches can be drawn with labels

Instance details

Defined in Tgraph.Prelude

Drawable VPatch Source #

VPatches are drawable

Instance details

Defined in Tgraph.Prelude

Methods

drawWith :: OKBackend b => (Piece -> Diagram b) -> VPatch -> Diagram b Source #

Show VPatch Source # 
Instance details

Defined in Tgraph.Prelude

Transformable VPatch Source #

Make VPatch Transformable.

Instance details

Defined in Tgraph.Prelude

type N VPatch Source #

needed for making VPatch transformable

Instance details

Defined in Tgraph.Prelude

type N VPatch = Double
type V VPatch Source #

needed for making VPatch transformable

Instance details

Defined in Tgraph.Prelude

type V VPatch = V2

type VertexLocMap = IntMap (Point V2 Double) Source #

Abbreviation for finite mappings from Vertex to Location (i.e Point)

makeVP :: Tgraph -> VPatch Source #

Convert a Tgraph to a VPatch. This uses locateVertices to form an intermediate VertexLocMap (mapping of vertices to positions). This makes the join of the face with lowest origin and lowest oppV align on the positive x axis.

subVP :: VPatch -> [TileFace] -> VPatch Source #

Creates a VPatch from a list of tile faces, using the vertex location map from the given VPatch. The vertices in the tile faces should have locations assigned in the given VPatch vertex locations. However THIS IS NOT CHECKED so missing locations for vertices will raise an error when drawing. subVP vp fcs can be used for both subsets of tile faces of vp, and also for larger scale faces which use the same vertex to point assignment (e.g in compositions). The vertex location map is not changed (see also relevantVP and restrictVP).

relevantVP :: VPatch -> VPatch Source #

removes locations for vertices not used in the faces of a VPatch. (Useful when restricting which labels get drawn). relevantVP vp will raise an error if any vertex in the faces of vp is not a key in the location map of vp.

restrictVP :: VPatch -> [TileFace] -> VPatch Source #

A combination of subVP and relevantVP. Restricts a vp to a list of faces, removing locations for vertices not in the faces. (Useful when restricting which labels get drawn) restrictVP vp fcs will raise an error if any vertex in fcs is not a key in the location map of vp.

graphFromVP :: VPatch -> Tgraph Source #

Recover a Tgraph from a VPatch by dropping the vertex positions and checking Tgraph properties.

removeFacesVP :: VPatch -> [TileFace] -> VPatch Source #

remove a list of faces from a VPatch

selectFacesVP :: VPatch -> [TileFace] -> VPatch Source #

make a new VPatch with a list of selected faces from a VPatch. This will ignore any faces that are not in the given VPatch.

findLoc :: Vertex -> VPatch -> Maybe (Point V2 Double) Source #

find the location of a single vertex in a VPatch

class DrawableLabelled a where Source #

A class for things that can be drawn with labels when given a colour and a measure (size) for the label and a a draw function (for Patches). So labelColourSize c m modifies a Patch drawing function to add labels (of colour c and size measure m). Measures are defined in Diagrams. In particular: tiny, verySmall, small, normal, large, veryLarge, huge.

Instances

Instances details
DrawableLabelled Tgraph Source #

Tgraphs can be drawn with labels

Instance details

Defined in Tgraph.Prelude

DrawableLabelled VPatch Source #

VPatches can be drawn with labels

Instance details

Defined in Tgraph.Prelude

labelSize :: (OKBackend b, DrawableLabelled a) => Measure Double -> (Patch -> Diagram b) -> a -> Diagram b Source #

Default Version of labelColourSize with colour red. Example usage: labelSize tiny draw a , labelSize normal drawj a

labelled :: (OKBackend b, DrawableLabelled a) => (Patch -> Diagram b) -> a -> Diagram b Source #

Default Version of labelColourSize using red and small (rather than normal label size). Example usage: labelled draw a , labelled drawj a

rotateBefore :: (VPatch -> a) -> Angle Double -> Tgraph -> a Source #

rotateBefore vfun a g - makes a VPatch from g then rotates by angle a before applying the VPatch function vfun. Tgraphs need to be rotated after a VPatch is calculated but before any labelled drawing. E.g. rotateBefore (labelled draw) angle graph.

dropLabels :: VPatch -> Patch Source #

converts a VPatch to a Patch, removing vertex information and converting faces to Located Pieces. (Usage can be confined to Drawable VPatch instance and DrawableLabelled VPatch instance.)

centerOn :: Vertex -> VPatch -> VPatch Source #

center a VPatch on a particular vertex. (Raises an error if the vertex is not in the VPatch vertices)

alignXaxis :: (Vertex, Vertex) -> VPatch -> VPatch Source #

alignXaxis takes a vertex pair (a,b) and a VPatch vp for centering vp on a and rotating the result so that b is on the positive X axis. (Raises an error if either a or b are not in the VPatch vertices)

alignments :: [(Vertex, Vertex)] -> [VPatch] -> [VPatch] Source #

alignments takes a list of vertex pairs for respective alignments of VPatches in the second list. For a pair (a,b) the corresponding VPatch is centered on a then b is aligned along the positive x axis. The vertex pair list can be shorter than the list of VPatch - the remaining VPatch are left as they are. (Raises an error if either vertex in a pair is not in the corresponding VPatch vertices)

alignAll :: (Vertex, Vertex) -> [VPatch] -> [VPatch] Source #

alignAll (a,b) vpList provided both vertices a and b exist in each VPatch in vpList, the VPatch are all aligned centred on a, with b on the positive x axis. An error is raised if any VPatch does not contain both a and b vertices.

alignBefore :: (VPatch -> a) -> (Vertex, Vertex) -> Tgraph -> a Source #

alignBefore vfun (a,b) g - makes a VPatch from g oriented with centre on a and b aligned on the x-axis before applying the VPatch function vfun Will raise an error if either a or b is not a vertex in g. Tgraphs need to be aligned after a VPatch is calculated but before any labelled drawing. E.g. alignBefore (labelled draw) (a,b) g

makeAlignedVP :: (Vertex, Vertex) -> Tgraph -> VPatch Source #

makeAlignedVP (a,b) g - make a VPatch from g oriented with centre on a and b aligned on the x-axis. Will raise an error if either a or b is not a vertex in g.

drawEdgesVP :: OKBackend b => VPatch -> [Dedge] -> Diagram b Source #

produce a diagram of a list of edges (given a VPatch) Will raise an error if any vertex of the edges is not a key in the vertex to location mapping of the VPatch.

drawEdgeVP :: OKBackend b => VPatch -> Dedge -> Diagram b Source #

produce a diagram of a single edge (given a VPatch) Will raise an error if either vertex of the edge is not a key in the vertex to location mapping of the VPatch.

drawLocatedEdges :: OKBackend b => VertexLocMap -> [Dedge] -> Diagram b Source #

produce a diagram of a list of edges (given a mapping of vertices to locations) Will raise an error if any vertex of the edges is not a key in the mapping.

drawLocatedEdge :: OKBackend b => VertexLocMap -> Dedge -> Diagram b Source #

produce a diagram of a single edge (given a mapping of vertices to locations). Will raise an error if either vertex of the edge is not a key in the mapping.

locateVertices :: [TileFace] -> VertexLocMap Source #

locateVertices: processes a list of faces to associate points for each vertex using a default scale and orientation. The default scale is 1 unit for short edges (phi units for long edges). It aligns the lowest numbered join of the faces on the x-axis, and returns a vertex-to-point Map. It will raise an error if faces are not connected. If faces have crossing boundaries (i.e not locally tile-connected), this could raise an error or a result with touching vertices (i.e. more than one vertex label with the same location).

addVPoint :: TileFace -> VertexLocMap -> VertexLocMap Source #

Given a tileface and a vertex to location map which gives locations for at least 2 of the tileface vertices this returns a new map by adding a location for the third vertex (when missing) or the same map when not missing. It will raise an error if there are fewer than 2 tileface vertices with a location in the map (indicating a non tile-connected face). It is possible that a newly added location is already in the range of the map (creating a touching vertices), so this needs to be checked for.

axisJoin :: TileFace -> VertexLocMap Source #

axisJoin face - initialises a vertex to point mapping with locations for the join edge vertices of face with originV face at the origin and aligned along the x axis with unit length for a half dart and length phi for a half kite. (Used to initialise locateVertices)

touchingVertices :: [TileFace] -> [(Vertex, Vertex)] Source #

touchingVertices finds if any vertices are too close to each other using locateVertices. If vertices are too close that indicates we may have different vertex labels at the same location (the touching vertex problem). It returns pairs of vertices that are too close with higher number first in each pair, and no repeated first numbers. An empty list is returned if there are no touching vertices. Complexity has order of the square of the number of vertices.

This is used in makeTgraph and fullUnion (via correctTouchingVertices).

touching :: Point V2 Double -> Point V2 Double -> Bool Source #

touching checks if two points are considered close. Close means the square of the distance between them is less than a certain number (currently 0.1) so they cannot be vertex locations for 2 different vertices in a VPatch using unit scale for short edges. It is used in touchingVertices and touchingVerticesGen and Force.touchCheck).

touchingVerticesGen :: [TileFace] -> [(Vertex, Vertex)] Source #

touchingVerticesGen generalises touchingVertices to allow for multiple faces sharing a directed edge. This can arise when applied to the union of faces from 2 Tgraphs which might clash in places. It is used in the calculation of commonFaces.

locateVerticesGen :: [TileFace] -> VertexLocMap Source #

locateVerticesGen generalises locateVertices to allow for multiple faces sharing an edge. This can arise when applied to the union of faces from 2 Tgraphs (e.g. in commonFaces)

drawEdges :: OKBackend b => VertexLocMap -> [Dedge] -> Diagram b Source #

Deprecated: Use drawLocatedEdge, drawLocatedEdges instead

deprecated (use drawLocatedEdges)

drawEdge :: OKBackend b => VertexLocMap -> Dedge -> Diagram b Source #

Deprecated: Use drawLocatedEdge, drawLocatedEdges instead

deprecated (use drawLocatedEdge)

decompositions :: Tgraph -> [Tgraph] Source #

infinite list of decompositions of a Tgraph

phiVMap :: Tgraph -> Map Dedge Vertex Source #

phiVMap g produces a finite map from the phi edges (the long edges including kite joins) to assigned new vertices not in g. Both (a,b) and (b,a) get the same new vertex number. This is used(in decompFace and decompose. (Sort is used to fix order of assigned numbers). (Exported for use in TrackedTgraphs in Tgraphs module).

decompFace :: Map Dedge Vertex -> TileFace -> [TileFace] Source #

Decompose a face producing new faces. This requires an edge to vertex map to get a unique new vertex assigned to each phi edge (as created by phiVMap). (Exported for use in TrackedTgraphs in Tgraphs module).

partCompose :: Tgraph -> ([TileFace], Tgraph) Source #

partCompose g is a partial function producing a pair consisting of remainder faces (faces from g which will not compose) and a composed Tgraph. It does not assume the given Tgraph is forced. It checks the composed Tgraph for connectedness and no crossing boundaries raising an error if this check fails.

partComposeF :: Forced Tgraph -> ([TileFace], Forced Tgraph) Source #

partComposeF fg - produces a pair consisting of remainder faces (faces from fg which will not compose) and a composed (Forced) Tgraph. Since fg is a forced Tgraph it does not need a check for validity of the composed Tgraph. The fact that the result is also Forced relies on a theorem.

composeF :: Forced Tgraph -> Forced Tgraph Source #

composeF - produces a composed Forced Tgraph from a Forced Tgraph. Since the argument is a forced Tgraph it does not need a check for validity of the composed Tgraph. The fact that the function is total and the result is also Forced relies on theorems established for composing.

tryPartCompose :: Tgraph -> Try ([TileFace], Tgraph) Source #

tryPartCompose g tries to produce a Tgraph by composing faces which uniquely compose in g, It checks the resulting new faces for connectedness and no crossing boundaries. If the check is OK it produces Right (remainder, g') where g' is the composed Tgraph and remainder is a list of faces from g which will not compose. If the check fails it produces Left s where s is a failure report. It does not assume the given Tgraph is forced.

partComposeFaces :: Tgraph -> ([TileFace], [TileFace]) Source #

partComposeFaces g - produces a pair of the remainder faces (faces from g which will not compose) and the composed faces (which may or may not constitute faces of a valid Tgraph). It does not assume that g is forced.

data DartWingInfo Source #

DartWingInfo is a record type for the result of classifying dart wings in a Tgraph. It includes a faceMap from dart wings to faces at that vertex.

Instances

Instances details
Show DartWingInfo Source # 
Instance details

Defined in Tgraph.Compose

getDartWingInfo :: Tgraph -> DartWingInfo Source #

getDartWingInfo g, classifies the dart wings in g and calculates a faceMap for each dart wing, returning as DartWingInfo. It does not assume g is forced and is more expensive than getDartWingInfoForced

getDartWingInfoForced :: Forced Tgraph -> DartWingInfo Source #

getDartWingInfoForced fg (fg an explicitly Forced Tgraph) classifies the dart wings in fg and calculates a faceMap for each dart wing, returning as DartWingInfo.

composedFaceGroups :: DartWingInfo -> [(TileFace, [TileFace])] Source #

Creates a list of new composed faces, each paired with a list of old faces (components of the new face) using dart wing information. Auxiliary function but exported for experimenting.

forgetF :: Forced a -> a Source #

unwraps a Forced

class Forcible a where Source #

Forcible class has operations to (indirectly) implement forcing and single step forcing (tryForceWith, tryStepForceWith) for any Forcible. The class operations are more general to allow for other force related operations to be generalised for use on any Forcible. Both tryForceWith and tryStepForceWith are implemented using tryFSOpWith, and tryAddHalfKite and tryAddHalfDart are implemented using tryChangeBoundaryWith.

To improve performance of a sequence of force related operations, express each as a ForceState -> Try ForceState, then use (or (=>) to combine and pass to tryFSOpWith. This ensures there are no unnecessary conversions between steps.

Methods

tryFSOpWith :: UpdateGenerator -> (ForceState -> Try ForceState) -> a -> Try a Source #

tryFSOpWith (try ForseState Operation with) when given an update generator, generalises a (try) ForceState operation to a (try) Forcible operation. The update generator is only used to initialise a ForceState when there is not one already available (i.e not used when the Forcible is a ForceState)

tryInitFSWith :: UpdateGenerator -> a -> Try ForceState Source #

tryInitFSWith (try initialising a ForceState with) when given an update generator tries to create an initial ForceState (ready for forcing) from a Forcible. Again, the update generator is not used when the instance is a ForceState.

tryChangeBoundaryWith :: UpdateGenerator -> (BoundaryState -> Try BoundaryChange) -> a -> Try a Source #

tryChangeBoundaryWith when given an update generator, converts a (try) BoundaryState changing operation to a (try) Forcible operation. The update generator is only used when the instance is a ForceState (to revise the update map in the result).

Instances

Instances details
Forcible BoundaryState Source #

BoundaryStates are Forcible

Instance details

Defined in Tgraph.Force

Forcible ForceState Source #

ForceStates are Forcible

Instance details

Defined in Tgraph.Force

Forcible Tgraph Source #

Tgraphs are Forcible

Instance details

Defined in Tgraph.Force

Forcible TrackedTgraph Source #

TrackedTgraphs are Forcible

Instance details

Defined in Tgraphs

forceWith :: Forcible a => UpdateGenerator -> a -> a Source #

forceWith ugen: force using the given UpdateGenerator This raises an error on discovering a stuck/incorrect Forcible.

tryForce :: Forcible a => a -> Try a Source #

A try version of the main force function using defaultAllUGen representing all 10 rules for updates. This returns Left report on discovering a stuck Tgraph and Right a (with a the resulting forcible) otherwise.

tryForceWith :: Forcible a => UpdateGenerator -> a -> Try a Source #

try forcing using a given UpdateGenerator. tryForceWith uGen fs - does updates using uGen until there are no more updates. It produces Left report if it encounters a Forcible representing a stuck/incorrect Tgraph.

wholeTiles :: Forcible a => a -> a Source #

special case of forcing only half tiles to whole tiles

stepForce :: Forcible a => Int -> a -> a Source #

stepForce n a - produces an intermediate Forcible after n steps (n face additions) starting from Forcible a. It raises an error if it encounters a stuck/incorrect Forcible within n steps. If forcing finishes successfully in n or fewer steps, it will return that final Forcible.

tryStepForce :: Forcible a => Int -> a -> Try a Source #

tryStepForce n a - produces a (Right) intermediate Forcible after n steps (n face additions) starting from Forcible a. or a Left report if it encounters a stuck/incorrect Forcible within n steps. If forcing finishes successfully in n or fewer steps, it will return that final Forcible.

tryStepForceWith :: Forcible a => UpdateGenerator -> Int -> a -> Try a Source #

try a given number of force steps using a given UpdateGenerator.

tryFSOp :: Forcible a => (ForceState -> Try ForceState) -> a -> Try a Source #

A version of tryFSOpWith using defaultAllUGen representing all 10 rules for updates.

initFS :: Forcible a => a -> ForceState Source #

initialize a force state with the default UpdateGenerator. Raises aan error if it finds a stuck Forcible.

tryInitFS :: Forcible a => a -> Try ForceState Source #

try to initialize a force state with the default UpdateGenerator. Returns a Left report if it finds a stuck Forcible.

tryChangeBoundary :: Forcible a => (BoundaryState -> Try BoundaryChange) -> a -> Try a Source #

specialises tryChangeBoundaryWith to the default update generator.

tryForceF :: Forcible a => a -> Try (Forced a) Source #

tryForceF is the same as tryForce except that the successful result is explitly indicated as Forced.

forceF :: Forcible a => a -> Forced a Source #

forceF is the same partial function as force except that the (successful) result is explitly indicated as Forced.

addHalfKite :: Forcible a => Dedge -> a -> a Source #

addHalfKite is for adding a single half kite on a chosen boundary Dedge of a Forcible. The Dedge must be a boundary edge but the direction is not important as the correct direction is automatically calculated. It will raise an error if the edge is a dart join or if a conflict (stuck graph) is detected or if the edge is not a boundary edge.

tryAddHalfKite :: Forcible a => Dedge -> a -> Try a Source #

tryAddHalfKite is a version of addHalfKite which returns a Try with a Left report if it finds a stuck/incorrect graph, or if the edge is a dart join, or if the edge is not a boundary edge.

addHalfDart :: Forcible a => Dedge -> a -> a Source #

addHalfDart is for adding a single half dart on a chosen boundary Dedge of a Forcible. The Dedge must be a boundary edge but the direction is not important as the correct direction is automatically calculated. It will raise an error if the edge is a dart short edge or kite join or if a conflict (stuck graph) is detected or if the edge is not a boundary edge.

tryAddHalfDart :: Forcible a => Dedge -> a -> Try a Source #

tryAddHalfDart is a version of addHalfDart which returns a Try with a Left report if it finds a stuck/incorrect graph, or if the edge is a dart short edge or kite join, or if the edge is not a boundary edge.

tryOneStepWith :: UpdateGenerator -> ForceState -> Try (Maybe (ForceState, BoundaryChange)) Source #

tryOneStepWith uGen fs does one force step (used for debugging purposes). It returns either (1) a Right(Just (f,bc)) with a new ForceState f paired with a BoundaryChange bc (using uGen to revise updates in the final ForceState), or (2) a Right Nothing indicating forcing has finished and there are no more updates, or (3) a Left report for a stuck/incorrect graph.

tryOneStepForce :: ForceState -> Try (Maybe (ForceState, BoundaryChange)) Source #

tryOneStepForce is a special case of tryOneStepWith using defaultAllUGen (used for debugging).

data ForceState Source #

ForceState: The force state records information between executing single face updates during forcing (a BoundaryState and an UpdateMap).

data BoundaryState Source #

A BoundaryState records the boundary directed edges (directed so that faces are on LHS and exterior is on RHS) plus a mapping of boundary vertices to their incident faces, plus a mapping of boundary vertices to positions (using Tgraph.Prelude.locateVertices). It also keeps track of all the faces and the next vertex label to be used when adding a new vertex.

Constructors

BoundaryState 

Fields

data BoundaryChange Source #

After a face addition to a BoundaryState (by either trySafeUpdate or tryUnsafeUpdate), a BoundaryChange records (1) the new BoundaryState (2) the list of directed edges that were, but are no longer on the boundary (1,2,or 3), (3) a list of boundary edges requiring updates to be recalculated - i.e the new boundary edges and their immediate neighbours (4,3,or 0). (4) the face that has been added.

Constructors

BoundaryChange 

Fields

Instances

Instances details
Show BoundaryChange Source # 
Instance details

Defined in Tgraph.Force

data Update Source #

An Update is either safe or unsafe. A safe update has a new face involving 3 existing vertices. An unsafe update has a makeFace function to create the new face when given a fresh third vertex.

Instances

Instances details
Show Update Source #

0 is used as a dummy variable to show unsafe updates (to display the function explicitly)

Instance details

Defined in Tgraph.Force

type UpdateMap = Map Dedge Update Source #

UpdateMap: partial map associating updates with (some) boundary directed edges. (Any boundary directed edge will have the opposite direction in some face.)

newtype UpdateGenerator Source #

UpdateGenerator is a newtype for functions which capture one or more of the forcing rules. The functions can be applied using the unwrapper applyUG and produce a (Try) UpdateMap when given a BoundaryState and a focus list of particular directed boundary edges. Each forcing rule has a particular UpdateGenerator, but they can also be combined (e.g in sequence - allUGenerator or otherwise - defaultAllUGenerator).

Constructors

UpdateGenerator 

type UFinder = BoundaryState -> [Dedge] -> [(Dedge, TileFace)] Source #

UFinder (Update case finder functions). Given a BoundaryState and a list of (focus) boundary directed edges, such a function returns each focus edge satisfying the particular update case paired with the tileface matching that edge. For example, if the function is looking for dart short edges on the boundary, it will return only those focus edges which are half-dart short edges, each paired with its half-dart face.

type UChecker = BoundaryState -> TileFace -> Try Update Source #

UChecker (Update checker functions). Given a BoundaryState and a particular tileface (on the boundary), such functions try to produce particular updates on the boundary edge of the given tileface. [They are called update checkers because they may uncover an incorrect/stuck tiling (using tryFindThirdV) when creating the update.] As an example, addKiteShortE will try to produce an update to add a half-kite with short edge against the boundary. Such a function can be used with a UFinder that either returns dart halves with short edge on the boundary (nonKDarts in rule 2) or returns kite halves with short edge on the boundary (kitesWingDartOrigin in rule 3).

makeBoundaryState :: Tgraph -> BoundaryState Source #

Calculates BoundaryState information from a Tgraph also checks for no crossing boundaries as these could cause difficult to trace errors in forcing.

recoverGraph :: BoundaryState -> Tgraph Source #

Converts a BoundaryState back to a Tgraph

facesAtBV :: BoundaryState -> Vertex -> [TileFace] Source #

facesAtBV bd v - returns the faces found at v (which must be a boundary vertex)

boundaryFaces :: BoundaryState -> [TileFace] Source #

return a list of faces which have a boundary vertex from a BoundaryState

affectedBoundary :: BoundaryState -> [Dedge] -> [Dedge] Source #

Given a BoundaryState with a list of one boundary edge or two adjacent boundary edges (or exceptionally no boundary edges), it extends the list with adjacent boundary edges (to produce 3 or 4 or none). It will raise an error if given more than 2 or 2 non-adjacent boundary edges. (Used to calculate revisedEdges in a BoundaryChange. (N.B. When a new face is fitted in to a hole with 3 sides there is no new boundary. Hence the need to allow for an empty list.)

tryReviseUpdates :: UpdateGenerator -> BoundaryChange -> UpdateMap -> Try UpdateMap Source #

tryReviseUpdates uGen bdChange: revises the UpdateMap after boundary change (bdChange) using uGen to calculate new updates.

tryReviseFSWith :: UpdateGenerator -> BoundaryChange -> ForceState -> Try ForceState Source #

tryReviseFSWith ugen bdC fs tries to revise fs after a boundary change (bdC) by calculating the revised updates with ugen (and using the new boundary state in bdC).

findSafeUpdate :: UpdateMap -> Maybe Update Source #

finds the first safe update - Nothing if there are none (ordering is directed edge key ordering)

tryUnsafes :: ForceState -> Try (Maybe BoundaryChange) Source #

tryUnsafes: Should only be used when there are no Safe updates in the UpdateMap. tryUnsafes works through the unsafe updates in (directed edge) key order and completes the first unsafe update that is not blocked (by a touching vertex), returning Right (Just bdC) where bdC is the resulting boundary change (if there is one). It returns Right Nothing if there are no unsafe updates but Left report if there are unsafes but all unsafes are blocked, where report describes the problem.

checkUnsafeUpdate :: BoundaryState -> Update -> Maybe BoundaryChange Source #

checkUnsafeUpdate bd u, calculates the resulting boundary change for an unsafe update (u) with a new vertex (raising an error if u is a safe update). It performs a touching vertex check with the new vertex returning Nothing if there is a touching vertex (blocked case). Otherwise it returns Just bdc with bdc a boundary change. [Note: Try is not used as a conflict cannot be found in the unsafe case, and blocking is only a problem when all unsafe updates are blocked (and there is at least one) - see tryUnsafes]

trySafeUpdate :: BoundaryState -> Update -> Try BoundaryChange Source #

trySafeUpdate bd u adds a new face by completing a safe update u on BoundaryState bd (raising an error if u is an unsafe update). It returns a Right BoundaryChange (containing a new BoundaryState, removed boundary edges and revised boundary edge list), unless a stuck/incorrect graph is found. It checks that the new face is not in conflict with existing faces, producing (Left report) if there is a conflict. It should cater for the exceptional case where the update removes 3 boundary edges in a triangle (and removes 3 boundary vertices), closing a hole.

tryUpdate :: BoundaryState -> Update -> Try BoundaryChange Source #

tryUpdate: tries a single update (safe or unsafe), producing Left report if the update creates a touching vertex in the unsafe case, or if a stuck/incorrect Tgraph is discovered in the safe case.

recalibratingForce :: Forcible c => c -> c Source #

A version of force that recalibrates at 20,000 step intervals by recalculating boundary vertex positions from scratch. This is needed to limit accumulation of errors when large numbers of faces are added in forcing. This raises an error on discovering a stuck/incorrect Forcible.

tryRecalibratingForce :: Forcible c => c -> Try c Source #

A version of tryForce that recalibrates at 20,000 step intervals by recalculating boundary vertex positions from scratch. This is needed to limit accumulated inaccuracies when large numbers of faces are added in forcing.

recalculateBVLocs :: BoundaryState -> BoundaryState Source #

This recalibrates a BoundaryState by recalculating boundary vertex positions from scratch with locateVertices. (Used at intervals in tryRecalibratingForce and recalibratingForce).

defaultAllUGen :: UpdateGenerator Source #

The default all update generator (see also allUGenerator). It uses the 10 rules (and the same UCheckers as allUGenerator), but makes decisions based on the EdgeType of a boundary edge (instead of trying each UFinder in turn). If there are any Left..(fail reports) for the given boundary edges the result is a single Left, concatenating all the failure reports (unlike allUGenerator).

combineUpdateGenerators :: [UpdateGenerator] -> UpdateGenerator Source #

combineUpdateGenerators combines a list of update generators into a single update generator. When used, the generators are tried in order on each boundary edge (in the supplied focus edges), and will return a Left..(fail report) for the first generator that produces a Left..(fail report) if any.

allUGenerator :: UpdateGenerator Source #

allUGenerator was the original generator for all updates. It combines the individual update generators for each of the 10 rules in sequence using combineUpdateGenerators (See also defaultAllUGen which is defined without using combineUpdateGenerators)

wholeTileUpdates :: UpdateGenerator Source #

Update generator for rule (1)

incompleteHalves :: UFinder Source #

Find faces with missing opposite face (mirror face)

aceKiteUpdates :: UpdateGenerator Source #

Update generator for rule (2)

nonKDarts :: UFinder Source #

Find half darts with boundary short edge

queenOrKingUpdates :: UpdateGenerator Source #

Update generator for rule (3) queen and king vertices add a missing kite half (on a boundary kite short edge)

kitesWingDartOrigin :: UFinder Source #

Find kites with boundary short edge where the wing is also a dart origin

deuceDartUpdates :: UpdateGenerator Source #

Update generator for rule (4) (for deuce vertices = largeKiteCentres) Kites whose short edge (b,a) matches a boundary edge (a,b) where their oppV has 2 other kite halves sharing a shortE. These need a dart adding on the short edge.

kiteGaps :: UFinder Source #

Find kite halves with a short edge on the boundary (a,b) where there are 2 other kite halves sharing a short edge at oppV of the kite half (a for left kite and b for right kite)

jackDartUpdates :: UpdateGenerator Source #

Update generator for rule (5) jackDartUpdates - jack vertex add a missing second dart

noTouchingDart :: UFinder Source #

Find kite halves with a short edge on the boundary (a,b) where oppV must be a jack vertex (oppV is a for left kite and b for right kite). The function mustbeJack finds if a vertex must be a jack

sunStarUpdates :: UpdateGenerator Source #

Update generator for rule (6) sunStarUpdates is for vertices that must be either sun or star almostSunStar finds half-kites/half-darts with a long edge on the boundary where their origin vertex has 8 total half-kites/half-darts respectively or their origin vertex has 6 total half-kites in the case of kites only completeSunStar will add a new face of the same type (dart/kite) sharing the long edge.

almostSunStar :: UFinder Source #

Find a boundary long edge of either a dart where there are at least 7 dart origins, or a kite where there are at least 5 kite origins

jackKiteUpdates :: UpdateGenerator Source #

Update generator for rule (7) jack vertices with dart long edge on the boundary - add missing kite top. The function mustbeJack finds if a vertex must be a jack.

jackMissingKite :: UFinder Source #

Find jack vertices with dart long edge on the boundary. The function mustbeJack finds if a vertex must be a jack

kingDartUpdates :: UpdateGenerator Source #

Update generator for rule (8) king vertices with 2 of the 3 darts - add another half dart on a boundary long edge of existing darts

kingMissingThirdDart :: UFinder Source #

Find king vertices with a dart long edge on the boundary and 2 of the 3 darts at its origin plus a kite wing at its origin

queenDartUpdates :: UpdateGenerator Source #

Update generator for rule (9) queen vertices (more than 2 kite wings) with a boundary kite long edge - add a half dart

queenMissingDarts :: UFinder Source #

Find queen vertices (more than 2 kite wings) with a boundary kite long edge

queenKiteUpdates :: UpdateGenerator Source #

Update generator for rule (10) queen vertices with more than 2 kite wings -- add missing half kite on a boundary kite short edge

queenMissingKite :: UFinder Source #

Find queen vertices (2 or more kite wings) and a kite short edge on the boundary

completeHalf :: UChecker Source #

completeHalf will check an update to add a symmetric (mirror) face for a given face at a boundary join edge.

addKiteShortE :: UChecker Source #

add a (missing) half kite on a (boundary) short edge of a dart or kite

addDartShortE :: UChecker Source #

add a half dart top to a boundary short edge of a half kite.

completeSunStar :: UChecker Source #

add a kite half to a kite long edge or dart half to a dart long edge

addKiteLongE :: UChecker Source #

add a kite to a long edge of a dart or kite

addDartLongE :: UChecker Source #

add a half dart on a boundary long edge of a dart or kite

mustbeStar :: BoundaryState -> Vertex -> Bool Source #

A vertex on the boundary must be a star if it has 7 or more dart origins

mustbeSun :: BoundaryState -> Vertex -> Bool Source #

A vertex on the boundary must be a sun if it has 5 or more kite origins

mustbeDeuce :: BoundaryState -> Vertex -> Bool Source #

A vertex on the boundary which is an oppV of a kite must be a deuce if there is a shared kite short edge at the vertex.

mustbeKing :: BoundaryState -> Vertex -> Bool Source #

A boundary vertex which is a kite wing and has 4 dart origins must be a king vertex

isKiteWing :: BoundaryState -> Vertex -> Bool Source #

isKiteWing bd v - Vertex v is a kite wing in BoundaryState bd

isKiteOppV :: BoundaryState -> Vertex -> Bool Source #

isKiteOppV bd v - Vertex v is a kite oppV in BoundaryState bd

isDartOrigin :: BoundaryState -> Vertex -> Bool Source #

isDartOrigin bd v - Vertex v is a dart origin in BoundaryState bd

mustbeQueen :: BoundaryState -> Vertex -> Bool Source #

A boundary vertex with >2 kite wings is a queen vertex (needing a fourth kite on a kite short edge or dart on a kite long edge)

kiteWingCount :: BoundaryState -> Vertex -> Int Source #

kiteWingCount bd v - the number of kite wings at v in BoundaryState bd

mustbeJack :: BoundaryState -> Vertex -> Bool Source #

mustbeJack is true of a boundary vertex if it is the wing of two darts not sharing a long edge or it is a wing of a dart and also a kite origin (false means it is either undetermined or is a deuce).

newUpdateGenerator :: UChecker -> UFinder -> UpdateGenerator Source #

newUpdateGenerator combines an update case finder (UFinder) with its corresponding update checker (UChecker) to produce an update generator. This is used to make each of the 10 update generators corresponding to 10 rules.

When the generator is applied (with applyUG) to a BoundaryState and list of focus edges, the finder produces a list of pairs of dedge and face, the checker is used to convert the face in each pair to an update (which can fail with a Left report), and the new updates are returned as a map (with the dedges as keys) in a Right result.

makeGenerator :: UChecker -> UFinder -> UpdateGenerator Source #

makeGenerator (deprecated) this is renamed as newUpdateGenerator.

boundaryFilter :: (BoundaryState -> Dedge -> TileFace -> Bool) -> UFinder Source #

This is a general purpose filter used to create UFinder functions for each force rule. It requires a face predicate. The face predicate takes a BoundaryState bd, a boundary Dedge (a,b) and the TileFace with the edge (b,a) and decides whether the face is wanted or not (True = wanted) This will be used to filter all the faces at the focus edges (when given a BoundaryState and list of focus edges). For some predicates the BoundaryState argument is not used (eg boundaryJoin in incompleteHalves), but for others it is used to look at other faces at b or at a besides the supplied face (eg in kitesWingDartOrigin)

makeUpdate :: (Vertex -> TileFace) -> Maybe Vertex -> Update Source #

makeUpdate f x constructs a safe update if x is Just .. and an unsafe update if x is Nothing

tryFindThirdV :: BoundaryState -> Dedge -> (Int, Int) -> Try (Maybe Vertex) Source #

tryFindThirdV finds a neighbouring third vertex on the boundary if there is one in the correct direction for a face added to the right hand side of a directed boundary edge. In tryFindThirdV bd (a,b) (n,m), the two integer arguments n and m are the INTERNAL angles for the new face on the boundary directed edge (a,b) (for a and b respectively) expressed as multiples of tt (tt being a tenth turn) and must both be either 1,2, or 3. tryFindThirdV compares these internal angles with the external angles of the boundary calculated at a and b. If one of them matches, then an adjacent boundary edge will lead to the required vertex. If either n or m is too large a Left report is returned indicating an incorrect graph (stuck tiling). If n and m are smaller than the respective external angles, Right Nothing is returned.

externalAngle :: BoundaryState -> Vertex -> Int Source #

externalAngle bd v - calculates the external angle at boundary vertex v in BoundaryState bd as an integer multiple of tt (tenth turn), so 1..9. It relies on there being no crossing boundaries, so that there is a single external angle at each boundary vertex.

touchCheck :: Point V2 Double -> VertexMap (Point V2 Double) -> Bool Source #

touchCheck p vpMap - check if a vertex location p touches (is too close to) any other vertex location in the mapping vpMap

fullUnion :: (Tgraph, Dedge) -> (Tgraph, Dedge) -> Tgraph Source #

fullUnion (g1,e1) (g2,e2) will try to create the union of g1 and g2. That is, it will try to combine the faces of g1 and (possibly relabelled) faces of g2 as a Tgraph. It does this by first matching the respective edges e1 and e2 and relabelling g2 to match g1 on a tile-connected region containing e1. It will raise an error if there is a mismatch. If succesfull it then uses geometry of tiles (vertex locations) to correct for multiple overlapping regions of tiles in g1 and relabelled g2 by a further relabelling of any touching vertices. The resulting union of faces requires an expensive tryTgraphProps if touching vertices were found. However the check is not needed when there are no touching vertices (i.e. a single tile-connected overlap).

tryFullUnion :: (Tgraph, Dedge) -> (Tgraph, Dedge) -> Try Tgraph Source #

tryFullUnion (g1,e1) (g2,e2) will try to create the union of g1 and g2. That is, it will try to combine the faces of g1 and (possibly relabelled) faces of g2 as a Tgraph. It does this by first matching the respective edges e1 and e2 and relabelling g2 to match g1 on a tile-connected region containing e1. It returns Left lines if there is a mismatch (where lines explains the problem). If succesfull it then uses geometry of tiles (vertex locations) to correct for multiple overlapping regions of tiles in g1 and relabelled g2 by a further relabelling of any touching vertices. The resulting union of faces requires an expensive tryTgraphProps if any touching vertices were found, and will return Left ... if this fails and Right t otherwise, where t is a Tgraph containing the union of faces. The check is not used when there are no touching vertices (i.e. a single tile-connected overlap).

commonFaces :: (Tgraph, Dedge) -> (Tgraph, Dedge) -> [TileFace] Source #

commonFaces (g1,e1) (g2,e2) relabels g2 to match with g1 (where they match) and returns the common faces as a subset of faces of g1. i.e. with g1 vertex labelling. It requires a face in g1 with directed edge e1 to match a face in g2 with directed edge e2, (apart from the third vertex label) otherwise an error is raised. This uses vertex locations to correct touching vertices in multiply overlapping regions. >>>> touching vertices being 1-1 is sensitive to nearness check of touchingVerticesGen <<<<<<<<<

sameGraph :: (Tgraph, Dedge) -> (Tgraph, Dedge) -> Bool Source #

sameGraph (g1,e1) (g2,e2) checks to see if g1 and g2 are the same Tgraph after relabelling g2. The relabelling is based on directed edge e2 in g2 matching e1 in g1 (where the direction is clockwise round a face) and uses tryRelabelToMatch.

newRelabelling :: [(Vertex, Vertex)] -> Relabelling Source #

newRelabelling prs - make a relabelling from a finite list of vertex pairs. The first item in each pair relabels to the second in the pair. The resulting relabelling excludes any identity mappings of vertices. An error is raised if second items of the pairs contain duplicated numbers or a number<1

relabelToMatch :: (Tgraph, Dedge) -> (Tgraph, Dedge) -> Tgraph Source #

relabelToMatch (g1,e1) (g2,e2) produces a relabelled version of g2 that is consistent with g1 on a single tile-connected region of overlap. The overlapping region must contain the directed edge e1 in g1. The edge e2 in g2 will be identified with e1 by the relabelling of g2. This produces an error if a mismatch is found anywhere in the overlap.

CAVEAT: The relabelling may not be complete if the overlap is not just a SINGLE tile-connected region in g1. If the overlap is more than a single tile-connected region, then the union of the relabelled faces with faces in g1 will be tile-connected but may have touching vertices. This limitation is addressed by fullUnion.

tryRelabelToMatch :: (Tgraph, Dedge) -> (Tgraph, Dedge) -> Try Tgraph Source #

tryRelabelToMatch (g1,e1) (g2,e2) produces either Right g where g is a relabelled version of g2 that is consistent with g1 on an overlapping tile-connected region or Left lines if there is a mismatch (lines explaining the problem). The overlapping region must contain the directed edge e1 in g1. The edge e2 in g2 will be identified with e1 by the relabelling of g2.

CAVEAT: The relabelling may not be complete if the overlap is not just a SINGLE tile-connected region in g1. If the overlap is more than a single tile-connected region, then the union of the relabelled faces with faces in g1 will be tile-connected but may have touching vertices. This limitation is addressed by tryFullUnion.

relabelToMatchIgnore :: (Tgraph, Dedge) -> (Tgraph, Dedge) -> Tgraph Source #

same as relabelToMatch but ignores non-matching faces (except for the initial 2) The initial 2 faces are those on the given edges, and an error is raised if they do not match. This is used by commonFaces

relabelGraph :: Relabelling -> Tgraph -> Tgraph Source #

relabelGraph rlab g - uses a Relabelling rlab to change vertices in a Tgraph g. Caveat: This should only be used when it is known that: rlab is 1-1 on its (representation) domain, and the vertices of g are disjoint from those vertices that are in the representation range but which are not in the representation domain of rlab. This ensures rlab (extended with the identity) remains 1-1 on vertices in g, so that the resulting Tgraph does not need an expensive check for Tgraph properties. (See also checkRelabelGraph)

checkRelabelGraph :: Relabelling -> Tgraph -> Tgraph Source #

checkRelabelGraph uses a relabelling map to change vertices in a Tgraph, then checks that the result is a valid Tgraph. (see also relabelGraph)

relabelFace :: Relabelling -> TileFace -> TileFace Source #

Uses a relabelling to relabel the three vertices of a face. Any vertex not in the domain of the mapping is left unchanged. The mapping should be 1-1 on the 3 vertices to avoid creating a self loop edge.

relabelV :: Relabelling -> Vertex -> Vertex Source #

relabelV rlab v - uses relabelling rlab to find a replacement for v (leaves as v if none found). I.e relabelV turns a Relabelling into a total function using identity for undefined cases in the Relabelling representation.

prepareFixAvoid :: [Vertex] -> VertexSet -> Tgraph -> Tgraph Source #

prepareFixAvoid fix avoid g - produces a new Tgraph from g by relabelling. Any vertex in g that is in the set avoid but not in the list fix will be changed to a new vertex that is neither in g nor in the set (avoid with fix removed). All other vertices of g (including those in fix) will remain the same. Usage: This is used to prepare a graph by avoiding accidental label clashes with the avoid set (usually vertices of another graph). However we fix a list of vertices which we intend to control in a subsequent relabelling. (this is usually a pair of vertices from a directed edge that will get a specific subsequent relabelling). Note: If any element of the list fix is not a vertex in g, it could end up in the relabelled Tgraph.

relabelContig :: Tgraph -> Tgraph Source #

Relabel all vertices in a Tgraph using new labels 1..n (where n is the number of vertices).

module TileLib

makeUncheckedTgraph :: [TileFace] -> Tgraph Source #

Warning: Bypasses checks for required Tgraph properties. Use makeTgraph instead

Now has a warning.