Skip to content

Instantly share code, notes, and snippets.

@maxkrieger
Created April 14, 2021 21:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxkrieger/a5cae3df23808082e14189b427854801 to your computer and use it in GitHub Desktop.
Save maxkrieger/a5cae3df23808082e14189b427854801 to your computer and use it in GitHub Desktop.
nested.sub: a trio from https://penrose.ink
type Set
type Point
type Map
constructor Singleton : Point p -> Set
function Intersection : Set a * Set b -> Set
function Union : Set a * Set b -> Set
function Subtraction : Set a * Set b -> Set
function CartesianProduct : Set a * Set b -> Set
function Difference : Set a * Set b -> Set
function Subset : Set a * Set b -> Set
function AddPoint : Point p * Set s1 -> Set
predicate Not : Prop p1
predicate From : Map f * Set domain * Set codomain
predicate Empty : Set s
predicate Intersecting : Set s1 * Set s2
predicate IsSubset : Set s1 * Set s2
predicate PointIn : Set s * Point p
predicate In : Point p * Set s
predicate Injection : Map m
predicate Surjection : Map m
predicate Bijection : Map m
predicate PairIn : Point * Point * Map
notation "A ⊂ B" ~ "IsSubset(A, B)"
notation "p ∈ A" ~ "PointIn(A, p)"
notation "p ∉ A" ~ "PointNotIn(A, p)"
notation "A ∩ B = ∅" ~ "Not(Intersecting(A, B))"
notation "f: A -> B" ~ "Map f; From(f, A, B)"
forall Set x {
x.icon = Circle {
strokeWidth : 0.0
}
x.text = Text {
string : x.label
}
ensure contains(x.icon, x.text)
ensure minSize(x.icon)
ensure maxSize(x.icon)
encourage sameCenter(x.text, x.icon)
x.textLayering = x.text above x.icon
}
forall Set x; Set y
where IsSubset(x, y) {
ensure smallerThan(x.icon, y.icon)
ensure outsideOf(y.text, x.icon)
ensure contains(y.icon, x.icon, 5.0)
x.icon above y.icon
}
-- TODO: Fix that the resample hack breaks on switching examples since it saves the cached functions...
-- TOOD: Also breaks if you resample without generating the function on first sample. Clearly this should be part of the state
---
forall Set x; Set y
where Not(Intersecting(x, y)) {
ensure disjoint(x.icon, y.icon)
}
-- --------- NEW
forall Set x; Set y
where Intersecting(x, y) {
ensure overlapping(x.icon, y.icon)
ensure outsideOf(y.text, x.icon)
ensure outsideOf(x.text, y.icon)
}
forall Point p {
p.offset = 20.0
p.icon = Circle {
strokeWidth : 0.0
color : rgba(0.0, 0.0, 0.0, 1.0)
r : 3.0
}
p.text = Text {
string : p.label
center : p.icon.center + (p.offset, p.offset)
}
p.textLayering = p.text above p.icon
}
Point p
with Set A
where PointIn(A, p) {
ensure contains(A.icon, p.icon, 0.3 * A.icon.r)
p.layering = p.icon above A.icon
}
Point p
with Set A
where Not(PointIn(A, p)) {
ensure disjoint(A.icon, p.icon)
}
Set A
Set B
Set C
Set D
Set E
Set F
Set G
IsSubset(B, A)
IsSubset(C, B)
IsSubset(D, C)
IsSubset(E, D)
IsSubset(F, E)
IsSubset(G, F)
AutoLabel All
{"authorship":{"madeBy":"maxkrieger","name":"nested.sub","avatar":"https://avatars.githubusercontent.com/u/2660634?v=4"}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment