Skip to content

Commit 89d8cf9

Browse files
committed
Add SVG!PointOnLine
[Feature]
1 parent 752d225 commit 89d8cf9

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

modules/SVG.tla

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,8 @@ NodesOfDirectedMultiGraph(nodes, edges, options) ==
174174
(**************************************************************************)
175175
CHOOSE f \in [ nodes -> [x: Int, y: Int] ]: TRUE
176176

177+
PointOnLine(from, to, segment) ==
178+
[x |-> from.x + ((to.x - from.x) \div segment),
179+
y |-> from.y + ((to.y - from.y) \div segment)]
180+
177181
=============================================================================

modules/tlc2/overrides/SVG.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,4 +219,18 @@ private static LayoutAlgorithm<Value> getAlgo(final String algo, final RecordVal
219219
.vertexBoundsFunction(v -> Rectangle.of(-5, -5, nodeW.val, nodeH.val)).build();
220220
}
221221
}
222+
223+
@TLAPlusOperator(identifier = "PointOnLine", module = "SVG", warn = false)
224+
public static Value pointOnLine(final RecordValue from, final RecordValue to, final IntValue idx) throws Exception {
225+
int fx = ((IntValue) from.select(new StringValue("x"))).val;
226+
int fy = ((IntValue) from.select(new StringValue("y"))).val;
227+
228+
int tx = ((IntValue) to.select(new StringValue("x"))).val;
229+
int ty = ((IntValue) to.select(new StringValue("y"))).val;
230+
231+
int x = (int) (fx + ((tx - fx) / (idx.val * 1d)));
232+
int y = (int) (fy + ((ty - fy) / (idx.val * 1d)));
233+
234+
return new RecordValue(new UniqueString[] {UniqueString.of("x"), UniqueString.of("y")}, new Value[] {IntValue.gen(x), IntValue.gen(y)}, false);
235+
}
222236
}

0 commit comments

Comments
 (0)