zone

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 30, 2018 License: GPL-3.0, GPL-3.0-or-later Imports: 4 Imported by: 0

Documentation

Overview

Package zone implement Zone model.

Index

Constants

View Source
const RootID = 0

RootID indicate that zone with the given number is a root.

Variables

This section is empty.

Functions

This section is empty.

Types

type ID

type ID int64

ID is key type in Zone map.

type Operation

type Operation struct {
	BodyID body.ID       `json:"bodyId"`
	Type   OperationType `json:"-"`
}

Operation determines construction of Zone.

func (*Operation) MarshalJSON

func (o *Operation) MarshalJSON() ([]byte, error)

MarshalJSON custom Marshal function.

func (*Operation) UnmarshalJSON

func (o *Operation) UnmarshalJSON(b []byte) error

UnmarshalJSON custom Unmarshal function.

type OperationType

type OperationType int

OperationType determines operation type. OperationTypes are based on mathematical operations on sets.

const (
	// Intersect operation: A ∩ B.
	Intersect OperationType = iota
	// Subtract operation: A \ B.
	Subtract
	// Union operation: A ∪ B.
	Union
)

type Zone

type Zone struct {
	ID ID `json:"id"`

	// ID of parent. If ID == RootID then Zone is a root.
	ParentID ID `json:"parentId"`

	Name         string       `json:"name"`
	BaseID       body.ID      `json:"baseId"`
	MaterialID   material.ID  `json:"materialId"`
	Construction []*Operation `json:"construction"`
}

Zone is composed from list of bodies. Every Zone have Base body. Zone 3D model is created by using an pseudo algorithm:

currentResult := zone.Base
for _, construction := range(zone.Construction) {
	currentResult = construction.Type(currentResult, construction.Body)
}

Operations order is determined by Constructions array order.

Eg: Base{cuboid}, Construction[{sphere, union}] is zone made from union of cuboid and sphere.

Eg: Base{sphere}. Construction{{sphere, union}, {cuboid, intersect}] is zone made from intersection of cuboid and union of 2 spheres.

Zones are structured as forest of B-trees. Parent <-> Children relationship means that children is contained entirely in parent. Zone is a tree root, if ID == RootID.

TODO: intersections other than children <-> one parent like beetween childrens of same parent are not allowed.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL