This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
proc split[T](self: BSPTree[T], target: Leaf, parent: ParentNode[T]): Leaf[T] = | |
var mp: int | |
parent.backward = target | |
if (parent of VSplit[T]): | |
var casted = (VSplit[T])parent | |
mp = midpoint(casted, target) | |
casted.adjustSource(target, mp) | |
casted.forward = casted.newSibling(target, mp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template `isA` (a, b: untyped): untyped = | |
# this definition exists in the System module | |
compiles((b)a) | |
# test.nim(19, 16) Error: type mismatch: got (typedesc[Leaf[system.string]]) | |
# but expected one of: | |
# template isA(a, b: untyped): untyped |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type | |
NodeKind = enum | |
HSplit, VSplit, Leaf | |
BSPNode[T] = ref object | |
parent: BSPNode[T] | |
case kind: NodeKind | |
of HSplit: | |
hPos: float | |
topNode: BSPNode[T] | |
bottomNode: BSPNode[T] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
proc hsplit[T](self: BSPNode[T], pos: float) = | |
if self.kind != Leaf: | |
return | |
var | |
width = (self.right - self.left) | |
midpoint = self.left + (width * pos) | |
# create split parent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type | |
NodeKind = enum | |
HSplit, VSplit, Leaf | |
BSPNode[T] = ref object | |
parent: BSPNode | |
case kind: NodeKind | |
of HSplit: | |
hPos: float | |
left: BSPNode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
proc get[T](self: Inlet): T = | |
case Inlet.kind: | |
of Bool: | |
return self.boolParam.value | |
of Int: | |
return self.intParam.value | |
of Float: | |
return self.floatParam.value | |
of String: | |
return self.stringParam.value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
proc send[T](self: Inlet, value: T): bool = | |
result = false | |
when T is bool: | |
if self.kind != Bool: | |
raise newException(PortKindError, "Cannot send $1 to $2" % [$(value), self.name]) | |
if self.boolParam.set(value): | |
return self.boolParam.handler(value) | |
when T is int: | |
if self.kind != Int: | |
raise newException(PortKindError, "Cannot send $1 to $2" % [$(value), self.name]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
import strutils | |
include main | |
suite "port tests": | |
setup: | |
var | |
m = newModule() | |
m2 = newModule() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type | |
ValidType = concept c | |
c is bool or c is int | |
NumericType = concept c | |
c is ValidType | |
c is int | |
type | |
Parameter[T:ValidType] = object |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
include main | |
suite "inlet tests": | |
setup: | |
var | |
m = newModule() | |
m2 = newModule() |