mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-10-29 17:27:08 +08:00
1 parent
bec13d523f
commit
b3c4bbc844
45 files changed
+1885
-1453
No files matched your search
@@ -0,0 +1,71 @@
|
||||
// Copyright 2025-2026 肖其顿 (XIAO QI DUN)
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package pdf
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
basethreed "github.com/xiaoqidun/ofdgo/internal/base/threed"
|
||||
"github.com/xiaoqidun/pdfgo"
|
||||
)
|
||||
|
||||
// threeDSections 按XYZ顺序构造剖切方向,中心保持为世界坐标固定点
|
||||
// 入参: ctx 取消上下文, sections PDF剖切面, options 绘制选项
|
||||
// 返回: error 方向、预算或取消错误
|
||||
func threeDSections(ctx context.Context, sections []pdfgo.ThreeDCrossSection, options *basethreed.U3DRenderOptions) error {
|
||||
if len(sections) == 0 {
|
||||
return nil
|
||||
}
|
||||
limit := options.MaxMemoryBytes
|
||||
if limit == 0 {
|
||||
limit = basethreed.DefaultBytes
|
||||
}
|
||||
if limit <= 0 || uint64(len(sections)) >= uint64(limit)/136 {
|
||||
return fmt.Errorf("PDF 3D section memory exceeds limit")
|
||||
}
|
||||
options.MaxMemoryBytes = limit - int64(len(sections))*136
|
||||
options.Sections = make([]basethreed.U3DCrossSection, len(sections))
|
||||
for i, source := range sections {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
if source.Axis < 0 || source.Axis > 2 {
|
||||
return fmt.Errorf("invalid PDF 3D section axis")
|
||||
}
|
||||
section := basethreed.U3DCrossSection{Center: source.Center, Color: source.Color, Opacity: source.Opacity}
|
||||
section.AxisU[(source.Axis+1)%3], section.AxisV[(source.Axis+2)%3] = 1, 1
|
||||
for axis, angle := range source.Rotation {
|
||||
if axis == source.Axis {
|
||||
continue
|
||||
}
|
||||
if !finite(angle) {
|
||||
return fmt.Errorf("invalid PDF 3D section rotation")
|
||||
}
|
||||
sin, cos := math.Sincos(math.Remainder(angle, 360) * math.Pi / 180)
|
||||
a, b := (axis+1)%3, (axis+2)%3
|
||||
for _, vector := range []*[3]float64{§ion.AxisU, §ion.AxisV} {
|
||||
vector[a], vector[b] = cos*vector[a]-sin*vector[b], sin*vector[a]+cos*vector[b]
|
||||
}
|
||||
}
|
||||
if source.IntersectionVisible {
|
||||
color := source.IntersectionColor
|
||||
section.Intersection = &color
|
||||
}
|
||||
options.Sections[i] = section
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user