topolys 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitattributes +2 -0
- data/.github/workflows/pull_request.yaml +25 -0
- data/.gitignore +37 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/Gemfile +6 -0
- data/LICENSE.md +21 -0
- data/README.md +36 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/design/Classes.pptx +0 -0
- data/lib/topolys/geometry.rb +351 -0
- data/lib/topolys/model.rb +1431 -0
- data/lib/topolys/schema/topolys.json +135 -0
- data/lib/topolys/transformation.rb +121 -0
- data/lib/topolys/version.rb +3 -0
- data/lib/topolys.rb +4 -0
- data/topolys.gemspec +61 -0
- metadata +162 -0
@@ -0,0 +1,135 @@
|
|
1
|
+
{
|
2
|
+
"$schema": "http://json-schema.org/draft-04/schema#",
|
3
|
+
"id": "http://json-schema.org/automaticmagic/topolys.json#",
|
4
|
+
"title": "Topolys Schema",
|
5
|
+
"description": "Schema for the Topolys Model",
|
6
|
+
|
7
|
+
"type": "object",
|
8
|
+
"properties": {
|
9
|
+
"vertices": {
|
10
|
+
"type": "array",
|
11
|
+
"items": { "$ref": "#/definitions/Vertex" },
|
12
|
+
"default": []
|
13
|
+
},
|
14
|
+
"edges": {
|
15
|
+
"type": "array",
|
16
|
+
"items": { "$ref": "#/definitions/Edge" },
|
17
|
+
"default": []
|
18
|
+
},
|
19
|
+
"directed_edges": {
|
20
|
+
"type": "array",
|
21
|
+
"items": { "$ref": "#/definitions/DirectedEdge" },
|
22
|
+
"default": []
|
23
|
+
},
|
24
|
+
"wires": {
|
25
|
+
"type": "array",
|
26
|
+
"items": { "$ref": "#/definitions/Wire" },
|
27
|
+
"default": []
|
28
|
+
},
|
29
|
+
"faces": {
|
30
|
+
"type": "array",
|
31
|
+
"items": { "$ref": "#/definitions/Face" },
|
32
|
+
"default": []
|
33
|
+
},
|
34
|
+
"shells": {
|
35
|
+
"type": "array",
|
36
|
+
"items": { "$ref": "#/definitions/Shell" },
|
37
|
+
"default": []
|
38
|
+
}
|
39
|
+
},
|
40
|
+
|
41
|
+
"definitions": {
|
42
|
+
"Point3D": {
|
43
|
+
"type": "object",
|
44
|
+
"properties": {
|
45
|
+
"x": { "type": "number" },
|
46
|
+
"y": { "type": "number" },
|
47
|
+
"z": { "type": "number" }
|
48
|
+
},
|
49
|
+
"additionalProperties": false,
|
50
|
+
"required": ["x", "y", "z"]
|
51
|
+
},
|
52
|
+
"Vector3D": {
|
53
|
+
"type": "object",
|
54
|
+
"properties": {
|
55
|
+
"x": { "type": "number" },
|
56
|
+
"y": { "type": "number" },
|
57
|
+
"z": { "type": "number" }
|
58
|
+
},
|
59
|
+
"additionalProperties": false,
|
60
|
+
"required": ["x", "y", "z"]
|
61
|
+
},
|
62
|
+
"Plane3D": {
|
63
|
+
"type": "object",
|
64
|
+
"properties": {
|
65
|
+
"point": { "$ref": "#/definitions/Point3D" },
|
66
|
+
"normal": { "$ref": "#/definitions/Vector3D" }
|
67
|
+
},
|
68
|
+
"additionalProperties": false,
|
69
|
+
"required": ["x", "y", "z"]
|
70
|
+
},
|
71
|
+
"Vertex": {
|
72
|
+
"type": "object",
|
73
|
+
"properties": {
|
74
|
+
"id": { "type": "string" },
|
75
|
+
"attributes": { "type": "object", "additionalProperties": true },
|
76
|
+
"point": { "$ref": "#/definitions/Point3D" }
|
77
|
+
},
|
78
|
+
"additionalProperties": false,
|
79
|
+
"required": ["id", "point"]
|
80
|
+
},
|
81
|
+
"Edge": {
|
82
|
+
"type": "object",
|
83
|
+
"properties": {
|
84
|
+
"id": { "type": "string" },
|
85
|
+
"attributes": { "type": "object", "additionalProperties": true },
|
86
|
+
"v0": { "type": "string" },
|
87
|
+
"v1": { "type": "string" }
|
88
|
+
},
|
89
|
+
"additionalProperties": false,
|
90
|
+
"required": ["id", "v0", "v1"]
|
91
|
+
},
|
92
|
+
"DirectedEdge": {
|
93
|
+
"type": "object",
|
94
|
+
"properties": {
|
95
|
+
"id": { "type": "string" },
|
96
|
+
"attributes": { "type": "object", "additionalProperties": true },
|
97
|
+
"edge": { "type": "string" },
|
98
|
+
"inverted": { "type": "boolean" }
|
99
|
+
},
|
100
|
+
"additionalProperties": false,
|
101
|
+
"required": ["id", "edge", "inverted"]
|
102
|
+
},
|
103
|
+
"Wire": {
|
104
|
+
"type": "object",
|
105
|
+
"properties": {
|
106
|
+
"id": { "type": "string" },
|
107
|
+
"attributes": { "type": "object", "additionalProperties": true },
|
108
|
+
"directed_edges": { "type": "array", "contains": { "type": "string"} }
|
109
|
+
},
|
110
|
+
"additionalProperties": false,
|
111
|
+
"required": ["id", "directed_edges"]
|
112
|
+
},
|
113
|
+
"Face": {
|
114
|
+
"type": "object",
|
115
|
+
"properties": {
|
116
|
+
"id": { "type": "string" },
|
117
|
+
"attributes": { "type": "object", "additionalProperties": true },
|
118
|
+
"outer": { "type": "string" },
|
119
|
+
"holes": { "type": "array", "contains": { "type": "string"} }
|
120
|
+
},
|
121
|
+
"additionalProperties": false,
|
122
|
+
"required": ["id", "outer", "holes"]
|
123
|
+
},
|
124
|
+
"Shell": {
|
125
|
+
"type": "object",
|
126
|
+
"properties": {
|
127
|
+
"id": { "type": "string" },
|
128
|
+
"attributes": { "type": "object", "additionalProperties": true },
|
129
|
+
"faces": { "type": "array", "contains": { "type": "string"} }
|
130
|
+
},
|
131
|
+
"additionalProperties": false,
|
132
|
+
"required": ["id", "faces"]
|
133
|
+
}
|
134
|
+
}
|
135
|
+
}
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'matrix'
|
2
|
+
|
3
|
+
class Matrix
|
4
|
+
def []=(i, j, x)
|
5
|
+
@rows[i][j] = x
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
module Topolys
|
10
|
+
|
11
|
+
# Transformations can be applied to Geometry. Ported from OpenStudio Transformation library.
|
12
|
+
|
13
|
+
class Transformation
|
14
|
+
|
15
|
+
# @return [Matrix] internal 4x4 matrix
|
16
|
+
attr_reader :matrix
|
17
|
+
|
18
|
+
##
|
19
|
+
# Initializes an Transformation object
|
20
|
+
#
|
21
|
+
# @param [Matrix] matrix A 4x4 matrix, defaults to identity
|
22
|
+
def initialize(matrix=Matrix.identity(4))
|
23
|
+
raise "Incorrect argument for Transformation, expected Matrix but got #{matrix.class}" unless matrix.is_a?(Matrix)
|
24
|
+
@matrix = matrix
|
25
|
+
end
|
26
|
+
|
27
|
+
# translation along vector
|
28
|
+
def Transformation.translation(translation)
|
29
|
+
return nil if !translation.is_a?(Vector3D)
|
30
|
+
|
31
|
+
matrix = Matrix.identity(4)
|
32
|
+
matrix[0,3] = translation.x
|
33
|
+
matrix[1,3] = translation.y
|
34
|
+
matrix[2,3] = translation.z
|
35
|
+
|
36
|
+
return Transformation.new(matrix)
|
37
|
+
end
|
38
|
+
|
39
|
+
##
|
40
|
+
# Initializes a rotation about origin defined by axis and angle (radians)
|
41
|
+
#
|
42
|
+
def Transformation.rotation(axis, radians)
|
43
|
+
return nil if !axis.is_a?(Vector3D)
|
44
|
+
return nil if !radians.is_a?(Numeric)
|
45
|
+
return nil if (axis.magnitude < Float::EPSILON)
|
46
|
+
normal = axis
|
47
|
+
normal.normalize!
|
48
|
+
|
49
|
+
# Rodrigues' rotation formula / Rotation matrix from Euler axis/angle
|
50
|
+
# I*cos(radians) + I*(1-cos(radians))*axis*axis^T + Q*sin(radians)
|
51
|
+
# Q = [0, -axis[2], axis[1]; axis[2], 0, -axis[0]; -axis[1], axis[0], 0]
|
52
|
+
p = normal.outer_product(normal)
|
53
|
+
i = Matrix.identity(3)
|
54
|
+
q = Matrix.zero(3)
|
55
|
+
q[0,1] = -normal.z
|
56
|
+
q[0,2] = normal.y
|
57
|
+
q[1,0] = normal.z
|
58
|
+
q[1,2] = -normal.x
|
59
|
+
q[2,0] = -normal.y
|
60
|
+
q[2,1] = normal.x
|
61
|
+
|
62
|
+
# rotation matrix
|
63
|
+
r = i*Math.cos(radians) + (1-Math.cos(radians))*p + q*Math.sin(radians)
|
64
|
+
|
65
|
+
matrix = Matrix.identity(4)
|
66
|
+
matrix[0,0] = r[0,0]
|
67
|
+
matrix[0,1] = r[0,1]
|
68
|
+
matrix[0,2] = r[0,2]
|
69
|
+
matrix[1,0] = r[1,0]
|
70
|
+
matrix[1,1] = r[1,1]
|
71
|
+
matrix[1,2] = r[1,2]
|
72
|
+
matrix[2,0] = r[2,0]
|
73
|
+
matrix[2,1] = r[2,1]
|
74
|
+
matrix[2,2] = r[2,2]
|
75
|
+
|
76
|
+
return Transformation.new(matrix)
|
77
|
+
end
|
78
|
+
|
79
|
+
##
|
80
|
+
# Multiplies a Transformation by geometry class
|
81
|
+
#
|
82
|
+
# @param [Obj] obj A geometry object
|
83
|
+
#
|
84
|
+
# @return [Obj] Returns a new, transformed object - nil if not a geometry object
|
85
|
+
def *(obj)
|
86
|
+
if obj.is_a?(Point3D)
|
87
|
+
return mult_point(obj)
|
88
|
+
elsif obj.is_a?(Vector3D)
|
89
|
+
return mult_vector(obj)
|
90
|
+
elsif obj.is_a?(Array)
|
91
|
+
return mult_array(obj)
|
92
|
+
elsif obj.is_a?(Transformation)
|
93
|
+
return mult_transformation(obj)
|
94
|
+
end
|
95
|
+
return nil
|
96
|
+
end
|
97
|
+
|
98
|
+
private
|
99
|
+
|
100
|
+
def mult_point(point)
|
101
|
+
temp = Matrix.column_vector([point.x, point.y, point.z, 1])
|
102
|
+
temp = @matrix*temp
|
103
|
+
return Point3D.new(temp[0,0],temp[1,0],temp[2,0])
|
104
|
+
end
|
105
|
+
|
106
|
+
def mult_vector(vector)
|
107
|
+
temp = Matrix.column_vector([vector.x, vector.y, vector.z, 1])
|
108
|
+
temp = @matrix*temp
|
109
|
+
return Vector3D.new(temp[0,0],temp[1,0],temp[2,0])
|
110
|
+
end
|
111
|
+
|
112
|
+
def mult_array(array)
|
113
|
+
array.map {|obj| self*obj}
|
114
|
+
end
|
115
|
+
|
116
|
+
def mult_transformation(obj)
|
117
|
+
Transformation.new(@matrix * obj.matrix)
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
end
|
data/lib/topolys.rb
ADDED
data/topolys.gemspec
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "topolys/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "topolys"
|
8
|
+
spec.version = Topolys::VERSION
|
9
|
+
spec.authors = ["Dan Macumber & Denis Bourgeois"]
|
10
|
+
spec.email = ["dan@automaticmagic.com"]
|
11
|
+
|
12
|
+
spec.summary = ""
|
13
|
+
spec.description = ""
|
14
|
+
spec.homepage = "https://github.com/macumber/topolys.git"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the " \
|
18
|
+
# 'allowed_push_host'to allow pushing to a single host or delete this section " \
|
19
|
+
# to allow pushing to any host.
|
20
|
+
#if spec.respond_to?(:metadata)
|
21
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
22
|
+
|
23
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
24
|
+
spec.metadata["source_code_uri"] = "https://github.com/macumber/topolys/tree/v#{spec.version}"
|
25
|
+
#spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
26
|
+
#else
|
27
|
+
#raise "RubyGems 2.0 or newer is required to protect against " \
|
28
|
+
# "public gem pushes."
|
29
|
+
#end
|
30
|
+
|
31
|
+
# Specify which files should be added to the gem when it is released.
|
32
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
33
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
34
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
35
|
+
end
|
36
|
+
spec.bindir = "exe"
|
37
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
38
|
+
spec.require_paths = ["lib"]
|
39
|
+
|
40
|
+
if /^2.2/.match(RUBY_VERSION)
|
41
|
+
spec.required_ruby_version = "~> 2.2.0"
|
42
|
+
|
43
|
+
spec.add_development_dependency "public_suffix", "~> 3.1.1"
|
44
|
+
spec.add_development_dependency "json-schema", "~> 2.7.0"
|
45
|
+
spec.add_development_dependency "bundler", "~> 1.17.1"
|
46
|
+
spec.add_development_dependency "rake", "~> 12.3"
|
47
|
+
spec.add_development_dependency "rspec", "~> 3.7.0"
|
48
|
+
spec.add_development_dependency "rubocop", "~> 0.54.0"
|
49
|
+
spec.add_development_dependency "yard", "~> 0.9"
|
50
|
+
spec.add_development_dependency "parallel","~> 1.19.2"
|
51
|
+
|
52
|
+
else
|
53
|
+
spec.add_development_dependency "public_suffix", "~> 3.1.1"
|
54
|
+
spec.add_development_dependency "json-schema", "~> 2.7.0"
|
55
|
+
spec.add_development_dependency "bundler", "~> 2.1"
|
56
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
57
|
+
spec.add_development_dependency "rspec", "~> 3.9"
|
58
|
+
spec.add_development_dependency "rubocop", "~> 0.54.0"
|
59
|
+
spec.add_development_dependency "yard", "~> 0.9"
|
60
|
+
end
|
61
|
+
end
|
metadata
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: topolys
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dan Macumber & Denis Bourgeois
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-07-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: public_suffix
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.1.1
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.1.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json-schema
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.7.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.7.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.1'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '13.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '13.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.9'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.9'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.54.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.54.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: yard
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.9'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.9'
|
111
|
+
description: ''
|
112
|
+
email:
|
113
|
+
- dan@automaticmagic.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitattributes"
|
119
|
+
- ".github/workflows/pull_request.yaml"
|
120
|
+
- ".gitignore"
|
121
|
+
- ".rspec"
|
122
|
+
- ".travis.yml"
|
123
|
+
- Gemfile
|
124
|
+
- LICENSE.md
|
125
|
+
- README.md
|
126
|
+
- Rakefile
|
127
|
+
- bin/console
|
128
|
+
- bin/setup
|
129
|
+
- design/Classes.pptx
|
130
|
+
- lib/topolys.rb
|
131
|
+
- lib/topolys/geometry.rb
|
132
|
+
- lib/topolys/model.rb
|
133
|
+
- lib/topolys/schema/topolys.json
|
134
|
+
- lib/topolys/transformation.rb
|
135
|
+
- lib/topolys/version.rb
|
136
|
+
- topolys.gemspec
|
137
|
+
homepage: https://github.com/macumber/topolys.git
|
138
|
+
licenses:
|
139
|
+
- MIT
|
140
|
+
metadata:
|
141
|
+
homepage_uri: https://github.com/macumber/topolys.git
|
142
|
+
source_code_uri: https://github.com/macumber/topolys/tree/v0.5.2
|
143
|
+
post_install_message:
|
144
|
+
rdoc_options: []
|
145
|
+
require_paths:
|
146
|
+
- lib
|
147
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
|
+
requirements:
|
154
|
+
- - ">="
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: '0'
|
157
|
+
requirements: []
|
158
|
+
rubygems_version: 3.1.4
|
159
|
+
signing_key:
|
160
|
+
specification_version: 4
|
161
|
+
summary: ''
|
162
|
+
test_files: []
|