Skip to content

When attempting to serialise a part of a spline, the full spline gets serialised instead. #4030

@OceanNuclear

Description

@OceanNuclear

Describe the bug

Image

Extracting only the blue part of the wire:

Image

Serialising and saving as a JSON file, and then reading from the JSON file and deserialising:

Image

Steps to reproduce

  1. Create a spline
  2. Cut it into at least two shorter pieces.
  3. Serialise one of the shorter piece
  4. deserialise
  5. the deserialised wire is the FULL, uncut spline.
import json

import matplotlib.pyplot as plt
import numpy as np

from bluemira.display import plot_2d, show_cad
from bluemira.display.displayer import DisplayCADOptions
from bluemira.geometry.tools import split_wire, interpolate_bspline
# boolean_cut, make_circle, make_polygon
from bluemira.geometry.tools import deserialise_shape, serialise_shape
from bluemira.geometry.wire import BluemiraWire

x = np.linspace(0, 10, 1000)
y = np.zeros(1000)
z = 0.5 * np.sin(x) + 3 * np.cos(x) ** 2

spline = interpolate_bspline(np.array([x, y, z]))

cut_point = (1.5* np.pi, 0, 0.5* -1 + 3 * 0**2)

wire_1, wire_2 = split_wire(spline, cut_point, 1E-5)
show_cad([wire_1, wire_2], [DisplayCADOptions(color="blue"), DisplayCADOptions(color="red")])

with open("/tmp/half-of-a-wire.json", "w") as j:
    ax = plt.subplot()
    ax.set_title("Wire being saved into a json file")
    plot_2d(wire_1, ax=ax)
    json.dump(serialise_shape(wire_1), j)

with open("/tmp/half-of-a-wire.json") as j:
    reconstructed_wire = deserialise_shape(json.load(j))
    
ax = plt.subplot()
ax.set_title("Wire re-constructed from the json file")
plot_2d(reconstructed_wire, ax=ax)

Tracebacks

Version

develop

OS

Ubuntu 24 (or equivalent recent Linux distribution)

OS details

No response

Metadata

Metadata

Assignees

Labels

cadTasks relating to the cad modulecodesTasks relating to integration of external codesgeometryTasks relating to the geometry module

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions