@@ -118,12 +118,10 @@ trait Adjacencies extends SharedDiagonals { this: RuleGenerator =>
118118}
119119
120120trait SharedDiagonals { this : RuleGenerator =>
121- private def withLocalRemap [U ](remap : Rule [ SymTile ] => Rule [ SymTile ] )(action : => U ): U = {
121+ private def withLocalContext [U ](modifyContext : RuleTransducer . Context => RuleTransducer . Context )(action : => U ): U = {
122122 val originalContext = context
123123 try {
124- context = originalContext.copy(
125- preprocess = rule => originalContext.preprocess(remap(rule)),
126- )
124+ context = modifyContext(originalContext)
127125 action
128126 } finally {
129127 context = originalContext
@@ -141,9 +139,27 @@ trait SharedDiagonals { this: RuleGenerator =>
141139 * See `NetworkProperties.transformSharedDiagonals` for the implementation.
142140 */
143141 protected def withSharedDiagonals (action : => Unit ): Unit = {
144- withLocalRemap(_.map {
145- case tile : Tile => transformSharedDiagonals(tile)
146- case tile : SymTile => tile
147- })(action)
142+ withLocalContext { context =>
143+ context.copy(preprocess = rule => context.preprocess(rule.map {
144+ case tile : Tile => transformSharedDiagonals(tile)
145+ case tile : SymTile => tile
146+ }))
147+ }(action)
148+ }
149+
150+ /** Ignore all rules containing tiles that are not resolvable to IDs.
151+ *
152+ * Use this with care, as it is easy to omit lots of rules unintentionally.
153+ */
154+ protected def withResolvableRulesOnly (action : => Unit ): Unit = {
155+ withLocalContext { context =>
156+ context.copy(preprocess = rule => {
157+ val resolve = context.resolve.asInstanceOf [PartialFunction [Tile , IdTile ]] // TODO resolver function should always be partial
158+ context.preprocess(rule).filter(_.forall {
159+ case tile : Tile => resolve.isDefinedAt(tile)
160+ case tile : SymTile => true
161+ })
162+ })
163+ }(action)
148164 }
149165}
0 commit comments