File: internal.R

package info (click to toggle)
rgl 1.3.34-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,968 kB
  • sloc: cpp: 23,234; ansic: 7,462; javascript: 6,125; sh: 3,555; makefile: 2
file content (132 lines) | stat: -rw-r--r-- 2,321 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
##
## R source file
## This file is part of rgl
##
##

##
## ===[ SECTION: internal ]===================================================
##

#
# rgl.clamp
#
# clamp value if lower than low or higher than high
#

rgl.clamp <- function(value, low, high) {
  if (value < low) {
    warning( gettextf("Value clamped to %s",low), domain = NA )
    result <- low
  }
  else if (value > high) {
    warning( gettextf("Value clamped to %s",high), domain = NA )
    result <- high
  }
  else {
    result <- value
  }

  return(result)
}

##
## types verification
##


#
# single field bool
#

rgl.bool <- function( x ) {
  if (length(x) > 1)
    stop( gettextf("'%s' must be a single boolean value", deparse(substitute(x))),
          domain = NA)
}


#
# single field numeric
#

rgl.numeric <- function( x ) {
  if (length(x) > 1)
    stop( gettextf("'%s' must be a single numeric value", deparse(substitute(x))),
          domain = NA)
}

#
# single string
#

rgl.string <- function( x ) {
  if (length(x) != 1)
    stop( gettextf("'%s' must be a single character value",
                   deparse(substitute(x))), domain = NA)
}


#
# vertex data object
#

rgl.vertex <- function(x, y = NULL, z = NULL) {
  xyz <- xyz.coords(x, y, z, recycle=TRUE)
  # This is not the same as just rbind(xyz$x,xyz$y,xyz$z)!
  # xyz.coords puts all of named vector x into xyz$x
  return( matrix( rbind(xyz$x,xyz$y,xyz$z), nrow=3, dimnames=list( c("x","y","z"), NULL ) ) )
}

#
# texture coordinate data object
#

rgl.texcoords <- function(s,t=NULL) {
  xy <- xy.coords(s, t, recycle=TRUE)
  return( matrix( rbind(xy$x, xy$y), nrow=2, dimnames=list( c("s", "t"), NULL ) ) )
}

#
# obtain number of vertices
#

rgl.nvertex <- function(vertex) {
  return( ncol(vertex) )
}


#
# rgl.color - single field color
#

rgl.color <- function( color ) {
  if (length(color) > 1)
    stop( gettextf("'%s' must be a single color character string", deparse(substitute(color))), 
          domain = NA)
  else
    return(col2rgb(color))
}


#
# rgl.mcolor - multiple field colors
#

rgl.mcolor <- function( colors ) {
  return( col2rgb(colors) )
}


#
# if vattr > 1, recycle data
#

rgl.attr <- function(vattr, nvertex) {
  nvattr <- length(vattr)

  if ((nvattr > 1) && (nvattr != nvertex))
    vattr  <- rep(vattr,length.out=nvertex)
  
  return(vattr)
}